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" |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 19 | #include "av1/common/cdef.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | #include "av1/common/filter.h" |
| 21 | #include "av1/common/idct.h" |
| 22 | #include "av1/common/reconinter.h" |
| 23 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 24 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #include "av1/common/tile_common.h" |
| 26 | |
| 27 | #include "av1/encoder/aq_complexity.h" |
| 28 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 29 | #include "av1/encoder/aq_variance.h" |
| 30 | #include "av1/encoder/bitstream.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | #include "av1/encoder/context_tree.h" |
| 32 | #include "av1/encoder/encodeframe.h" |
| 33 | #include "av1/encoder/encodemv.h" |
| 34 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 35 | #include "av1/encoder/encodetxb.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | #include "av1/encoder/ethread.h" |
| 37 | #include "av1/encoder/firstpass.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 38 | #include "av1/encoder/hash_motion.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | #include "av1/encoder/mbgraph.h" |
| 40 | #include "av1/encoder/picklpf.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 41 | #include "av1/encoder/pickrst.h" |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 42 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | #include "av1/encoder/ratectrl.h" |
| 44 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 45 | #include "av1/encoder/segmentation.h" |
| 46 | #include "av1/encoder/speed_features.h" |
| 47 | #include "av1/encoder/temporal_filter.h" |
| 48 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 49 | #include "./av1_rtcd.h" |
| 50 | #include "./aom_dsp_rtcd.h" |
| 51 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 52 | #include "aom_dsp/psnr.h" |
| 53 | #if CONFIG_INTERNAL_STATS |
| 54 | #include "aom_dsp/ssim.h" |
| 55 | #endif |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 56 | #include "av1/encoder/grain_test_vectors.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 57 | #include "aom_dsp/aom_dsp_common.h" |
| 58 | #include "aom_dsp/aom_filter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 59 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | #include "aom_ports/mem.h" |
| 61 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | #include "aom_scale/aom_scale.h" |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 63 | #if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | #include "aom_util/debug_util.h" |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 65 | #endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 67 | #define DEFAULT_EXPLICIT_ORDER_HINT_BITS 7 |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 68 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 69 | #if CONFIG_ENTROPY_STATS |
| 70 | FRAME_COUNTS aggregate_fc; |
| 71 | #endif // CONFIG_ENTROPY_STATS |
| 72 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 74 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 75 | |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 76 | // Whether to use high precision mv for altref computation. |
| 77 | #define ALTREF_HIGH_PRECISION_MV 1 |
| 78 | |
| 79 | // Q threshold for high precision mv. Choose a very high value for now so that |
| 80 | // HIGH_PRECISION is always chosen. |
| 81 | #define HIGH_PRECISION_MV_QTHRESH 200 |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 82 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 83 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | #ifdef OUTPUT_YUV_SKINMAP |
| 85 | FILE *yuv_skinmap_file = NULL; |
| 86 | #endif |
| 87 | #ifdef OUTPUT_YUV_REC |
| 88 | FILE *yuv_rec_file; |
| 89 | #define FILE_NAME_LEN 100 |
| 90 | #endif |
| 91 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 92 | #if CONFIG_INTERNAL_STATS |
| 93 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
| 94 | #endif // CONFIG_INTERNAL_STATS |
| 95 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 97 | switch (mode) { |
| 98 | case NORMAL: |
| 99 | *hr = 1; |
| 100 | *hs = 1; |
| 101 | break; |
| 102 | case FOURFIVE: |
| 103 | *hr = 4; |
| 104 | *hs = 5; |
| 105 | break; |
| 106 | case THREEFIVE: |
| 107 | *hr = 3; |
| 108 | *hs = 5; |
| 109 | break; |
| 110 | case ONETWO: |
| 111 | *hr = 1; |
| 112 | *hs = 2; |
| 113 | break; |
| 114 | default: |
| 115 | *hr = 1; |
| 116 | *hs = 1; |
| 117 | assert(0); |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 123 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 125 | unsigned char *const seg_map = cpi->segmentation_map; |
| 126 | int i; |
| 127 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 128 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 129 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 130 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 131 | } |
| 132 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 133 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | struct segmentation *const seg = &cpi->common.seg; |
| 135 | unsigned char *const seg_map = cpi->segmentation_map; |
| 136 | const unsigned char *const active_map = cpi->active_map.map; |
| 137 | int i; |
| 138 | |
| 139 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 140 | |
| 141 | if (frame_is_intra_only(&cpi->common)) { |
| 142 | cpi->active_map.enabled = 0; |
| 143 | cpi->active_map.update = 1; |
| 144 | } |
| 145 | |
| 146 | if (cpi->active_map.update) { |
| 147 | if (cpi->active_map.enabled) { |
| 148 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 149 | 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] | 150 | av1_enable_segmentation(seg); |
| 151 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 152 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 153 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 154 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 155 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 156 | |
| 157 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 158 | -MAX_LOOP_FILTER); |
| 159 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 160 | -MAX_LOOP_FILTER); |
| 161 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 162 | -MAX_LOOP_FILTER); |
| 163 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 164 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 166 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 167 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 168 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 169 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 170 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 171 | if (seg->enabled) { |
| 172 | seg->update_data = 1; |
| 173 | seg->update_map = 1; |
| 174 | } |
| 175 | } |
| 176 | cpi->active_map.update = 0; |
| 177 | } |
| 178 | } |
| 179 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 180 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 181 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 182 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 183 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 184 | const int mi_rows = cpi->common.mi_rows; |
| 185 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 186 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 187 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 188 | cpi->active_map.update = 1; |
| 189 | if (new_map_16x16) { |
| 190 | int r, c; |
| 191 | for (r = 0; r < mi_rows; ++r) { |
| 192 | for (c = 0; c < mi_cols; ++c) { |
| 193 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 194 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 195 | ? AM_SEGMENT_ID_ACTIVE |
| 196 | : AM_SEGMENT_ID_INACTIVE; |
| 197 | } |
| 198 | } |
| 199 | cpi->active_map.enabled = 1; |
| 200 | } else { |
| 201 | cpi->active_map.enabled = 0; |
| 202 | } |
| 203 | return 0; |
| 204 | } else { |
| 205 | return -1; |
| 206 | } |
| 207 | } |
| 208 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 209 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 210 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 211 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 212 | new_map_16x16) { |
| 213 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 214 | const int mi_rows = cpi->common.mi_rows; |
| 215 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 216 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 217 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 218 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 220 | if (cpi->active_map.enabled) { |
| 221 | int r, c; |
| 222 | for (r = 0; r < mi_rows; ++r) { |
| 223 | for (c = 0; c < mi_cols; ++c) { |
| 224 | // Cyclic refresh segments are considered active despite not having |
| 225 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 226 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 227 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | return 0; |
| 232 | } else { |
| 233 | return -1; |
| 234 | } |
| 235 | } |
| 236 | |
Yaowu Xu | 45295c3 | 2018-03-29 12:06:10 -0700 | [diff] [blame] | 237 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv, |
| 238 | int cur_frame_force_integer_mv) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 239 | MACROBLOCK *const mb = &cpi->td.mb; |
Hui Su | 5036115 | 2018-03-02 11:01:42 -0800 | [diff] [blame] | 240 | cpi->common.allow_high_precision_mv = |
| 241 | allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 242 | const int copy_hp = |
| 243 | cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 244 | int *(*src)[2] = copy_hp ? &mb->nmvcost_hp : &mb->nmvcost; |
| 245 | mb->mv_cost_stack = *src; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 248 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 249 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 250 | return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 251 | #if CONFIG_FILEOPTIONS |
| 252 | if (cpi->common.options && cpi->common.options->ext_partition) |
| 253 | #endif |
| 254 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 255 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 256 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 257 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 258 | |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 259 | // TODO(any): Possibly could improve this with a heuristic. |
| 260 | #if CONFIG_FILEOPTIONS |
| 261 | if (cpi->common.options && !cpi->common.options->ext_partition) |
| 262 | return BLOCK_64X64; |
| 263 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 264 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 267 | static void setup_frame(AV1_COMP *cpi) { |
| 268 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 269 | // Set up entropy context depending on frame type. The decoder mandates |
| 270 | // the use of the default context, index 0, for keyframes and inter |
| 271 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 272 | // other inter-frames the encoder currently uses only two contexts; |
| 273 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 274 | |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 275 | cm->primary_ref_frame = PRIMARY_REF_NONE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 276 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 277 | av1_setup_past_independence(cm); |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 278 | for (int i = 0; i < REF_FRAMES; i++) { |
| 279 | cm->fb_of_context_type[i] = -1; |
| 280 | } |
| 281 | cm->fb_of_context_type[REGULAR_FRAME] = |
| 282 | get_ref_frame_map_idx(cpi, GOLDEN_FRAME); |
Thomas Daede | 3f2853a | 2018-03-12 17:40:32 -0700 | [diff] [blame] | 283 | } else if (!cm->large_scale_tile) { |
| 284 | // for large scale tile we leave the default PRIMARY_REF_NONE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 286 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 287 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 288 | else if (cpi->refresh_alt_ref_frame) |
| 289 | cm->frame_context_idx = ARF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 290 | else if (cpi->rc.is_src_frame_alt_ref) |
| 291 | cm->frame_context_idx = OVERLAY_FRAME; |
| 292 | else if (cpi->refresh_golden_frame) |
| 293 | cm->frame_context_idx = GLD_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 294 | else if (cpi->refresh_bwd_ref_frame) |
| 295 | cm->frame_context_idx = BRF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 296 | else |
| 297 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 298 | int wanted_fb = cm->fb_of_context_type[cm->frame_context_idx]; |
| 299 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { |
| 300 | int fb = get_ref_frame_map_idx(cpi, ref_frame); |
| 301 | if (fb == wanted_fb) { |
| 302 | cm->primary_ref_frame = ref_frame - LAST_FRAME; |
| 303 | } |
| 304 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | if (cm->frame_type == KEY_FRAME) { |
| 308 | cpi->refresh_golden_frame = 1; |
| 309 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 310 | av1_zero(cpi->interp_filter_selected); |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 311 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 312 | set_use_reference_buffer(cm, 0); |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 313 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 314 | } else if (frame_is_sframe(cm)) { |
| 315 | cpi->refresh_golden_frame = 1; |
| 316 | cpi->refresh_alt_ref_frame = 1; |
| 317 | av1_zero(cpi->interp_filter_selected); |
| 318 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | } else { |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 320 | if (cm->primary_ref_frame == PRIMARY_REF_NONE || |
| 321 | cm->frame_refs[cm->primary_ref_frame].idx < 0) { |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 322 | av1_setup_past_independence(cm); |
| 323 | cm->seg.update_map = 1; |
| 324 | cm->seg.update_data = 1; |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 325 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 326 | } else { |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 327 | *cm->fc = cm->frame_contexts[cm->frame_refs[cm->primary_ref_frame].idx]; |
| 328 | cm->pre_fc = |
| 329 | &cm->frame_contexts[cm->frame_refs[cm->primary_ref_frame].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 330 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 331 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 334 | cm->prev_frame = get_prev_frame(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 335 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 338 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | int i; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 340 | cm->mi = cm->mip; |
| 341 | memset(cm->mip, 0, cm->mi_stride * cm->mi_rows * sizeof(*cm->mip)); |
| 342 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 343 | // Clear top border row |
| 344 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 345 | // Clear left border column |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 346 | for (i = 0; i < cm->mi_rows; ++i) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip)); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 348 | cm->mi_grid_visible = cm->mi_grid_base; |
| 349 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 350 | |
| 351 | memset(cm->mi_grid_base, 0, |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 352 | cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base)); |
Frank Bossen | 4ef06b5 | 2018-01-18 19:51:15 -0500 | [diff] [blame] | 353 | |
| 354 | memset(cm->boundary_info, 0, |
| 355 | cm->boundary_info_alloc_size * sizeof(*cm->boundary_info)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 358 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 359 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 360 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 361 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 362 | if (!cm->prev_mip) return 1; |
| 363 | cm->mi_alloc_size = mi_size; |
| 364 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 365 | cm->mi_grid_base = |
| 366 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 367 | if (!cm->mi_grid_base) return 1; |
| 368 | cm->prev_mi_grid_base = |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 369 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 370 | if (!cm->prev_mi_grid_base) return 1; |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 375 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 376 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 378 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 379 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 380 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 381 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 382 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 384 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 387 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 388 | // Current mip will be the prev_mip for the next frame. |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 389 | MB_MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 390 | MB_MODE_INFO *temp = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 391 | cm->prev_mip = cm->mip; |
| 392 | cm->mip = temp; |
| 393 | |
| 394 | // Update the upper left visible macroblock ptrs. |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 395 | cm->mi = cm->mip; |
| 396 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 397 | |
| 398 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 399 | cm->mi_grid_base = temp_base; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 400 | cm->mi_grid_visible = cm->mi_grid_base; |
| 401 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 404 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 405 | static volatile int init_done = 0; |
| 406 | |
| 407 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 408 | av1_rtcd(); |
| 409 | aom_dsp_rtcd(); |
| 410 | aom_scale_rtcd(); |
| 411 | av1_init_intra_predictors(); |
| 412 | av1_init_me_luts(); |
| 413 | av1_rc_init_minq_luts(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 414 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 415 | init_done = 1; |
| 416 | } |
| 417 | } |
| 418 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 419 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 420 | if (cpi->mbmi_ext_base) { |
| 421 | aom_free(cpi->mbmi_ext_base); |
| 422 | cpi->mbmi_ext_base = NULL; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 427 | AV1_COMMON *cm = &cpi->common; |
| 428 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 429 | |
| 430 | dealloc_context_buffers_ext(cpi); |
| 431 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 432 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 433 | } |
| 434 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 435 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 436 | const AV1EncoderConfig *oxcf) { |
| 437 | AV1_COMMON *const cm = &cpi->common; |
| 438 | cpi->oxcf = *oxcf; |
| 439 | |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 440 | if (cm->film_grain_table) { |
| 441 | aom_film_grain_table_free(cm->film_grain_table); |
| 442 | aom_free(cm->film_grain_table); |
| 443 | } |
| 444 | cm->film_grain_table = 0; |
| 445 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 446 | if (oxcf->film_grain_test_vector) { |
| 447 | cm->film_grain_params_present = 1; |
| 448 | if (cm->frame_type == KEY_FRAME) { |
| 449 | memcpy(&cm->film_grain_params, |
| 450 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 451 | sizeof(cm->film_grain_params)); |
| 452 | |
| 453 | cm->film_grain_params.bit_depth = cm->bit_depth; |
| 454 | if (cm->color_range == AOM_CR_FULL_RANGE) { |
| 455 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 456 | } |
| 457 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 458 | } else if (oxcf->film_grain_table_filename) { |
| 459 | cm->film_grain_table = aom_malloc(sizeof(*cm->film_grain_table)); |
| 460 | memset(cm->film_grain_table, 0, sizeof(aom_film_grain_table_t)); |
| 461 | |
| 462 | aom_film_grain_table_read(cm->film_grain_table, |
| 463 | oxcf->film_grain_table_filename, &cm->error); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 464 | } else { |
| 465 | cm->film_grain_params_present = 0; |
| 466 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 467 | } |
| 468 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 469 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 470 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 471 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 472 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 473 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 474 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 475 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 476 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 477 | cpi->tile_data = NULL; |
| 478 | |
| 479 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 480 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 481 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 482 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 483 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 484 | cpi->cyclic_refresh = NULL; |
| 485 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 486 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 487 | cpi->active_map.map = NULL; |
| 488 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 489 | aom_free(cpi->td.mb.above_pred_buf); |
| 490 | cpi->td.mb.above_pred_buf = NULL; |
| 491 | |
| 492 | aom_free(cpi->td.mb.left_pred_buf); |
| 493 | cpi->td.mb.left_pred_buf = NULL; |
| 494 | |
| 495 | aom_free(cpi->td.mb.wsrc_buf); |
| 496 | cpi->td.mb.wsrc_buf = NULL; |
| 497 | |
| 498 | aom_free(cpi->td.mb.mask_buf); |
| 499 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 500 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 501 | aom_free(cm->tpl_mvs); |
| 502 | cm->tpl_mvs = NULL; |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 503 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 504 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 505 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 506 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 507 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 508 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 509 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 510 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 511 | aom_free_frame_buffer(&cpi->scaled_source); |
| 512 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 513 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 514 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 515 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 516 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 517 | cpi->tile_tok[0][0] = 0; |
| 518 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 519 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 520 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 521 | aom_free(cpi->td.mb.palette_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 524 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 525 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 526 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 527 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 528 | // Stores a snapshot of key state variables which can subsequently be |
| 529 | // restored with a call to av1_restore_coding_context. These functions are |
| 530 | // intended for use in a re-code loop in av1_compress_frame where the |
| 531 | // quantizer value is adjusted between loop iterations. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 532 | av1_copy(cc->nmv_vec_cost, cpi->td.mb.nmv_vec_cost); |
| 533 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 534 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 535 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 536 | cc->fc = *cm->fc; |
| 537 | } |
| 538 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 539 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 540 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 541 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 542 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 543 | // Restore key state variables to the snapshot state stored in the |
| 544 | // previous call to av1_save_coding_context. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 545 | av1_copy(cpi->td.mb.nmv_vec_cost, cc->nmv_vec_cost); |
| 546 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 547 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 548 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 549 | *cm->fc = cc->fc; |
| 550 | } |
| 551 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 552 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 553 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 554 | const RATE_CONTROL *const rc = &cpi->rc; |
| 555 | struct segmentation *const seg = &cm->seg; |
| 556 | |
| 557 | int high_q = (int)(rc->avg_q > 48.0); |
| 558 | int qi_delta; |
| 559 | |
| 560 | // Disable and clear down for KF |
| 561 | if (cm->frame_type == KEY_FRAME) { |
| 562 | // Clear down the global segmentation map |
| 563 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 564 | seg->update_map = 0; |
| 565 | seg->update_data = 0; |
| 566 | cpi->static_mb_pct = 0; |
| 567 | |
| 568 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 570 | |
| 571 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 572 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 573 | } else if (cpi->refresh_alt_ref_frame) { |
| 574 | // If this is an alt ref frame |
| 575 | // Clear down the global segmentation map |
| 576 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 577 | seg->update_map = 0; |
| 578 | seg->update_data = 0; |
| 579 | cpi->static_mb_pct = 0; |
| 580 | |
| 581 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 582 | av1_disable_segmentation(seg); |
| 583 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 584 | |
| 585 | // Scan frames from current to arf frame. |
| 586 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 587 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 588 | |
| 589 | // If segmentation was enabled set those features needed for the |
| 590 | // arf itself. |
| 591 | if (seg->enabled) { |
| 592 | seg->update_map = 1; |
| 593 | seg->update_data = 1; |
| 594 | |
| 595 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 596 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 597 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 598 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 599 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 600 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 601 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 602 | |
| 603 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 604 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 605 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 606 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 607 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 608 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 609 | } |
| 610 | } else if (seg->enabled) { |
| 611 | // All other frames if segmentation has been enabled |
| 612 | |
| 613 | // First normal frame in a valid gf or alt ref group |
| 614 | if (rc->frames_since_golden == 0) { |
| 615 | // Set up segment features for normal frames in an arf group |
| 616 | if (rc->source_alt_ref_active) { |
| 617 | seg->update_map = 0; |
| 618 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 619 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 620 | qi_delta = |
| 621 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 622 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 623 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 624 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 625 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 626 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 627 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 628 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 629 | |
| 630 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 631 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 632 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 633 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 634 | |
| 635 | // Segment coding disabled for compred testing |
| 636 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 637 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 638 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 639 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 640 | } |
| 641 | } else { |
| 642 | // Disable segmentation and clear down features if alt ref |
| 643 | // is not active for this group |
| 644 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 645 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 646 | |
| 647 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 648 | |
| 649 | seg->update_map = 0; |
| 650 | seg->update_data = 0; |
| 651 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 652 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 653 | } |
| 654 | } else if (rc->is_src_frame_alt_ref) { |
| 655 | // Special case where we are coding over the top of a previous |
| 656 | // alt ref frame. |
| 657 | // Segment coding disabled for compred testing |
| 658 | |
| 659 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 660 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 661 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 662 | |
| 663 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 664 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 665 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 666 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 667 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 668 | |
| 669 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 670 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 671 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 672 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 673 | } |
| 674 | // Enable data update |
| 675 | seg->update_data = 1; |
| 676 | } else { |
| 677 | // All other frames. |
| 678 | |
| 679 | // No updates.. leave things as they are. |
| 680 | seg->update_map = 0; |
| 681 | seg->update_data = 0; |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 686 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 687 | AV1_COMMON *const cm = &cpi->common; |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 688 | MB_MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 689 | uint8_t *cache_ptr = cm->current_frame_seg_map; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 690 | int row, col; |
| 691 | |
| 692 | for (row = 0; row < cm->mi_rows; row++) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 693 | MB_MODE_INFO **mi_8x8 = mi_8x8_ptr; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 694 | uint8_t *cache = cache_ptr; |
| 695 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 696 | cache[0] = mi_8x8[0]->segment_id; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 697 | mi_8x8_ptr += cm->mi_stride; |
| 698 | cache_ptr += cm->mi_cols; |
| 699 | } |
| 700 | } |
| 701 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 702 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 703 | AV1_COMMON *cm = &cpi->common; |
| 704 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 705 | |
| 706 | if (!cpi->lookahead) |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 707 | cpi->lookahead = av1_lookahead_init( |
| 708 | oxcf->width, oxcf->height, cm->subsampling_x, cm->subsampling_y, |
| 709 | cm->use_highbitdepth, oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 710 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 711 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 712 | "Failed to allocate lag buffers"); |
| 713 | |
| 714 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 715 | 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] | 716 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 717 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 718 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 719 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 720 | "Failed to allocate altref buffer"); |
| 721 | } |
| 722 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 723 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 724 | AV1_COMMON *const cm = &cpi->common; |
| 725 | 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] | 726 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 727 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 728 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 729 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 730 | "Failed to allocate last frame buffer"); |
| 731 | |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 732 | if (aom_realloc_frame_buffer( |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 733 | &cpi->trial_frame_rst, cm->superres_upscaled_width, |
| 734 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
| 735 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 736 | NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 737 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 738 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 739 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 740 | if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 741 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 742 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 743 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 744 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 745 | "Failed to allocate scaled source buffer"); |
| 746 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 747 | 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] | 748 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 749 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 750 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 751 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | "Failed to allocate scaled last source buffer"); |
| 753 | } |
| 754 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 755 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 756 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 757 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 758 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 759 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 760 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 761 | av1_alloc_txb_buf(cpi); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 762 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 763 | alloc_context_buffers_ext(cpi); |
| 764 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 765 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 766 | |
| 767 | { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 768 | unsigned int tokens = |
| 769 | get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 770 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 771 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 774 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 777 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 778 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 779 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 782 | static void set_tile_info_max_tile(AV1_COMP *cpi) { |
| 783 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 784 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 785 | |
| 786 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 787 | |
| 788 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 789 | if (cpi->oxcf.tile_width_count == 0 || cpi->oxcf.tile_height_count == 0) { |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 790 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 791 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 792 | cm->log2_tile_cols = AOMMIN(cm->log2_tile_cols, cm->max_log2_tile_cols); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 793 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 794 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 795 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 796 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 797 | cm->uniform_tile_spacing_flag = 0; |
| 798 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 799 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 800 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 801 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
David Barker | 6cd5a82 | 2018-03-05 16:19:28 +0000 | [diff] [blame] | 802 | start_sb += AOMMIN(size_sb, cm->max_tile_width_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 803 | } |
| 804 | cm->tile_cols = i; |
| 805 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 806 | } |
| 807 | av1_calculate_tile_cols(cm); |
| 808 | |
| 809 | // configure tile rows |
| 810 | if (cm->uniform_tile_spacing_flag) { |
| 811 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 812 | cm->log2_tile_rows = AOMMIN(cm->log2_tile_rows, cm->max_log2_tile_rows); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 813 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 814 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 815 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 816 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 817 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 818 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 819 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 820 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 821 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 822 | } |
| 823 | cm->tile_rows = i; |
| 824 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 825 | } |
| 826 | av1_calculate_tile_rows(cm); |
| 827 | } |
| 828 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 829 | static void set_tile_info(AV1_COMP *cpi) { |
| 830 | AV1_COMMON *const cm = &cpi->common; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 831 | if (cpi->oxcf.large_scale_tile) { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 832 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
| 833 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 834 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 835 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 836 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 837 | } else { |
| 838 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 839 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 840 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 841 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 842 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 843 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 844 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 845 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 846 | |
Yaowu Xu | 8d0039c | 2017-10-13 07:51:46 -0700 | [diff] [blame] | 847 | assert(cm->tile_width >> MAX_MIB_SIZE_LOG2 <= 32); |
| 848 | assert(cm->tile_height >> MAX_MIB_SIZE_LOG2 <= 32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 850 | // Get the number of tiles |
| 851 | cm->tile_cols = 1; |
| 852 | while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 853 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 854 | cm->tile_rows = 1; |
| 855 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 856 | int i; |
| 857 | for (i = 0; i <= cm->tile_cols; i++) { |
| 858 | cm->tile_col_start_sb[i] = |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 859 | ((i * cm->tile_width - 1) >> cm->seq_params.mib_size_log2) + 1; |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 860 | } |
| 861 | for (i = 0; i <= cm->tile_rows; i++) { |
| 862 | cm->tile_row_start_sb[i] = |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 863 | ((i * cm->tile_height - 1) >> cm->seq_params.mib_size_log2) + 1; |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 864 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 865 | } else { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 866 | set_tile_info_max_tile(cpi); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 867 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 870 | static void update_frame_size(AV1_COMP *cpi) { |
| 871 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 872 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 873 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 874 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 875 | av1_init_context_buffers(cm); |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 876 | av1_init_macroblockd(cm, xd, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 877 | memset(cpi->mbmi_ext_base, 0, |
| 878 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 879 | set_tile_info(cpi); |
| 880 | } |
| 881 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 882 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 883 | int fb_idx; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 884 | for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx) |
| 885 | cpi->ref_fb_idx[fb_idx] = fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 886 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 887 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 888 | cpi->rate_index = 0; |
| 889 | cpi->rate_size = 0; |
| 890 | cpi->cur_poc = -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 893 | void init_seq_coding_tools(SequenceHeader *seq, const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | 5d6e3fb | 2018-04-03 13:05:54 -0700 | [diff] [blame] | 894 | seq->still_picture = 0; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 895 | seq->force_screen_content_tools = 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 896 | seq->force_integer_mv = 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 897 | seq->order_hint_bits_minus1 = DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 898 | seq->enable_dual_filter = oxcf->enable_dual_filter; |
| 899 | seq->enable_order_hint = oxcf->enable_order_hint; |
| 900 | seq->enable_jnt_comp = oxcf->enable_jnt_comp; |
| 901 | seq->enable_jnt_comp &= seq->enable_order_hint; |
| 902 | seq->enable_ref_frame_mvs = oxcf->enable_ref_frame_mvs; |
| 903 | seq->enable_ref_frame_mvs &= seq->enable_order_hint; |
| 904 | seq->enable_superres = oxcf->enable_superres; |
| 905 | seq->enable_cdef = oxcf->enable_cdef; |
| 906 | seq->enable_restoration = oxcf->enable_restoration; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 907 | seq->enable_warped_motion = oxcf->enable_warped_motion; |
Debargha Mukherjee | 97095fb | 2018-03-26 07:51:48 -0700 | [diff] [blame] | 908 | seq->enable_interintra_compound = 1; |
| 909 | seq->enable_masked_compound = 1; |
Debargha Mukherjee | 365eae8 | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 910 | seq->enable_intra_edge_filter = 1; |
| 911 | seq->enable_filter_intra = 1; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 914 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 915 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | |
| 917 | cpi->oxcf = *oxcf; |
| 918 | cpi->framerate = oxcf->init_framerate; |
| 919 | |
| 920 | cm->profile = oxcf->profile; |
| 921 | cm->bit_depth = oxcf->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 922 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 923 | cm->color_primaries = oxcf->color_primaries; |
| 924 | cm->transfer_characteristics = oxcf->transfer_characteristics; |
| 925 | cm->matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 926 | cm->seq_params.monochrome = oxcf->monochrome; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 927 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 928 | cm->color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 929 | cm->timing_info_present = oxcf->timing_info_present; |
| 930 | cm->num_units_in_tick = oxcf->num_units_in_tick; |
| 931 | cm->time_scale = oxcf->time_scale; |
| 932 | cm->equal_picture_interval = oxcf->equal_picture_interval; |
| 933 | cm->num_ticks_per_picture = oxcf->num_ticks_per_picture; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 934 | cm->width = oxcf->width; |
| 935 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 936 | set_sb_size(&cm->seq_params, |
| 937 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 938 | alloc_compressor_data(cpi); |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 939 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 940 | update_film_grain_parameters(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 941 | |
| 942 | // Single thread case: use counts in common. |
| 943 | cpi->td.counts = &cm->counts; |
| 944 | |
| 945 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 946 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 947 | |
| 948 | cpi->static_mb_pct = 0; |
| 949 | cpi->ref_frame_flags = 0; |
| 950 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 951 | // Reset resize pending flags |
| 952 | cpi->resize_pending_width = 0; |
| 953 | cpi->resize_pending_height = 0; |
| 954 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 955 | init_buffer_indices(cpi); |
| 956 | } |
| 957 | |
| 958 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 959 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 960 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 961 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 962 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 963 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 964 | |
| 965 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 966 | rc->optimal_buffer_level = |
| 967 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 968 | rc->maximum_buffer_size = |
| 969 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 970 | } |
| 971 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 972 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, \ |
| 973 | JSVAF) \ |
| 974 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 975 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 976 | cpi->fn_ptr[BT].vf = VF; \ |
| 977 | cpi->fn_ptr[BT].svf = SVF; \ |
| 978 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 979 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 980 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 981 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 982 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
| 983 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 984 | |
| 985 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 986 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 987 | int source_stride, \ |
| 988 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 989 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 990 | } \ |
| 991 | static unsigned int fnname##_bits10( \ |
| 992 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 993 | int ref_stride) { \ |
| 994 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 995 | } \ |
| 996 | static unsigned int fnname##_bits12( \ |
| 997 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 998 | int ref_stride) { \ |
| 999 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1000 | } |
| 1001 | |
| 1002 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1003 | static unsigned int fnname##_bits8( \ |
| 1004 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1005 | int ref_stride, const uint8_t *second_pred) { \ |
| 1006 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1007 | } \ |
| 1008 | static unsigned int fnname##_bits10( \ |
| 1009 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1010 | int ref_stride, const uint8_t *second_pred) { \ |
| 1011 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1012 | 2; \ |
| 1013 | } \ |
| 1014 | static unsigned int fnname##_bits12( \ |
| 1015 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1016 | int ref_stride, const uint8_t *second_pred) { \ |
| 1017 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1018 | 4; \ |
| 1019 | } |
| 1020 | |
| 1021 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1022 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1023 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1024 | unsigned int *sad_array) { \ |
| 1025 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1026 | } \ |
| 1027 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1028 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1029 | unsigned int *sad_array) { \ |
| 1030 | int i; \ |
| 1031 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1032 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1033 | } \ |
| 1034 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1035 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1036 | unsigned int *sad_array) { \ |
| 1037 | int i; \ |
| 1038 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1039 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1040 | } |
| 1041 | |
| 1042 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1043 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1044 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1045 | unsigned int *sad_array) { \ |
| 1046 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1047 | } \ |
| 1048 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1049 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1050 | unsigned int *sad_array) { \ |
| 1051 | int i; \ |
| 1052 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1053 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1054 | } \ |
| 1055 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1056 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1057 | unsigned int *sad_array) { \ |
| 1058 | int i; \ |
| 1059 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1060 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1061 | } |
| 1062 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1063 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1064 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1065 | unsigned int *sad_array) { \ |
| 1066 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1067 | } \ |
| 1068 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1069 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1070 | unsigned int *sad_array) { \ |
| 1071 | int i; \ |
| 1072 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1073 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1074 | } \ |
| 1075 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1076 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1077 | unsigned int *sad_array) { \ |
| 1078 | int i; \ |
| 1079 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1080 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1081 | } |
| 1082 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1083 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1084 | static unsigned int fnname##_bits8( \ |
| 1085 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1086 | int ref_stride, const uint8_t *second_pred, \ |
| 1087 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1088 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1089 | jcp_param); \ |
| 1090 | } \ |
| 1091 | static unsigned int fnname##_bits10( \ |
| 1092 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1093 | int ref_stride, const uint8_t *second_pred, \ |
| 1094 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1095 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1096 | jcp_param) >> \ |
| 1097 | 2; \ |
| 1098 | } \ |
| 1099 | static unsigned int fnname##_bits12( \ |
| 1100 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1101 | int ref_stride, const uint8_t *second_pred, \ |
| 1102 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1103 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1104 | jcp_param) >> \ |
| 1105 | 4; \ |
| 1106 | } |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1107 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1108 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1109 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1110 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1111 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1112 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1113 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1114 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1115 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1116 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1117 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1118 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1119 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1120 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1121 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1122 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1123 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1124 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1125 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1126 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1127 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1128 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1129 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1130 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1131 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1132 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1133 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1134 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1135 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1136 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1137 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1138 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1139 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1140 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1141 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1142 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1143 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1144 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1145 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1146 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1147 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1148 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1149 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1150 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1151 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1152 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1153 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1154 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1155 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1156 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1157 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1158 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1159 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1160 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1161 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1162 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1163 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1164 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1165 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1166 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1167 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1168 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1169 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1170 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1171 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1172 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1173 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1174 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1175 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1176 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1177 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1178 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1179 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1180 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1181 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1182 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1183 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1184 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1185 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1186 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1187 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1188 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1189 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1190 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1191 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1192 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1193 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1194 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x128_avg) |
| 1195 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x64_avg) |
| 1196 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x128_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1197 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x16_avg) |
| 1198 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x32_avg) |
| 1199 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x32_avg) |
| 1200 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x64_avg) |
| 1201 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x32_avg) |
| 1202 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x64_avg) |
| 1203 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x16_avg) |
| 1204 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x8_avg) |
| 1205 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x16_avg) |
| 1206 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x8_avg) |
| 1207 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x4_avg) |
| 1208 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x8_avg) |
| 1209 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x4_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1210 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x16_avg) |
| 1211 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x4_avg) |
| 1212 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x32_avg) |
| 1213 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x8_avg) |
| 1214 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x64_avg) |
| 1215 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x16_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1216 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1217 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1218 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1219 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1220 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1221 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1222 | static unsigned int fnname##_bits8( \ |
| 1223 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1224 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1225 | int m_stride, int invert_mask) { \ |
| 1226 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1227 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1228 | } \ |
| 1229 | static unsigned int fnname##_bits10( \ |
| 1230 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1231 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1232 | int m_stride, int invert_mask) { \ |
| 1233 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1234 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1235 | 2; \ |
| 1236 | } \ |
| 1237 | static unsigned int fnname##_bits12( \ |
| 1238 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1239 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1240 | int m_stride, int invert_mask) { \ |
| 1241 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1242 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1243 | 4; \ |
| 1244 | } |
| 1245 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1246 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1247 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1248 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1249 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1250 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1251 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1252 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1253 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1254 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1255 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1256 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1257 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1258 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1259 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1260 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1261 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1262 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1263 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1264 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1265 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1266 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1267 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1268 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1269 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1270 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1271 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1272 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1273 | |
| 1274 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1275 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1276 | const int32_t *wsrc, \ |
| 1277 | const int32_t *msk) { \ |
| 1278 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1279 | } \ |
| 1280 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1281 | const int32_t *wsrc, \ |
| 1282 | const int32_t *msk) { \ |
| 1283 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1284 | } \ |
| 1285 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1286 | const int32_t *wsrc, \ |
| 1287 | const int32_t *msk) { \ |
| 1288 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1289 | } |
| 1290 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1291 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1292 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1293 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1294 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1295 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1296 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1297 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1298 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1299 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1300 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1301 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1302 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1303 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1304 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1305 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1306 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1307 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1308 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1309 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1310 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1311 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1312 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1313 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1314 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1315 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1316 | if (cm->use_highbitdepth) { |
| 1317 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1318 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1319 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1320 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1321 | aom_highbd_8_sub_pixel_variance64x16, |
| 1322 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1323 | aom_highbd_sad64x16x4d_bits8, |
| 1324 | aom_highbd_jnt_sad64x16_avg_bits8, |
| 1325 | aom_highbd_8_jnt_sub_pixel_avg_variance64x16) |
| 1326 | |
| 1327 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1328 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1329 | aom_highbd_8_sub_pixel_variance16x64, |
| 1330 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1331 | aom_highbd_sad16x64x4d_bits8, |
| 1332 | aom_highbd_jnt_sad16x64_avg_bits8, |
| 1333 | aom_highbd_8_jnt_sub_pixel_avg_variance16x64) |
| 1334 | |
| 1335 | HIGHBD_BFP( |
| 1336 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1337 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
| 1338 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1339 | aom_highbd_sad32x8x4d_bits8, aom_highbd_jnt_sad32x8_avg_bits8, |
| 1340 | aom_highbd_8_jnt_sub_pixel_avg_variance32x8) |
| 1341 | |
| 1342 | HIGHBD_BFP( |
| 1343 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1344 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
| 1345 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1346 | aom_highbd_sad8x32x4d_bits8, aom_highbd_jnt_sad8x32_avg_bits8, |
| 1347 | aom_highbd_8_jnt_sub_pixel_avg_variance8x32) |
| 1348 | |
| 1349 | HIGHBD_BFP( |
| 1350 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1351 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
| 1352 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1353 | aom_highbd_sad16x4x4d_bits8, aom_highbd_jnt_sad16x4_avg_bits8, |
| 1354 | aom_highbd_8_jnt_sub_pixel_avg_variance16x4) |
| 1355 | |
| 1356 | HIGHBD_BFP( |
| 1357 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1358 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
| 1359 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1360 | aom_highbd_sad4x16x4d_bits8, aom_highbd_jnt_sad4x16_avg_bits8, |
| 1361 | aom_highbd_8_jnt_sub_pixel_avg_variance4x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1362 | |
| 1363 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1364 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1365 | aom_highbd_8_sub_pixel_variance32x16, |
| 1366 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1367 | aom_highbd_sad32x16x4d_bits8, |
| 1368 | aom_highbd_jnt_sad32x16_avg_bits8, |
| 1369 | aom_highbd_8_jnt_sub_pixel_avg_variance32x16) |
| 1370 | |
| 1371 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1372 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1373 | aom_highbd_8_sub_pixel_variance16x32, |
| 1374 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1375 | aom_highbd_sad16x32x4d_bits8, |
| 1376 | aom_highbd_jnt_sad16x32_avg_bits8, |
| 1377 | aom_highbd_8_jnt_sub_pixel_avg_variance16x32) |
| 1378 | |
| 1379 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1380 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1381 | aom_highbd_8_sub_pixel_variance64x32, |
| 1382 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1383 | aom_highbd_sad64x32x4d_bits8, |
| 1384 | aom_highbd_jnt_sad64x32_avg_bits8, |
| 1385 | aom_highbd_8_jnt_sub_pixel_avg_variance64x32) |
| 1386 | |
| 1387 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1388 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1389 | aom_highbd_8_sub_pixel_variance32x64, |
| 1390 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1391 | aom_highbd_sad32x64x4d_bits8, |
| 1392 | aom_highbd_jnt_sad32x64_avg_bits8, |
| 1393 | aom_highbd_8_jnt_sub_pixel_avg_variance32x64) |
| 1394 | |
| 1395 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1396 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1397 | aom_highbd_8_sub_pixel_variance32x32, |
| 1398 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1399 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1400 | aom_highbd_sad32x32x4d_bits8, |
| 1401 | aom_highbd_jnt_sad32x32_avg_bits8, |
| 1402 | aom_highbd_8_jnt_sub_pixel_avg_variance32x32) |
| 1403 | |
| 1404 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1405 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1406 | aom_highbd_8_sub_pixel_variance64x64, |
| 1407 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1408 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1409 | aom_highbd_sad64x64x4d_bits8, |
| 1410 | aom_highbd_jnt_sad64x64_avg_bits8, |
| 1411 | aom_highbd_8_jnt_sub_pixel_avg_variance64x64) |
| 1412 | |
| 1413 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1414 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1415 | aom_highbd_8_sub_pixel_variance16x16, |
| 1416 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1417 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1418 | aom_highbd_sad16x16x4d_bits8, |
| 1419 | aom_highbd_jnt_sad16x16_avg_bits8, |
| 1420 | aom_highbd_8_jnt_sub_pixel_avg_variance16x16) |
| 1421 | |
| 1422 | HIGHBD_BFP( |
| 1423 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1424 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1425 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1426 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8, |
| 1427 | aom_highbd_jnt_sad16x8_avg_bits8, |
| 1428 | aom_highbd_8_jnt_sub_pixel_avg_variance16x8) |
| 1429 | |
| 1430 | HIGHBD_BFP( |
| 1431 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1432 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1433 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1434 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8, |
| 1435 | aom_highbd_jnt_sad8x16_avg_bits8, |
| 1436 | aom_highbd_8_jnt_sub_pixel_avg_variance8x16) |
| 1437 | |
| 1438 | HIGHBD_BFP(BLOCK_8X8, aom_highbd_sad8x8_bits8, |
| 1439 | aom_highbd_sad8x8_avg_bits8, aom_highbd_8_variance8x8, |
| 1440 | aom_highbd_8_sub_pixel_variance8x8, |
| 1441 | aom_highbd_8_sub_pixel_avg_variance8x8, |
| 1442 | aom_highbd_sad8x8x3_bits8, aom_highbd_sad8x8x8_bits8, |
| 1443 | aom_highbd_sad8x8x4d_bits8, aom_highbd_jnt_sad8x8_avg_bits8, |
| 1444 | aom_highbd_8_jnt_sub_pixel_avg_variance8x8) |
| 1445 | |
| 1446 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1447 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1448 | aom_highbd_8_sub_pixel_variance8x4, |
| 1449 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1450 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8, |
| 1451 | aom_highbd_jnt_sad8x4_avg_bits8, |
| 1452 | aom_highbd_8_jnt_sub_pixel_avg_variance8x4) |
| 1453 | |
| 1454 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1455 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1456 | aom_highbd_8_sub_pixel_variance4x8, |
| 1457 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1458 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8, |
| 1459 | aom_highbd_jnt_sad4x8_avg_bits8, |
| 1460 | aom_highbd_8_jnt_sub_pixel_avg_variance4x8) |
| 1461 | |
| 1462 | HIGHBD_BFP(BLOCK_4X4, aom_highbd_sad4x4_bits8, |
| 1463 | aom_highbd_sad4x4_avg_bits8, aom_highbd_8_variance4x4, |
| 1464 | aom_highbd_8_sub_pixel_variance4x4, |
| 1465 | aom_highbd_8_sub_pixel_avg_variance4x4, |
| 1466 | aom_highbd_sad4x4x3_bits8, aom_highbd_sad4x4x8_bits8, |
| 1467 | aom_highbd_sad4x4x4d_bits8, aom_highbd_jnt_sad4x4_avg_bits8, |
| 1468 | aom_highbd_8_jnt_sub_pixel_avg_variance4x4) |
| 1469 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1470 | HIGHBD_BFP( |
| 1471 | BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1472 | aom_highbd_sad128x128_avg_bits8, aom_highbd_8_variance128x128, |
| 1473 | aom_highbd_8_sub_pixel_variance128x128, |
| 1474 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1475 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1476 | aom_highbd_sad128x128x4d_bits8, aom_highbd_jnt_sad128x128_avg_bits8, |
| 1477 | aom_highbd_8_jnt_sub_pixel_avg_variance128x128) |
| 1478 | |
| 1479 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1480 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1481 | aom_highbd_8_sub_pixel_variance128x64, |
| 1482 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1483 | aom_highbd_sad128x64x4d_bits8, |
| 1484 | aom_highbd_jnt_sad128x64_avg_bits8, |
| 1485 | aom_highbd_8_jnt_sub_pixel_avg_variance128x64) |
| 1486 | |
| 1487 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1488 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1489 | aom_highbd_8_sub_pixel_variance64x128, |
| 1490 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1491 | aom_highbd_sad64x128x4d_bits8, |
| 1492 | aom_highbd_jnt_sad64x128_avg_bits8, |
| 1493 | aom_highbd_8_jnt_sub_pixel_avg_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1494 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1495 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1496 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1497 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1498 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1499 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1500 | aom_highbd_8_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1501 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1502 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1503 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1504 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1505 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1506 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1507 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1508 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1509 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1510 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1511 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1512 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1513 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1514 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1515 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1516 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1517 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1518 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1519 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1520 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1521 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1522 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1523 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1524 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1525 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1526 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1527 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1528 | aom_highbd_8_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1529 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1530 | aom_highbd_8_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1531 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1532 | aom_highbd_8_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1533 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1534 | aom_highbd_8_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1535 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1536 | aom_highbd_8_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1537 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1538 | aom_highbd_8_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1539 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1540 | aom_highbd_obmc_variance128x128, |
| 1541 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1542 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1543 | aom_highbd_obmc_variance128x64, |
| 1544 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1545 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1546 | aom_highbd_obmc_variance64x128, |
| 1547 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1548 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1549 | aom_highbd_obmc_variance64x64, |
| 1550 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1551 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1552 | aom_highbd_obmc_variance64x32, |
| 1553 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1554 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1555 | aom_highbd_obmc_variance32x64, |
| 1556 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1557 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1558 | aom_highbd_obmc_variance32x32, |
| 1559 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1560 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1561 | aom_highbd_obmc_variance32x16, |
| 1562 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1563 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1564 | aom_highbd_obmc_variance16x32, |
| 1565 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1566 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1567 | aom_highbd_obmc_variance16x16, |
| 1568 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1569 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1570 | aom_highbd_obmc_variance8x16, |
| 1571 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1572 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1573 | aom_highbd_obmc_variance16x8, |
| 1574 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1575 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1576 | aom_highbd_obmc_variance8x8, |
| 1577 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1578 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1579 | aom_highbd_obmc_variance4x8, |
| 1580 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1581 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1582 | aom_highbd_obmc_variance8x4, |
| 1583 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1584 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1585 | aom_highbd_obmc_variance4x4, |
| 1586 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1587 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1588 | aom_highbd_obmc_variance64x16, |
| 1589 | aom_highbd_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1590 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1591 | aom_highbd_obmc_variance16x64, |
| 1592 | aom_highbd_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1593 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1594 | aom_highbd_obmc_variance32x8, |
| 1595 | aom_highbd_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1596 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1597 | aom_highbd_obmc_variance8x32, |
| 1598 | aom_highbd_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1599 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1600 | aom_highbd_obmc_variance16x4, |
| 1601 | aom_highbd_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1602 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1603 | aom_highbd_obmc_variance4x16, |
| 1604 | aom_highbd_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1605 | break; |
| 1606 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1607 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1608 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1609 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1610 | aom_highbd_10_sub_pixel_variance64x16, |
| 1611 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1612 | aom_highbd_sad64x16x4d_bits10, |
| 1613 | aom_highbd_jnt_sad64x16_avg_bits10, |
| 1614 | aom_highbd_10_jnt_sub_pixel_avg_variance64x16); |
| 1615 | |
| 1616 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1617 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1618 | aom_highbd_10_sub_pixel_variance16x64, |
| 1619 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1620 | aom_highbd_sad16x64x4d_bits10, |
| 1621 | aom_highbd_jnt_sad16x64_avg_bits10, |
| 1622 | aom_highbd_10_jnt_sub_pixel_avg_variance16x64); |
| 1623 | |
| 1624 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1625 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1626 | aom_highbd_10_sub_pixel_variance32x8, |
| 1627 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1628 | aom_highbd_sad32x8x4d_bits10, |
| 1629 | aom_highbd_jnt_sad32x8_avg_bits10, |
| 1630 | aom_highbd_10_jnt_sub_pixel_avg_variance32x8); |
| 1631 | |
| 1632 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1633 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1634 | aom_highbd_10_sub_pixel_variance8x32, |
| 1635 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1636 | aom_highbd_sad8x32x4d_bits10, |
| 1637 | aom_highbd_jnt_sad8x32_avg_bits10, |
| 1638 | aom_highbd_10_jnt_sub_pixel_avg_variance8x32); |
| 1639 | |
| 1640 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1641 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1642 | aom_highbd_10_sub_pixel_variance16x4, |
| 1643 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1644 | aom_highbd_sad16x4x4d_bits10, |
| 1645 | aom_highbd_jnt_sad16x4_avg_bits10, |
| 1646 | aom_highbd_10_jnt_sub_pixel_avg_variance16x4); |
| 1647 | |
| 1648 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1649 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1650 | aom_highbd_10_sub_pixel_variance4x16, |
| 1651 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1652 | aom_highbd_sad4x16x4d_bits10, |
| 1653 | aom_highbd_jnt_sad4x16_avg_bits10, |
| 1654 | aom_highbd_10_jnt_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1655 | |
| 1656 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1657 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1658 | aom_highbd_10_sub_pixel_variance32x16, |
| 1659 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1660 | aom_highbd_sad32x16x4d_bits10, |
| 1661 | aom_highbd_jnt_sad32x16_avg_bits10, |
| 1662 | aom_highbd_10_jnt_sub_pixel_avg_variance32x16); |
| 1663 | |
| 1664 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1665 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1666 | aom_highbd_10_sub_pixel_variance16x32, |
| 1667 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1668 | aom_highbd_sad16x32x4d_bits10, |
| 1669 | aom_highbd_jnt_sad16x32_avg_bits10, |
| 1670 | aom_highbd_10_jnt_sub_pixel_avg_variance16x32); |
| 1671 | |
| 1672 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1673 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1674 | aom_highbd_10_sub_pixel_variance64x32, |
| 1675 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1676 | aom_highbd_sad64x32x4d_bits10, |
| 1677 | aom_highbd_jnt_sad64x32_avg_bits10, |
| 1678 | aom_highbd_10_jnt_sub_pixel_avg_variance64x32); |
| 1679 | |
| 1680 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1681 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1682 | aom_highbd_10_sub_pixel_variance32x64, |
| 1683 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1684 | aom_highbd_sad32x64x4d_bits10, |
| 1685 | aom_highbd_jnt_sad32x64_avg_bits10, |
| 1686 | aom_highbd_10_jnt_sub_pixel_avg_variance32x64); |
| 1687 | |
| 1688 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1689 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1690 | aom_highbd_10_sub_pixel_variance32x32, |
| 1691 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 1692 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 1693 | aom_highbd_sad32x32x4d_bits10, |
| 1694 | aom_highbd_jnt_sad32x32_avg_bits10, |
| 1695 | aom_highbd_10_jnt_sub_pixel_avg_variance32x32); |
| 1696 | |
| 1697 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1698 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1699 | aom_highbd_10_sub_pixel_variance64x64, |
| 1700 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 1701 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 1702 | aom_highbd_sad64x64x4d_bits10, |
| 1703 | aom_highbd_jnt_sad64x64_avg_bits10, |
| 1704 | aom_highbd_10_jnt_sub_pixel_avg_variance64x64); |
| 1705 | |
| 1706 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1707 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1708 | aom_highbd_10_sub_pixel_variance16x16, |
| 1709 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 1710 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 1711 | aom_highbd_sad16x16x4d_bits10, |
| 1712 | aom_highbd_jnt_sad16x16_avg_bits10, |
| 1713 | aom_highbd_10_jnt_sub_pixel_avg_variance16x16); |
| 1714 | |
| 1715 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1716 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1717 | aom_highbd_10_sub_pixel_variance16x8, |
| 1718 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 1719 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 1720 | aom_highbd_sad16x8x4d_bits10, |
| 1721 | aom_highbd_jnt_sad16x8_avg_bits10, |
| 1722 | aom_highbd_10_jnt_sub_pixel_avg_variance16x8); |
| 1723 | |
| 1724 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1725 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1726 | aom_highbd_10_sub_pixel_variance8x16, |
| 1727 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 1728 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 1729 | aom_highbd_sad8x16x4d_bits10, |
| 1730 | aom_highbd_jnt_sad8x16_avg_bits10, |
| 1731 | aom_highbd_10_jnt_sub_pixel_avg_variance8x16); |
| 1732 | |
| 1733 | HIGHBD_BFP( |
| 1734 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1735 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 1736 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 1737 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10, |
| 1738 | aom_highbd_jnt_sad8x8_avg_bits10, |
| 1739 | aom_highbd_10_jnt_sub_pixel_avg_variance8x8); |
| 1740 | |
| 1741 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 1742 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 1743 | aom_highbd_10_sub_pixel_variance8x4, |
| 1744 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 1745 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10, |
| 1746 | aom_highbd_jnt_sad8x4_avg_bits10, |
| 1747 | aom_highbd_10_jnt_sub_pixel_avg_variance8x4); |
| 1748 | |
| 1749 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 1750 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 1751 | aom_highbd_10_sub_pixel_variance4x8, |
| 1752 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 1753 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10, |
| 1754 | aom_highbd_jnt_sad4x8_avg_bits10, |
| 1755 | aom_highbd_10_jnt_sub_pixel_avg_variance4x8); |
| 1756 | |
| 1757 | HIGHBD_BFP( |
| 1758 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1759 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 1760 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 1761 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10, |
| 1762 | aom_highbd_jnt_sad4x4_avg_bits10, |
| 1763 | aom_highbd_10_jnt_sub_pixel_avg_variance4x4); |
| 1764 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1765 | HIGHBD_BFP( |
| 1766 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1767 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 1768 | aom_highbd_10_sub_pixel_variance128x128, |
| 1769 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1770 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 1771 | aom_highbd_sad128x128x4d_bits10, |
| 1772 | aom_highbd_jnt_sad128x128_avg_bits10, |
| 1773 | aom_highbd_10_jnt_sub_pixel_avg_variance128x128); |
| 1774 | |
| 1775 | HIGHBD_BFP( |
| 1776 | BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1777 | aom_highbd_sad128x64_avg_bits10, aom_highbd_10_variance128x64, |
| 1778 | aom_highbd_10_sub_pixel_variance128x64, |
| 1779 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1780 | aom_highbd_sad128x64x4d_bits10, aom_highbd_jnt_sad128x64_avg_bits10, |
| 1781 | aom_highbd_10_jnt_sub_pixel_avg_variance128x64); |
| 1782 | |
| 1783 | HIGHBD_BFP( |
| 1784 | BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1785 | aom_highbd_sad64x128_avg_bits10, aom_highbd_10_variance64x128, |
| 1786 | aom_highbd_10_sub_pixel_variance64x128, |
| 1787 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1788 | aom_highbd_sad64x128x4d_bits10, aom_highbd_jnt_sad64x128_avg_bits10, |
| 1789 | aom_highbd_10_jnt_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1790 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1791 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1792 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1793 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1794 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1795 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1796 | aom_highbd_10_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1797 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1798 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1799 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1800 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1801 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1802 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1803 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1804 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1805 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1806 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1807 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1808 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1809 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1810 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1811 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1812 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1813 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1814 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1815 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1816 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1817 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1818 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1819 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1820 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1821 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1822 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1823 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1824 | aom_highbd_10_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1825 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1826 | aom_highbd_10_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1827 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1828 | aom_highbd_10_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1829 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 1830 | aom_highbd_10_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1831 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 1832 | aom_highbd_10_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1833 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 1834 | aom_highbd_10_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1835 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1836 | aom_highbd_10_obmc_variance128x128, |
| 1837 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1838 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1839 | aom_highbd_10_obmc_variance128x64, |
| 1840 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1841 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1842 | aom_highbd_10_obmc_variance64x128, |
| 1843 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1844 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 1845 | aom_highbd_10_obmc_variance64x64, |
| 1846 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 1847 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 1848 | aom_highbd_10_obmc_variance64x32, |
| 1849 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 1850 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 1851 | aom_highbd_10_obmc_variance32x64, |
| 1852 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 1853 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 1854 | aom_highbd_10_obmc_variance32x32, |
| 1855 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 1856 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 1857 | aom_highbd_10_obmc_variance32x16, |
| 1858 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 1859 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 1860 | aom_highbd_10_obmc_variance16x32, |
| 1861 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 1862 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 1863 | aom_highbd_10_obmc_variance16x16, |
| 1864 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 1865 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 1866 | aom_highbd_10_obmc_variance8x16, |
| 1867 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 1868 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 1869 | aom_highbd_10_obmc_variance16x8, |
| 1870 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 1871 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 1872 | aom_highbd_10_obmc_variance8x8, |
| 1873 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 1874 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 1875 | aom_highbd_10_obmc_variance4x8, |
| 1876 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 1877 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 1878 | aom_highbd_10_obmc_variance8x4, |
| 1879 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 1880 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 1881 | aom_highbd_10_obmc_variance4x4, |
| 1882 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1883 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1884 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 1885 | aom_highbd_10_obmc_variance64x16, |
| 1886 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 1887 | |
| 1888 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 1889 | aom_highbd_10_obmc_variance16x64, |
| 1890 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 1891 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1892 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 1893 | aom_highbd_10_obmc_variance32x8, |
| 1894 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 1895 | |
| 1896 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 1897 | aom_highbd_10_obmc_variance8x32, |
| 1898 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 1899 | |
| 1900 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 1901 | aom_highbd_10_obmc_variance16x4, |
| 1902 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 1903 | |
| 1904 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 1905 | aom_highbd_10_obmc_variance4x16, |
| 1906 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1907 | break; |
| 1908 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1909 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1910 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 1911 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 1912 | aom_highbd_12_sub_pixel_variance64x16, |
| 1913 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1914 | aom_highbd_sad64x16x4d_bits12, |
| 1915 | aom_highbd_jnt_sad64x16_avg_bits12, |
| 1916 | aom_highbd_12_jnt_sub_pixel_avg_variance64x16); |
| 1917 | |
| 1918 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 1919 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 1920 | aom_highbd_12_sub_pixel_variance16x64, |
| 1921 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1922 | aom_highbd_sad16x64x4d_bits12, |
| 1923 | aom_highbd_jnt_sad16x64_avg_bits12, |
| 1924 | aom_highbd_12_jnt_sub_pixel_avg_variance16x64); |
| 1925 | |
| 1926 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 1927 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 1928 | aom_highbd_12_sub_pixel_variance32x8, |
| 1929 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1930 | aom_highbd_sad32x8x4d_bits12, |
| 1931 | aom_highbd_jnt_sad32x8_avg_bits12, |
| 1932 | aom_highbd_12_jnt_sub_pixel_avg_variance32x8); |
| 1933 | |
| 1934 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 1935 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 1936 | aom_highbd_12_sub_pixel_variance8x32, |
| 1937 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1938 | aom_highbd_sad8x32x4d_bits12, |
| 1939 | aom_highbd_jnt_sad8x32_avg_bits12, |
| 1940 | aom_highbd_12_jnt_sub_pixel_avg_variance8x32); |
| 1941 | |
| 1942 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 1943 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 1944 | aom_highbd_12_sub_pixel_variance16x4, |
| 1945 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1946 | aom_highbd_sad16x4x4d_bits12, |
| 1947 | aom_highbd_jnt_sad16x4_avg_bits12, |
| 1948 | aom_highbd_12_jnt_sub_pixel_avg_variance16x4); |
| 1949 | |
| 1950 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 1951 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 1952 | aom_highbd_12_sub_pixel_variance4x16, |
| 1953 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1954 | aom_highbd_sad4x16x4d_bits12, |
| 1955 | aom_highbd_jnt_sad4x16_avg_bits12, |
| 1956 | aom_highbd_12_jnt_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1957 | |
| 1958 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 1959 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 1960 | aom_highbd_12_sub_pixel_variance32x16, |
| 1961 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1962 | aom_highbd_sad32x16x4d_bits12, |
| 1963 | aom_highbd_jnt_sad32x16_avg_bits12, |
| 1964 | aom_highbd_12_jnt_sub_pixel_avg_variance32x16); |
| 1965 | |
| 1966 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 1967 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 1968 | aom_highbd_12_sub_pixel_variance16x32, |
| 1969 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1970 | aom_highbd_sad16x32x4d_bits12, |
| 1971 | aom_highbd_jnt_sad16x32_avg_bits12, |
| 1972 | aom_highbd_12_jnt_sub_pixel_avg_variance16x32); |
| 1973 | |
| 1974 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 1975 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 1976 | aom_highbd_12_sub_pixel_variance64x32, |
| 1977 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1978 | aom_highbd_sad64x32x4d_bits12, |
| 1979 | aom_highbd_jnt_sad64x32_avg_bits12, |
| 1980 | aom_highbd_12_jnt_sub_pixel_avg_variance64x32); |
| 1981 | |
| 1982 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 1983 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 1984 | aom_highbd_12_sub_pixel_variance32x64, |
| 1985 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1986 | aom_highbd_sad32x64x4d_bits12, |
| 1987 | aom_highbd_jnt_sad32x64_avg_bits12, |
| 1988 | aom_highbd_12_jnt_sub_pixel_avg_variance32x64); |
| 1989 | |
| 1990 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 1991 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 1992 | aom_highbd_12_sub_pixel_variance32x32, |
| 1993 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 1994 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 1995 | aom_highbd_sad32x32x4d_bits12, |
| 1996 | aom_highbd_jnt_sad32x32_avg_bits12, |
| 1997 | aom_highbd_12_jnt_sub_pixel_avg_variance32x32); |
| 1998 | |
| 1999 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2000 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2001 | aom_highbd_12_sub_pixel_variance64x64, |
| 2002 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2003 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2004 | aom_highbd_sad64x64x4d_bits12, |
| 2005 | aom_highbd_jnt_sad64x64_avg_bits12, |
| 2006 | aom_highbd_12_jnt_sub_pixel_avg_variance64x64); |
| 2007 | |
| 2008 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2009 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2010 | aom_highbd_12_sub_pixel_variance16x16, |
| 2011 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2012 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2013 | aom_highbd_sad16x16x4d_bits12, |
| 2014 | aom_highbd_jnt_sad16x16_avg_bits12, |
| 2015 | aom_highbd_12_jnt_sub_pixel_avg_variance16x16); |
| 2016 | |
| 2017 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2018 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2019 | aom_highbd_12_sub_pixel_variance16x8, |
| 2020 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2021 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2022 | aom_highbd_sad16x8x4d_bits12, |
| 2023 | aom_highbd_jnt_sad16x8_avg_bits12, |
| 2024 | aom_highbd_12_jnt_sub_pixel_avg_variance16x8); |
| 2025 | |
| 2026 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2027 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2028 | aom_highbd_12_sub_pixel_variance8x16, |
| 2029 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2030 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2031 | aom_highbd_sad8x16x4d_bits12, |
| 2032 | aom_highbd_jnt_sad8x16_avg_bits12, |
| 2033 | aom_highbd_12_jnt_sub_pixel_avg_variance8x16); |
| 2034 | |
| 2035 | HIGHBD_BFP( |
| 2036 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2037 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2038 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2039 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12, |
| 2040 | aom_highbd_jnt_sad8x8_avg_bits12, |
| 2041 | aom_highbd_12_jnt_sub_pixel_avg_variance8x8); |
| 2042 | |
| 2043 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2044 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2045 | aom_highbd_12_sub_pixel_variance8x4, |
| 2046 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2047 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12, |
| 2048 | aom_highbd_jnt_sad8x4_avg_bits12, |
| 2049 | aom_highbd_12_jnt_sub_pixel_avg_variance8x4); |
| 2050 | |
| 2051 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 2052 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2053 | aom_highbd_12_sub_pixel_variance4x8, |
| 2054 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2055 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12, |
| 2056 | aom_highbd_jnt_sad4x8_avg_bits12, |
| 2057 | aom_highbd_12_jnt_sub_pixel_avg_variance4x8); |
| 2058 | |
| 2059 | HIGHBD_BFP( |
| 2060 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2061 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2062 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2063 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12, |
| 2064 | aom_highbd_jnt_sad4x4_avg_bits12, |
| 2065 | aom_highbd_12_jnt_sub_pixel_avg_variance4x4); |
| 2066 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2067 | HIGHBD_BFP( |
| 2068 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2069 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2070 | aom_highbd_12_sub_pixel_variance128x128, |
| 2071 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2072 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2073 | aom_highbd_sad128x128x4d_bits12, |
| 2074 | aom_highbd_jnt_sad128x128_avg_bits12, |
| 2075 | aom_highbd_12_jnt_sub_pixel_avg_variance128x128); |
| 2076 | |
| 2077 | HIGHBD_BFP( |
| 2078 | BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2079 | aom_highbd_sad128x64_avg_bits12, aom_highbd_12_variance128x64, |
| 2080 | aom_highbd_12_sub_pixel_variance128x64, |
| 2081 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2082 | aom_highbd_sad128x64x4d_bits12, aom_highbd_jnt_sad128x64_avg_bits12, |
| 2083 | aom_highbd_12_jnt_sub_pixel_avg_variance128x64); |
| 2084 | |
| 2085 | HIGHBD_BFP( |
| 2086 | BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2087 | aom_highbd_sad64x128_avg_bits12, aom_highbd_12_variance64x128, |
| 2088 | aom_highbd_12_sub_pixel_variance64x128, |
| 2089 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2090 | aom_highbd_sad64x128x4d_bits12, aom_highbd_jnt_sad64x128_avg_bits12, |
| 2091 | aom_highbd_12_jnt_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2092 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2093 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2094 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2095 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2096 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2097 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2098 | aom_highbd_12_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2099 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2100 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2101 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2102 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2103 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2104 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2105 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2106 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2107 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2108 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2109 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2110 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2111 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2112 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2113 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2114 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2115 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2116 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2117 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2118 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2119 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2120 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2121 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2122 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2123 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2124 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2125 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2126 | aom_highbd_12_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2127 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2128 | aom_highbd_12_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2129 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2130 | aom_highbd_12_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2131 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2132 | aom_highbd_12_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2133 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2134 | aom_highbd_12_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2135 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2136 | aom_highbd_12_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2137 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2138 | aom_highbd_12_obmc_variance128x128, |
| 2139 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2140 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2141 | aom_highbd_12_obmc_variance128x64, |
| 2142 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2143 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2144 | aom_highbd_12_obmc_variance64x128, |
| 2145 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2146 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2147 | aom_highbd_12_obmc_variance64x64, |
| 2148 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2149 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2150 | aom_highbd_12_obmc_variance64x32, |
| 2151 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2152 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2153 | aom_highbd_12_obmc_variance32x64, |
| 2154 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2155 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2156 | aom_highbd_12_obmc_variance32x32, |
| 2157 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2158 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2159 | aom_highbd_12_obmc_variance32x16, |
| 2160 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2161 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2162 | aom_highbd_12_obmc_variance16x32, |
| 2163 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2164 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2165 | aom_highbd_12_obmc_variance16x16, |
| 2166 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2167 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2168 | aom_highbd_12_obmc_variance8x16, |
| 2169 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2170 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2171 | aom_highbd_12_obmc_variance16x8, |
| 2172 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2173 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2174 | aom_highbd_12_obmc_variance8x8, |
| 2175 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2176 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2177 | aom_highbd_12_obmc_variance4x8, |
| 2178 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2179 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2180 | aom_highbd_12_obmc_variance8x4, |
| 2181 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2182 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2183 | aom_highbd_12_obmc_variance4x4, |
| 2184 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2185 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2186 | aom_highbd_12_obmc_variance64x16, |
| 2187 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2188 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2189 | aom_highbd_12_obmc_variance16x64, |
| 2190 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2191 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2192 | aom_highbd_12_obmc_variance32x8, |
| 2193 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2194 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2195 | aom_highbd_12_obmc_variance8x32, |
| 2196 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2197 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2198 | aom_highbd_12_obmc_variance16x4, |
| 2199 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2200 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2201 | aom_highbd_12_obmc_variance4x16, |
| 2202 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2203 | break; |
| 2204 | |
| 2205 | default: |
| 2206 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2207 | "cm->bit_depth should be AOM_BITS_8, " |
| 2208 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2209 | } |
| 2210 | } |
| 2211 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2212 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2213 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2214 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2215 | |
| 2216 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2217 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2218 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2219 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2220 | |
| 2221 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2222 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2223 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2224 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2225 | |
| 2226 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2227 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2228 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2229 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2232 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2233 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2234 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2235 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2236 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2237 | |
| 2238 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 2239 | cm->bit_depth = oxcf->bit_depth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 2240 | cm->color_primaries = oxcf->color_primaries; |
| 2241 | cm->transfer_characteristics = oxcf->transfer_characteristics; |
| 2242 | cm->matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 2243 | cm->seq_params.monochrome = oxcf->monochrome; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2244 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2245 | cm->color_range = oxcf->color_range; |
| 2246 | |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 2247 | assert(IMPLIES(cm->profile <= PROFILE_1, cm->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2248 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2249 | cm->timing_info_present = oxcf->timing_info_present; |
| 2250 | cm->num_units_in_tick = oxcf->num_units_in_tick; |
| 2251 | cm->time_scale = oxcf->time_scale; |
| 2252 | cm->equal_picture_interval = oxcf->equal_picture_interval; |
| 2253 | cm->num_ticks_per_picture = oxcf->num_ticks_per_picture; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2254 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2255 | update_film_grain_parameters(cpi, oxcf); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2256 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2257 | cpi->oxcf = *oxcf; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 2258 | cpi->common.options = oxcf->cfg; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2259 | x->e_mbd.bd = (int)cm->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2260 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2261 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2262 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2263 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2264 | } else { |
| 2265 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2266 | } |
| 2267 | |
| 2268 | cpi->refresh_last_frame = 1; |
| 2269 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2270 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2271 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2272 | |
Debargha Mukherjee | 229fdc8 | 2018-03-10 07:45:33 -0800 | [diff] [blame] | 2273 | cm->refresh_frame_context = (oxcf->frame_parallel_decoding_mode) |
| 2274 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 2275 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2276 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 2277 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2278 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2279 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2280 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2281 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2282 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2283 | av1_reset_segment_features(cm); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2284 | set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2285 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2286 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2287 | |
| 2288 | // Under a configuration change, where maximum_buffer_size may change, |
| 2289 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2290 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2291 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2292 | |
| 2293 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2294 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2295 | |
| 2296 | // Set absolute upper and lower quality limits |
| 2297 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2298 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2299 | |
Yunqing Wang | b6e23bc | 2017-11-15 13:18:55 -0800 | [diff] [blame] | 2300 | if (!oxcf->large_scale_tile) |
Yunqing Wang | b6e23bc | 2017-11-15 13:18:55 -0800 | [diff] [blame] | 2301 | cm->interp_filter = cpi->sf.default_interp_filter; |
Yunqing Wang | b6e23bc | 2017-11-15 13:18:55 -0800 | [diff] [blame] | 2302 | else |
| 2303 | cm->interp_filter = EIGHTTAP_REGULAR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2304 | |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 2305 | cm->switchable_motion_mode = 1; |
| 2306 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2307 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2308 | cm->render_width = cpi->oxcf.render_width; |
| 2309 | cm->render_height = cpi->oxcf.render_height; |
| 2310 | } else { |
| 2311 | cm->render_width = cpi->oxcf.width; |
| 2312 | cm->render_height = cpi->oxcf.height; |
| 2313 | } |
| 2314 | cm->width = cpi->oxcf.width; |
| 2315 | cm->height = cpi->oxcf.height; |
| 2316 | |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 2317 | int sb_size = cm->seq_params.sb_size; |
| 2318 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2319 | |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 2320 | if (cpi->initial_width || sb_size != cm->seq_params.sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2321 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 2322 | cm->seq_params.sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2323 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2324 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2325 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2326 | realloc_segmentation_maps(cpi); |
| 2327 | cpi->initial_width = cpi->initial_height = 0; |
| 2328 | } |
| 2329 | } |
| 2330 | update_frame_size(cpi); |
| 2331 | |
| 2332 | cpi->alt_ref_source = NULL; |
| 2333 | rc->is_src_frame_alt_ref = 0; |
| 2334 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2335 | rc->is_bwd_ref_frame = 0; |
| 2336 | rc->is_last_bipred_frame = 0; |
| 2337 | rc->is_bipred_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2338 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2339 | set_tile_info(cpi); |
| 2340 | |
| 2341 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2342 | cpi->ext_refresh_frame_context_pending = 0; |
| 2343 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2344 | highbd_set_var_fns(cpi); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 2345 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 2346 | // Init sequence level coding tools |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2347 | // This should not be called after the first key frame. |
| 2348 | if (!cpi->seq_params_locked) { |
| 2349 | init_seq_coding_tools(&cm->seq_params, oxcf); |
| 2350 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2353 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2354 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2355 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2356 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2357 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2358 | |
| 2359 | if (!cm) return NULL; |
| 2360 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2361 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2362 | |
| 2363 | if (setjmp(cm->error.jmp)) { |
| 2364 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2365 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2366 | return 0; |
| 2367 | } |
| 2368 | |
| 2369 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2370 | cm->alloc_mi = enc_alloc_mi; |
| 2371 | cm->free_mi = enc_free_mi; |
| 2372 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2373 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2374 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2375 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2376 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2377 | (FRAME_CONTEXT *)aom_memalign( |
| 2378 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2379 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2380 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2381 | |
| 2382 | cpi->resize_state = 0; |
| 2383 | cpi->resize_avg_qp = 0; |
| 2384 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2385 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2386 | cpi->common.buffer_pool = pool; |
| 2387 | |
| 2388 | init_config(cpi, oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2389 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2390 | |
| 2391 | cm->current_video_frame = 0; |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2392 | cpi->seq_params_locked = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2393 | cpi->partition_search_skippable_frame = 0; |
| 2394 | cpi->tile_data = NULL; |
| 2395 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2396 | |
| 2397 | realloc_segmentation_maps(cpi); |
| 2398 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2399 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2400 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2401 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2402 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2403 | i++) { |
| 2404 | CHECK_MEM_ERROR( |
| 2405 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2406 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | #if CONFIG_FP_MB_STATS |
| 2410 | cpi->use_fp_mb_stats = 0; |
| 2411 | if (cpi->use_fp_mb_stats) { |
| 2412 | // a place holder used to store the first pass mb stats in the first pass |
| 2413 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2414 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2415 | } else { |
| 2416 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2417 | } |
| 2418 | #endif |
| 2419 | |
| 2420 | cpi->refresh_alt_ref_frame = 0; |
| 2421 | cpi->multi_arf_last_grp_enabled = 0; |
| 2422 | |
| 2423 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2424 | #if CONFIG_INTERNAL_STATS |
| 2425 | cpi->b_calculate_blockiness = 1; |
| 2426 | cpi->b_calculate_consistency = 1; |
| 2427 | cpi->total_inconsistency = 0; |
| 2428 | cpi->psnr.worst = 100.0; |
| 2429 | cpi->worst_ssim = 100.0; |
| 2430 | |
| 2431 | cpi->count = 0; |
| 2432 | cpi->bytes = 0; |
| 2433 | |
| 2434 | if (cpi->b_calculate_psnr) { |
| 2435 | cpi->total_sq_error = 0; |
| 2436 | cpi->total_samples = 0; |
| 2437 | cpi->tot_recode_hits = 0; |
| 2438 | cpi->summed_quality = 0; |
| 2439 | cpi->summed_weights = 0; |
| 2440 | } |
| 2441 | |
| 2442 | cpi->fastssim.worst = 100.0; |
| 2443 | cpi->psnrhvs.worst = 100.0; |
| 2444 | |
| 2445 | if (cpi->b_calculate_blockiness) { |
| 2446 | cpi->total_blockiness = 0; |
| 2447 | cpi->worst_blockiness = 0.0; |
| 2448 | } |
| 2449 | |
| 2450 | if (cpi->b_calculate_consistency) { |
| 2451 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2452 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2453 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2454 | cpi->worst_consistency = 100.0; |
| 2455 | } |
| 2456 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2457 | #if CONFIG_ENTROPY_STATS |
| 2458 | av1_zero(aggregate_fc); |
| 2459 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2460 | |
| 2461 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2462 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2463 | cpi->td.mb.nmvcost[0] = &cpi->nmv_costs[0][MV_MAX]; |
| 2464 | cpi->td.mb.nmvcost[1] = &cpi->nmv_costs[1][MV_MAX]; |
| 2465 | cpi->td.mb.nmvcost_hp[0] = &cpi->nmv_costs_hp[0][MV_MAX]; |
| 2466 | cpi->td.mb.nmvcost_hp[1] = &cpi->nmv_costs_hp[1][MV_MAX]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2467 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2468 | #ifdef OUTPUT_YUV_SKINMAP |
| 2469 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2470 | #endif |
| 2471 | #ifdef OUTPUT_YUV_REC |
| 2472 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2473 | #endif |
| 2474 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2475 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2476 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2477 | } else if (oxcf->pass == 2) { |
| 2478 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2479 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2480 | |
| 2481 | #if CONFIG_FP_MB_STATS |
| 2482 | if (cpi->use_fp_mb_stats) { |
| 2483 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2484 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2485 | |
| 2486 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2487 | oxcf->firstpass_mb_stats_in.buf; |
| 2488 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2489 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2490 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2491 | } |
| 2492 | #endif |
| 2493 | |
| 2494 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2495 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2496 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2497 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2498 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2501 | CHECK_MEM_ERROR( |
| 2502 | cm, cpi->td.mb.above_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2503 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2504 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2505 | CHECK_MEM_ERROR( |
| 2506 | cm, cpi->td.mb.left_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2507 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2508 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2509 | |
| 2510 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2511 | (int32_t *)aom_memalign( |
| 2512 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2513 | |
| 2514 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2515 | (int32_t *)aom_memalign( |
| 2516 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2517 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2518 | av1_set_speed_features_framesize_independent(cpi); |
| 2519 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2520 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2521 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, JSVAF) \ |
| 2522 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2523 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2524 | cpi->fn_ptr[BT].vf = VF; \ |
| 2525 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2526 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2527 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2528 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2529 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 2530 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
| 2531 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2532 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2533 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 2534 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2535 | aom_sad4x16x4d, aom_jnt_sad4x16_avg, aom_jnt_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2536 | |
| 2537 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 2538 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2539 | aom_sad16x4x4d, aom_jnt_sad16x4_avg, aom_jnt_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2540 | |
| 2541 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 2542 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2543 | aom_sad8x32x4d, aom_jnt_sad8x32_avg, aom_jnt_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2544 | |
| 2545 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 2546 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2547 | aom_sad32x8x4d, aom_jnt_sad32x8_avg, aom_jnt_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2548 | |
| 2549 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 2550 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2551 | aom_sad16x64x4d, aom_jnt_sad16x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2552 | aom_jnt_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2553 | |
| 2554 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 2555 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2556 | aom_sad64x16x4d, aom_jnt_sad64x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2557 | aom_jnt_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2558 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2559 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2560 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2561 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2562 | aom_jnt_sad128x128_avg, aom_jnt_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2563 | |
| 2564 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2565 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2566 | NULL, aom_sad128x64x4d, aom_jnt_sad128x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2567 | aom_jnt_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2568 | |
| 2569 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2570 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2571 | NULL, aom_sad64x128x4d, aom_jnt_sad64x128_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2572 | aom_jnt_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2573 | |
| 2574 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2575 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2576 | aom_sad32x16x4d, aom_jnt_sad32x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2577 | aom_jnt_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2578 | |
| 2579 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2580 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2581 | aom_sad16x32x4d, aom_jnt_sad16x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2582 | aom_jnt_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2583 | |
| 2584 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2585 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2586 | aom_sad64x32x4d, aom_jnt_sad64x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2587 | aom_jnt_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2588 | |
| 2589 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2590 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2591 | aom_sad32x64x4d, aom_jnt_sad32x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2592 | aom_jnt_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2593 | |
| 2594 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2595 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2596 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d, aom_jnt_sad32x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2597 | aom_jnt_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2598 | |
| 2599 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2600 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2601 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d, aom_jnt_sad64x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2602 | aom_jnt_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2603 | |
| 2604 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2605 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2606 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d, aom_jnt_sad16x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2607 | aom_jnt_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2608 | |
| 2609 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2610 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2611 | aom_sad16x8x8, aom_sad16x8x4d, aom_jnt_sad16x8_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2612 | aom_jnt_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2613 | |
| 2614 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2615 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2616 | aom_sad8x16x8, aom_sad8x16x4d, aom_jnt_sad8x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2617 | aom_jnt_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2618 | |
| 2619 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 2620 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2621 | aom_sad8x8x8, aom_sad8x8x4d, aom_jnt_sad8x8_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2622 | aom_jnt_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2623 | |
| 2624 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 2625 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2626 | aom_sad8x4x8, aom_sad8x4x4d, aom_jnt_sad8x4_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2627 | aom_jnt_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2628 | |
| 2629 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 2630 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2631 | aom_sad4x8x8, aom_sad4x8x4d, aom_jnt_sad4x8_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2632 | aom_jnt_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2633 | |
| 2634 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 2635 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2636 | aom_sad4x4x8, aom_sad4x4x4d, aom_jnt_sad4x4_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2637 | aom_jnt_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2638 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2639 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2640 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2641 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2642 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2643 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2644 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2645 | aom_obmc_sub_pixel_variance128x128) |
| 2646 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2647 | aom_obmc_sub_pixel_variance128x64) |
| 2648 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2649 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2650 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2651 | aom_obmc_sub_pixel_variance64x64) |
| 2652 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2653 | aom_obmc_sub_pixel_variance64x32) |
| 2654 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2655 | aom_obmc_sub_pixel_variance32x64) |
| 2656 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2657 | aom_obmc_sub_pixel_variance32x32) |
| 2658 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2659 | aom_obmc_sub_pixel_variance32x16) |
| 2660 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2661 | aom_obmc_sub_pixel_variance16x32) |
| 2662 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2663 | aom_obmc_sub_pixel_variance16x16) |
| 2664 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2665 | aom_obmc_sub_pixel_variance16x8) |
| 2666 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2667 | aom_obmc_sub_pixel_variance8x16) |
| 2668 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2669 | aom_obmc_sub_pixel_variance8x8) |
| 2670 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2671 | aom_obmc_sub_pixel_variance4x8) |
| 2672 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2673 | aom_obmc_sub_pixel_variance8x4) |
| 2674 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2675 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2676 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2677 | aom_obmc_sub_pixel_variance4x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2678 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2679 | aom_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2680 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2681 | aom_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2682 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2683 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2684 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2685 | aom_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2686 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2687 | aom_obmc_sub_pixel_variance64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2688 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2689 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2690 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2691 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2692 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2693 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2694 | aom_masked_sub_pixel_variance128x128) |
| 2695 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2696 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2697 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2698 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2699 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2700 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2701 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2702 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2703 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2704 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2705 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2706 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2707 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2708 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2709 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2710 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2711 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 2712 | |
| 2713 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 2714 | |
| 2715 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 2716 | |
| 2717 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2718 | |
| 2719 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 2720 | |
| 2721 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2722 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2723 | highbd_set_var_fns(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2724 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2725 | /* av1_init_quantizer() is first called here. Add check in |
| 2726 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2727 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2728 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2729 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2730 | av1_init_quantizer(cpi); |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 2731 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2732 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2733 | av1_loop_filter_init(cm); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 2734 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 2735 | cm->superres_upscaled_width = oxcf->width; |
| 2736 | cm->superres_upscaled_height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2737 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2738 | |
| 2739 | cm->error.setjmp = 0; |
| 2740 | |
| 2741 | return cpi; |
| 2742 | } |
| 2743 | |
| 2744 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2745 | |
| 2746 | #define SNPRINT2(H, T, V) \ |
| 2747 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 2748 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2749 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2750 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2751 | unsigned int i; |
| 2752 | int t; |
| 2753 | |
| 2754 | if (!cpi) return; |
| 2755 | |
| 2756 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2757 | const int num_planes = av1_num_planes(cm); |
| 2758 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2759 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2760 | #if CONFIG_ENTROPY_STATS |
| 2761 | if (cpi->oxcf.pass != 1) { |
| 2762 | fprintf(stderr, "Writing counts.stt\n"); |
| 2763 | FILE *f = fopen("counts.stt", "wb"); |
| 2764 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 2765 | fclose(f); |
| 2766 | } |
| 2767 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2768 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2769 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2770 | |
| 2771 | if (cpi->oxcf.pass != 1) { |
| 2772 | char headings[512] = { 0 }; |
| 2773 | char results[512] = { 0 }; |
| 2774 | FILE *f = fopen("opsnr.stt", "a"); |
| 2775 | double time_encoded = |
| 2776 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 2777 | 10000000.000; |
| 2778 | double total_encode_time = |
| 2779 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 2780 | const double dr = |
| 2781 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 2782 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 2783 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 2784 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 2785 | |
| 2786 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2787 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2788 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 2789 | const double total_ssim = |
| 2790 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 2791 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2792 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2793 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 2794 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2795 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2796 | snprintf(results, sizeof(results), |
| 2797 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2798 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 2799 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2800 | "%7.3f\t%7.3f\t%7.3f", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2801 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2802 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2803 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 2804 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 2805 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2806 | cpi->psnr.stat[Y] / cpi->count, cpi->psnr.stat[U] / cpi->count, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 2807 | cpi->psnr.stat[V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2808 | |
| 2809 | if (cpi->b_calculate_blockiness) { |
| 2810 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 2811 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 2812 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 2813 | } |
| 2814 | |
| 2815 | if (cpi->b_calculate_consistency) { |
| 2816 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2817 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2818 | (double)cpi->total_inconsistency); |
| 2819 | |
| 2820 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 2821 | SNPRINT2(results, "\t%7.3f", consistency); |
| 2822 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 2823 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 2824 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 2825 | 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] | 2826 | rate_err, fabs(rate_err)); |
| 2827 | } |
| 2828 | |
| 2829 | fclose(f); |
| 2830 | } |
| 2831 | |
| 2832 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2836 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2837 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 2838 | |
| 2839 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2840 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2841 | |
| 2842 | // Deallocate allocated thread data. |
| 2843 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2844 | aom_free(thread_data->td->palette_buffer); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2845 | aom_free(thread_data->td->above_pred_buf); |
| 2846 | aom_free(thread_data->td->left_pred_buf); |
| 2847 | aom_free(thread_data->td->wsrc_buf); |
| 2848 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2849 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2850 | av1_free_pc_tree(thread_data->td, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2851 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2852 | } |
| 2853 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2854 | aom_free(cpi->tile_thr_data); |
| 2855 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2856 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2857 | dealloc_compressor_data(cpi); |
| 2858 | |
| 2859 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 2860 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2861 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | #if CONFIG_FP_MB_STATS |
| 2865 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2866 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2867 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2868 | } |
| 2869 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 2870 | #if CONFIG_INTERNAL_STATS |
| 2871 | aom_free(cpi->ssim_vars); |
| 2872 | cpi->ssim_vars = NULL; |
| 2873 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2874 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2875 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 2876 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 2877 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 2878 | } |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 2879 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2880 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 2881 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2882 | |
| 2883 | #ifdef OUTPUT_YUV_SKINMAP |
| 2884 | fclose(yuv_skinmap_file); |
| 2885 | #endif |
| 2886 | #ifdef OUTPUT_YUV_REC |
| 2887 | fclose(yuv_rec_file); |
| 2888 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2889 | } |
| 2890 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2891 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 2892 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2893 | int i; |
| 2894 | PSNR_STATS psnr; |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 2895 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2896 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2897 | |
| 2898 | for (i = 0; i < 4; ++i) { |
| 2899 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 2900 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 2901 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 2902 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2903 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 2904 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2907 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2908 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 2909 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 2910 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2911 | return 0; |
| 2912 | } |
| 2913 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 2914 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) { |
| 2915 | cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0; |
| 2916 | cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0; |
| 2917 | cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0; |
| 2918 | cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0; |
| 2919 | cpi->ext_refresh_alt2_ref_frame = (ref_frame_upd_flags & AOM_ALT2_FLAG) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2920 | cpi->ext_refresh_frame_flags_pending = 1; |
| 2921 | } |
| 2922 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 2923 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 2924 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2925 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 2926 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2927 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2928 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2929 | return 0; |
| 2930 | } else { |
| 2931 | return -1; |
| 2932 | } |
| 2933 | } |
| 2934 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 2935 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 2936 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2937 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 2938 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2939 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2940 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2941 | return 0; |
| 2942 | } else { |
| 2943 | return -1; |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2948 | cpi->ext_refresh_frame_context = update; |
| 2949 | cpi->ext_refresh_frame_context_pending = 1; |
| 2950 | return 0; |
| 2951 | } |
| 2952 | |
| 2953 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 2954 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 2955 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 2956 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 2957 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2958 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2959 | uint8_t *src = s->y_buffer; |
| 2960 | int h = s->y_height; |
| 2961 | |
| 2962 | do { |
| 2963 | fwrite(src, s->y_width, 1, f); |
| 2964 | src += s->y_stride; |
| 2965 | } while (--h); |
| 2966 | |
| 2967 | src = s->u_buffer; |
| 2968 | h = s->uv_height; |
| 2969 | |
| 2970 | do { |
| 2971 | fwrite(src, s->uv_width, 1, f); |
| 2972 | src += s->uv_stride; |
| 2973 | } while (--h); |
| 2974 | |
| 2975 | src = s->v_buffer; |
| 2976 | h = s->uv_height; |
| 2977 | |
| 2978 | do { |
| 2979 | fwrite(src, s->uv_width, 1, f); |
| 2980 | src += s->uv_stride; |
| 2981 | } while (--h); |
| 2982 | } |
| 2983 | #endif |
| 2984 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 2985 | #if USE_GF16_MULTI_LAYER |
| 2986 | static void check_show_existing_frame_gf16(AV1_COMP *cpi) { |
| 2987 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2988 | AV1_COMMON *const cm = &cpi->common; |
| 2989 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 2990 | gf_group->update_type[gf_group->index]; |
| 2991 | |
| 2992 | if (cm->show_existing_frame == 1) { |
| 2993 | cm->show_existing_frame = 0; |
| 2994 | } else if (cpi->rc.is_last_bipred_frame) { |
| 2995 | cpi->rc.is_last_bipred_frame = 0; |
| 2996 | cm->show_existing_frame = 1; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 2997 | cpi->existing_fb_idx_to_show = cpi->ref_fb_idx[BWDREF_FRAME - 1]; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 2998 | } else if (next_frame_update_type == OVERLAY_UPDATE || |
| 2999 | next_frame_update_type == INTNL_OVERLAY_UPDATE) { |
| 3000 | // Check the temporal filtering status for the next OVERLAY frame |
| 3001 | const int num_arfs_in_gf = cpi->num_extra_arfs + 1; |
| 3002 | int which_arf = 0, arf_idx; |
| 3003 | // Identify the index to the next overlay frame. |
| 3004 | for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) { |
| 3005 | if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) { |
| 3006 | which_arf = arf_idx; |
| 3007 | break; |
| 3008 | } |
| 3009 | } |
| 3010 | assert(arf_idx < num_arfs_in_gf); |
| 3011 | if (cpi->is_arf_filter_off[which_arf]) { |
| 3012 | cm->show_existing_frame = 1; |
| 3013 | cpi->rc.is_src_frame_alt_ref = 1; |
| 3014 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3015 | ? cpi->ref_fb_idx[ALTREF_FRAME - 1] |
| 3016 | : cpi->ref_fb_idx[BWDREF_FRAME - 1]; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3017 | cpi->is_arf_filter_off[which_arf] = 0; |
| 3018 | } |
| 3019 | } |
| 3020 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3021 | } |
| 3022 | #endif // USE_GF16_MULTI_LAYER |
| 3023 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3024 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3025 | #if USE_GF16_MULTI_LAYER |
| 3026 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3027 | check_show_existing_frame_gf16(cpi); |
| 3028 | return; |
| 3029 | } |
| 3030 | #endif // USE_GF16_MULTI_LAYER |
| 3031 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3032 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3033 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3034 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3035 | gf_group->update_type[gf_group->index]; |
| 3036 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3037 | |
| 3038 | if (cm->show_existing_frame == 1) { |
| 3039 | cm->show_existing_frame = 0; |
| 3040 | } else if (cpi->rc.is_last_bipred_frame) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3041 | // NOTE: If the current frame is a last bi-predictive frame, it is |
| 3042 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3043 | // the last_fb_idxes[0] after reference frame buffer update |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3044 | cpi->rc.is_last_bipred_frame = 0; |
| 3045 | cm->show_existing_frame = 1; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3046 | cpi->existing_fb_idx_to_show = cpi->ref_fb_idx[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3047 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3048 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3049 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 3050 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3051 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3052 | cm->show_existing_frame = 1; |
| 3053 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3054 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3055 | ? cpi->ref_fb_idx[ALTREF_FRAME - 1] |
| 3056 | : cpi->ref_fb_idx[ALTREF2_FRAME - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3057 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3058 | } |
| 3059 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3060 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3061 | |
| 3062 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3063 | 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] | 3064 | uint8_t *src = s->y_buffer; |
| 3065 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3066 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3067 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3068 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3069 | |
| 3070 | do { |
| 3071 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3072 | src16 += s->y_stride; |
| 3073 | } while (--h); |
| 3074 | |
| 3075 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3076 | h = s->uv_height; |
| 3077 | |
| 3078 | do { |
| 3079 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3080 | src16 += s->uv_stride; |
| 3081 | } while (--h); |
| 3082 | |
| 3083 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3084 | h = s->uv_height; |
| 3085 | |
| 3086 | do { |
| 3087 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3088 | src16 += s->uv_stride; |
| 3089 | } while (--h); |
| 3090 | |
| 3091 | fflush(yuv_rec_file); |
| 3092 | return; |
| 3093 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3094 | |
| 3095 | do { |
| 3096 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3097 | src += s->y_stride; |
| 3098 | } while (--h); |
| 3099 | |
| 3100 | src = s->u_buffer; |
| 3101 | h = s->uv_height; |
| 3102 | |
| 3103 | do { |
| 3104 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3105 | src += s->uv_stride; |
| 3106 | } while (--h); |
| 3107 | |
| 3108 | src = s->v_buffer; |
| 3109 | h = s->uv_height; |
| 3110 | |
| 3111 | do { |
| 3112 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3113 | src += s->uv_stride; |
| 3114 | } while (--h); |
| 3115 | |
| 3116 | fflush(yuv_rec_file); |
| 3117 | } |
| 3118 | #endif // OUTPUT_YUV_REC |
| 3119 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3120 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3121 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3122 | int i; |
| 3123 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3124 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3125 | AV1_COMMON *const cm = &cpi->common; |
| 3126 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3127 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3128 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3129 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3130 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3131 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3132 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3133 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 3134 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 3135 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 3136 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | return recode; |
| 3140 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3141 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3142 | // Function to test for conditions that indicate we should loop |
| 3143 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3144 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3145 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3146 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3147 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3148 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3149 | int force_recode = 0; |
| 3150 | |
| 3151 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3152 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3153 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3154 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3155 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3156 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3157 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3158 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3159 | // Deal with frame undershoot and whether or not we are |
| 3160 | // below the automatically set cq level. |
| 3161 | if (q > oxcf->cq_level && |
| 3162 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3163 | force_recode = 1; |
| 3164 | } |
| 3165 | } |
| 3166 | } |
| 3167 | return force_recode; |
| 3168 | } |
| 3169 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3170 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3171 | |
| 3172 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3173 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3174 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3175 | char *file_name) { |
| 3176 | int h; |
| 3177 | FILE *f_ref = NULL; |
| 3178 | |
| 3179 | if (ref_buf == NULL) { |
| 3180 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3181 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3185 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3186 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | // --- Y --- |
| 3190 | for (h = 0; h < cm->height; ++h) { |
| 3191 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3192 | } |
| 3193 | // --- U --- |
| 3194 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3195 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3196 | f_ref); |
| 3197 | } |
| 3198 | // --- V --- |
| 3199 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3200 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3201 | f_ref); |
| 3202 | } |
| 3203 | |
| 3204 | fclose(f_ref); |
| 3205 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3206 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3209 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3210 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3211 | MV_REFERENCE_FRAME ref_frame; |
| 3212 | |
| 3213 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3214 | char file_name[256] = ""; |
| 3215 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3216 | cm->current_video_frame, ref_frame); |
| 3217 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3218 | } |
| 3219 | } |
| 3220 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3221 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3222 | // This function is used to shift the virtual indices of last reference frames |
| 3223 | // as follows: |
| 3224 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3225 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3226 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3227 | // TODO(isbs): shift the scaled indices as well |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3228 | int ref_frame; |
| 3229 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3230 | cpi->ref_fb_idx[ref_frame] = cpi->ref_fb_idx[ref_frame - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3231 | |
| 3232 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3233 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3234 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3235 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3236 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3237 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3241 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3242 | #if USE_GF16_MULTI_LAYER |
| 3243 | static void update_reference_frames_gf16(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3244 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3245 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3246 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3247 | if (cm->frame_type == KEY_FRAME) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3248 | for (int ref_frame = 0; ref_frame < REF_FRAMES; ++ref_frame) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3249 | ref_cnt_fb(pool->frame_bufs, |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3250 | &cm->ref_frame_map[cpi->ref_fb_idx[ref_frame]], |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3251 | cm->new_fb_idx); |
| 3252 | } |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3253 | } else { |
| 3254 | if (cpi->refresh_last_frame || cpi->refresh_golden_frame || |
| 3255 | cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame || |
| 3256 | cpi->refresh_alt_ref_frame) { |
| 3257 | assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES); |
| 3258 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx], |
| 3259 | cm->new_fb_idx); |
| 3260 | } |
| 3261 | |
| 3262 | // TODO(zoeliu): To handle cpi->interp_filter_selected[]. |
| 3263 | |
| 3264 | // For GF of 16, an additional ref frame index mapping needs to be handled |
| 3265 | // if this is the last frame to encode in the current GF group. |
| 3266 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3267 | if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE) |
| 3268 | av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1); |
| 3269 | } |
| 3270 | |
| 3271 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3272 | // Dump out all reference frame images. |
| 3273 | dump_ref_frame_images(cpi); |
| 3274 | #endif // DUMP_REF_FRAME_IMAGES |
| 3275 | } |
| 3276 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3277 | |
| 3278 | static void update_reference_frames(AV1_COMP *cpi) { |
| 3279 | AV1_COMMON *const cm = &cpi->common; |
| 3280 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3281 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3282 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3283 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3284 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3285 | #if USE_GF16_MULTI_LAYER |
| 3286 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3287 | update_reference_frames_gf16(cpi); |
| 3288 | return; |
| 3289 | } |
| 3290 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3291 | |
| 3292 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3293 | // At this point the new frame has been encoded. |
| 3294 | // If any buffer copy / swapping is signaled it should be done here. |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 3295 | if (cm->frame_type == KEY_FRAME || frame_is_sframe(cm)) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3296 | ref_cnt_fb(pool->frame_bufs, |
| 3297 | &cm->ref_frame_map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3298 | cm->new_fb_idx); |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3299 | ref_cnt_fb(pool->frame_bufs, |
| 3300 | &cm->ref_frame_map[cpi->ref_fb_idx[BWDREF_FRAME - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3301 | cm->new_fb_idx); |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3302 | ref_cnt_fb(pool->frame_bufs, |
| 3303 | &cm->ref_frame_map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]], |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3304 | cm->new_fb_idx); |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3305 | ref_cnt_fb(pool->frame_bufs, |
| 3306 | &cm->ref_frame_map[cpi->ref_fb_idx[ALTREF_FRAME - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3307 | cm->new_fb_idx); |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3308 | ref_cnt_fb(pool->frame_bufs, |
| 3309 | &cm->ref_frame_map[cpi->ref_fb_idx[REF_FRAMES - 1]], |
Imdad Sardharwalla | 53462b3 | 2018-03-13 18:10:49 +0000 | [diff] [blame] | 3310 | cm->new_fb_idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3311 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3312 | // We have decided to preserve the previously existing golden frame as our |
| 3313 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3314 | // 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] | 3315 | // we're updating the GF with the current decoded frame, we save it to the |
| 3316 | // ARF slot instead. |
| 3317 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3318 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3319 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3320 | int tmp; |
| 3321 | |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3322 | ref_cnt_fb(pool->frame_bufs, |
| 3323 | &cm->ref_frame_map[cpi->ref_fb_idx[ALTREF_FRAME - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3324 | cm->new_fb_idx); |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3325 | tmp = cpi->ref_fb_idx[ALTREF_FRAME - 1]; |
| 3326 | cpi->ref_fb_idx[ALTREF_FRAME - 1] = cpi->ref_fb_idx[GOLDEN_FRAME - 1]; |
| 3327 | cpi->ref_fb_idx[GOLDEN_FRAME - 1] = tmp; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3328 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3329 | // We need to modify the mapping accordingly |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3330 | cpi->arf_map[0] = cpi->ref_fb_idx[ALTREF_FRAME - 1]; |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3331 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3332 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3333 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 3334 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3335 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3336 | // by updating the virtual indices. |
| 3337 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3338 | const int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 3339 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3340 | |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3341 | const int tmp = cpi->ref_fb_idx[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3342 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3343 | |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3344 | cpi->ref_fb_idx[LAST_FRAME - 1] = cpi->ref_fb_idx[ALTREF2_FRAME - 1]; |
| 3345 | cpi->ref_fb_idx[ALTREF2_FRAME - 1] = tmp; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3346 | // We need to modify the mapping accordingly |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3347 | cpi->arf_map[which_arf] = cpi->ref_fb_idx[ALTREF2_FRAME - 1]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3348 | |
| 3349 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3350 | cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3351 | sizeof(cpi->interp_filter_selected[ALTREF2_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3352 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3353 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3354 | if (cpi->refresh_alt_ref_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3355 | int arf_idx = cpi->ref_fb_idx[ALTREF_FRAME - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3356 | int which_arf = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3357 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[arf_idx], cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3358 | |
| 3359 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3360 | cpi->interp_filter_selected[0], |
| 3361 | sizeof(cpi->interp_filter_selected[0])); |
| 3362 | } |
| 3363 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3364 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3365 | if (cpi->refresh_golden_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3366 | ref_cnt_fb(pool->frame_bufs, |
| 3367 | &cm->ref_frame_map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3368 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3369 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3370 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3371 | cpi->interp_filter_selected[0], |
| 3372 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3375 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3376 | if (cpi->refresh_bwd_ref_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3377 | ref_cnt_fb(pool->frame_bufs, |
| 3378 | &cm->ref_frame_map[cpi->ref_fb_idx[BWDREF_FRAME - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3379 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3380 | |
| 3381 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3382 | cpi->interp_filter_selected[0], |
| 3383 | sizeof(cpi->interp_filter_selected[0])); |
| 3384 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3385 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3386 | // === ALTREF2_FRAME === |
| 3387 | if (cpi->refresh_alt2_ref_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3388 | ref_cnt_fb(pool->frame_bufs, |
| 3389 | &cm->ref_frame_map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]], |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3390 | cm->new_fb_idx); |
| 3391 | |
| 3392 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3393 | cpi->interp_filter_selected[0], |
| 3394 | sizeof(cpi->interp_filter_selected[0])); |
| 3395 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | if (cpi->refresh_last_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3399 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3400 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3401 | // the virtual index to the reference frame buffer physical index: |
| 3402 | // |
| 3403 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3404 | // | | | |
| 3405 | // v v v |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3406 | // ref_fb_idx[0], ..., ref_fb_idx[2], ..., ref_fb_idx[ALTREF_FRAME-1] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3407 | // | | | |
| 3408 | // v v v |
| 3409 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3410 | // |
| 3411 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3412 | // have the other 2 LAST reference frames shifted as follows: |
| 3413 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3414 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3415 | // |
| 3416 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3417 | // |
| 3418 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3419 | // to point to the newly coded frame, i.e. |
| 3420 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3421 | // |
| 3422 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3423 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3424 | // shifted as follows: |
| 3425 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3426 | // | | | |
| 3427 | // v v v |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3428 | // ref_fb_idx[2], ref_fb_idx[0], ref_fb_idx[1] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3429 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3430 | |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 3431 | if (cm->frame_type == KEY_FRAME || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3432 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3433 | ref_cnt_fb(pool->frame_bufs, |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3434 | &cm->ref_frame_map[cpi->ref_fb_idx[ref_frame]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3435 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3436 | } |
| 3437 | } else { |
| 3438 | int tmp; |
| 3439 | |
| 3440 | ref_cnt_fb(pool->frame_bufs, |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3441 | &cm->ref_frame_map[cpi->ref_fb_idx[LAST_REF_FRAMES - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3442 | cm->new_fb_idx); |
| 3443 | |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3444 | tmp = cpi->ref_fb_idx[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3445 | |
| 3446 | shift_last_ref_frames(cpi); |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3447 | cpi->ref_fb_idx[0] = tmp; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3448 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3449 | assert(cm->show_existing_frame == 0); |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3450 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3451 | cpi->interp_filter_selected[0], |
| 3452 | sizeof(cpi->interp_filter_selected[0])); |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3453 | |
| 3454 | if (cpi->rc.is_last_bipred_frame) { |
| 3455 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3456 | // LAST3_FRAME by updating the virtual indices. |
| 3457 | // |
| 3458 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3459 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3460 | // virtual index reshuffling for BWDREF, the encoder always |
| 3461 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3462 | // reshuffling job accordingly. |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3463 | tmp = cpi->ref_fb_idx[LAST_REF_FRAMES - 1]; |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3464 | |
| 3465 | shift_last_ref_frames(cpi); |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3466 | cpi->ref_fb_idx[0] = cpi->ref_fb_idx[BWDREF_FRAME - 1]; |
| 3467 | cpi->ref_fb_idx[BWDREF_FRAME - 1] = tmp; |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3468 | |
| 3469 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3470 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3471 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
| 3472 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3473 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3477 | // Dump out all reference frame images. |
| 3478 | dump_ref_frame_images(cpi); |
| 3479 | #endif // DUMP_REF_FRAME_IMAGES |
| 3480 | } |
| 3481 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3482 | static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) { |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 3483 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3484 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3485 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3486 | new_fb_ptr->width = cm->width; |
| 3487 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3490 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3491 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3492 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3493 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3494 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3495 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 3496 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3497 | }; |
| 3498 | |
| 3499 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3500 | // 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] | 3501 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3502 | BufferPool *const pool = cm->buffer_pool; |
| 3503 | const YV12_BUFFER_CONFIG *const ref = |
| 3504 | get_ref_frame_buffer(cpi, ref_frame); |
| 3505 | |
| 3506 | if (ref == NULL) { |
| 3507 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3508 | continue; |
| 3509 | } |
| 3510 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3511 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3512 | RefCntBuffer *new_fb_ptr = NULL; |
| 3513 | int force_scaling = 0; |
| 3514 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3515 | if (new_fb == INVALID_IDX) { |
| 3516 | new_fb = get_free_fb(cm); |
| 3517 | force_scaling = 1; |
| 3518 | } |
| 3519 | if (new_fb == INVALID_IDX) return; |
| 3520 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3521 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3522 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3523 | if (aom_realloc_frame_buffer( |
| 3524 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 3525 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3526 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3527 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3528 | "Failed to allocate frame buffer"); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3529 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth, |
| 3530 | num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3531 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3532 | alloc_frame_mvs(cm, new_fb); |
| 3533 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3534 | } else { |
| 3535 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3536 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3537 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3538 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3539 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3540 | ++buf->ref_count; |
| 3541 | } |
| 3542 | } else { |
| 3543 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3544 | } |
| 3545 | } |
| 3546 | } |
| 3547 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3548 | static void release_scaled_references(AV1_COMP *cpi) { |
| 3549 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3550 | int i; |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3551 | // TODO(isbs): only refresh the necessary frames, rather than all of them |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 3552 | for (i = 0; i < REF_FRAMES; ++i) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3553 | const int idx = cpi->scaled_ref_idx[i]; |
| 3554 | RefCntBuffer *const buf = |
| 3555 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3556 | if (buf != NULL) { |
| 3557 | --buf->ref_count; |
| 3558 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3559 | } |
| 3560 | } |
| 3561 | } |
| 3562 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3563 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3564 | const AV1_COMMON *const cm = &cpi->common; |
| 3565 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3566 | |
| 3567 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3568 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3569 | |
| 3570 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3571 | if (frame_is_intra_only(cm)) { |
| 3572 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3573 | // after a key/intra-only frame. |
| 3574 | cpi->max_mv_magnitude = max_mv_def; |
| 3575 | } else { |
| 3576 | if (cm->show_frame) { |
| 3577 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3578 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3579 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3580 | cpi->mv_step_param = av1_init_search_range( |
| 3581 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3582 | } |
| 3583 | cpi->max_mv_magnitude = 0; |
| 3584 | } |
| 3585 | } |
| 3586 | } |
| 3587 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3588 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3589 | int i; |
| 3590 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3591 | cpi->common.global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3592 | } |
| 3593 | cpi->global_motion_search_done = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3594 | av1_set_speed_features_framesize_independent(cpi); |
| 3595 | av1_set_rd_speed_thresholds(cpi); |
| 3596 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3597 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 3598 | cpi->common.switchable_motion_mode = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3601 | 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] | 3602 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3603 | AV1_COMMON *const cm = &cpi->common; |
| 3604 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3605 | |
| 3606 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3607 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3608 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 3609 | // Decide q and q bounds. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3610 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 3611 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3612 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3613 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3614 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3615 | cpi->common.cur_frame_force_integer_mv); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3616 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3617 | |
| 3618 | // Configure experimental use of segmentation for enhanced coding of |
| 3619 | // static regions if indicated. |
| 3620 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3621 | // lagged coding, and if the relevant speed feature flag is set. |
| 3622 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3623 | configure_static_seg_features(cpi); |
| 3624 | } |
| 3625 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3626 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3627 | int y_stride = cpi->scaled_source.y_stride; |
| 3628 | |
| 3629 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3630 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3631 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3632 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3633 | } |
| 3634 | } |
| 3635 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3636 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3637 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 3638 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3639 | (void)width; |
| 3640 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3641 | (void)sx; |
| 3642 | (void)sy; |
| 3643 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3644 | int s = AOMMIN(sx, sy); |
| 3645 | #else |
| 3646 | int s = 0; |
| 3647 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3648 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3649 | if (width * height > 352 * 288) |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3650 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3651 | else |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3652 | rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3653 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 3654 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3655 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3656 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3657 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
| 3658 | int i; |
| 3659 | BufferPool *const pool = cm->buffer_pool; |
| 3660 | cm->new_fb_idx = INVALID_IDX; |
| 3661 | for (i = 0; i < REF_FRAMES; ++i) { |
| 3662 | cm->ref_frame_map[i] = INVALID_IDX; |
| 3663 | pool->frame_bufs[i].ref_count = 0; |
| 3664 | } |
RogerZhou | 86902d0 | 2018-02-28 15:29:16 -0800 | [diff] [blame] | 3665 | if (cm->seq_params.force_screen_content_tools) { |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 3666 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3667 | av1_hash_table_init(&pool->frame_bufs[i].hash_table); |
| 3668 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3669 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3670 | } |
| 3671 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 3672 | static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3673 | int subsampling_x, int subsampling_y) { |
| 3674 | AV1_COMMON *const cm = &cpi->common; |
| 3675 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 3676 | if (!cpi->initial_width || cm->use_highbitdepth != use_highbitdepth || |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3677 | cm->subsampling_x != subsampling_x || |
| 3678 | cm->subsampling_y != subsampling_y) { |
| 3679 | cm->subsampling_x = subsampling_x; |
| 3680 | cm->subsampling_y = subsampling_y; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3681 | cm->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3682 | |
| 3683 | alloc_raw_frame_buffers(cpi); |
| 3684 | init_ref_frame_bufs(cm); |
| 3685 | alloc_util_frame_buffers(cpi); |
| 3686 | |
| 3687 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 3688 | |
| 3689 | cpi->initial_width = cm->width; |
| 3690 | cpi->initial_height = cm->height; |
| 3691 | cpi->initial_mbs = cm->MBs; |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | // Returns 1 if the assigned width or height was <= 0. |
| 3696 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 3697 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3698 | const int num_planes = av1_num_planes(cm); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3699 | check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x, |
| 3700 | cm->subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3701 | |
| 3702 | if (width <= 0 || height <= 0) return 1; |
| 3703 | |
| 3704 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3705 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3706 | |
| 3707 | if (cpi->initial_width && cpi->initial_height && |
| 3708 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 3709 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3710 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3711 | alloc_compressor_data(cpi); |
| 3712 | realloc_segmentation_maps(cpi); |
| 3713 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3714 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3715 | update_frame_size(cpi); |
| 3716 | |
| 3717 | return 0; |
| 3718 | } |
| 3719 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3720 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3721 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3722 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3723 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3724 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3725 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3726 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 3727 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3728 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3729 | set_mv_search_params(cpi); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 3730 | // Recalculate 'all_lossless' in case super-resolution was (un)selected. |
| 3731 | cm->all_lossless = cm->coded_lossless && av1_superres_unscaled(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3734 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3735 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 3739 | |
| 3740 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3741 | 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] | 3742 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 3743 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3744 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3745 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3746 | "Failed to allocate frame buffer"); |
| 3747 | |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3748 | const int frame_width = cm->superres_upscaled_width; |
| 3749 | const int frame_height = cm->superres_upscaled_height; |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3750 | set_restoration_unit_size(frame_width, frame_height, cm->subsampling_x, |
| 3751 | cm->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3752 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 3753 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3754 | |
| 3755 | av1_alloc_restoration_buffers(cm); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 3756 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3757 | init_motion_estimation(cpi); |
| 3758 | |
| 3759 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3760 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3761 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3762 | |
| 3763 | ref_buf->idx = buf_idx; |
| 3764 | |
| 3765 | if (buf_idx != INVALID_IDX) { |
| 3766 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 3767 | ref_buf->buf = buf; |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 3768 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 3769 | buf->y_crop_height, cm->width, |
| 3770 | cm->height); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3771 | if (av1_is_scaled(&ref_buf->sf)) |
| 3772 | aom_extend_frame_borders(buf, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3773 | } else { |
| 3774 | ref_buf->buf = NULL; |
| 3775 | } |
| 3776 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3777 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 3778 | av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 3779 | cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3780 | |
| 3781 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3782 | } |
| 3783 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3784 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 3785 | // Choose an arbitrary random number |
| 3786 | static unsigned int seed = 56789; |
| 3787 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3788 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3789 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3790 | |
| 3791 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3792 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3793 | case RESIZE_FIXED: |
| 3794 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3795 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3796 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3797 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3798 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3799 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3800 | default: assert(0); |
| 3801 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3802 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3805 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 3806 | // Choose an arbitrary random number |
| 3807 | static unsigned int seed = 34567; |
| 3808 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3809 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3810 | uint8_t new_denom = SCALE_NUMERATOR; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3811 | |
| 3812 | // Make sure that superres mode of the frame is consistent with the |
| 3813 | // sequence-level flag. |
| 3814 | assert(IMPLIES(oxcf->superres_mode != SUPERRES_NONE, |
| 3815 | cpi->common.seq_params.enable_superres)); |
| 3816 | assert(IMPLIES(!cpi->common.seq_params.enable_superres, |
| 3817 | oxcf->superres_mode == SUPERRES_NONE)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3818 | |
| 3819 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3820 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3821 | case SUPERRES_FIXED: |
| 3822 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3823 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3824 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3825 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3826 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3827 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3828 | case SUPERRES_QTHRESH: { |
| 3829 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3830 | const RATE_FACTOR_LEVEL rf_level = gf_group->rf_level[gf_group->index]; |
| 3831 | const double rate_factor_delta = rate_factor_deltas[rf_level]; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3832 | const int qthresh = (rate_factor_delta <= 1.0) |
| 3833 | ? oxcf->superres_qthresh |
| 3834 | : oxcf->superres_kf_qthresh; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3835 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3836 | int bottom_index, top_index; |
| 3837 | const int q = av1_rc_pick_q_and_bounds( |
| 3838 | cpi, cpi->oxcf.width, cpi->oxcf.height, &bottom_index, &top_index); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3839 | if (q < qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3840 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3841 | } else { |
Urvang Joshi | 28983f7 | 2017-10-25 14:41:06 -0700 | [diff] [blame] | 3842 | const uint8_t min_denom = SCALE_NUMERATOR + 1; |
| 3843 | const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3; |
Imdad Sardharwalla | f6154fd | 2018-03-02 16:53:41 +0000 | [diff] [blame] | 3844 | |
| 3845 | if (q == qthresh) { |
| 3846 | new_denom = min_denom; |
| 3847 | } else if (denom_step == 0) { |
| 3848 | new_denom = SCALE_NUMERATOR << 1; |
| 3849 | } else { |
| 3850 | const uint8_t additional_denom = (q - qthresh) / denom_step; |
| 3851 | new_denom = |
| 3852 | AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1); |
| 3853 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3854 | } |
| 3855 | break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3856 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3857 | default: assert(0); |
| 3858 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3859 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3862 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 3863 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 3864 | } |
| 3865 | |
| 3866 | static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) { |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 3867 | // Only need to check the width, as scaling is horizontal only. |
| 3868 | (void)oheight; |
| 3869 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3870 | } |
| 3871 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3872 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3873 | SUPERRES_MODE superres_mode, int owidth, |
| 3874 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3875 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3876 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3877 | } |
| 3878 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 3879 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3880 | int resize_denom = |
| 3881 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 3882 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 3883 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3884 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3885 | // Alter superres scale as needed to enforce conformity. |
| 3886 | rsz->superres_denom = |
| 3887 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 3888 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 3889 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3890 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3891 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3892 | // Alter resize scale as needed to enforce conformity. |
| 3893 | resize_denom = |
| 3894 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3895 | rsz->resize_width = owidth; |
| 3896 | rsz->resize_height = oheight; |
| 3897 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3898 | resize_denom); |
| 3899 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 3900 | if (resize_denom > SCALE_NUMERATOR) { |
| 3901 | --resize_denom; |
| 3902 | rsz->resize_width = owidth; |
| 3903 | rsz->resize_height = oheight; |
| 3904 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 3905 | resize_denom); |
| 3906 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3907 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3908 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3909 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3910 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3911 | if (resize_denom > rsz->superres_denom) |
| 3912 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3913 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3914 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3915 | rsz->resize_width = owidth; |
| 3916 | rsz->resize_height = oheight; |
| 3917 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3918 | resize_denom); |
| 3919 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 3920 | (resize_denom > SCALE_NUMERATOR || |
| 3921 | rsz->superres_denom > SCALE_NUMERATOR)); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3922 | } else { // We are allowed to alter neither resize scale nor superres |
| 3923 | // scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3924 | return 0; |
| 3925 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3926 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3927 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3928 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3929 | // Calculates resize and superres params for next frame |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3930 | size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) { |
| 3931 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 3932 | size_params_type rsz = { oxcf->width, oxcf->height, SCALE_NUMERATOR }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3933 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3934 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3935 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 3936 | rsz.resize_width = cpi->resize_pending_width; |
| 3937 | rsz.resize_height = cpi->resize_pending_height; |
| 3938 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 3939 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3940 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3941 | rsz.resize_width = cpi->oxcf.width; |
| 3942 | rsz.resize_height = cpi->oxcf.height; |
| 3943 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3944 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3945 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3946 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3947 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 3948 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3949 | assert(0 && "Invalid scale parameters"); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3950 | return rsz; |
| 3951 | } |
| 3952 | |
| 3953 | static void setup_frame_size_from_params(AV1_COMP *cpi, size_params_type *rsz) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3954 | int encode_width = rsz->resize_width; |
| 3955 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3956 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3957 | AV1_COMMON *cm = &cpi->common; |
| 3958 | cm->superres_upscaled_width = encode_width; |
| 3959 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3960 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 3961 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 3962 | rsz->superres_denom); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3963 | set_frame_size(cpi, encode_width, encode_height); |
| 3964 | } |
| 3965 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3966 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3967 | size_params_type rsz = av1_calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3968 | setup_frame_size_from_params(cpi, &rsz); |
| 3969 | } |
| 3970 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3971 | static void superres_post_encode(AV1_COMP *cpi) { |
| 3972 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3973 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3974 | |
| 3975 | if (av1_superres_unscaled(cm)) return; |
| 3976 | |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 3977 | assert(cpi->oxcf.enable_superres); |
| 3978 | assert(!is_lossless_requested(&cpi->oxcf)); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 3979 | assert(!cm->all_lossless); |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 3980 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3981 | av1_superres_upscale(cm, NULL); |
| 3982 | |
| 3983 | // If regular resizing is occurring the source will need to be downscaled to |
| 3984 | // match the upscaled superres resolution. Otherwise the original source is |
| 3985 | // used. |
| 3986 | if (av1_resize_unscaled(cm)) { |
| 3987 | cpi->source = cpi->unscaled_source; |
| 3988 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 3989 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 3990 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 3991 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3992 | // Do downscale. cm->(width|height) has been updated by |
| 3993 | // av1_superres_upscale |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3994 | if (aom_realloc_frame_buffer( |
| 3995 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 3996 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 3997 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3998 | NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3999 | aom_internal_error( |
| 4000 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4001 | "Failed to reallocate scaled source buffer for superres"); |
| 4002 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4003 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4004 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4005 | (int)cm->bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4006 | cpi->source = &cpi->scaled_source; |
| 4007 | } |
| 4008 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4009 | |
| 4010 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4011 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4012 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4013 | |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4014 | assert(IMPLIES(is_lossless_requested(&cpi->oxcf), |
| 4015 | cm->coded_lossless && cm->all_lossless)); |
| 4016 | |
| 4017 | const int no_loopfilter = cm->coded_lossless || cm->large_scale_tile; |
| 4018 | const int no_cdef = |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 4019 | !cm->seq_params.enable_cdef || cm->coded_lossless || cm->large_scale_tile; |
| 4020 | const int no_restoration = !cm->seq_params.enable_restoration || |
| 4021 | cm->all_lossless || cm->large_scale_tile; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4022 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4023 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4024 | |
| 4025 | if (no_loopfilter) { |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4026 | lf->filter_level[0] = 0; |
| 4027 | lf->filter_level[1] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4028 | } else { |
| 4029 | struct aom_usec_timer timer; |
| 4030 | |
| 4031 | aom_clear_system_state(); |
| 4032 | |
| 4033 | aom_usec_timer_start(&timer); |
| 4034 | |
| 4035 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4036 | |
| 4037 | aom_usec_timer_mark(&timer); |
| 4038 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4039 | } |
| 4040 | |
Debargha Mukherjee | 2382b14 | 2018-02-26 14:31:32 -0800 | [diff] [blame] | 4041 | if (lf->filter_level[0] || lf->filter_level[1]) { |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4042 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0], |
| 4043 | lf->filter_level[1], 0, 0); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4044 | if (num_planes > 1) { |
| 4045 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, |
| 4046 | lf->filter_level_u, 1, 0); |
| 4047 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, |
| 4048 | lf->filter_level_v, 2, 0); |
| 4049 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4050 | } |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4051 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4052 | if (!no_restoration) |
| 4053 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4054 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4055 | if (no_cdef) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4056 | cm->cdef_bits = 0; |
| 4057 | cm->cdef_strengths[0] = 0; |
| 4058 | cm->nb_cdef_strengths = 1; |
Yunqing Wang | dad63d4 | 2017-12-08 12:45:07 -0800 | [diff] [blame] | 4059 | cm->cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4060 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4061 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4062 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
Debargha Mukherjee | d7338aa | 2017-11-04 07:34:50 -0700 | [diff] [blame] | 4063 | cpi->sf.fast_cdef_search); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4064 | |
| 4065 | // Apply the filter |
| 4066 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4067 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4068 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4069 | superres_post_encode(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4070 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4071 | if (no_restoration) { |
| 4072 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4073 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4074 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
| 4075 | } else { |
| 4076 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1); |
| 4077 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4078 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4079 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4080 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Rupert Swarbrick | 70c399e | 2017-12-12 09:47:49 +0000 | [diff] [blame] | 4081 | av1_loop_restoration_filter_frame(cm->frame_to_show, cm); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4082 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4083 | } |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4086 | static int encode_without_recode_loop(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4087 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4088 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4089 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4090 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4091 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4092 | set_size_independent_vars(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4093 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4094 | setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4095 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4096 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4097 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4098 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4099 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4100 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4101 | cpi->source = |
| 4102 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4103 | if (cpi->unscaled_last_source != NULL) |
| 4104 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4105 | &cpi->scaled_last_source); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4106 | cpi->source->buf_8bit_valid = 0; |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4107 | if (frame_is_intra_only(cm) == 0) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4108 | scale_references(cpi); |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4109 | } |
| 4110 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4111 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4112 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4113 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4114 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4115 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4116 | // exclusive. |
| 4117 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4118 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4119 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4120 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4121 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4122 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4123 | } |
| 4124 | apply_active_map(cpi); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4125 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4126 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4127 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4128 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4129 | } else { |
| 4130 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4131 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4132 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4133 | |
| 4134 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4135 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4136 | |
| 4137 | // Update some stats from cyclic refresh, and check if we should not update |
| 4138 | // golden reference, for 1 pass CBR. |
| 4139 | 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] | 4140 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4141 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4142 | |
| 4143 | // Update the skip mb flag probabilities based on the distribution |
| 4144 | // seen in the last encoder iteration. |
| 4145 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4146 | aom_clear_system_state(); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4147 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4150 | static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4151 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4152 | RATE_CONTROL *const rc = &cpi->rc; |
| 4153 | int bottom_index, top_index; |
| 4154 | int loop_count = 0; |
| 4155 | int loop_at_this_size = 0; |
| 4156 | int loop = 0; |
| 4157 | int overshoot_seen = 0; |
| 4158 | int undershoot_seen = 0; |
| 4159 | int frame_over_shoot_limit; |
| 4160 | int frame_under_shoot_limit; |
| 4161 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4162 | |
| 4163 | set_size_independent_vars(cpi); |
| 4164 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4165 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4166 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4167 | aom_clear_system_state(); |
| 4168 | setup_frame_size(cpi); |
| 4169 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4170 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4171 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4172 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4173 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4174 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4175 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4176 | set_mv_search_params(cpi); |
| 4177 | |
| 4178 | // Reset the loop state for new frame size. |
| 4179 | overshoot_seen = 0; |
| 4180 | undershoot_seen = 0; |
| 4181 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4182 | q_low = bottom_index; |
| 4183 | q_high = top_index; |
| 4184 | |
| 4185 | loop_at_this_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4186 | |
Urvang Joshi | 2a74cf2 | 2017-12-18 17:21:41 -0800 | [diff] [blame] | 4187 | // Decide frame size bounds first time through. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4188 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4189 | &frame_under_shoot_limit, |
| 4190 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4191 | } |
| 4192 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4193 | // if frame was scaled calculate global_motion_search again if already |
| 4194 | // done |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4195 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) |
| 4196 | if (cpi->source->y_crop_width != cm->width || |
| 4197 | cpi->source->y_crop_height != cm->height) |
| 4198 | cpi->global_motion_search_done = 0; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4199 | cpi->source = |
| 4200 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4201 | if (cpi->unscaled_last_source != NULL) |
| 4202 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4203 | &cpi->scaled_last_source); |
| 4204 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4205 | if (frame_is_intra_only(cm) == 0) { |
| 4206 | if (loop_count > 0) { |
| 4207 | release_scaled_references(cpi); |
| 4208 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4209 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4210 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4211 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4212 | |
| 4213 | if (loop_count == 0) setup_frame(cpi); |
| 4214 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4215 | // Base q-index may have changed, so we need to assign proper default coef |
| 4216 | // probs before every iteration. |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 4217 | if (cm->primary_ref_frame == PRIMARY_REF_NONE || |
| 4218 | cm->frame_refs[cm->primary_ref_frame].idx < 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4219 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 4220 | av1_setup_frame_contexts(cm); |
David Barker | fc91b39 | 2018-03-09 15:32:03 +0000 | [diff] [blame] | 4221 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4222 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4223 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4224 | // exclusive. |
| 4225 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4226 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4227 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4228 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4229 | } |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4230 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4231 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4232 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4233 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4234 | } else { |
| 4235 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4236 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4237 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4238 | |
| 4239 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4240 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4241 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4242 | |
| 4243 | // Update the skip mb flag probabilities based on the distribution |
| 4244 | // seen in the last encoder iteration. |
| 4245 | // update_base_skip_probs(cpi); |
| 4246 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4247 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4248 | |
| 4249 | // Dummy pack of the bitstream using up to date stats to get an |
| 4250 | // accurate estimate of output frame size to determine if we need |
| 4251 | // to recode. |
| 4252 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4253 | restore_coding_context(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4254 | |
| 4255 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 4256 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4257 | |
| 4258 | rc->projected_frame_size = (int)(*size) << 3; |
| 4259 | restore_coding_context(cpi); |
| 4260 | |
| 4261 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4262 | } |
| 4263 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4264 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4265 | loop = 0; |
| 4266 | } else { |
| 4267 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4268 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4269 | int last_q = q; |
| 4270 | int64_t kf_err; |
| 4271 | |
| 4272 | int64_t high_err_target = cpi->ambient_err; |
| 4273 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4274 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4275 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4276 | 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] | 4277 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4278 | 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] | 4279 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4280 | // Prevent possible divide by zero error below for perfect KF |
| 4281 | kf_err += !kf_err; |
| 4282 | |
| 4283 | // The key frame is not good enough or we can afford |
| 4284 | // to make it better without undue risk of popping. |
| 4285 | if ((kf_err > high_err_target && |
| 4286 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4287 | (kf_err > low_err_target && |
| 4288 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4289 | // Lower q_high |
| 4290 | q_high = q > q_low ? q - 1 : q_low; |
| 4291 | |
| 4292 | // Adjust Q |
| 4293 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4294 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4295 | } else if (kf_err < low_err_target && |
| 4296 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4297 | // The key frame is much better than the previous frame |
| 4298 | // Raise q_low |
| 4299 | q_low = q < q_high ? q + 1 : q_high; |
| 4300 | |
| 4301 | // Adjust Q |
| 4302 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4303 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | // Clamp Q to upper and lower limits: |
| 4307 | q = clamp(q, q_low, q_high); |
| 4308 | |
| 4309 | loop = q != last_q; |
| 4310 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4311 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4312 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4313 | // Is the projected frame size out of range and are we allowed |
| 4314 | // to attempt to recode. |
| 4315 | int last_q = q; |
| 4316 | int retries = 0; |
| 4317 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4318 | // Frame size out of permitted range: |
| 4319 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4320 | // Frame is too large |
| 4321 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4322 | // Special case if the projected size is > the max allowed. |
| 4323 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4324 | q_high = rc->worst_quality; |
| 4325 | |
| 4326 | // Raise Qlow as to at least the current value |
| 4327 | q_low = q < q_high ? q + 1 : q_high; |
| 4328 | |
| 4329 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4330 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4331 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4332 | |
| 4333 | q = (q_high + q_low + 1) / 2; |
| 4334 | } else { |
| 4335 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4336 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4337 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4338 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4339 | AOMMAX(q_high, top_index), cm->width, |
| 4340 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4341 | |
| 4342 | while (q < q_low && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4343 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4344 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4345 | AOMMAX(q_high, top_index), cm->width, |
| 4346 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4347 | retries++; |
| 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | overshoot_seen = 1; |
| 4352 | } else { |
| 4353 | // Frame is too small |
| 4354 | q_high = q > q_low ? q - 1 : q_low; |
| 4355 | |
| 4356 | if (overshoot_seen || loop_at_this_size > 1) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4357 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4358 | q = (q_high + q_low) / 2; |
| 4359 | } else { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4360 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4361 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4362 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4363 | // Special case reset for qlow for constrained quality. |
| 4364 | // This should only trigger where there is very substantial |
| 4365 | // undershoot on a frame and the auto cq level is above |
| 4366 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4367 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4368 | q_low = q; |
| 4369 | } |
| 4370 | |
| 4371 | while (q > q_high && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4372 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4373 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4374 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4375 | retries++; |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | undershoot_seen = 1; |
| 4380 | } |
| 4381 | |
| 4382 | // Clamp Q to upper and lower limits: |
| 4383 | q = clamp(q, q_low, q_high); |
| 4384 | |
| 4385 | loop = (q != last_q); |
| 4386 | } else { |
| 4387 | loop = 0; |
| 4388 | } |
| 4389 | } |
| 4390 | |
| 4391 | // Special case for overlay frame. |
| 4392 | if (rc->is_src_frame_alt_ref && |
| 4393 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4394 | loop = 0; |
| 4395 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4396 | if (recode_loop_test_global_motion(cpi)) { |
| 4397 | loop = 1; |
| 4398 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4399 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4400 | if (loop) { |
| 4401 | ++loop_count; |
| 4402 | ++loop_at_this_size; |
| 4403 | |
| 4404 | #if CONFIG_INTERNAL_STATS |
| 4405 | ++cpi->tot_recode_hits; |
| 4406 | #endif |
| 4407 | } |
| 4408 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4409 | |
| 4410 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4413 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4414 | const int *const map = cpi->common.ref_frame_map; |
| 4415 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4416 | // No.1 Priority: LAST_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4417 | const int last2_is_last = map[cpi->ref_fb_idx[1]] == map[cpi->ref_fb_idx[0]]; |
| 4418 | const int last3_is_last = map[cpi->ref_fb_idx[2]] == map[cpi->ref_fb_idx[0]]; |
| 4419 | const int gld_is_last = |
| 4420 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == map[cpi->ref_fb_idx[0]]; |
| 4421 | const int bwd_is_last = |
| 4422 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == map[cpi->ref_fb_idx[0]]; |
| 4423 | const int alt2_is_last = |
| 4424 | map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == map[cpi->ref_fb_idx[0]]; |
| 4425 | const int alt_is_last = |
| 4426 | map[cpi->ref_fb_idx[ALTREF_FRAME - 1]] == map[cpi->ref_fb_idx[0]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4427 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4428 | // No.2 Priority: ALTREF_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4429 | const int last2_is_alt = |
| 4430 | map[cpi->ref_fb_idx[1]] == map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4431 | const int last3_is_alt = |
| 4432 | map[cpi->ref_fb_idx[2]] == map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4433 | const int gld_is_alt = map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == |
| 4434 | map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4435 | const int bwd_is_alt = map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == |
| 4436 | map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4437 | const int alt2_is_alt = map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == |
| 4438 | map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4439 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4440 | // No.3 Priority: LAST2_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4441 | const int last3_is_last2 = map[cpi->ref_fb_idx[2]] == map[cpi->ref_fb_idx[1]]; |
| 4442 | const int gld_is_last2 = |
| 4443 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == map[cpi->ref_fb_idx[1]]; |
| 4444 | const int bwd_is_last2 = |
| 4445 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == map[cpi->ref_fb_idx[1]]; |
| 4446 | const int alt2_is_last2 = |
| 4447 | map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == map[cpi->ref_fb_idx[1]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4448 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4449 | // No.4 Priority: LAST3_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4450 | const int gld_is_last3 = |
| 4451 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == map[cpi->ref_fb_idx[2]]; |
| 4452 | const int bwd_is_last3 = |
| 4453 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == map[cpi->ref_fb_idx[2]]; |
| 4454 | const int alt2_is_last3 = |
| 4455 | map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == map[cpi->ref_fb_idx[2]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4456 | |
| 4457 | // No.5 Priority: GOLDEN_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4458 | const int bwd_is_gld = map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == |
| 4459 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]]; |
| 4460 | const int alt2_is_gld = map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == |
| 4461 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4462 | |
| 4463 | // No.6 Priority: BWDREF_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4464 | const int alt2_is_bwd = map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == |
| 4465 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4466 | |
| 4467 | // No.7 Priority: ALTREF2_FRAME |
| 4468 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 4469 | // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be |
| 4470 | // adjusted according to external encoder flags. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 4471 | int flags = cpi->ext_ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4472 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4473 | 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] | 4474 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4475 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4476 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4477 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4478 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4479 | if (last3_is_last || last3_is_alt || last3_is_last2) flags &= ~AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4480 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4481 | if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3) |
| 4482 | flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4483 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4484 | if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 || |
| 4485 | bwd_is_gld) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4486 | (flags & AOM_BWD_FLAG)) |
| 4487 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4488 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4489 | if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 || |
| 4490 | alt2_is_gld || alt2_is_bwd) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4491 | (flags & AOM_ALT2_FLAG)) |
| 4492 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4493 | |
| 4494 | return flags; |
| 4495 | } |
| 4496 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4497 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4498 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4499 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4500 | // Note: The overrides are valid only for the next frame passed |
| 4501 | // to encode_frame_to_data_rate() function |
Debargha Mukherjee | 52fb047 | 2018-03-29 15:48:11 -0700 | [diff] [blame] | 4502 | if (cpi->oxcf.s_frame_mode) cpi->common.frame_type = S_FRAME; |
| 4503 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4504 | if (cpi->ext_refresh_frame_context_pending) { |
| 4505 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 4506 | cpi->ext_refresh_frame_context_pending = 0; |
| 4507 | } |
| 4508 | if (cpi->ext_refresh_frame_flags_pending) { |
| 4509 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 4510 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 4511 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 4512 | cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame; |
| 4513 | cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4514 | cpi->ext_refresh_frame_flags_pending = 0; |
| 4515 | } |
| 4516 | } |
| 4517 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4518 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 4519 | InterpFilter ifilter; |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 4520 | int ref_total[REF_FRAMES] = { 0 }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4521 | MV_REFERENCE_FRAME ref; |
| 4522 | int mask = 0; |
| 4523 | int arf_idx = ALTREF_FRAME; |
| 4524 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4525 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
| 4526 | cpi->refresh_alt2_ref_frame) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4527 | return mask; |
| 4528 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4529 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 4530 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4531 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4532 | |
| 4533 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 4534 | if ((ref_total[LAST_FRAME] && |
| 4535 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4536 | (ref_total[LAST2_FRAME] == 0 || |
| 4537 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 4538 | ref_total[LAST2_FRAME]) && |
| 4539 | (ref_total[LAST3_FRAME] == 0 || |
| 4540 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 4541 | ref_total[LAST3_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4542 | (ref_total[GOLDEN_FRAME] == 0 || |
| 4543 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 4544 | ref_total[GOLDEN_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4545 | (ref_total[BWDREF_FRAME] == 0 || |
| 4546 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 4547 | ref_total[BWDREF_FRAME]) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4548 | (ref_total[ALTREF2_FRAME] == 0 || |
| 4549 | cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 < |
| 4550 | ref_total[ALTREF2_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4551 | (ref_total[ALTREF_FRAME] == 0 || |
| 4552 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 4553 | ref_total[ALTREF_FRAME])) |
| 4554 | mask |= 1 << ifilter; |
| 4555 | } |
| 4556 | return mask; |
| 4557 | } |
| 4558 | |
| 4559 | #define DUMP_RECON_FRAMES 0 |
| 4560 | |
| 4561 | #if DUMP_RECON_FRAMES == 1 |
| 4562 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4563 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4564 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4565 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4566 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4567 | if (recon_buf == NULL) { |
| 4568 | printf("Frame %d is not ready.\n", cm->current_video_frame); |
| 4569 | return; |
| 4570 | } |
| 4571 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 4572 | static const int flag_list[REF_FRAMES] = { 0, |
| 4573 | AOM_LAST_FLAG, |
| 4574 | AOM_LAST2_FLAG, |
| 4575 | AOM_LAST3_FLAG, |
| 4576 | AOM_GOLD_FLAG, |
| 4577 | AOM_BWD_FLAG, |
| 4578 | AOM_ALT2_FLAG, |
| 4579 | AOM_ALT_FLAG }; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4580 | printf( |
| 4581 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 4582 | "show_existing_frame=%d) " |
| 4583 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
| 4584 | cm->current_video_frame, cm->frame_offset, cm->show_frame, |
| 4585 | cm->show_existing_frame); |
| 4586 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4587 | const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 4588 | const int ref_offset = |
| 4589 | (buf_idx >= 0) |
| 4590 | ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset |
| 4591 | : -1; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 4592 | printf( |
| 4593 | " %d(%c-%d-%4.2f)", ref_offset, |
| 4594 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N', |
| 4595 | (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1, |
| 4596 | (buf_idx >= 0) ? rate_factor_deltas[cpi->frame_rf_level[buf_idx]] : -1); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4597 | } |
| 4598 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4599 | |
| 4600 | if (!cm->show_frame) { |
| 4601 | printf("Frame %d is a no show frame, so no image dump.\n", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4602 | cm->current_video_frame); |
| 4603 | return; |
| 4604 | } |
| 4605 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4606 | int h; |
| 4607 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4608 | FILE *f_recon = NULL; |
| 4609 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4610 | if (cm->current_video_frame == 0) { |
| 4611 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4612 | printf("Unable to open file %s to write.\n", file_name); |
| 4613 | return; |
| 4614 | } |
| 4615 | } else { |
| 4616 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4617 | printf("Unable to open file %s to append.\n", file_name); |
| 4618 | return; |
| 4619 | } |
| 4620 | } |
| 4621 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4622 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 4623 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
| 4624 | "refresh_alt_ref_frame=%d, rf_level=%d, " |
| 4625 | "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4626 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 4627 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4628 | cm->frame_offset, cm->show_frame, cm->show_existing_frame, |
| 4629 | cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame, |
| 4630 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 4631 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4632 | #if 0 |
| 4633 | int ref_frame; |
| 4634 | printf("get_ref_frame_map_idx: ["); |
| 4635 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 4636 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 4637 | printf(" ]\n"); |
| 4638 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 4639 | printf("cm->ref_frame_map = ["); |
| 4640 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4641 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 4642 | } |
| 4643 | printf(" ]\n"); |
| 4644 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4645 | |
| 4646 | // --- Y --- |
| 4647 | for (h = 0; h < cm->height; ++h) { |
| 4648 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4649 | f_recon); |
| 4650 | } |
| 4651 | // --- U --- |
| 4652 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4653 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4654 | f_recon); |
| 4655 | } |
| 4656 | // --- V --- |
| 4657 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4658 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4659 | f_recon); |
| 4660 | } |
| 4661 | |
| 4662 | fclose(f_recon); |
| 4663 | } |
| 4664 | #endif // DUMP_RECON_FRAMES |
| 4665 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4666 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 4667 | int skip_adapt, |
| 4668 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4669 | AV1_COMMON *const cm = &cpi->common; |
| 4670 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4671 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 4672 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4673 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4674 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4675 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 4676 | // frame type has been decided outside of this function call |
Zoe Liu | d78ce2d | 2018-02-24 05:50:57 -0800 | [diff] [blame] | 4677 | cm->cur_frame->intra_only = frame_is_intra_only(cm); |
Zoe Liu | 2723a9d | 2018-02-22 20:17:00 -0800 | [diff] [blame] | 4678 | cm->cur_frame->frame_type = cm->frame_type; |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 4679 | |
| 4680 | // S_FRAMEs are always error resilient |
| 4681 | cm->error_resilient_mode = oxcf->error_resilient_mode || frame_is_sframe(cm); |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 4682 | cm->allow_ref_frame_mvs = |
| 4683 | cpi->oxcf.allow_ref_frame_mvs && frame_might_allow_ref_frame_mvs(cm); |
Debargha Mukherjee | 1d7217e | 2018-03-26 13:32:13 -0700 | [diff] [blame] | 4684 | cm->allow_warped_motion = |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 4685 | cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4686 | |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 4687 | // Reset the frame packet stamp index. |
| 4688 | if (cm->frame_type == KEY_FRAME) cm->current_video_frame = 0; |
| 4689 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4690 | // NOTE: |
| 4691 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 4692 | // determined by the current frame properties; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4693 | // (2) The setup of the ref_frame_flags applies to both |
| 4694 | // show_existing_frame's |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4695 | // and the other cases. |
| 4696 | if (cm->current_video_frame > 0) |
| 4697 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 4698 | |
| 4699 | if (cm->show_existing_frame) { |
| 4700 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 4701 | // BWDREF_FRAME in the reference frame buffer. |
| 4702 | cm->frame_type = INTER_FRAME; |
| 4703 | cm->show_frame = 1; |
| 4704 | cpi->frame_flags = *frame_flags; |
| 4705 | |
| 4706 | // In the case of show_existing frame, we will not send fresh flag |
| 4707 | // to decoder. Any change in the reference frame buffer can be done by |
| 4708 | // switching the virtual indices. |
| 4709 | |
| 4710 | cpi->refresh_last_frame = 0; |
| 4711 | cpi->refresh_golden_frame = 0; |
| 4712 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4713 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4714 | cpi->refresh_alt_ref_frame = 0; |
| 4715 | |
| 4716 | cpi->rc.is_bwd_ref_frame = 0; |
| 4717 | cpi->rc.is_last_bipred_frame = 0; |
| 4718 | cpi->rc.is_bipred_frame = 0; |
| 4719 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4720 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4721 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4722 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4723 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 4724 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4725 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4726 | cpi->seq_params_locked = 1; |
| 4727 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4728 | // Set up frame to show to get ready for stats collection. |
| 4729 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 4730 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4731 | // Update current frame offset. |
| 4732 | cm->frame_offset = |
| 4733 | cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4734 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4735 | #if DUMP_RECON_FRAMES == 1 |
| 4736 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4737 | dump_filtered_recon_frames(cpi); |
| 4738 | #endif // DUMP_RECON_FRAMES |
| 4739 | |
| 4740 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4741 | // NOTE: |
| 4742 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 4743 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 4744 | // right before BWDREF_FRAME (in the display order); |
| 4745 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4746 | // update will be done when the following is called, which will |
| 4747 | // exchange |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4748 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4749 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, |
| 4750 | // and |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4751 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4752 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4753 | |
| 4754 | // Update frame flags |
| 4755 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 4756 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 4757 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 4758 | |
| 4759 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 4760 | |
| 4761 | // Update the frame type |
| 4762 | cm->last_frame_type = cm->frame_type; |
| 4763 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4764 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 4765 | // to do post-encoding update accordingly. |
| 4766 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4767 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4768 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4769 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4770 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4771 | ++cm->current_video_frame; |
| 4772 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4773 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4774 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4775 | |
| 4776 | // Set default state for segment based loop filter update flags. |
| 4777 | cm->lf.mode_ref_delta_update = 0; |
| 4778 | |
| 4779 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 4780 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 4781 | |
| 4782 | // Set various flags etc to special state if it is a key frame. |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 4783 | if (frame_is_intra_only(cm) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4784 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4785 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4786 | |
| 4787 | // If segmentation is enabled force a map update for key frames. |
| 4788 | if (seg->enabled) { |
| 4789 | seg->update_map = 1; |
| 4790 | seg->update_data = 1; |
| 4791 | } |
| 4792 | |
| 4793 | // The alternate reference frame cannot be active for a key frame. |
| 4794 | cpi->rc.source_alt_ref_active = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4795 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4796 | if (cpi->oxcf.mtu == 0) { |
| 4797 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 4798 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 4799 | // Use a default value for the purposes of weighting costs in probability |
| 4800 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4801 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 4802 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4803 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4804 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 4805 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | b6e23bc | 2017-11-15 13:18:55 -0800 | [diff] [blame] | 4806 | if (cm->large_scale_tile) cm->seq_params.frame_id_numbers_present_flag = 0; |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 4807 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4808 | // For 1 pass CBR, check if we are dropping this frame. |
| 4809 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4810 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4811 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4812 | if (av1_rc_drop_frame(cpi)) { |
| 4813 | av1_rc_postencode_update_drop_frame(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4814 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4815 | } |
| 4816 | } |
| 4817 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4818 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4819 | |
| 4820 | #if CONFIG_INTERNAL_STATS |
| 4821 | memset(cpi->mode_chosen_counts, 0, |
| 4822 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 4823 | #endif |
| 4824 | |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 4825 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4826 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 4827 | * wraparound) */ |
Sebastien Alaiwan | d418f68 | 2017-10-19 15:06:52 +0200 | [diff] [blame] | 4828 | const int frame_id_length = FRAME_ID_LENGTH; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4829 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4830 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4831 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4832 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4833 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 4834 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4835 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4836 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 4837 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4838 | } |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4839 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 4840 | |
| 4841 | // S_frame is meant for stitching different streams of different |
| 4842 | // resolutions together, so current_frame_id must be the |
| 4843 | // same across different streams of the same content current_frame_id |
| 4844 | // should be the same and not random. 0x37 is a chosen number as start |
| 4845 | // point |
| 4846 | if (cpi->oxcf.sframe_enabled) cm->current_frame_id = 0x37; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4847 | } else { |
| 4848 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4849 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 4850 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4851 | } |
| 4852 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4853 | |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 4854 | switch (cpi->oxcf.cdf_update_mode) { |
| 4855 | case 0: // No CDF update for any frames(4~6% compression loss). |
| 4856 | cm->disable_cdf_update = 1; |
| 4857 | break; |
| 4858 | case 1: // Enable CDF update for all frames. |
| 4859 | cm->disable_cdf_update = 0; |
| 4860 | break; |
| 4861 | case 2: |
| 4862 | // Strategically determine at which frames to do CDF update. |
| 4863 | // Currently only enable CDF update for all-intra and no-show frames(1.5% |
| 4864 | // compression loss). |
| 4865 | // TODO(huisu@google.com): design schemes for various trade-offs between |
| 4866 | // compression quality and decoding speed. |
Hui Su | b1b76b3 | 2018-02-27 15:24:48 -0800 | [diff] [blame] | 4867 | cm->disable_cdf_update = |
| 4868 | (frame_is_intra_only(cm) || !cm->show_frame) ? 0 : 1; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 4869 | break; |
| 4870 | } |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 4871 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4872 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4873 | if (encode_without_recode_loop(cpi) != AOM_CODEC_OK) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4874 | } else { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4875 | if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK) |
| 4876 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 4879 | cm->last_tile_cols = cm->tile_cols; |
| 4880 | cm->last_tile_rows = cm->tile_rows; |
| 4881 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4882 | #ifdef OUTPUT_YUV_SKINMAP |
| 4883 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4884 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4885 | } |
| 4886 | #endif // OUTPUT_YUV_SKINMAP |
| 4887 | |
| 4888 | // Special case code to reduce pulsing when key frames are forced at a |
| 4889 | // fixed interval. Note the reconstruction error if it is the frame before |
| 4890 | // the force key frame |
| 4891 | if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4892 | if (cm->use_highbitdepth) { |
| 4893 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4894 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4895 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4896 | 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] | 4897 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4898 | } |
| 4899 | |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 4900 | // If the encoder forced a KEY_FRAME decision or if frame is an S_FRAME |
| 4901 | if (cm->frame_type == KEY_FRAME || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4902 | cpi->refresh_last_frame = 1; |
| 4903 | } |
| 4904 | |
| 4905 | cm->frame_to_show = get_frame_new_buffer(cm); |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 4906 | cm->frame_to_show->color_primaries = cm->color_primaries; |
| 4907 | cm->frame_to_show->transfer_characteristics = cm->transfer_characteristics; |
| 4908 | cm->frame_to_show->matrix_coefficients = cm->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 4909 | cm->frame_to_show->monochrome = cm->seq_params.monochrome; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 4910 | cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4911 | cm->frame_to_show->color_range = cm->color_range; |
| 4912 | cm->frame_to_show->render_width = cm->render_width; |
| 4913 | cm->frame_to_show->render_height = cm->render_height; |
| 4914 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 4915 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 4916 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4917 | |
| 4918 | // Pick the loop filter level for the frame. |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 4919 | if (!(cm->allow_intrabc && NO_FILTER_FOR_IBC)) { |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 4920 | loopfilter_frame(cpi, cm); |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 4921 | } else { |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 4922 | cm->lf.filter_level[0] = 0; |
| 4923 | cm->lf.filter_level[1] = 0; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 4924 | cm->cdef_bits = 0; |
| 4925 | cm->cdef_strengths[0] = 0; |
| 4926 | cm->nb_cdef_strengths = 1; |
| 4927 | cm->cdef_uv_strengths[0] = 0; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 4928 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4929 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4930 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 4931 | } |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 4932 | |
| 4933 | // TODO(debargha): Fix mv search range on encoder side |
| 4934 | // aom_extend_frame_inner_borders(cm->frame_to_show, av1_num_planes(cm)); |
| 4935 | aom_extend_frame_borders(cm->frame_to_show, av1_num_planes(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4936 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 4937 | #ifdef OUTPUT_YUV_REC |
| 4938 | aom_write_one_yuv_frame(cm, cm->frame_to_show); |
| 4939 | #endif |
| 4940 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4941 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4942 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 4943 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4944 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4945 | cpi->seq_params_locked = 1; |
| 4946 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 4947 | if (skip_adapt) return AOM_CODEC_OK; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4948 | |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 4949 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4950 | int i; |
| 4951 | /* Update reference frame id values based on the value of refresh_mask */ |
| 4952 | for (i = 0; i < REF_FRAMES; i++) { |
| 4953 | if ((cm->refresh_mask >> i) & 1) { |
| 4954 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 4955 | } |
| 4956 | } |
| 4957 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4958 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4959 | #if DUMP_RECON_FRAMES == 1 |
| 4960 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4961 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4962 | #endif // DUMP_RECON_FRAMES |
| 4963 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 4964 | if (cm->seg.enabled) { |
| 4965 | if (cm->seg.update_map) { |
| 4966 | update_reference_segmentation_map(cpi); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4967 | } else if (cm->last_frame_seg_map) { |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 4968 | memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map, |
| 4969 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 4970 | } |
| 4971 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4972 | |
| 4973 | if (frame_is_intra_only(cm) == 0) { |
| 4974 | release_scaled_references(cpi); |
| 4975 | } |
| 4976 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4977 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4978 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 4979 | #if CONFIG_ENTROPY_STATS |
| 4980 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
| 4981 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4982 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 4983 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
| 4984 | *cm->fc = cpi->tile_data[cm->largest_tile_id].tctx; |
| 4985 | av1_reset_cdf_symbol_counters(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | if (cpi->refresh_golden_frame == 1) |
| 4989 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 4990 | else |
| 4991 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 4992 | |
| 4993 | if (cpi->refresh_alt_ref_frame == 1) |
| 4994 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 4995 | else |
| 4996 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 4997 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4998 | if (cpi->refresh_bwd_ref_frame == 1) |
| 4999 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5000 | else |
| 5001 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5002 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5003 | cm->last_frame_type = cm->frame_type; |
| 5004 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5005 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5006 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5007 | if (cm->frame_type == KEY_FRAME) { |
| 5008 | // Tell the caller that the frame was coded as a key frame |
| 5009 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5010 | } else { |
| 5011 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5012 | } |
| 5013 | |
| 5014 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5015 | // filter deltas. |
| 5016 | cm->seg.update_map = 0; |
| 5017 | cm->seg.update_data = 0; |
| 5018 | cm->lf.mode_ref_delta_update = 0; |
| 5019 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5020 | if (cm->show_frame) { |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5021 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that |
| 5022 | // are |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5023 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5024 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5025 | // Don't increment frame counters if this was an altref buffer |
| 5026 | // update not a real frame |
| 5027 | ++cm->current_video_frame; |
| 5028 | } |
| 5029 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5030 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5031 | if (cm->is_reference_frame) { |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5032 | // keep track of the last coded dimensions |
| 5033 | cm->last_width = cm->width; |
| 5034 | cm->last_height = cm->height; |
| 5035 | |
| 5036 | // reset to normal state now that we are done. |
| 5037 | cm->last_show_frame = cm->show_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5038 | } |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5039 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5040 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5041 | } |
| 5042 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5043 | static int Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5044 | int skip_adapt, unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5045 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5046 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5047 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5048 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5049 | } |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5050 | return encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5051 | } |
| 5052 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5053 | static int Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5054 | unsigned int *frame_flags) { |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 5055 | #if CONFIG_MISMATCH_DEBUG |
| 5056 | mismatch_move_frame_idx_w(); |
| 5057 | #endif |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 5058 | #if TXCOEFF_COST_TIMER |
| 5059 | AV1_COMMON *cm = &cpi->common; |
| 5060 | cm->txcoeff_cost_timer = 0; |
| 5061 | cm->txcoeff_cost_count = 0; |
| 5062 | #endif |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5063 | |
| 5064 | if (encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags) != |
| 5065 | AOM_CODEC_OK) { |
| 5066 | return AOM_CODEC_ERROR; |
| 5067 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5068 | |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 5069 | #if TXCOEFF_COST_TIMER |
| 5070 | cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer; |
| 5071 | fprintf(stderr, |
| 5072 | "\ntxb coeff cost block number: %ld, frame time: %ld, cum time %ld " |
| 5073 | "in us\n", |
| 5074 | cm->txcoeff_cost_count, cm->txcoeff_cost_timer, |
| 5075 | cm->cum_txcoeff_cost_timer); |
| 5076 | #endif |
| 5077 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5078 | // Do not do post-encoding update for those frames that do not have a spot |
| 5079 | // in |
| 5080 | // a gf group, but note that an OVERLAY frame always has a spot in a gf |
| 5081 | // group, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5082 | // even when show_existing_frame is used. |
| 5083 | 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] | 5084 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5085 | } |
| 5086 | check_show_existing_frame(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5087 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5090 | 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] | 5091 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5092 | int64_t end_time) { |
| 5093 | AV1_COMMON *const cm = &cpi->common; |
| 5094 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5095 | int res = 0; |
| 5096 | const int subsampling_x = sd->subsampling_x; |
| 5097 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5098 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5099 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5100 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5101 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5102 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5103 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5104 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5105 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5106 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5107 | aom_usec_timer_mark(&timer); |
| 5108 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5109 | |
Yaowu Xu | c1fdb4b | 2018-03-16 08:44:13 -0700 | [diff] [blame] | 5110 | if ((cm->profile == PROFILE_0) && !cm->seq_params.monochrome && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5111 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5112 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5113 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5114 | res = -1; |
| 5115 | } |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5116 | if ((cm->profile == PROFILE_1) && |
| 5117 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5118 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5119 | "Profile 1 requires 4:4:4 color format"); |
| 5120 | res = -1; |
| 5121 | } |
| 5122 | if ((cm->profile == PROFILE_2) && (cm->bit_depth <= AOM_BITS_10) && |
| 5123 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 5124 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 5125 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5126 | res = -1; |
| 5127 | } |
| 5128 | |
| 5129 | return res; |
| 5130 | } |
| 5131 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5132 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5133 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5134 | |
| 5135 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5136 | cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame || |
| 5137 | cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame || |
| 5138 | !cm->error_resilient_mode || cm->lf.mode_ref_delta_update || |
| 5139 | cm->seg.update_map || cm->seg.update_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5142 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5143 | const struct lookahead_entry *source) { |
| 5144 | int64_t this_duration; |
| 5145 | int step = 0; |
| 5146 | |
| 5147 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5148 | this_duration = source->ts_end - source->ts_start; |
| 5149 | step = 1; |
| 5150 | } else { |
| 5151 | int64_t last_duration = |
| 5152 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5153 | |
| 5154 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5155 | |
| 5156 | // do a step update if the duration changes by 10% |
| 5157 | if (last_duration) |
| 5158 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5159 | } |
| 5160 | |
| 5161 | if (this_duration) { |
| 5162 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5163 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5164 | } else { |
| 5165 | // Average this frame's rate into the last second's average |
| 5166 | // frame rate. If we haven't seen 1 second yet, then average |
| 5167 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5168 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5169 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5170 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5171 | avg_duration *= (interval - avg_duration + this_duration); |
| 5172 | avg_duration /= interval; |
| 5173 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5174 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5175 | } |
| 5176 | } |
| 5177 | cpi->last_time_stamp_seen = source->ts_start; |
| 5178 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5179 | } |
| 5180 | |
| 5181 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5182 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5183 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5184 | RATE_CONTROL *const rc = &cpi->rc; |
| 5185 | int arf_src_index = 0; |
| 5186 | if (is_altref_enabled(cpi)) { |
| 5187 | if (cpi->oxcf.pass == 2) { |
| 5188 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5189 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5190 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5191 | } |
| 5192 | } else if (rc->source_alt_ref_pending) { |
| 5193 | arf_src_index = rc->frames_till_gf_update_due; |
| 5194 | } |
| 5195 | } |
| 5196 | return arf_src_index; |
| 5197 | } |
| 5198 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5199 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5200 | int brf_src_index = 0; |
| 5201 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5202 | |
| 5203 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5204 | // flag. |
| 5205 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5206 | if (cpi->oxcf.pass == 2) { |
| 5207 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5208 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5209 | } else { |
| 5210 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5211 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5212 | } |
| 5213 | } |
| 5214 | |
| 5215 | return brf_src_index; |
| 5216 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5217 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5218 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5219 | // used as the arf midpoint. |
| 5220 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5221 | int arf2_src_index = 0; |
| 5222 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5223 | if (cpi->oxcf.pass == 2) { |
| 5224 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5225 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 5226 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5227 | } |
| 5228 | } |
| 5229 | } |
| 5230 | return arf2_src_index; |
| 5231 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5232 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5233 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5234 | const struct lookahead_entry *source) { |
| 5235 | RATE_CONTROL *const rc = &cpi->rc; |
| 5236 | |
| 5237 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5238 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5239 | |
| 5240 | if (cpi->oxcf.pass == 2) { |
| 5241 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5242 | rc->is_src_frame_alt_ref = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5243 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5244 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5245 | rc->is_src_frame_ext_arf = |
| 5246 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5247 | } else { |
| 5248 | rc->is_src_frame_alt_ref = |
| 5249 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5250 | } |
| 5251 | |
| 5252 | if (rc->is_src_frame_alt_ref) { |
| 5253 | // Current frame is an ARF overlay frame. |
| 5254 | cpi->alt_ref_source = NULL; |
| 5255 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5256 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 5257 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 5258 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 5259 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 5260 | cpi->refresh_last_frame = 1; |
| 5261 | } else { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5262 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 5263 | // become the GF so preserve last as an alternative prediction option. |
| 5264 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5265 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5266 | } |
| 5267 | } |
| 5268 | |
| 5269 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5270 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5271 | const unsigned char *img2, int img2_pitch, |
| 5272 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5273 | |
| 5274 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5275 | ImageStat *s) { |
| 5276 | s->stat[Y] += y; |
| 5277 | s->stat[U] += u; |
| 5278 | s->stat[V] += v; |
| 5279 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5280 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5281 | } |
| 5282 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5283 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5284 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5285 | double samples = 0.0; |
| 5286 | uint32_t in_bit_depth = 8; |
| 5287 | uint32_t bit_depth = 8; |
| 5288 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5289 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 5290 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5291 | #endif |
| 5292 | cpi->bytes += frame_bytes; |
| 5293 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5294 | if (cm->use_highbitdepth) { |
| 5295 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 5296 | bit_depth = cm->bit_depth; |
| 5297 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5298 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5299 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5300 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 5301 | double y, u, v, frame_all; |
| 5302 | |
| 5303 | cpi->count++; |
| 5304 | if (cpi->b_calculate_psnr) { |
| 5305 | PSNR_STATS psnr; |
| 5306 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5307 | aom_clear_system_state(); |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5308 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5309 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5310 | |
| 5311 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5312 | &cpi->psnr); |
| 5313 | cpi->total_sq_error += psnr.sse[0]; |
| 5314 | cpi->total_samples += psnr.samples[0]; |
| 5315 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5316 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5317 | if (cm->use_highbitdepth) |
| 5318 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5319 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5320 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5321 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5322 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5323 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5324 | cpi->summed_quality += frame_ssim2 * weight; |
| 5325 | cpi->summed_weights += weight; |
| 5326 | |
| 5327 | #if 0 |
| 5328 | { |
| 5329 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 5330 | double y2 = psnr.psnr[1]; |
| 5331 | double u2 = psnr.psnr[2]; |
| 5332 | double v2 = psnr.psnr[3]; |
| 5333 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5334 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 5335 | cm->current_video_frame, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5336 | frame_psnr2, frame_ssim2); |
| 5337 | fclose(f); |
| 5338 | } |
| 5339 | #endif |
| 5340 | } |
| 5341 | if (cpi->b_calculate_blockiness) { |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5342 | if (!cm->use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5343 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5344 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5345 | recon->y_stride, orig->y_width, orig->y_height); |
| 5346 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5347 | cpi->total_blockiness += frame_blockiness; |
| 5348 | } |
| 5349 | |
| 5350 | if (cpi->b_calculate_consistency) { |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5351 | if (!cm->use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5352 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5353 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5354 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5355 | |
| 5356 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5357 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5358 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5359 | if (consistency > 0.0) |
| 5360 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5361 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5362 | cpi->total_inconsistency += this_inconsistency; |
| 5363 | } |
| 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5368 | 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] | 5369 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5370 | 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] | 5371 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5372 | } |
| 5373 | } |
| 5374 | #endif // CONFIG_INTERNAL_STATS |
| 5375 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5376 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 5377 | const YV12_BUFFER_CONFIG *last_picture, |
| 5378 | hash_table *last_hash_table) { |
| 5379 | aom_clear_system_state(); |
| 5380 | // check use hash ME |
| 5381 | int k; |
| 5382 | uint32_t hash_value_1; |
| 5383 | uint32_t hash_value_2; |
| 5384 | |
| 5385 | const int block_size = 8; |
| 5386 | const double threshold_current = 0.8; |
| 5387 | const double threshold_average = 0.95; |
| 5388 | const int max_history_size = 32; |
| 5389 | int T = 0; // total block |
| 5390 | int C = 0; // match with collocated block |
| 5391 | int S = 0; // smooth region but not match with collocated block |
| 5392 | int M = 0; // match with other block |
| 5393 | |
| 5394 | const int pic_width = cur_picture->y_width; |
| 5395 | const int pic_height = cur_picture->y_height; |
| 5396 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 5397 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 5398 | const int x_pos = j; |
| 5399 | const int y_pos = i; |
| 5400 | int match = 1; |
| 5401 | T++; |
| 5402 | |
| 5403 | // check whether collocated block match with current |
| 5404 | uint8_t *p_cur = cur_picture->y_buffer; |
| 5405 | uint8_t *p_ref = last_picture->y_buffer; |
| 5406 | int stride_cur = cur_picture->y_stride; |
| 5407 | int stride_ref = last_picture->y_stride; |
| 5408 | p_cur += (y_pos * stride_cur + x_pos); |
| 5409 | p_ref += (y_pos * stride_ref + x_pos); |
| 5410 | |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5411 | if (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5412 | uint16_t *p16_cur = CONVERT_TO_SHORTPTR(p_cur); |
| 5413 | uint16_t *p16_ref = CONVERT_TO_SHORTPTR(p_ref); |
| 5414 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5415 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5416 | if (p16_cur[tmpX] != p16_ref[tmpX]) { |
| 5417 | match = 0; |
| 5418 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5419 | } |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5420 | p16_cur += stride_cur; |
| 5421 | p16_ref += stride_ref; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5422 | } |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5423 | } else { |
| 5424 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5425 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5426 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 5427 | match = 0; |
| 5428 | } |
| 5429 | } |
| 5430 | p_cur += stride_cur; |
| 5431 | p_ref += stride_ref; |
| 5432 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | if (match) { |
| 5436 | C++; |
| 5437 | continue; |
| 5438 | } |
| 5439 | |
| 5440 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 5441 | y_pos) || |
| 5442 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 5443 | S++; |
| 5444 | continue; |
| 5445 | } |
| 5446 | |
| 5447 | av1_get_block_hash_value( |
| 5448 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5449 | block_size, &hash_value_1, &hash_value_2, |
| 5450 | (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH)); |
| 5451 | // Hashing does not work for highbitdepth currently. |
| 5452 | // TODO(Roger): Make it work for highbitdepth. |
| 5453 | if (av1_use_hash_me(&cpi->common)) { |
| 5454 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 5455 | M++; |
| 5456 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5457 | } |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | assert(T > 0); |
| 5462 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 5463 | double m_rate = ((double)(M)) / ((double)(T)); |
| 5464 | |
| 5465 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 5466 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 5467 | |
| 5468 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 5469 | cpi->rate_size++; |
| 5470 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 5471 | |
| 5472 | if (csm_rate < threshold_current) { |
| 5473 | return 0; |
| 5474 | } |
| 5475 | |
| 5476 | if (C == T) { |
| 5477 | return 1; |
| 5478 | } |
| 5479 | |
| 5480 | double csm_average = 0.0; |
| 5481 | double m_average = 0.0; |
| 5482 | |
| 5483 | for (k = 0; k < cpi->rate_size; k++) { |
| 5484 | csm_average += cpi->csm_rate_array[k]; |
| 5485 | m_average += cpi->m_rate_array[k]; |
| 5486 | } |
| 5487 | csm_average /= cpi->rate_size; |
| 5488 | m_average /= cpi->rate_size; |
| 5489 | |
| 5490 | if (csm_average < threshold_average) { |
| 5491 | return 0; |
| 5492 | } |
| 5493 | |
| 5494 | if (M > (T - C - S) / 3) { |
| 5495 | return 1; |
| 5496 | } |
| 5497 | |
| 5498 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 5499 | return 1; |
| 5500 | } |
| 5501 | |
| 5502 | if (csm_average + m_average > 1.01) { |
| 5503 | return 1; |
| 5504 | } |
| 5505 | |
| 5506 | return 0; |
| 5507 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5508 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5509 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 5510 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 5511 | int64_t *time_end, int flush) { |
| 5512 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5513 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5514 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5515 | BufferPool *const pool = cm->buffer_pool; |
| 5516 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5517 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5518 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 5519 | struct lookahead_entry *last_source = NULL; |
| 5520 | struct lookahead_entry *source = NULL; |
| 5521 | int arf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5522 | int brf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5523 | int i; |
| 5524 | |
| 5525 | #if CONFIG_BITSTREAM_DEBUG |
| 5526 | assert(cpi->oxcf.max_threads == 0 && |
| 5527 | "bitstream debug tool does not support multithreading"); |
| 5528 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 5529 | 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] | 5530 | #endif |
| 5531 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5532 | cm->showable_frame = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5533 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5534 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5535 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5536 | |
| 5537 | // Is multi-arf enabled. |
| 5538 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 5539 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 5540 | cpi->multi_arf_allowed = 1; |
| 5541 | else |
| 5542 | cpi->multi_arf_allowed = 0; |
| 5543 | |
Debargha Mukherjee | ba7b8fe | 2018-03-15 23:10:07 -0700 | [diff] [blame] | 5544 | // Normal defaults |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5545 | cm->refresh_frame_context = |
| 5546 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 5547 | ? REFRESH_FRAME_CONTEXT_DISABLED |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5548 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 5549 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 5550 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5551 | |
| 5552 | cpi->refresh_last_frame = 1; |
| 5553 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5554 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5555 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5556 | cpi->refresh_alt_ref_frame = 0; |
| 5557 | |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 5558 | // TODO(zoeliu@gmail.com): To support forward-KEY_FRAME and set up the |
| 5559 | // following flag accordingly. |
| 5560 | cm->reset_decoder_state = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 5561 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5562 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 5563 | // Manage the source buffer and flush out the source frame that has been |
| 5564 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5565 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5566 | *size = 0; |
| 5567 | return -1; |
| 5568 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5569 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5570 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 5571 | // the frame rate. |
| 5572 | *time_stamp = source->ts_start; |
| 5573 | *time_end = source->ts_end; |
| 5574 | |
| 5575 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5576 | 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] | 5577 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5578 | // Find a free buffer for the new frame, releasing the reference |
| 5579 | // previously |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5580 | // held. |
| 5581 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5582 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5583 | } |
| 5584 | cm->new_fb_idx = get_free_fb(cm); |
| 5585 | |
| 5586 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5587 | |
| 5588 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5589 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5590 | |
| 5591 | // Start with a 0 size frame. |
| 5592 | *size = 0; |
| 5593 | |
| 5594 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5595 | 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] | 5596 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5597 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 5598 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5599 | |
| 5600 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 5601 | |
| 5602 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5603 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5604 | #endif // CONFIG_INTERNAL_STATS |
| 5605 | |
| 5606 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5607 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5608 | |
| 5609 | cm->show_existing_frame = 0; |
| 5610 | return 0; |
| 5611 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5612 | |
| 5613 | // Should we encode an arf frame. |
| 5614 | arf_src_index = get_arf_src_index(cpi); |
| 5615 | if (arf_src_index) { |
| 5616 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5617 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5618 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5619 | if (e == NULL) { |
| 5620 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5621 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5622 | arf_src_index = 0; |
| 5623 | flush = 1; |
| 5624 | break; |
| 5625 | } |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | if (arf_src_index) { |
| 5630 | assert(arf_src_index <= rc->frames_to_key); |
| 5631 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5632 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5633 | cm->showable_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5634 | cpi->alt_ref_source = source; |
| 5635 | |
| 5636 | if (oxcf->arnr_max_frames > 0) { |
Sebastien Alaiwan | 6697acf | 2018-02-21 16:59:17 +0100 | [diff] [blame] | 5637 | // Produce the filtered ARF frame. |
| 5638 | av1_temporal_filter(cpi, arf_src_index); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5639 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5640 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5641 | } |
| 5642 | |
| 5643 | cm->show_frame = 0; |
| 5644 | cm->intra_only = 0; |
| 5645 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5646 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5647 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5648 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5649 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5650 | rc->is_src_frame_alt_ref = 0; |
| 5651 | } |
| 5652 | rc->source_alt_ref_pending = 0; |
| 5653 | } |
| 5654 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5655 | // Should we encode an arf2 frame. |
| 5656 | arf_src_index = get_arf2_src_index(cpi); |
| 5657 | if (arf_src_index) { |
| 5658 | for (i = 0; i <= arf_src_index; ++i) { |
| 5659 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 5660 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5661 | if (e == NULL) { |
| 5662 | break; |
| 5663 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 5664 | arf_src_index = 0; |
| 5665 | flush = 1; |
| 5666 | break; |
| 5667 | } |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | if (arf_src_index) { |
| 5672 | assert(arf_src_index <= rc->frames_to_key); |
| 5673 | |
| 5674 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5675 | cm->showable_frame = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5676 | cpi->alt_ref_source = source; |
| 5677 | |
| 5678 | if (oxcf->arnr_max_frames > 0) { |
| 5679 | // Produce the filtered ARF frame. |
Sebastien Alaiwan | 6697acf | 2018-02-21 16:59:17 +0100 | [diff] [blame] | 5680 | av1_temporal_filter(cpi, arf_src_index); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5681 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5682 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5683 | } |
| 5684 | |
| 5685 | cm->show_frame = 0; |
| 5686 | cm->intra_only = 0; |
| 5687 | cpi->refresh_alt2_ref_frame = 1; |
| 5688 | cpi->refresh_last_frame = 0; |
| 5689 | cpi->refresh_golden_frame = 0; |
| 5690 | cpi->refresh_bwd_ref_frame = 0; |
| 5691 | cpi->refresh_alt_ref_frame = 0; |
| 5692 | rc->is_src_frame_alt_ref = 0; |
| 5693 | rc->is_src_frame_ext_arf = 0; |
| 5694 | } |
| 5695 | rc->source_alt_ref_pending = 0; |
| 5696 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5697 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5698 | rc->is_bwd_ref_frame = 0; |
| 5699 | brf_src_index = get_brf_src_index(cpi); |
| 5700 | if (brf_src_index) { |
| 5701 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5702 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5703 | cm->showable_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5704 | cm->show_frame = 0; |
| 5705 | cm->intra_only = 0; |
| 5706 | |
| 5707 | cpi->refresh_bwd_ref_frame = 1; |
| 5708 | cpi->refresh_last_frame = 0; |
| 5709 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5710 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5711 | cpi->refresh_alt_ref_frame = 0; |
| 5712 | |
| 5713 | rc->is_bwd_ref_frame = 1; |
| 5714 | } |
| 5715 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5716 | |
| 5717 | if (!source) { |
| 5718 | // Get last frame source. |
| 5719 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5720 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5721 | return -1; |
| 5722 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5723 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5724 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5725 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5726 | |
| 5727 | if (source != NULL) { |
| 5728 | cm->show_frame = 1; |
| 5729 | cm->intra_only = 0; |
| 5730 | |
| 5731 | // Check to see if the frame should be encoded as an arf overlay. |
| 5732 | check_src_altref(cpi, source); |
| 5733 | } |
| 5734 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5735 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5736 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5737 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5738 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 5739 | |
| 5740 | *time_stamp = source->ts_start; |
| 5741 | *time_end = source->ts_end; |
Sarah Parker | 7355677 | 2018-03-28 18:28:05 -0700 | [diff] [blame] | 5742 | av1_apply_encoding_flags(cpi, source->flags); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5743 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5744 | |
| 5745 | } else { |
| 5746 | *size = 0; |
| 5747 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5748 | av1_end_first_pass(cpi); /* get last stats packet */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5749 | cpi->twopass.first_pass_done = 1; |
| 5750 | } |
| 5751 | return -1; |
| 5752 | } |
| 5753 | |
| 5754 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 5755 | cpi->first_time_stamp_ever = source->ts_start; |
| 5756 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 5757 | } |
| 5758 | |
| 5759 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5760 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5761 | |
| 5762 | // adjust frame rates based on timestamps given |
| 5763 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 5764 | |
| 5765 | // Find a free buffer for the new frame, releasing the reference previously |
| 5766 | // held. |
| 5767 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5768 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5769 | } |
| 5770 | cm->new_fb_idx = get_free_fb(cm); |
| 5771 | |
| 5772 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5773 | |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 5774 | // Retain the RF_LEVEL for the current newly coded frame. |
| 5775 | cpi->frame_rf_level[cm->new_fb_idx] = |
| 5776 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index]; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 5777 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5778 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5779 | cm->cur_frame->buf.buf_8bit_valid = 0; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 5780 | |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 5781 | if (cm->film_grain_table) { |
| 5782 | cm->film_grain_params_present = aom_film_grain_table_lookup( |
| 5783 | cm->film_grain_table, *time_stamp, *time_end, 0 /* erase */, |
| 5784 | &cm->film_grain_params); |
| 5785 | } |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5786 | cm->cur_frame->film_grain_params_present = cm->film_grain_params_present; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5787 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5788 | // Start with a 0 size frame. |
| 5789 | *size = 0; |
| 5790 | |
| 5791 | cpi->frame_flags = *frame_flags; |
| 5792 | |
| 5793 | if (oxcf->pass == 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5794 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5795 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 5796 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 5800 | for (i = 0; i < REF_FRAMES; ++i) cpi->scaled_ref_idx[i] = INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5801 | } |
| 5802 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5803 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 5804 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 5805 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5806 | |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5807 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 5808 | if (*time_stamp == 0) { |
| 5809 | cpi->common.current_frame_id = -1; |
| 5810 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5811 | } |
Zoe Liu | ca0cd3f | 2018-02-26 15:07:50 -0800 | [diff] [blame] | 5812 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5813 | cpi->cur_poc++; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 5814 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools && |
| 5815 | !frame_is_intra_only(cm)) { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 5816 | if (cpi->common.seq_params.force_integer_mv == 2) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5817 | struct lookahead_entry *previous_entry = |
Debargha Mukherjee | a71e3db | 2018-02-28 07:47:17 -0800 | [diff] [blame] | 5818 | av1_lookahead_peek(cpi->lookahead, cpi->previous_index); |
| 5819 | if (!previous_entry) |
| 5820 | cpi->common.cur_frame_force_integer_mv = 0; |
| 5821 | else |
| 5822 | cpi->common.cur_frame_force_integer_mv = is_integer_mv( |
| 5823 | cpi, cpi->source, &previous_entry->img, cpi->previous_hash_table); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5824 | } else { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 5825 | cpi->common.cur_frame_force_integer_mv = |
| 5826 | cpi->common.seq_params.force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5827 | } |
| 5828 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 5829 | cpi->common.cur_frame_force_integer_mv = 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5830 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5831 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5832 | if (oxcf->pass == 1) { |
| 5833 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5834 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5835 | } else if (oxcf->pass == 2) { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5836 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 5837 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5838 | } else { |
| 5839 | // One pass encode |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5840 | if (Pass0Encode(cpi, size, dest, 0, frame_flags) != AOM_CODEC_OK) |
| 5841 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5842 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 5843 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 5844 | cpi->previous_hash_table = &cm->cur_frame->hash_table; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5845 | { |
| 5846 | int l; |
| 5847 | for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) { |
| 5848 | if ((cpi->lookahead->buf + l) == source) { |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 5849 | cpi->previous_index = l; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5850 | break; |
| 5851 | } |
| 5852 | } |
| 5853 | |
| 5854 | if (l == cpi->lookahead->max_sz) { |
| 5855 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5856 | "Failed to find last frame original buffer"); |
| 5857 | } |
| 5858 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 5859 | } |
| 5860 | |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 5861 | if (!cm->large_scale_tile) { |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 5862 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 5863 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5864 | |
Yunqing Wang | b041d8a | 2017-11-15 12:31:18 -0800 | [diff] [blame] | 5865 | #define EXT_TILE_DEBUG 0 |
| 5866 | #if EXT_TILE_DEBUG |
| 5867 | if (cm->large_scale_tile && oxcf->pass == 2) { |
| 5868 | char fn[20] = "./fc"; |
| 5869 | fn[4] = cm->current_video_frame / 100 + '0'; |
| 5870 | fn[5] = (cm->current_video_frame % 100) / 10 + '0'; |
| 5871 | fn[6] = (cm->current_video_frame % 10) + '0'; |
| 5872 | fn[7] = '\0'; |
| 5873 | av1_print_frame_contexts(cm->fc, fn); |
| 5874 | } |
| 5875 | #endif // EXT_TILE_DEBUG |
| 5876 | #undef EXT_TILE_DEBUG |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 5877 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5878 | cm->showable_frame = !cm->show_frame && cm->showable_frame; |
Yunqing Wang | b041d8a | 2017-11-15 12:31:18 -0800 | [diff] [blame] | 5879 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5880 | // No frame encoded, or frame was dropped, release scaled references. |
| 5881 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 5882 | release_scaled_references(cpi); |
| 5883 | } |
| 5884 | |
| 5885 | if (*size > 0) { |
| 5886 | cpi->droppable = !frame_is_reference(cpi); |
| 5887 | } |
| 5888 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5889 | aom_usec_timer_mark(&cmptimer); |
| 5890 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5891 | |
| 5892 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 5893 | generate_psnr_packet(cpi); |
| 5894 | |
| 5895 | #if CONFIG_INTERNAL_STATS |
| 5896 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5897 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5898 | } |
| 5899 | #endif // CONFIG_INTERNAL_STATS |
| 5900 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5901 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5902 | |
| 5903 | return 0; |
| 5904 | } |
| 5905 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5906 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 5907 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5908 | if (!cm->show_frame) { |
| 5909 | return -1; |
| 5910 | } else { |
| 5911 | int ret; |
| 5912 | if (cm->frame_to_show) { |
| 5913 | *dest = *cm->frame_to_show; |
| 5914 | dest->y_width = cm->width; |
| 5915 | dest->y_height = cm->height; |
| 5916 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 5917 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 5918 | ret = 0; |
| 5919 | } else { |
| 5920 | ret = -1; |
| 5921 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5922 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5923 | return ret; |
| 5924 | } |
| 5925 | } |
| 5926 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5927 | 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] | 5928 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 5929 | |
| 5930 | *frame = |
| 5931 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 5932 | return 0; |
| 5933 | } |
| 5934 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5935 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 5936 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5937 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 5938 | |
| 5939 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 5940 | |
| 5941 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 5942 | Scale2Ratio(vert_mode, &vr, &vs); |
| 5943 | |
| 5944 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5945 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 5946 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5947 | |
| 5948 | return 0; |
| 5949 | } |
| 5950 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5951 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5952 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5953 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *frame_size) { |
| 5954 | size_t output_size = 0; |
| 5955 | size_t total_bytes_read = 0; |
| 5956 | size_t remaining_size = *frame_size; |
| 5957 | uint8_t *buff_ptr = buffer; |
| 5958 | |
| 5959 | // go through each OBUs |
| 5960 | while (total_bytes_read < *frame_size) { |
| 5961 | uint8_t saved_obu_header[2]; |
| 5962 | uint64_t obu_payload_size; |
| 5963 | size_t length_of_payload_size; |
| 5964 | size_t length_of_obu_size; |
| 5965 | uint32_t obu_header_size = (buff_ptr[0] >> 2) & 0x1 ? 2 : 1; |
| 5966 | size_t obu_bytes_read = obu_header_size; // bytes read for current obu |
| 5967 | |
| 5968 | // save the obu header (1 or 2 bytes) |
| 5969 | memmove(saved_obu_header, buff_ptr, obu_header_size); |
| 5970 | // clear the obu_has_size_field |
| 5971 | saved_obu_header[0] = saved_obu_header[0] & (~0x2); |
| 5972 | |
| 5973 | // get the payload_size and length of payload_size |
| 5974 | if (aom_uleb_decode(buff_ptr + obu_header_size, remaining_size, |
| 5975 | &obu_payload_size, &length_of_payload_size) != 0) { |
| 5976 | return AOM_CODEC_ERROR; |
| 5977 | } |
| 5978 | obu_bytes_read += length_of_payload_size; |
| 5979 | |
| 5980 | // calculate the length of size of the obu header plus payload |
| 5981 | length_of_obu_size = |
| 5982 | aom_uleb_size_in_bytes((uint64_t)(obu_header_size + obu_payload_size)); |
| 5983 | |
| 5984 | // move the rest of data to new location |
| 5985 | memmove(buff_ptr + length_of_obu_size + obu_header_size, |
| 5986 | buff_ptr + obu_bytes_read, remaining_size - obu_bytes_read); |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 5987 | obu_bytes_read += (size_t)obu_payload_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5988 | |
| 5989 | // write the new obu size |
| 5990 | const uint64_t obu_size = obu_header_size + obu_payload_size; |
| 5991 | size_t coded_obu_size; |
| 5992 | if (aom_uleb_encode(obu_size, sizeof(obu_size), buff_ptr, |
| 5993 | &coded_obu_size) != 0) { |
| 5994 | return AOM_CODEC_ERROR; |
| 5995 | } |
| 5996 | |
| 5997 | // write the saved (modified) obu_header following obu size |
| 5998 | memmove(buff_ptr + length_of_obu_size, saved_obu_header, obu_header_size); |
| 5999 | |
| 6000 | total_bytes_read += obu_bytes_read; |
| 6001 | remaining_size -= obu_bytes_read; |
| 6002 | buff_ptr += length_of_obu_size + obu_size; |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 6003 | output_size += length_of_obu_size + (size_t)obu_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | *frame_size = output_size; |
| 6007 | return AOM_CODEC_OK; |
| 6008 | } |
| 6009 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6010 | void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) { |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6011 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 6012 | // should be consistent with internal reference frame selection. Need to |
| 6013 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 6014 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
| 6015 | // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be |
| 6016 | // LAST. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6017 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6018 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6019 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 6020 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 6021 | AOM_EFLAG_NO_REF_ARF2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6022 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6023 | cpi->ext_ref_frame_flags = 0; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6024 | } else { |
| 6025 | int ref = AOM_REFFRAME_ALL; |
| 6026 | |
| 6027 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 6028 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 6029 | |
| 6030 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 6031 | |
| 6032 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 6033 | ref ^= AOM_ALT_FLAG; |
| 6034 | ref ^= AOM_BWD_FLAG; |
| 6035 | ref ^= AOM_ALT2_FLAG; |
| 6036 | } else { |
| 6037 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 6038 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
| 6039 | } |
| 6040 | |
| 6041 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6042 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6046 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6047 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6048 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6049 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 6050 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6051 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6052 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6053 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6054 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 6055 | upd ^= AOM_ALT_FLAG; |
| 6056 | upd ^= AOM_BWD_FLAG; |
| 6057 | upd ^= AOM_ALT2_FLAG; |
| 6058 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6059 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6060 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6061 | } |
| 6062 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6063 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6064 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6065 | } |
| 6066 | } |