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 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 16 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 17 | #include "config/aom_dsp_rtcd.h" |
| 18 | #include "config/aom_scale_rtcd.h" |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 19 | #include "config/av1_rtcd.h" |
| 20 | |
| 21 | #include "aom_dsp/aom_dsp_common.h" |
| 22 | #include "aom_dsp/aom_filter.h" |
| 23 | #if CONFIG_DENOISE |
| 24 | #include "aom_dsp/grain_table.h" |
| 25 | #include "aom_dsp/noise_util.h" |
| 26 | #include "aom_dsp/noise_model.h" |
| 27 | #endif |
| 28 | #include "aom_dsp/psnr.h" |
| 29 | #if CONFIG_INTERNAL_STATS |
| 30 | #include "aom_dsp/ssim.h" |
| 31 | #endif |
| 32 | #include "aom_ports/aom_timer.h" |
| 33 | #include "aom_ports/mem.h" |
| 34 | #include "aom_ports/system_state.h" |
| 35 | #include "aom_scale/aom_scale.h" |
| 36 | #if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
| 37 | #include "aom_util/debug_util.h" |
| 38 | #endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | |
| 40 | #include "av1/common/alloccommon.h" |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 41 | #include "av1/common/cdef.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | #include "av1/common/filter.h" |
| 43 | #include "av1/common/idct.h" |
| 44 | #include "av1/common/reconinter.h" |
| 45 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 46 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | #include "av1/common/tile_common.h" |
| 48 | |
| 49 | #include "av1/encoder/aq_complexity.h" |
| 50 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 51 | #include "av1/encoder/aq_variance.h" |
| 52 | #include "av1/encoder/bitstream.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | #include "av1/encoder/context_tree.h" |
| 54 | #include "av1/encoder/encodeframe.h" |
| 55 | #include "av1/encoder/encodemv.h" |
| 56 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 57 | #include "av1/encoder/encodetxb.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | #include "av1/encoder/ethread.h" |
| 59 | #include "av1/encoder/firstpass.h" |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 60 | #include "av1/encoder/grain_test_vectors.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 61 | #include "av1/encoder/hash_motion.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 62 | #include "av1/encoder/mbgraph.h" |
| 63 | #include "av1/encoder/picklpf.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | #include "av1/encoder/pickrst.h" |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 65 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | #include "av1/encoder/ratectrl.h" |
| 67 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | #include "av1/encoder/segmentation.h" |
| 69 | #include "av1/encoder/speed_features.h" |
| 70 | #include "av1/encoder/temporal_filter.h" |
| 71 | |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 72 | #define DEFAULT_EXPLICIT_ORDER_HINT_BITS 7 |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 73 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 74 | // av1 uses 10,000,000 ticks/second as time stamp |
| 75 | #define TICKS_PER_SEC 10000000LL |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 76 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 77 | #if CONFIG_ENTROPY_STATS |
| 78 | FRAME_COUNTS aggregate_fc; |
| 79 | #endif // CONFIG_ENTROPY_STATS |
| 80 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 81 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 82 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 83 | |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 84 | // Whether to use high precision mv for altref computation. |
| 85 | #define ALTREF_HIGH_PRECISION_MV 1 |
| 86 | |
| 87 | // Q threshold for high precision mv. Choose a very high value for now so that |
| 88 | // HIGH_PRECISION is always chosen. |
| 89 | #define HIGH_PRECISION_MV_QTHRESH 200 |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 90 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 91 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | #ifdef OUTPUT_YUV_SKINMAP |
| 93 | FILE *yuv_skinmap_file = NULL; |
| 94 | #endif |
| 95 | #ifdef OUTPUT_YUV_REC |
| 96 | FILE *yuv_rec_file; |
| 97 | #define FILE_NAME_LEN 100 |
| 98 | #endif |
| 99 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 100 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 101 | switch (mode) { |
| 102 | case NORMAL: |
| 103 | *hr = 1; |
| 104 | *hs = 1; |
| 105 | break; |
| 106 | case FOURFIVE: |
| 107 | *hr = 4; |
| 108 | *hs = 5; |
| 109 | break; |
| 110 | case THREEFIVE: |
| 111 | *hr = 3; |
| 112 | *hs = 5; |
| 113 | break; |
| 114 | case ONETWO: |
| 115 | *hr = 1; |
| 116 | *hs = 2; |
| 117 | break; |
| 118 | default: |
| 119 | *hr = 1; |
| 120 | *hs = 1; |
| 121 | assert(0); |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 127 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 128 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 129 | unsigned char *const seg_map = cpi->segmentation_map; |
| 130 | int i; |
| 131 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 132 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 133 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 134 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 135 | } |
| 136 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 137 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 138 | struct segmentation *const seg = &cpi->common.seg; |
| 139 | unsigned char *const seg_map = cpi->segmentation_map; |
| 140 | const unsigned char *const active_map = cpi->active_map.map; |
| 141 | int i; |
| 142 | |
| 143 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 144 | |
| 145 | if (frame_is_intra_only(&cpi->common)) { |
| 146 | cpi->active_map.enabled = 0; |
| 147 | cpi->active_map.update = 1; |
| 148 | } |
| 149 | |
| 150 | if (cpi->active_map.update) { |
| 151 | if (cpi->active_map.enabled) { |
| 152 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 153 | 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] | 154 | av1_enable_segmentation(seg); |
| 155 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 156 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 157 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 158 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 159 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 160 | |
| 161 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 162 | -MAX_LOOP_FILTER); |
| 163 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 164 | -MAX_LOOP_FILTER); |
| 165 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 166 | -MAX_LOOP_FILTER); |
| 167 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 168 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 170 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 171 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 172 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 173 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 174 | 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] | 175 | if (seg->enabled) { |
| 176 | seg->update_data = 1; |
| 177 | seg->update_map = 1; |
| 178 | } |
| 179 | } |
| 180 | cpi->active_map.update = 0; |
| 181 | } |
| 182 | } |
| 183 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 184 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 185 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 186 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 187 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 188 | const int mi_rows = cpi->common.mi_rows; |
| 189 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 190 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 191 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 192 | cpi->active_map.update = 1; |
| 193 | if (new_map_16x16) { |
| 194 | int r, c; |
| 195 | for (r = 0; r < mi_rows; ++r) { |
| 196 | for (c = 0; c < mi_cols; ++c) { |
| 197 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 198 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | ? AM_SEGMENT_ID_ACTIVE |
| 200 | : AM_SEGMENT_ID_INACTIVE; |
| 201 | } |
| 202 | } |
| 203 | cpi->active_map.enabled = 1; |
| 204 | } else { |
| 205 | cpi->active_map.enabled = 0; |
| 206 | } |
| 207 | return 0; |
| 208 | } else { |
| 209 | return -1; |
| 210 | } |
| 211 | } |
| 212 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 213 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 214 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 215 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 216 | new_map_16x16) { |
| 217 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 218 | const int mi_rows = cpi->common.mi_rows; |
| 219 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 220 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 221 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 222 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 223 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 224 | if (cpi->active_map.enabled) { |
| 225 | int r, c; |
| 226 | for (r = 0; r < mi_rows; ++r) { |
| 227 | for (c = 0; c < mi_cols; ++c) { |
| 228 | // Cyclic refresh segments are considered active despite not having |
| 229 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 230 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 231 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | return 0; |
| 236 | } else { |
| 237 | return -1; |
| 238 | } |
| 239 | } |
| 240 | |
Yaowu Xu | 45295c3 | 2018-03-29 12:06:10 -0700 | [diff] [blame] | 241 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv, |
| 242 | int cur_frame_force_integer_mv) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 243 | MACROBLOCK *const mb = &cpi->td.mb; |
Hui Su | 5036115 | 2018-03-02 11:01:42 -0800 | [diff] [blame] | 244 | cpi->common.allow_high_precision_mv = |
| 245 | allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 246 | const int copy_hp = |
| 247 | cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 248 | int *(*src)[2] = copy_hp ? &mb->nmvcost_hp : &mb->nmvcost; |
| 249 | mb->mv_cost_stack = *src; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 252 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 253 | const AV1_COMMON *const cm = &cpi->common; |
| 254 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 255 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 256 | return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 257 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 258 | if (cm->options && cm->options->ext_partition) |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 259 | #endif |
| 260 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 261 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 262 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 263 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 264 | |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 265 | // TODO(any): Possibly could improve this with a heuristic. |
| 266 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 267 | if (cm->options && !cm->options->ext_partition) return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 268 | #endif |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 269 | |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 270 | // When superres / resize is on, 'cm->width / height' can change between |
| 271 | // calls, so we don't apply this heuristic there. Also, this heuristic gives |
| 272 | // compression gain for speed >= 2 only. |
| 273 | if (cpi->oxcf.superres_mode == SUPERRES_NONE && |
| 274 | cpi->oxcf.resize_mode == RESIZE_NONE && cpi->oxcf.speed >= 2) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 275 | return (cm->width >= 480 && cm->height >= 360) ? BLOCK_128X128 |
| 276 | : BLOCK_64X64; |
| 277 | } |
| 278 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 282 | static void setup_frame(AV1_COMP *cpi) { |
| 283 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 284 | // Set up entropy context depending on frame type. The decoder mandates |
| 285 | // the use of the default context, index 0, for keyframes and inter |
| 286 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 287 | // other inter-frames the encoder currently uses only two contexts; |
| 288 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 289 | |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 290 | cm->primary_ref_frame = PRIMARY_REF_NONE; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 291 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 292 | cm->force_primary_ref_none) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 293 | av1_setup_past_independence(cm); |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 294 | for (int i = 0; i < REF_FRAMES; i++) { |
| 295 | cm->fb_of_context_type[i] = -1; |
| 296 | } |
| 297 | cm->fb_of_context_type[REGULAR_FRAME] = |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 298 | cm->show_frame ? get_ref_frame_map_idx(cpi, GOLDEN_FRAME) |
| 299 | : get_ref_frame_map_idx(cpi, ALTREF_FRAME); |
Sarah Parker | 167546f | 2018-04-24 12:14:45 -0700 | [diff] [blame] | 300 | cm->frame_context_idx = REGULAR_FRAME; |
Yunqing Wang | 19aefd1 | 2018-05-14 15:38:57 -0700 | [diff] [blame] | 301 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 302 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 303 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 305 | else if (cpi->refresh_alt_ref_frame) |
| 306 | cm->frame_context_idx = ARF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 307 | else if (cpi->rc.is_src_frame_alt_ref) |
| 308 | cm->frame_context_idx = OVERLAY_FRAME; |
| 309 | else if (cpi->refresh_golden_frame) |
| 310 | cm->frame_context_idx = GLD_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 311 | else if (cpi->refresh_bwd_ref_frame) |
| 312 | cm->frame_context_idx = BRF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 313 | else |
| 314 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 315 | int wanted_fb = cm->fb_of_context_type[cm->frame_context_idx]; |
| 316 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { |
| 317 | int fb = get_ref_frame_map_idx(cpi, ref_frame); |
| 318 | if (fb == wanted_fb) { |
| 319 | cm->primary_ref_frame = ref_frame - LAST_FRAME; |
| 320 | } |
| 321 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 324 | if (cm->frame_type == KEY_FRAME && cm->show_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 325 | cpi->refresh_golden_frame = 1; |
| 326 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 327 | av1_zero(cpi->interp_filter_selected); |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 328 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 329 | set_use_reference_buffer(cm, 0); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 330 | } else if (frame_is_sframe(cm)) { |
| 331 | cpi->refresh_golden_frame = 1; |
| 332 | cpi->refresh_alt_ref_frame = 1; |
| 333 | av1_zero(cpi->interp_filter_selected); |
| 334 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 335 | } else { |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 336 | if (cm->primary_ref_frame == PRIMARY_REF_NONE || |
| 337 | cm->frame_refs[cm->primary_ref_frame].idx < 0) { |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 338 | av1_setup_past_independence(cm); |
| 339 | cm->seg.update_map = 1; |
| 340 | cm->seg.update_data = 1; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 341 | } else { |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 342 | *cm->fc = cm->frame_contexts[cm->frame_refs[cm->primary_ref_frame].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 343 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 344 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 347 | cm->prev_frame = get_prev_frame(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 348 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 351 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 352 | int i; |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 353 | int mi_rows_sb_aligned = calc_mi_size(cm->mi_rows); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 354 | cm->mi = cm->mip; |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 355 | memset(cm->mip, 0, cm->mi_stride * mi_rows_sb_aligned * sizeof(*cm->mip)); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 356 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 357 | // Clear top border row |
| 358 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 359 | // Clear left border column |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 360 | for (i = 0; i < mi_rows_sb_aligned; ++i) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 361 | 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] | 362 | cm->mi_grid_visible = cm->mi_grid_base; |
| 363 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | |
| 365 | memset(cm->mi_grid_base, 0, |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 366 | cm->mi_stride * mi_rows_sb_aligned * sizeof(*cm->mi_grid_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 369 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 370 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 371 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 372 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | if (!cm->prev_mip) return 1; |
| 374 | cm->mi_alloc_size = mi_size; |
| 375 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 376 | cm->mi_grid_base = |
| 377 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 378 | if (!cm->mi_grid_base) return 1; |
| 379 | cm->prev_mi_grid_base = |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 380 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 381 | if (!cm->prev_mi_grid_base) return 1; |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 386 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 387 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 388 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 389 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 390 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 391 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 392 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 393 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 394 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 395 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 398 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 399 | // Current mip will be the prev_mip for the next frame. |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 400 | MB_MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 401 | MB_MODE_INFO *temp = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | cm->prev_mip = cm->mip; |
| 403 | cm->mip = temp; |
| 404 | |
| 405 | // Update the upper left visible macroblock ptrs. |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 406 | cm->mi = cm->mip; |
| 407 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 408 | |
| 409 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 410 | cm->mi_grid_base = temp_base; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 411 | cm->mi_grid_visible = cm->mi_grid_base; |
| 412 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 415 | void av1_initialize_enc(void) { |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 416 | av1_rtcd(); |
| 417 | aom_dsp_rtcd(); |
| 418 | aom_scale_rtcd(); |
| 419 | av1_init_intra_predictors(); |
| 420 | av1_init_me_luts(); |
| 421 | av1_rc_init_minq_luts(); |
| 422 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 425 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 426 | if (cpi->mbmi_ext_base) { |
| 427 | aom_free(cpi->mbmi_ext_base); |
| 428 | cpi->mbmi_ext_base = NULL; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 433 | AV1_COMMON *cm = &cpi->common; |
| 434 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 435 | |
| 436 | dealloc_context_buffers_ext(cpi); |
| 437 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 438 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 439 | } |
| 440 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 441 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 442 | const AV1EncoderConfig *oxcf) { |
| 443 | AV1_COMMON *const cm = &cpi->common; |
| 444 | cpi->oxcf = *oxcf; |
| 445 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 446 | if (cpi->film_grain_table) { |
| 447 | aom_film_grain_table_free(cpi->film_grain_table); |
| 448 | aom_free(cpi->film_grain_table); |
| 449 | cpi->film_grain_table = NULL; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 450 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 451 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 452 | if (oxcf->film_grain_test_vector) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 453 | cm->seq_params.film_grain_params_present = 1; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 454 | if (cm->frame_type == KEY_FRAME) { |
| 455 | memcpy(&cm->film_grain_params, |
| 456 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 457 | sizeof(cm->film_grain_params)); |
| 458 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 459 | cm->film_grain_params.bit_depth = cm->seq_params.bit_depth; |
| 460 | if (cm->seq_params.color_range == AOM_CR_FULL_RANGE) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 461 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 462 | } |
| 463 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 464 | } else if (oxcf->film_grain_table_filename) { |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 465 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 466 | memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t)); |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 467 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 468 | aom_film_grain_table_read(cpi->film_grain_table, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 469 | oxcf->film_grain_table_filename, &cm->error); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 470 | } else { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 471 | cm->seq_params.film_grain_params_present = 0; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 472 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 473 | } |
| 474 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 475 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 476 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 477 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 478 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 479 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 480 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 481 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 482 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 483 | cpi->tile_data = NULL; |
| 484 | |
| 485 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 486 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 487 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 488 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 489 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 490 | cpi->cyclic_refresh = NULL; |
| 491 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 492 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 493 | cpi->active_map.map = NULL; |
| 494 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 495 | aom_free(cpi->td.mb.above_pred_buf); |
| 496 | cpi->td.mb.above_pred_buf = NULL; |
| 497 | |
| 498 | aom_free(cpi->td.mb.left_pred_buf); |
| 499 | cpi->td.mb.left_pred_buf = NULL; |
| 500 | |
| 501 | aom_free(cpi->td.mb.wsrc_buf); |
| 502 | cpi->td.mb.wsrc_buf = NULL; |
| 503 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 504 | for (int i = 0; i < 2; i++) |
| 505 | for (int j = 0; j < 2; j++) { |
| 506 | aom_free(cpi->td.mb.hash_value_buffer[i][j]); |
| 507 | cpi->td.mb.hash_value_buffer[i][j] = NULL; |
| 508 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 509 | aom_free(cpi->td.mb.mask_buf); |
| 510 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 511 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 512 | aom_free(cm->tpl_mvs); |
| 513 | cm->tpl_mvs = NULL; |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 514 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 515 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 516 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 517 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 519 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 520 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 521 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 522 | aom_free_frame_buffer(&cpi->scaled_source); |
| 523 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 524 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 525 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 526 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 527 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 528 | cpi->tile_tok[0][0] = 0; |
| 529 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 530 | aom_free(cpi->tplist[0][0]); |
| 531 | cpi->tplist[0][0] = NULL; |
| 532 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 533 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 534 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 535 | aom_free(cpi->td.mb.palette_buffer); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 536 | |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 537 | aom_free(cpi->td.mb.tmp_conv_dst); |
| 538 | for (int j = 0; j < 2; ++j) { |
| 539 | aom_free(cpi->td.mb.tmp_obmc_bufs[j]); |
| 540 | } |
| 541 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 542 | #if CONFIG_DENOISE |
| 543 | if (cpi->denoise_and_model) { |
| 544 | aom_denoise_and_model_free(cpi->denoise_and_model); |
| 545 | cpi->denoise_and_model = NULL; |
| 546 | } |
| 547 | #endif |
| 548 | if (cpi->film_grain_table) { |
| 549 | aom_film_grain_table_free(cpi->film_grain_table); |
| 550 | cpi->film_grain_table = NULL; |
| 551 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 554 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 555 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 556 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 557 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 558 | // Stores a snapshot of key state variables which can subsequently be |
| 559 | // restored with a call to av1_restore_coding_context. These functions are |
| 560 | // intended for use in a re-code loop in av1_compress_frame where the |
| 561 | // quantizer value is adjusted between loop iterations. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 562 | av1_copy(cc->nmv_vec_cost, cpi->td.mb.nmv_vec_cost); |
| 563 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 564 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 565 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 566 | cc->fc = *cm->fc; |
| 567 | } |
| 568 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 570 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 571 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 572 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 573 | // Restore key state variables to the snapshot state stored in the |
| 574 | // previous call to av1_save_coding_context. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 575 | av1_copy(cpi->td.mb.nmv_vec_cost, cc->nmv_vec_cost); |
| 576 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 577 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 578 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 579 | *cm->fc = cc->fc; |
| 580 | } |
| 581 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 582 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 583 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 584 | const RATE_CONTROL *const rc = &cpi->rc; |
| 585 | struct segmentation *const seg = &cm->seg; |
| 586 | |
| 587 | int high_q = (int)(rc->avg_q > 48.0); |
| 588 | int qi_delta; |
| 589 | |
| 590 | // Disable and clear down for KF |
| 591 | if (cm->frame_type == KEY_FRAME) { |
| 592 | // Clear down the global segmentation map |
| 593 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 594 | seg->update_map = 0; |
| 595 | seg->update_data = 0; |
| 596 | cpi->static_mb_pct = 0; |
| 597 | |
| 598 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 599 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 600 | |
| 601 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 602 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 603 | } else if (cpi->refresh_alt_ref_frame) { |
| 604 | // If this is an alt ref frame |
| 605 | // Clear down the global segmentation map |
| 606 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 607 | seg->update_map = 0; |
| 608 | seg->update_data = 0; |
| 609 | cpi->static_mb_pct = 0; |
| 610 | |
| 611 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 612 | av1_disable_segmentation(seg); |
| 613 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 614 | |
| 615 | // Scan frames from current to arf frame. |
| 616 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 617 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 618 | |
| 619 | // If segmentation was enabled set those features needed for the |
| 620 | // arf itself. |
| 621 | if (seg->enabled) { |
| 622 | seg->update_map = 1; |
| 623 | seg->update_data = 1; |
| 624 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 625 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, |
| 626 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 627 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 628 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 629 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 630 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 631 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 632 | |
| 633 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 634 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 635 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 636 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 637 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 638 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 639 | } |
| 640 | } else if (seg->enabled) { |
| 641 | // All other frames if segmentation has been enabled |
| 642 | |
| 643 | // First normal frame in a valid gf or alt ref group |
| 644 | if (rc->frames_since_golden == 0) { |
| 645 | // Set up segment features for normal frames in an arf group |
| 646 | if (rc->source_alt_ref_active) { |
| 647 | seg->update_map = 0; |
| 648 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 649 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 650 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, |
| 651 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 652 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 653 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 654 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 655 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 656 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 657 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 658 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 659 | |
| 660 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 661 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 662 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 663 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 664 | |
| 665 | // Segment coding disabled for compred testing |
| 666 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 667 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 668 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 669 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 670 | } |
| 671 | } else { |
| 672 | // Disable segmentation and clear down features if alt ref |
| 673 | // is not active for this group |
| 674 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 675 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 676 | |
| 677 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 678 | |
| 679 | seg->update_map = 0; |
| 680 | seg->update_data = 0; |
| 681 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 682 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 683 | } |
| 684 | } else if (rc->is_src_frame_alt_ref) { |
| 685 | // Special case where we are coding over the top of a previous |
| 686 | // alt ref frame. |
| 687 | // Segment coding disabled for compred testing |
| 688 | |
| 689 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 690 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 691 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 692 | |
| 693 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 694 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 695 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 696 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 697 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 698 | |
| 699 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 700 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 701 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 702 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 703 | } |
| 704 | // Enable data update |
| 705 | seg->update_data = 1; |
| 706 | } else { |
| 707 | // All other frames. |
| 708 | |
| 709 | // No updates.. leave things as they are. |
| 710 | seg->update_map = 0; |
| 711 | seg->update_data = 0; |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 716 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 717 | AV1_COMMON *const cm = &cpi->common; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 718 | MB_MODE_INFO **mi_4x4_ptr = cm->mi_grid_visible; |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 719 | uint8_t *cache_ptr = cm->current_frame_seg_map; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 720 | int row, col; |
| 721 | |
| 722 | for (row = 0; row < cm->mi_rows; row++) { |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 723 | MB_MODE_INFO **mi_4x4 = mi_4x4_ptr; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 724 | uint8_t *cache = cache_ptr; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 725 | for (col = 0; col < cm->mi_cols; col++, mi_4x4++, cache++) |
| 726 | cache[0] = mi_4x4[0]->segment_id; |
| 727 | mi_4x4_ptr += cm->mi_stride; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 728 | cache_ptr += cm->mi_cols; |
| 729 | } |
| 730 | } |
| 731 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 732 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 733 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 734 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 735 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 736 | |
| 737 | if (!cpi->lookahead) |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 738 | cpi->lookahead = |
| 739 | av1_lookahead_init(oxcf->width, oxcf->height, seq_params->subsampling_x, |
| 740 | seq_params->subsampling_y, |
| 741 | seq_params->use_highbitdepth, oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 742 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 743 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 744 | "Failed to allocate lag buffers"); |
| 745 | |
| 746 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 747 | if (aom_realloc_frame_buffer( |
| 748 | &cpi->alt_ref_buffer, oxcf->width, oxcf->height, |
| 749 | seq_params->subsampling_x, seq_params->subsampling_y, |
| 750 | seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 751 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 752 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 753 | "Failed to allocate altref buffer"); |
| 754 | } |
| 755 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 756 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 757 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 758 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 759 | if (aom_realloc_frame_buffer( |
| 760 | &cpi->last_frame_uf, cm->width, cm->height, seq_params->subsampling_x, |
| 761 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
| 762 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 763 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 764 | "Failed to allocate last frame buffer"); |
| 765 | |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 766 | if (aom_realloc_frame_buffer( |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 767 | &cpi->trial_frame_rst, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 768 | cm->superres_upscaled_height, seq_params->subsampling_x, |
| 769 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
| 770 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 771 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 772 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 773 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 774 | if (aom_realloc_frame_buffer( |
| 775 | &cpi->scaled_source, cm->width, cm->height, seq_params->subsampling_x, |
| 776 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
| 777 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 778 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 779 | "Failed to allocate scaled source buffer"); |
| 780 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 781 | if (aom_realloc_frame_buffer( |
| 782 | &cpi->scaled_last_source, cm->width, cm->height, |
| 783 | seq_params->subsampling_x, seq_params->subsampling_y, |
| 784 | seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 785 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 786 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 787 | "Failed to allocate scaled last source buffer"); |
| 788 | } |
| 789 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 790 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 791 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 792 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 794 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 795 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 796 | int mi_rows_aligned_to_sb = |
| 797 | ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 798 | int sb_rows = mi_rows_aligned_to_sb >> cm->seq_params.mib_size_log2; |
| 799 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 800 | av1_alloc_txb_buf(cpi); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 801 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 802 | alloc_context_buffers_ext(cpi); |
| 803 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 804 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 805 | |
| 806 | { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 807 | unsigned int tokens = |
| 808 | 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] | 809 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 810 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 811 | } |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 812 | aom_free(cpi->tplist[0][0]); |
| 813 | |
| 814 | CHECK_MEM_ERROR(cm, cpi->tplist[0][0], |
| 815 | aom_calloc(sb_rows * MAX_TILE_ROWS * MAX_TILE_COLS, |
| 816 | sizeof(*cpi->tplist[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 817 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 818 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 821 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 822 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 823 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Yunqing Wang | 75e20e8 | 2018-06-16 12:10:48 -0700 | [diff] [blame] | 826 | static void set_tile_info(AV1_COMP *cpi) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 827 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 828 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 829 | |
| 830 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 831 | |
| 832 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 833 | 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] | 834 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 835 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 836 | 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] | 837 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 838 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 839 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 840 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 841 | cm->uniform_tile_spacing_flag = 0; |
| 842 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 843 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 844 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 845 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
David Barker | 6cd5a82 | 2018-03-05 16:19:28 +0000 | [diff] [blame] | 846 | start_sb += AOMMIN(size_sb, cm->max_tile_width_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 847 | } |
| 848 | cm->tile_cols = i; |
| 849 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 850 | } |
| 851 | av1_calculate_tile_cols(cm); |
| 852 | |
| 853 | // configure tile rows |
| 854 | if (cm->uniform_tile_spacing_flag) { |
| 855 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 856 | 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] | 857 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 858 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 859 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 860 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 861 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 862 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 863 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 864 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 865 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 866 | } |
| 867 | cm->tile_rows = i; |
| 868 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 869 | } |
| 870 | av1_calculate_tile_rows(cm); |
| 871 | } |
| 872 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 873 | static void update_frame_size(AV1_COMP *cpi) { |
| 874 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 875 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 876 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 877 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 878 | av1_init_context_buffers(cm); |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 879 | av1_init_macroblockd(cm, xd, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | memset(cpi->mbmi_ext_base, 0, |
| 881 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 882 | set_tile_info(cpi); |
| 883 | } |
| 884 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 885 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 886 | int fb_idx; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 887 | for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx) |
| 888 | cpi->ref_fb_idx[fb_idx] = fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 889 | cpi->rate_index = 0; |
| 890 | cpi->rate_size = 0; |
| 891 | cpi->cur_poc = -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 894 | static INLINE int does_level_match(int width, int height, double fps, |
| 895 | int lvl_width, int lvl_height, |
| 896 | double lvl_fps, int lvl_dim_mult) { |
| 897 | const int64_t lvl_luma_pels = lvl_width * lvl_height; |
| 898 | const double lvl_display_sample_rate = lvl_luma_pels * lvl_fps; |
| 899 | const int64_t luma_pels = width * height; |
| 900 | const double display_sample_rate = luma_pels * fps; |
| 901 | return luma_pels <= lvl_luma_pels && |
| 902 | display_sample_rate <= lvl_display_sample_rate && |
| 903 | width <= lvl_width * lvl_dim_mult && |
| 904 | height <= lvl_height * lvl_dim_mult; |
| 905 | } |
| 906 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 907 | static void set_bitstream_level_tier(SequenceHeader *seq, AV1_COMMON *cm, |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 908 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 909 | // TODO(any): This is a placeholder function that only addresses dimensions |
| 910 | // and max display sample rates. |
| 911 | // Need to add checks for max bit rate, max decoded luma sample rate, header |
| 912 | // rate, etc. that are not covered by this function. |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 913 | (void)oxcf; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 914 | BitstreamLevel bl = { 9, 3 }; |
| 915 | if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, 512, |
| 916 | 288, 30.0, 4)) { |
| 917 | bl.major = 2; |
| 918 | bl.minor = 0; |
| 919 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 920 | 704, 396, 30.0, 4)) { |
| 921 | bl.major = 2; |
| 922 | bl.minor = 1; |
| 923 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 924 | 1088, 612, 30.0, 4)) { |
| 925 | bl.major = 3; |
| 926 | bl.minor = 0; |
| 927 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 928 | 1376, 774, 30.0, 4)) { |
| 929 | bl.major = 3; |
| 930 | bl.minor = 1; |
| 931 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 932 | 2048, 1152, 30.0, 3)) { |
| 933 | bl.major = 4; |
| 934 | bl.minor = 0; |
| 935 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 936 | 2048, 1152, 60.0, 3)) { |
| 937 | bl.major = 4; |
| 938 | bl.minor = 1; |
| 939 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 940 | 4096, 2176, 30.0, 2)) { |
| 941 | bl.major = 5; |
| 942 | bl.minor = 0; |
| 943 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 944 | 4096, 2176, 60.0, 2)) { |
| 945 | bl.major = 5; |
| 946 | bl.minor = 1; |
| 947 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 948 | 4096, 2176, 120.0, 2)) { |
| 949 | bl.major = 5; |
| 950 | bl.minor = 2; |
| 951 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 952 | 8192, 4352, 30.0, 2)) { |
| 953 | bl.major = 6; |
| 954 | bl.minor = 0; |
| 955 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 956 | 8192, 4352, 60.0, 2)) { |
| 957 | bl.major = 6; |
| 958 | bl.minor = 1; |
| 959 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 960 | 8192, 4352, 120.0, 2)) { |
| 961 | bl.major = 6; |
| 962 | bl.minor = 2; |
| 963 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 964 | 16384, 8704, 30.0, 2)) { |
| 965 | bl.major = 7; |
| 966 | bl.minor = 0; |
| 967 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 968 | 16384, 8704, 60.0, 2)) { |
| 969 | bl.major = 7; |
| 970 | bl.minor = 1; |
| 971 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 972 | 16384, 8704, 120.0, 2)) { |
| 973 | bl.major = 7; |
| 974 | bl.minor = 2; |
| 975 | } |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 976 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 977 | seq->level[i] = bl; |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 978 | seq->tier[i] = 0; // setting main tier by default |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 979 | // Set the maximum parameters for bitrate and buffer size for this profile, |
| 980 | // level, and tier |
| 981 | cm->op_params[i].bitrate = max_level_bitrate( |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 982 | cm->seq_params.profile, major_minor_to_seq_level_idx(seq->level[i]), |
| 983 | seq->tier[i]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 984 | // Level with seq_level_idx = 31 returns a high "dummy" bitrate to pass the |
| 985 | // check |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 986 | if (cm->op_params[i].bitrate == 0) |
| 987 | aom_internal_error( |
| 988 | &cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 989 | "AV1 does not support this combination of profile, level, and tier."); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 990 | // Buffer size in bits/s is bitrate in bits/s * 1 s |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 991 | cm->op_params[i].buffer_size = cm->op_params[i].bitrate; |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 995 | static void init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm, |
| 996 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 997 | seq->still_picture = (oxcf->limit == 1); |
| 998 | seq->reduced_still_picture_hdr = seq->still_picture; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 999 | seq->reduced_still_picture_hdr &= !oxcf->full_still_picture_hdr; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1000 | seq->force_screen_content_tools = 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1001 | seq->force_integer_mv = 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1002 | seq->enable_order_hint = oxcf->enable_order_hint; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1003 | seq->frame_id_numbers_present_flag = oxcf->large_scale_tile; |
| 1004 | if (seq->still_picture && seq->reduced_still_picture_hdr) { |
| 1005 | seq->enable_order_hint = 0; |
| 1006 | seq->frame_id_numbers_present_flag = 0; |
| 1007 | seq->force_screen_content_tools = 2; |
| 1008 | seq->force_integer_mv = 2; |
| 1009 | } |
Wan-Teh Chang | 6958297 | 2018-05-15 13:18:52 -0700 | [diff] [blame] | 1010 | seq->order_hint_bits_minus_1 = |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1011 | seq->enable_order_hint ? DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1 : -1; |
| 1012 | |
| 1013 | seq->enable_dual_filter = oxcf->enable_dual_filter; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1014 | seq->enable_jnt_comp = oxcf->enable_jnt_comp; |
| 1015 | seq->enable_jnt_comp &= seq->enable_order_hint; |
| 1016 | seq->enable_ref_frame_mvs = oxcf->enable_ref_frame_mvs; |
| 1017 | seq->enable_ref_frame_mvs &= seq->enable_order_hint; |
| 1018 | seq->enable_superres = oxcf->enable_superres; |
| 1019 | seq->enable_cdef = oxcf->enable_cdef; |
| 1020 | seq->enable_restoration = oxcf->enable_restoration; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 1021 | seq->enable_warped_motion = oxcf->enable_warped_motion; |
Debargha Mukherjee | 97095fb | 2018-03-26 07:51:48 -0700 | [diff] [blame] | 1022 | seq->enable_interintra_compound = 1; |
| 1023 | seq->enable_masked_compound = 1; |
Debargha Mukherjee | 365eae8 | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 1024 | seq->enable_intra_edge_filter = 1; |
| 1025 | seq->enable_filter_intra = 1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1026 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1027 | set_bitstream_level_tier(seq, cm, oxcf); |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1028 | |
| 1029 | if (seq->operating_points_cnt_minus_1 == 0) { |
| 1030 | seq->operating_point_idc[0] = 0; |
| 1031 | } else { |
| 1032 | // Set operating_point_idc[] such that for the i-th operating point the |
| 1033 | // first (operating_points_cnt-i) spatial layers and the first temporal |
| 1034 | // layer are decoded Note that highest quality operating point should come |
| 1035 | // first |
| 1036 | for (int i = 0; i < seq->operating_points_cnt_minus_1 + 1; i++) |
| 1037 | seq->operating_point_idc[i] = |
| 1038 | (~(~0u << (seq->operating_points_cnt_minus_1 + 1 - i)) << 8) | 1; |
| 1039 | } |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1042 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1043 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1044 | |
| 1045 | cpi->oxcf = *oxcf; |
| 1046 | cpi->framerate = oxcf->init_framerate; |
| 1047 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1048 | cm->seq_params.profile = oxcf->profile; |
| 1049 | cm->seq_params.bit_depth = oxcf->bit_depth; |
| 1050 | cm->seq_params.use_highbitdepth = oxcf->use_highbitdepth; |
| 1051 | cm->seq_params.color_primaries = oxcf->color_primaries; |
| 1052 | cm->seq_params.transfer_characteristics = oxcf->transfer_characteristics; |
| 1053 | cm->seq_params.matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1054 | cm->seq_params.monochrome = oxcf->monochrome; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1055 | cm->seq_params.chroma_sample_position = oxcf->chroma_sample_position; |
| 1056 | cm->seq_params.color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 1057 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1058 | cm->timing_info.num_units_in_display_tick = |
| 1059 | oxcf->timing_info.num_units_in_display_tick; |
| 1060 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 1061 | cm->timing_info.equal_picture_interval = |
| 1062 | oxcf->timing_info.equal_picture_interval; |
| 1063 | cm->timing_info.num_ticks_per_picture = |
| 1064 | oxcf->timing_info.num_ticks_per_picture; |
| 1065 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1066 | cm->seq_params.display_model_info_present_flag = |
| 1067 | oxcf->display_model_info_present_flag; |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1068 | cm->seq_params.decoder_model_info_present_flag = |
| 1069 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1070 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1071 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1072 | cm->buffer_model.num_units_in_decoding_tick = |
| 1073 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 1074 | cm->buffer_removal_time_present = 1; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1075 | set_aom_dec_model_info(&cm->buffer_model); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1076 | set_dec_model_op_parameters(&cm->op_params[0]); |
| 1077 | } else if (cm->timing_info_present && |
| 1078 | cm->timing_info.equal_picture_interval && |
| 1079 | !cm->seq_params.decoder_model_info_present_flag) { |
| 1080 | // set the decoder model parameters in resource availability mode |
| 1081 | set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1082 | } else { |
| 1083 | cm->op_params[0].initial_display_delay = |
| 1084 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1085 | } |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1086 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1087 | if (cm->seq_params.monochrome) { |
| 1088 | cm->seq_params.subsampling_x = 1; |
| 1089 | cm->seq_params.subsampling_y = 1; |
| 1090 | } else if (cm->seq_params.color_primaries == AOM_CICP_CP_BT_709 && |
| 1091 | cm->seq_params.transfer_characteristics == AOM_CICP_TC_SRGB && |
| 1092 | cm->seq_params.matrix_coefficients == AOM_CICP_MC_IDENTITY) { |
| 1093 | cm->seq_params.subsampling_x = 0; |
| 1094 | cm->seq_params.subsampling_y = 0; |
| 1095 | } else { |
| 1096 | if (cm->seq_params.profile == 0) { |
| 1097 | cm->seq_params.subsampling_x = 1; |
| 1098 | cm->seq_params.subsampling_y = 1; |
| 1099 | } else if (cm->seq_params.profile == 1) { |
| 1100 | cm->seq_params.subsampling_x = 0; |
| 1101 | cm->seq_params.subsampling_y = 0; |
| 1102 | } else { |
| 1103 | if (cm->seq_params.bit_depth == AOM_BITS_12) { |
| 1104 | cm->seq_params.subsampling_x = oxcf->chroma_subsampling_x; |
| 1105 | cm->seq_params.subsampling_y = oxcf->chroma_subsampling_y; |
| 1106 | } else { |
| 1107 | cm->seq_params.subsampling_x = 1; |
| 1108 | cm->seq_params.subsampling_y = 0; |
| 1109 | } |
| 1110 | } |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1113 | cm->width = oxcf->width; |
| 1114 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1115 | set_sb_size(&cm->seq_params, |
| 1116 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1117 | alloc_compressor_data(cpi); |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 1118 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 1119 | update_film_grain_parameters(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1120 | |
| 1121 | // Single thread case: use counts in common. |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 1122 | cpi->td.counts = &cpi->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1123 | |
| 1124 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1125 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1126 | |
| 1127 | cpi->static_mb_pct = 0; |
| 1128 | cpi->ref_frame_flags = 0; |
| 1129 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1130 | // Reset resize pending flags |
| 1131 | cpi->resize_pending_width = 0; |
| 1132 | cpi->resize_pending_height = 0; |
| 1133 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1134 | init_buffer_indices(cpi); |
| 1135 | } |
| 1136 | |
| 1137 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1138 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1139 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1140 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1141 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1142 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1143 | |
| 1144 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1145 | rc->optimal_buffer_level = |
| 1146 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1147 | rc->maximum_buffer_size = |
| 1148 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1149 | } |
| 1150 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1151 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 1152 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1153 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1154 | cpi->fn_ptr[BT].vf = VF; \ |
| 1155 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1156 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1157 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 1158 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1159 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1160 | |
| 1161 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1162 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1163 | int source_stride, \ |
| 1164 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1165 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1166 | } \ |
| 1167 | static unsigned int fnname##_bits10( \ |
| 1168 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1169 | int ref_stride) { \ |
| 1170 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1171 | } \ |
| 1172 | static unsigned int fnname##_bits12( \ |
| 1173 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1174 | int ref_stride) { \ |
| 1175 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1176 | } |
| 1177 | |
| 1178 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1179 | static unsigned int fnname##_bits8( \ |
| 1180 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1181 | int ref_stride, const uint8_t *second_pred) { \ |
| 1182 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1183 | } \ |
| 1184 | static unsigned int fnname##_bits10( \ |
| 1185 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1186 | int ref_stride, const uint8_t *second_pred) { \ |
| 1187 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1188 | 2; \ |
| 1189 | } \ |
| 1190 | static unsigned int fnname##_bits12( \ |
| 1191 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1192 | int ref_stride, const uint8_t *second_pred) { \ |
| 1193 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1194 | 4; \ |
| 1195 | } |
| 1196 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1197 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1198 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1199 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1200 | unsigned int *sad_array) { \ |
| 1201 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1202 | } \ |
| 1203 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1204 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1205 | unsigned int *sad_array) { \ |
| 1206 | int i; \ |
| 1207 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1208 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1209 | } \ |
| 1210 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1211 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1212 | unsigned int *sad_array) { \ |
| 1213 | int i; \ |
| 1214 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1215 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1216 | } |
| 1217 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1218 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1219 | static unsigned int fnname##_bits8( \ |
| 1220 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1221 | int ref_stride, const uint8_t *second_pred, \ |
| 1222 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1223 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1224 | jcp_param); \ |
| 1225 | } \ |
| 1226 | static unsigned int fnname##_bits10( \ |
| 1227 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1228 | int ref_stride, const uint8_t *second_pred, \ |
| 1229 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1230 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1231 | jcp_param) >> \ |
| 1232 | 2; \ |
| 1233 | } \ |
| 1234 | static unsigned int fnname##_bits12( \ |
| 1235 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1236 | int ref_stride, const uint8_t *second_pred, \ |
| 1237 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1238 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1239 | jcp_param) >> \ |
| 1240 | 4; \ |
| 1241 | } |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1242 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1243 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1244 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1245 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1246 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1247 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1248 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1249 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1250 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1251 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1252 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1253 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1254 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1255 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1256 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1257 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1258 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1259 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1260 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1261 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1262 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1263 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1264 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1265 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1266 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1267 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1268 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1269 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1270 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1271 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1272 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1273 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1274 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1275 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1276 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1277 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1278 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1279 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1280 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1281 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1282 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1283 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1284 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1285 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1286 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1287 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1288 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1289 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1290 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1291 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1292 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1293 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1294 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1295 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1296 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1297 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1298 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1299 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1300 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1301 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1302 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1303 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1304 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1305 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1306 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1307 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1308 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1309 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1310 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1311 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x128_avg) |
| 1312 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x64_avg) |
| 1313 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x128_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1314 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x16_avg) |
| 1315 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x32_avg) |
| 1316 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x32_avg) |
| 1317 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x64_avg) |
| 1318 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x32_avg) |
| 1319 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x64_avg) |
| 1320 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x16_avg) |
| 1321 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x8_avg) |
| 1322 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x16_avg) |
| 1323 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x8_avg) |
| 1324 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x4_avg) |
| 1325 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x8_avg) |
| 1326 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x4_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1327 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x16_avg) |
| 1328 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x4_avg) |
| 1329 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x32_avg) |
| 1330 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x8_avg) |
| 1331 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x64_avg) |
| 1332 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x16_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1333 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1334 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1335 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1336 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1337 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1338 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1339 | static unsigned int fnname##_bits8( \ |
| 1340 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1341 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1342 | int m_stride, int invert_mask) { \ |
| 1343 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1344 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1345 | } \ |
| 1346 | static unsigned int fnname##_bits10( \ |
| 1347 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1348 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1349 | int m_stride, int invert_mask) { \ |
| 1350 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1351 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1352 | 2; \ |
| 1353 | } \ |
| 1354 | static unsigned int fnname##_bits12( \ |
| 1355 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1356 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1357 | int m_stride, int invert_mask) { \ |
| 1358 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1359 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1360 | 4; \ |
| 1361 | } |
| 1362 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1363 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1364 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1365 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1366 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1367 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1368 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1369 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1370 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1371 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1372 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1373 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1374 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1375 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1376 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1377 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1378 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1379 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1380 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1381 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1382 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1383 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1384 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1385 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1386 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1387 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1388 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1389 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1390 | |
| 1391 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1392 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1393 | const int32_t *wsrc, \ |
| 1394 | const int32_t *msk) { \ |
| 1395 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1396 | } \ |
| 1397 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1398 | const int32_t *wsrc, \ |
| 1399 | const int32_t *msk) { \ |
| 1400 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1401 | } \ |
| 1402 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1403 | const int32_t *wsrc, \ |
| 1404 | const int32_t *msk) { \ |
| 1405 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1406 | } |
| 1407 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1408 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1409 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1410 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1411 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1412 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1413 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1414 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1415 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1416 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1417 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1418 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1419 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1420 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1421 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1422 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1423 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1424 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1425 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1426 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1427 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1428 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1429 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1430 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1431 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1432 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1433 | if (cm->seq_params.use_highbitdepth) { |
| 1434 | switch (cm->seq_params.bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1435 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1436 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1437 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1438 | aom_highbd_8_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1439 | aom_highbd_8_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1440 | aom_highbd_sad64x16x4d_bits8, |
| 1441 | aom_highbd_jnt_sad64x16_avg_bits8, |
| 1442 | aom_highbd_8_jnt_sub_pixel_avg_variance64x16) |
| 1443 | |
| 1444 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1445 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1446 | aom_highbd_8_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1447 | aom_highbd_8_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1448 | aom_highbd_sad16x64x4d_bits8, |
| 1449 | aom_highbd_jnt_sad16x64_avg_bits8, |
| 1450 | aom_highbd_8_jnt_sub_pixel_avg_variance16x64) |
| 1451 | |
| 1452 | HIGHBD_BFP( |
| 1453 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1454 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1455 | aom_highbd_8_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1456 | aom_highbd_sad32x8x4d_bits8, aom_highbd_jnt_sad32x8_avg_bits8, |
| 1457 | aom_highbd_8_jnt_sub_pixel_avg_variance32x8) |
| 1458 | |
| 1459 | HIGHBD_BFP( |
| 1460 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1461 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1462 | aom_highbd_8_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1463 | aom_highbd_sad8x32x4d_bits8, aom_highbd_jnt_sad8x32_avg_bits8, |
| 1464 | aom_highbd_8_jnt_sub_pixel_avg_variance8x32) |
| 1465 | |
| 1466 | HIGHBD_BFP( |
| 1467 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1468 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1469 | aom_highbd_8_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1470 | aom_highbd_sad16x4x4d_bits8, aom_highbd_jnt_sad16x4_avg_bits8, |
| 1471 | aom_highbd_8_jnt_sub_pixel_avg_variance16x4) |
| 1472 | |
| 1473 | HIGHBD_BFP( |
| 1474 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1475 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1476 | aom_highbd_8_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1477 | aom_highbd_sad4x16x4d_bits8, aom_highbd_jnt_sad4x16_avg_bits8, |
| 1478 | aom_highbd_8_jnt_sub_pixel_avg_variance4x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1479 | |
| 1480 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1481 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1482 | aom_highbd_8_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1483 | aom_highbd_8_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1484 | aom_highbd_sad32x16x4d_bits8, |
| 1485 | aom_highbd_jnt_sad32x16_avg_bits8, |
| 1486 | aom_highbd_8_jnt_sub_pixel_avg_variance32x16) |
| 1487 | |
| 1488 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1489 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1490 | aom_highbd_8_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1491 | aom_highbd_8_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1492 | aom_highbd_sad16x32x4d_bits8, |
| 1493 | aom_highbd_jnt_sad16x32_avg_bits8, |
| 1494 | aom_highbd_8_jnt_sub_pixel_avg_variance16x32) |
| 1495 | |
| 1496 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1497 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1498 | aom_highbd_8_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1499 | aom_highbd_8_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1500 | aom_highbd_sad64x32x4d_bits8, |
| 1501 | aom_highbd_jnt_sad64x32_avg_bits8, |
| 1502 | aom_highbd_8_jnt_sub_pixel_avg_variance64x32) |
| 1503 | |
| 1504 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1505 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1506 | aom_highbd_8_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1507 | aom_highbd_8_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1508 | aom_highbd_sad32x64x4d_bits8, |
| 1509 | aom_highbd_jnt_sad32x64_avg_bits8, |
| 1510 | aom_highbd_8_jnt_sub_pixel_avg_variance32x64) |
| 1511 | |
| 1512 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1513 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1514 | aom_highbd_8_sub_pixel_variance32x32, |
| 1515 | aom_highbd_8_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1516 | aom_highbd_sad32x32x4d_bits8, |
| 1517 | aom_highbd_jnt_sad32x32_avg_bits8, |
| 1518 | aom_highbd_8_jnt_sub_pixel_avg_variance32x32) |
| 1519 | |
| 1520 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1521 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1522 | aom_highbd_8_sub_pixel_variance64x64, |
| 1523 | aom_highbd_8_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1524 | aom_highbd_sad64x64x4d_bits8, |
| 1525 | aom_highbd_jnt_sad64x64_avg_bits8, |
| 1526 | aom_highbd_8_jnt_sub_pixel_avg_variance64x64) |
| 1527 | |
| 1528 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1529 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1530 | aom_highbd_8_sub_pixel_variance16x16, |
| 1531 | aom_highbd_8_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1532 | aom_highbd_sad16x16x4d_bits8, |
| 1533 | aom_highbd_jnt_sad16x16_avg_bits8, |
| 1534 | aom_highbd_8_jnt_sub_pixel_avg_variance16x16) |
| 1535 | |
| 1536 | HIGHBD_BFP( |
| 1537 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1538 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1539 | aom_highbd_8_sub_pixel_avg_variance16x8, |
| 1540 | aom_highbd_sad16x8x4d_bits8, aom_highbd_jnt_sad16x8_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1541 | aom_highbd_8_jnt_sub_pixel_avg_variance16x8) |
| 1542 | |
| 1543 | HIGHBD_BFP( |
| 1544 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1545 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1546 | aom_highbd_8_sub_pixel_avg_variance8x16, |
| 1547 | aom_highbd_sad8x16x4d_bits8, aom_highbd_jnt_sad8x16_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1548 | aom_highbd_8_jnt_sub_pixel_avg_variance8x16) |
| 1549 | |
| 1550 | HIGHBD_BFP(BLOCK_8X8, aom_highbd_sad8x8_bits8, |
| 1551 | aom_highbd_sad8x8_avg_bits8, aom_highbd_8_variance8x8, |
| 1552 | aom_highbd_8_sub_pixel_variance8x8, |
| 1553 | aom_highbd_8_sub_pixel_avg_variance8x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1554 | aom_highbd_sad8x8x4d_bits8, aom_highbd_jnt_sad8x8_avg_bits8, |
| 1555 | aom_highbd_8_jnt_sub_pixel_avg_variance8x8) |
| 1556 | |
| 1557 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1558 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1559 | aom_highbd_8_sub_pixel_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1560 | aom_highbd_8_sub_pixel_avg_variance8x4, |
| 1561 | aom_highbd_sad8x4x4d_bits8, aom_highbd_jnt_sad8x4_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1562 | aom_highbd_8_jnt_sub_pixel_avg_variance8x4) |
| 1563 | |
| 1564 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1565 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1566 | aom_highbd_8_sub_pixel_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1567 | aom_highbd_8_sub_pixel_avg_variance4x8, |
| 1568 | aom_highbd_sad4x8x4d_bits8, aom_highbd_jnt_sad4x8_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1569 | aom_highbd_8_jnt_sub_pixel_avg_variance4x8) |
| 1570 | |
| 1571 | HIGHBD_BFP(BLOCK_4X4, aom_highbd_sad4x4_bits8, |
| 1572 | aom_highbd_sad4x4_avg_bits8, aom_highbd_8_variance4x4, |
| 1573 | aom_highbd_8_sub_pixel_variance4x4, |
| 1574 | aom_highbd_8_sub_pixel_avg_variance4x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1575 | aom_highbd_sad4x4x4d_bits8, aom_highbd_jnt_sad4x4_avg_bits8, |
| 1576 | aom_highbd_8_jnt_sub_pixel_avg_variance4x4) |
| 1577 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1578 | HIGHBD_BFP( |
| 1579 | BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1580 | aom_highbd_sad128x128_avg_bits8, aom_highbd_8_variance128x128, |
| 1581 | aom_highbd_8_sub_pixel_variance128x128, |
| 1582 | aom_highbd_8_sub_pixel_avg_variance128x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1583 | aom_highbd_sad128x128x4d_bits8, aom_highbd_jnt_sad128x128_avg_bits8, |
| 1584 | aom_highbd_8_jnt_sub_pixel_avg_variance128x128) |
| 1585 | |
| 1586 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1587 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1588 | aom_highbd_8_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1589 | aom_highbd_8_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1590 | aom_highbd_sad128x64x4d_bits8, |
| 1591 | aom_highbd_jnt_sad128x64_avg_bits8, |
| 1592 | aom_highbd_8_jnt_sub_pixel_avg_variance128x64) |
| 1593 | |
| 1594 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1595 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1596 | aom_highbd_8_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1597 | aom_highbd_8_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1598 | aom_highbd_sad64x128x4d_bits8, |
| 1599 | aom_highbd_jnt_sad64x128_avg_bits8, |
| 1600 | aom_highbd_8_jnt_sub_pixel_avg_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1601 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1602 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1603 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1604 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1605 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1606 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1607 | aom_highbd_8_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1608 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1609 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1610 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1611 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1612 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1613 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1614 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1615 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1616 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1617 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1618 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1619 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1620 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1621 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1622 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1623 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1624 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1625 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1626 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1627 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1628 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1629 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1630 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1631 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1632 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1633 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1634 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1635 | aom_highbd_8_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1636 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1637 | aom_highbd_8_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1638 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1639 | aom_highbd_8_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1640 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1641 | aom_highbd_8_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1642 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1643 | aom_highbd_8_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1644 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1645 | aom_highbd_8_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1646 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1647 | aom_highbd_obmc_variance128x128, |
| 1648 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1649 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1650 | aom_highbd_obmc_variance128x64, |
| 1651 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1652 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1653 | aom_highbd_obmc_variance64x128, |
| 1654 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1655 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1656 | aom_highbd_obmc_variance64x64, |
| 1657 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1658 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1659 | aom_highbd_obmc_variance64x32, |
| 1660 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1661 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1662 | aom_highbd_obmc_variance32x64, |
| 1663 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1664 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1665 | aom_highbd_obmc_variance32x32, |
| 1666 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1667 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1668 | aom_highbd_obmc_variance32x16, |
| 1669 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1670 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1671 | aom_highbd_obmc_variance16x32, |
| 1672 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1673 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1674 | aom_highbd_obmc_variance16x16, |
| 1675 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1676 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1677 | aom_highbd_obmc_variance8x16, |
| 1678 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1679 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1680 | aom_highbd_obmc_variance16x8, |
| 1681 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1682 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1683 | aom_highbd_obmc_variance8x8, |
| 1684 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1685 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1686 | aom_highbd_obmc_variance4x8, |
| 1687 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1688 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1689 | aom_highbd_obmc_variance8x4, |
| 1690 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1691 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1692 | aom_highbd_obmc_variance4x4, |
| 1693 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1694 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1695 | aom_highbd_obmc_variance64x16, |
| 1696 | aom_highbd_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1697 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1698 | aom_highbd_obmc_variance16x64, |
| 1699 | aom_highbd_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1700 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1701 | aom_highbd_obmc_variance32x8, |
| 1702 | aom_highbd_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1703 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1704 | aom_highbd_obmc_variance8x32, |
| 1705 | aom_highbd_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1706 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1707 | aom_highbd_obmc_variance16x4, |
| 1708 | aom_highbd_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1709 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1710 | aom_highbd_obmc_variance4x16, |
| 1711 | aom_highbd_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1712 | break; |
| 1713 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1714 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1715 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1716 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1717 | aom_highbd_10_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1718 | aom_highbd_10_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1719 | aom_highbd_sad64x16x4d_bits10, |
| 1720 | aom_highbd_jnt_sad64x16_avg_bits10, |
| 1721 | aom_highbd_10_jnt_sub_pixel_avg_variance64x16); |
| 1722 | |
| 1723 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1724 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1725 | aom_highbd_10_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1726 | aom_highbd_10_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1727 | aom_highbd_sad16x64x4d_bits10, |
| 1728 | aom_highbd_jnt_sad16x64_avg_bits10, |
| 1729 | aom_highbd_10_jnt_sub_pixel_avg_variance16x64); |
| 1730 | |
| 1731 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1732 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1733 | aom_highbd_10_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1734 | aom_highbd_10_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1735 | aom_highbd_sad32x8x4d_bits10, |
| 1736 | aom_highbd_jnt_sad32x8_avg_bits10, |
| 1737 | aom_highbd_10_jnt_sub_pixel_avg_variance32x8); |
| 1738 | |
| 1739 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1740 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1741 | aom_highbd_10_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1742 | aom_highbd_10_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1743 | aom_highbd_sad8x32x4d_bits10, |
| 1744 | aom_highbd_jnt_sad8x32_avg_bits10, |
| 1745 | aom_highbd_10_jnt_sub_pixel_avg_variance8x32); |
| 1746 | |
| 1747 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1748 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1749 | aom_highbd_10_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1750 | aom_highbd_10_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1751 | aom_highbd_sad16x4x4d_bits10, |
| 1752 | aom_highbd_jnt_sad16x4_avg_bits10, |
| 1753 | aom_highbd_10_jnt_sub_pixel_avg_variance16x4); |
| 1754 | |
| 1755 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1756 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1757 | aom_highbd_10_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1758 | aom_highbd_10_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1759 | aom_highbd_sad4x16x4d_bits10, |
| 1760 | aom_highbd_jnt_sad4x16_avg_bits10, |
| 1761 | aom_highbd_10_jnt_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1762 | |
| 1763 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1764 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1765 | aom_highbd_10_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1766 | aom_highbd_10_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1767 | aom_highbd_sad32x16x4d_bits10, |
| 1768 | aom_highbd_jnt_sad32x16_avg_bits10, |
| 1769 | aom_highbd_10_jnt_sub_pixel_avg_variance32x16); |
| 1770 | |
| 1771 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1772 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1773 | aom_highbd_10_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1774 | aom_highbd_10_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1775 | aom_highbd_sad16x32x4d_bits10, |
| 1776 | aom_highbd_jnt_sad16x32_avg_bits10, |
| 1777 | aom_highbd_10_jnt_sub_pixel_avg_variance16x32); |
| 1778 | |
| 1779 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1780 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1781 | aom_highbd_10_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1782 | aom_highbd_10_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1783 | aom_highbd_sad64x32x4d_bits10, |
| 1784 | aom_highbd_jnt_sad64x32_avg_bits10, |
| 1785 | aom_highbd_10_jnt_sub_pixel_avg_variance64x32); |
| 1786 | |
| 1787 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1788 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1789 | aom_highbd_10_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1790 | aom_highbd_10_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1791 | aom_highbd_sad32x64x4d_bits10, |
| 1792 | aom_highbd_jnt_sad32x64_avg_bits10, |
| 1793 | aom_highbd_10_jnt_sub_pixel_avg_variance32x64); |
| 1794 | |
| 1795 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1796 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1797 | aom_highbd_10_sub_pixel_variance32x32, |
| 1798 | aom_highbd_10_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1799 | aom_highbd_sad32x32x4d_bits10, |
| 1800 | aom_highbd_jnt_sad32x32_avg_bits10, |
| 1801 | aom_highbd_10_jnt_sub_pixel_avg_variance32x32); |
| 1802 | |
| 1803 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1804 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1805 | aom_highbd_10_sub_pixel_variance64x64, |
| 1806 | aom_highbd_10_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1807 | aom_highbd_sad64x64x4d_bits10, |
| 1808 | aom_highbd_jnt_sad64x64_avg_bits10, |
| 1809 | aom_highbd_10_jnt_sub_pixel_avg_variance64x64); |
| 1810 | |
| 1811 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1812 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1813 | aom_highbd_10_sub_pixel_variance16x16, |
| 1814 | aom_highbd_10_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1815 | aom_highbd_sad16x16x4d_bits10, |
| 1816 | aom_highbd_jnt_sad16x16_avg_bits10, |
| 1817 | aom_highbd_10_jnt_sub_pixel_avg_variance16x16); |
| 1818 | |
| 1819 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1820 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1821 | aom_highbd_10_sub_pixel_variance16x8, |
| 1822 | aom_highbd_10_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1823 | aom_highbd_sad16x8x4d_bits10, |
| 1824 | aom_highbd_jnt_sad16x8_avg_bits10, |
| 1825 | aom_highbd_10_jnt_sub_pixel_avg_variance16x8); |
| 1826 | |
| 1827 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1828 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1829 | aom_highbd_10_sub_pixel_variance8x16, |
| 1830 | aom_highbd_10_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1831 | aom_highbd_sad8x16x4d_bits10, |
| 1832 | aom_highbd_jnt_sad8x16_avg_bits10, |
| 1833 | aom_highbd_10_jnt_sub_pixel_avg_variance8x16); |
| 1834 | |
| 1835 | HIGHBD_BFP( |
| 1836 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1837 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1838 | aom_highbd_10_sub_pixel_avg_variance8x8, |
| 1839 | aom_highbd_sad8x8x4d_bits10, aom_highbd_jnt_sad8x8_avg_bits10, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1840 | aom_highbd_10_jnt_sub_pixel_avg_variance8x8); |
| 1841 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1842 | HIGHBD_BFP( |
| 1843 | BLOCK_8X4, aom_highbd_sad8x4_bits10, aom_highbd_sad8x4_avg_bits10, |
| 1844 | aom_highbd_10_variance8x4, aom_highbd_10_sub_pixel_variance8x4, |
| 1845 | aom_highbd_10_sub_pixel_avg_variance8x4, |
| 1846 | aom_highbd_sad8x4x4d_bits10, aom_highbd_jnt_sad8x4_avg_bits10, |
| 1847 | aom_highbd_10_jnt_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1848 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1849 | HIGHBD_BFP( |
| 1850 | BLOCK_4X8, aom_highbd_sad4x8_bits10, aom_highbd_sad4x8_avg_bits10, |
| 1851 | aom_highbd_10_variance4x8, aom_highbd_10_sub_pixel_variance4x8, |
| 1852 | aom_highbd_10_sub_pixel_avg_variance4x8, |
| 1853 | aom_highbd_sad4x8x4d_bits10, aom_highbd_jnt_sad4x8_avg_bits10, |
| 1854 | aom_highbd_10_jnt_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1855 | |
| 1856 | HIGHBD_BFP( |
| 1857 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1858 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1859 | aom_highbd_10_sub_pixel_avg_variance4x4, |
| 1860 | aom_highbd_sad4x4x4d_bits10, aom_highbd_jnt_sad4x4_avg_bits10, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1861 | aom_highbd_10_jnt_sub_pixel_avg_variance4x4); |
| 1862 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1863 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1864 | aom_highbd_sad128x128_avg_bits10, |
| 1865 | aom_highbd_10_variance128x128, |
| 1866 | aom_highbd_10_sub_pixel_variance128x128, |
| 1867 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1868 | aom_highbd_sad128x128x4d_bits10, |
| 1869 | aom_highbd_jnt_sad128x128_avg_bits10, |
| 1870 | aom_highbd_10_jnt_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1871 | |
| 1872 | HIGHBD_BFP( |
| 1873 | BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1874 | aom_highbd_sad128x64_avg_bits10, aom_highbd_10_variance128x64, |
| 1875 | aom_highbd_10_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1876 | aom_highbd_10_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1877 | aom_highbd_sad128x64x4d_bits10, aom_highbd_jnt_sad128x64_avg_bits10, |
| 1878 | aom_highbd_10_jnt_sub_pixel_avg_variance128x64); |
| 1879 | |
| 1880 | HIGHBD_BFP( |
| 1881 | BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1882 | aom_highbd_sad64x128_avg_bits10, aom_highbd_10_variance64x128, |
| 1883 | aom_highbd_10_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1884 | aom_highbd_10_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1885 | aom_highbd_sad64x128x4d_bits10, aom_highbd_jnt_sad64x128_avg_bits10, |
| 1886 | aom_highbd_10_jnt_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1887 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1888 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1889 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1890 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1891 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1892 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1893 | aom_highbd_10_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1894 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1895 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1896 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1897 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1898 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1899 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1900 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1901 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1902 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1903 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1904 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1905 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1906 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1907 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1908 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1909 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1910 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1911 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1912 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1913 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1914 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1915 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1916 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1917 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1918 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1919 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1920 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1921 | aom_highbd_10_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1922 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1923 | aom_highbd_10_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1924 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1925 | aom_highbd_10_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1926 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 1927 | aom_highbd_10_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1928 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 1929 | aom_highbd_10_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1930 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 1931 | aom_highbd_10_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1932 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1933 | aom_highbd_10_obmc_variance128x128, |
| 1934 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1935 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1936 | aom_highbd_10_obmc_variance128x64, |
| 1937 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1938 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1939 | aom_highbd_10_obmc_variance64x128, |
| 1940 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1941 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 1942 | aom_highbd_10_obmc_variance64x64, |
| 1943 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 1944 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 1945 | aom_highbd_10_obmc_variance64x32, |
| 1946 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 1947 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 1948 | aom_highbd_10_obmc_variance32x64, |
| 1949 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 1950 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 1951 | aom_highbd_10_obmc_variance32x32, |
| 1952 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 1953 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 1954 | aom_highbd_10_obmc_variance32x16, |
| 1955 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 1956 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 1957 | aom_highbd_10_obmc_variance16x32, |
| 1958 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 1959 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 1960 | aom_highbd_10_obmc_variance16x16, |
| 1961 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 1962 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 1963 | aom_highbd_10_obmc_variance8x16, |
| 1964 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 1965 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 1966 | aom_highbd_10_obmc_variance16x8, |
| 1967 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 1968 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 1969 | aom_highbd_10_obmc_variance8x8, |
| 1970 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 1971 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 1972 | aom_highbd_10_obmc_variance4x8, |
| 1973 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 1974 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 1975 | aom_highbd_10_obmc_variance8x4, |
| 1976 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 1977 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 1978 | aom_highbd_10_obmc_variance4x4, |
| 1979 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1980 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1981 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 1982 | aom_highbd_10_obmc_variance64x16, |
| 1983 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 1984 | |
| 1985 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 1986 | aom_highbd_10_obmc_variance16x64, |
| 1987 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 1988 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1989 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 1990 | aom_highbd_10_obmc_variance32x8, |
| 1991 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 1992 | |
| 1993 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 1994 | aom_highbd_10_obmc_variance8x32, |
| 1995 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 1996 | |
| 1997 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 1998 | aom_highbd_10_obmc_variance16x4, |
| 1999 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2000 | |
| 2001 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2002 | aom_highbd_10_obmc_variance4x16, |
| 2003 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2004 | break; |
| 2005 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2006 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2007 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2008 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2009 | aom_highbd_12_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2010 | aom_highbd_12_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2011 | aom_highbd_sad64x16x4d_bits12, |
| 2012 | aom_highbd_jnt_sad64x16_avg_bits12, |
| 2013 | aom_highbd_12_jnt_sub_pixel_avg_variance64x16); |
| 2014 | |
| 2015 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2016 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2017 | aom_highbd_12_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2018 | aom_highbd_12_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2019 | aom_highbd_sad16x64x4d_bits12, |
| 2020 | aom_highbd_jnt_sad16x64_avg_bits12, |
| 2021 | aom_highbd_12_jnt_sub_pixel_avg_variance16x64); |
| 2022 | |
| 2023 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2024 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2025 | aom_highbd_12_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2026 | aom_highbd_12_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2027 | aom_highbd_sad32x8x4d_bits12, |
| 2028 | aom_highbd_jnt_sad32x8_avg_bits12, |
| 2029 | aom_highbd_12_jnt_sub_pixel_avg_variance32x8); |
| 2030 | |
| 2031 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2032 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2033 | aom_highbd_12_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2034 | aom_highbd_12_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2035 | aom_highbd_sad8x32x4d_bits12, |
| 2036 | aom_highbd_jnt_sad8x32_avg_bits12, |
| 2037 | aom_highbd_12_jnt_sub_pixel_avg_variance8x32); |
| 2038 | |
| 2039 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2040 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2041 | aom_highbd_12_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2042 | aom_highbd_12_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2043 | aom_highbd_sad16x4x4d_bits12, |
| 2044 | aom_highbd_jnt_sad16x4_avg_bits12, |
| 2045 | aom_highbd_12_jnt_sub_pixel_avg_variance16x4); |
| 2046 | |
| 2047 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2048 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2049 | aom_highbd_12_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2050 | aom_highbd_12_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2051 | aom_highbd_sad4x16x4d_bits12, |
| 2052 | aom_highbd_jnt_sad4x16_avg_bits12, |
| 2053 | aom_highbd_12_jnt_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2054 | |
| 2055 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2056 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2057 | aom_highbd_12_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2058 | aom_highbd_12_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2059 | aom_highbd_sad32x16x4d_bits12, |
| 2060 | aom_highbd_jnt_sad32x16_avg_bits12, |
| 2061 | aom_highbd_12_jnt_sub_pixel_avg_variance32x16); |
| 2062 | |
| 2063 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2064 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2065 | aom_highbd_12_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2066 | aom_highbd_12_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2067 | aom_highbd_sad16x32x4d_bits12, |
| 2068 | aom_highbd_jnt_sad16x32_avg_bits12, |
| 2069 | aom_highbd_12_jnt_sub_pixel_avg_variance16x32); |
| 2070 | |
| 2071 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2072 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2073 | aom_highbd_12_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2074 | aom_highbd_12_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2075 | aom_highbd_sad64x32x4d_bits12, |
| 2076 | aom_highbd_jnt_sad64x32_avg_bits12, |
| 2077 | aom_highbd_12_jnt_sub_pixel_avg_variance64x32); |
| 2078 | |
| 2079 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2080 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2081 | aom_highbd_12_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2082 | aom_highbd_12_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2083 | aom_highbd_sad32x64x4d_bits12, |
| 2084 | aom_highbd_jnt_sad32x64_avg_bits12, |
| 2085 | aom_highbd_12_jnt_sub_pixel_avg_variance32x64); |
| 2086 | |
| 2087 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2088 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2089 | aom_highbd_12_sub_pixel_variance32x32, |
| 2090 | aom_highbd_12_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2091 | aom_highbd_sad32x32x4d_bits12, |
| 2092 | aom_highbd_jnt_sad32x32_avg_bits12, |
| 2093 | aom_highbd_12_jnt_sub_pixel_avg_variance32x32); |
| 2094 | |
| 2095 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2096 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2097 | aom_highbd_12_sub_pixel_variance64x64, |
| 2098 | aom_highbd_12_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2099 | aom_highbd_sad64x64x4d_bits12, |
| 2100 | aom_highbd_jnt_sad64x64_avg_bits12, |
| 2101 | aom_highbd_12_jnt_sub_pixel_avg_variance64x64); |
| 2102 | |
| 2103 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2104 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2105 | aom_highbd_12_sub_pixel_variance16x16, |
| 2106 | aom_highbd_12_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2107 | aom_highbd_sad16x16x4d_bits12, |
| 2108 | aom_highbd_jnt_sad16x16_avg_bits12, |
| 2109 | aom_highbd_12_jnt_sub_pixel_avg_variance16x16); |
| 2110 | |
| 2111 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2112 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2113 | aom_highbd_12_sub_pixel_variance16x8, |
| 2114 | aom_highbd_12_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2115 | aom_highbd_sad16x8x4d_bits12, |
| 2116 | aom_highbd_jnt_sad16x8_avg_bits12, |
| 2117 | aom_highbd_12_jnt_sub_pixel_avg_variance16x8); |
| 2118 | |
| 2119 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2120 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2121 | aom_highbd_12_sub_pixel_variance8x16, |
| 2122 | aom_highbd_12_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2123 | aom_highbd_sad8x16x4d_bits12, |
| 2124 | aom_highbd_jnt_sad8x16_avg_bits12, |
| 2125 | aom_highbd_12_jnt_sub_pixel_avg_variance8x16); |
| 2126 | |
| 2127 | HIGHBD_BFP( |
| 2128 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2129 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2130 | aom_highbd_12_sub_pixel_avg_variance8x8, |
| 2131 | aom_highbd_sad8x8x4d_bits12, aom_highbd_jnt_sad8x8_avg_bits12, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2132 | aom_highbd_12_jnt_sub_pixel_avg_variance8x8); |
| 2133 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2134 | HIGHBD_BFP( |
| 2135 | BLOCK_8X4, aom_highbd_sad8x4_bits12, aom_highbd_sad8x4_avg_bits12, |
| 2136 | aom_highbd_12_variance8x4, aom_highbd_12_sub_pixel_variance8x4, |
| 2137 | aom_highbd_12_sub_pixel_avg_variance8x4, |
| 2138 | aom_highbd_sad8x4x4d_bits12, aom_highbd_jnt_sad8x4_avg_bits12, |
| 2139 | aom_highbd_12_jnt_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2140 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2141 | HIGHBD_BFP( |
| 2142 | BLOCK_4X8, aom_highbd_sad4x8_bits12, aom_highbd_sad4x8_avg_bits12, |
| 2143 | aom_highbd_12_variance4x8, aom_highbd_12_sub_pixel_variance4x8, |
| 2144 | aom_highbd_12_sub_pixel_avg_variance4x8, |
| 2145 | aom_highbd_sad4x8x4d_bits12, aom_highbd_jnt_sad4x8_avg_bits12, |
| 2146 | aom_highbd_12_jnt_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2147 | |
| 2148 | HIGHBD_BFP( |
| 2149 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2150 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2151 | aom_highbd_12_sub_pixel_avg_variance4x4, |
| 2152 | aom_highbd_sad4x4x4d_bits12, aom_highbd_jnt_sad4x4_avg_bits12, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2153 | aom_highbd_12_jnt_sub_pixel_avg_variance4x4); |
| 2154 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2155 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2156 | aom_highbd_sad128x128_avg_bits12, |
| 2157 | aom_highbd_12_variance128x128, |
| 2158 | aom_highbd_12_sub_pixel_variance128x128, |
| 2159 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2160 | aom_highbd_sad128x128x4d_bits12, |
| 2161 | aom_highbd_jnt_sad128x128_avg_bits12, |
| 2162 | aom_highbd_12_jnt_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2163 | |
| 2164 | HIGHBD_BFP( |
| 2165 | BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2166 | aom_highbd_sad128x64_avg_bits12, aom_highbd_12_variance128x64, |
| 2167 | aom_highbd_12_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2168 | aom_highbd_12_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2169 | aom_highbd_sad128x64x4d_bits12, aom_highbd_jnt_sad128x64_avg_bits12, |
| 2170 | aom_highbd_12_jnt_sub_pixel_avg_variance128x64); |
| 2171 | |
| 2172 | HIGHBD_BFP( |
| 2173 | BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2174 | aom_highbd_sad64x128_avg_bits12, aom_highbd_12_variance64x128, |
| 2175 | aom_highbd_12_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2176 | aom_highbd_12_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2177 | aom_highbd_sad64x128x4d_bits12, aom_highbd_jnt_sad64x128_avg_bits12, |
| 2178 | aom_highbd_12_jnt_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2179 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2180 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2181 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2182 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2183 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2184 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2185 | aom_highbd_12_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2186 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2187 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2188 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2189 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2190 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2191 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2192 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2193 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2194 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2195 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2196 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2197 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2198 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2199 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2200 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2201 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2202 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2203 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2204 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2205 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2206 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2207 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2208 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2209 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2210 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2211 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2212 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2213 | aom_highbd_12_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2214 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2215 | aom_highbd_12_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2216 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2217 | aom_highbd_12_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2218 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2219 | aom_highbd_12_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2220 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2221 | aom_highbd_12_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2222 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2223 | aom_highbd_12_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2224 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2225 | aom_highbd_12_obmc_variance128x128, |
| 2226 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2227 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2228 | aom_highbd_12_obmc_variance128x64, |
| 2229 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2230 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2231 | aom_highbd_12_obmc_variance64x128, |
| 2232 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2233 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2234 | aom_highbd_12_obmc_variance64x64, |
| 2235 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2236 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2237 | aom_highbd_12_obmc_variance64x32, |
| 2238 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2239 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2240 | aom_highbd_12_obmc_variance32x64, |
| 2241 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2242 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2243 | aom_highbd_12_obmc_variance32x32, |
| 2244 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2245 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2246 | aom_highbd_12_obmc_variance32x16, |
| 2247 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2248 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2249 | aom_highbd_12_obmc_variance16x32, |
| 2250 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2251 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2252 | aom_highbd_12_obmc_variance16x16, |
| 2253 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2254 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2255 | aom_highbd_12_obmc_variance8x16, |
| 2256 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2257 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2258 | aom_highbd_12_obmc_variance16x8, |
| 2259 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2260 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2261 | aom_highbd_12_obmc_variance8x8, |
| 2262 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2263 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2264 | aom_highbd_12_obmc_variance4x8, |
| 2265 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2266 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2267 | aom_highbd_12_obmc_variance8x4, |
| 2268 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2269 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2270 | aom_highbd_12_obmc_variance4x4, |
| 2271 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2272 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2273 | aom_highbd_12_obmc_variance64x16, |
| 2274 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2275 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2276 | aom_highbd_12_obmc_variance16x64, |
| 2277 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2278 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2279 | aom_highbd_12_obmc_variance32x8, |
| 2280 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2281 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2282 | aom_highbd_12_obmc_variance8x32, |
| 2283 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2284 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2285 | aom_highbd_12_obmc_variance16x4, |
| 2286 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2287 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2288 | aom_highbd_12_obmc_variance4x16, |
| 2289 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2290 | break; |
| 2291 | |
| 2292 | default: |
| 2293 | assert(0 && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2294 | "cm->seq_params.bit_depth should be AOM_BITS_8, " |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2295 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2296 | } |
| 2297 | } |
| 2298 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2299 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2300 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2301 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2302 | |
| 2303 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2304 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2305 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2306 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2307 | |
| 2308 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2309 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2310 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2311 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2312 | |
| 2313 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2314 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2315 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2316 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2319 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2320 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2321 | SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2322 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2323 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2324 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2325 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2326 | if (seq_params->profile != oxcf->profile) seq_params->profile = oxcf->profile; |
| 2327 | seq_params->bit_depth = oxcf->bit_depth; |
| 2328 | seq_params->color_primaries = oxcf->color_primaries; |
| 2329 | seq_params->transfer_characteristics = oxcf->transfer_characteristics; |
| 2330 | seq_params->matrix_coefficients = oxcf->matrix_coefficients; |
| 2331 | seq_params->monochrome = oxcf->monochrome; |
| 2332 | seq_params->chroma_sample_position = oxcf->chroma_sample_position; |
| 2333 | seq_params->color_range = oxcf->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2334 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2335 | assert(IMPLIES(seq_params->profile <= PROFILE_1, |
| 2336 | seq_params->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2337 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2338 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2339 | cm->timing_info.num_units_in_display_tick = |
| 2340 | oxcf->timing_info.num_units_in_display_tick; |
| 2341 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 2342 | cm->timing_info.equal_picture_interval = |
| 2343 | oxcf->timing_info.equal_picture_interval; |
| 2344 | cm->timing_info.num_ticks_per_picture = |
| 2345 | oxcf->timing_info.num_ticks_per_picture; |
| 2346 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2347 | seq_params->display_model_info_present_flag = |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2348 | oxcf->display_model_info_present_flag; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2349 | seq_params->decoder_model_info_present_flag = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2350 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2351 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2352 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2353 | cm->buffer_model.num_units_in_decoding_tick = |
| 2354 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 2355 | cm->buffer_removal_time_present = 1; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2356 | set_aom_dec_model_info(&cm->buffer_model); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2357 | set_dec_model_op_parameters(&cm->op_params[0]); |
| 2358 | } else if (cm->timing_info_present && |
| 2359 | cm->timing_info.equal_picture_interval && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2360 | !seq_params->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2361 | // set the decoder model parameters in resource availability mode |
| 2362 | set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 2363 | } else { |
| 2364 | cm->op_params[0].initial_display_delay = |
| 2365 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2366 | } |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2367 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2368 | update_film_grain_parameters(cpi, oxcf); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2369 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2370 | cpi->oxcf = *oxcf; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 2371 | cpi->common.options = oxcf->cfg; |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 2372 | cpi->row_mt = oxcf->row_mt; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2373 | x->e_mbd.bd = (int)seq_params->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2374 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2375 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2376 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2377 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2378 | } else { |
| 2379 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2380 | } |
| 2381 | |
| 2382 | cpi->refresh_last_frame = 1; |
| 2383 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2384 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2385 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2386 | |
Debargha Mukherjee | 229fdc8 | 2018-03-10 07:45:33 -0800 | [diff] [blame] | 2387 | cm->refresh_frame_context = (oxcf->frame_parallel_decoding_mode) |
| 2388 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 2389 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2390 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 2391 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2392 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2393 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2394 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2395 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2396 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2397 | |
| 2398 | if (x->tmp_conv_dst == NULL) { |
| 2399 | CHECK_MEM_ERROR( |
| 2400 | cm, x->tmp_conv_dst, |
| 2401 | aom_memalign(32, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(*x->tmp_conv_dst))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2402 | x->e_mbd.tmp_conv_dst = x->tmp_conv_dst; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2403 | } |
| 2404 | for (int i = 0; i < 2; ++i) { |
| 2405 | if (x->tmp_obmc_bufs[i] == NULL) { |
| 2406 | CHECK_MEM_ERROR(cm, x->tmp_obmc_bufs[i], |
| 2407 | aom_memalign(16, 2 * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2408 | sizeof(*x->tmp_obmc_bufs[i]))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2409 | x->e_mbd.tmp_obmc_bufs[i] = x->tmp_obmc_bufs[i]; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2413 | av1_reset_segment_features(cm); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2414 | set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2415 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2416 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2417 | |
| 2418 | // Under a configuration change, where maximum_buffer_size may change, |
| 2419 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2420 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2421 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2422 | |
| 2423 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2424 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2425 | |
| 2426 | // Set absolute upper and lower quality limits |
| 2427 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2428 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2429 | |
Urvang Joshi | b55cb5e | 2018-09-12 14:50:21 -0700 | [diff] [blame] | 2430 | cm->interp_filter = oxcf->large_scale_tile ? EIGHTTAP_REGULAR : SWITCHABLE; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 2431 | cm->switchable_motion_mode = 1; |
| 2432 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2433 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2434 | cm->render_width = cpi->oxcf.render_width; |
| 2435 | cm->render_height = cpi->oxcf.render_height; |
| 2436 | } else { |
| 2437 | cm->render_width = cpi->oxcf.width; |
| 2438 | cm->render_height = cpi->oxcf.height; |
| 2439 | } |
| 2440 | cm->width = cpi->oxcf.width; |
| 2441 | cm->height = cpi->oxcf.height; |
| 2442 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2443 | int sb_size = seq_params->sb_size; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2444 | // Superblock size should not be updated after the first key frame. |
| 2445 | if (!cpi->seq_params_locked) { |
| 2446 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
| 2447 | } |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2448 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2449 | if (cpi->initial_width || sb_size != seq_params->sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2450 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2451 | seq_params->sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2452 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2453 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2454 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2455 | realloc_segmentation_maps(cpi); |
| 2456 | cpi->initial_width = cpi->initial_height = 0; |
| 2457 | } |
| 2458 | } |
| 2459 | update_frame_size(cpi); |
| 2460 | |
| 2461 | cpi->alt_ref_source = NULL; |
| 2462 | rc->is_src_frame_alt_ref = 0; |
| 2463 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2464 | rc->is_bwd_ref_frame = 0; |
| 2465 | rc->is_last_bipred_frame = 0; |
| 2466 | rc->is_bipred_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2467 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2468 | set_tile_info(cpi); |
| 2469 | |
| 2470 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2471 | cpi->ext_refresh_frame_context_pending = 0; |
| 2472 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2473 | highbd_set_var_fns(cpi); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 2474 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 2475 | // Init sequence level coding tools |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2476 | // This should not be called after the first key frame. |
| 2477 | if (!cpi->seq_params_locked) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2478 | seq_params->operating_points_cnt_minus_1 = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2479 | cm->number_spatial_layers > 1 ? cm->number_spatial_layers - 1 : 0; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2480 | init_seq_coding_tools(&cm->seq_params, cm, oxcf); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2481 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2484 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2485 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2486 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2487 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2488 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2489 | |
| 2490 | if (!cm) return NULL; |
| 2491 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2492 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2493 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 2494 | // The jmp_buf is valid only for the duration of the function that calls |
| 2495 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 2496 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2497 | if (setjmp(cm->error.jmp)) { |
| 2498 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2499 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2500 | return 0; |
| 2501 | } |
| 2502 | |
| 2503 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2504 | cm->alloc_mi = enc_alloc_mi; |
| 2505 | cm->free_mi = enc_free_mi; |
| 2506 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2507 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2508 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2509 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2510 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2511 | (FRAME_CONTEXT *)aom_memalign( |
| 2512 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2513 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2514 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2515 | |
| 2516 | cpi->resize_state = 0; |
| 2517 | cpi->resize_avg_qp = 0; |
| 2518 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2519 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2520 | cpi->common.buffer_pool = pool; |
| 2521 | |
| 2522 | init_config(cpi, oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2523 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2524 | |
| 2525 | cm->current_video_frame = 0; |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2526 | cpi->seq_params_locked = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2527 | cpi->partition_search_skippable_frame = 0; |
| 2528 | cpi->tile_data = NULL; |
| 2529 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2530 | |
| 2531 | realloc_segmentation_maps(cpi); |
| 2532 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2533 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2534 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2535 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2536 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2537 | i++) { |
| 2538 | CHECK_MEM_ERROR( |
| 2539 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2540 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | #if CONFIG_FP_MB_STATS |
| 2544 | cpi->use_fp_mb_stats = 0; |
| 2545 | if (cpi->use_fp_mb_stats) { |
| 2546 | // a place holder used to store the first pass mb stats in the first pass |
| 2547 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2548 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2549 | } else { |
| 2550 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2551 | } |
| 2552 | #endif |
| 2553 | |
| 2554 | cpi->refresh_alt_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2555 | |
| 2556 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2557 | #if CONFIG_INTERNAL_STATS |
| 2558 | cpi->b_calculate_blockiness = 1; |
| 2559 | cpi->b_calculate_consistency = 1; |
| 2560 | cpi->total_inconsistency = 0; |
| 2561 | cpi->psnr.worst = 100.0; |
| 2562 | cpi->worst_ssim = 100.0; |
| 2563 | |
| 2564 | cpi->count = 0; |
| 2565 | cpi->bytes = 0; |
| 2566 | |
| 2567 | if (cpi->b_calculate_psnr) { |
| 2568 | cpi->total_sq_error = 0; |
| 2569 | cpi->total_samples = 0; |
| 2570 | cpi->tot_recode_hits = 0; |
| 2571 | cpi->summed_quality = 0; |
| 2572 | cpi->summed_weights = 0; |
| 2573 | } |
| 2574 | |
| 2575 | cpi->fastssim.worst = 100.0; |
| 2576 | cpi->psnrhvs.worst = 100.0; |
| 2577 | |
| 2578 | if (cpi->b_calculate_blockiness) { |
| 2579 | cpi->total_blockiness = 0; |
| 2580 | cpi->worst_blockiness = 0.0; |
| 2581 | } |
| 2582 | |
| 2583 | if (cpi->b_calculate_consistency) { |
| 2584 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2585 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2586 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2587 | cpi->worst_consistency = 100.0; |
| 2588 | } |
| 2589 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2590 | #if CONFIG_ENTROPY_STATS |
| 2591 | av1_zero(aggregate_fc); |
| 2592 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2593 | |
| 2594 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2595 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2596 | cpi->td.mb.nmvcost[0] = &cpi->nmv_costs[0][MV_MAX]; |
| 2597 | cpi->td.mb.nmvcost[1] = &cpi->nmv_costs[1][MV_MAX]; |
| 2598 | cpi->td.mb.nmvcost_hp[0] = &cpi->nmv_costs_hp[0][MV_MAX]; |
| 2599 | 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] | 2600 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2601 | #ifdef OUTPUT_YUV_SKINMAP |
| 2602 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2603 | #endif |
| 2604 | #ifdef OUTPUT_YUV_REC |
| 2605 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2606 | #endif |
| 2607 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2608 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2609 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2610 | } else if (oxcf->pass == 2) { |
| 2611 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2612 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2613 | |
| 2614 | #if CONFIG_FP_MB_STATS |
| 2615 | if (cpi->use_fp_mb_stats) { |
| 2616 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2617 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2618 | |
| 2619 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2620 | oxcf->firstpass_mb_stats_in.buf; |
| 2621 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2622 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2623 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2624 | } |
| 2625 | #endif |
| 2626 | |
| 2627 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2628 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2629 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2630 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2631 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2634 | CHECK_MEM_ERROR( |
| 2635 | cm, cpi->td.mb.above_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2636 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2637 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2638 | CHECK_MEM_ERROR( |
| 2639 | cm, cpi->td.mb.left_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2640 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2641 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2642 | |
| 2643 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2644 | (int32_t *)aom_memalign( |
| 2645 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2646 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 2647 | for (int x = 0; x < 2; x++) |
| 2648 | for (int y = 0; y < 2; y++) |
| 2649 | CHECK_MEM_ERROR( |
| 2650 | cm, cpi->td.mb.hash_value_buffer[x][y], |
| 2651 | (uint32_t *)aom_malloc(AOM_BUFFER_SIZE_FOR_BLOCK_HASH * |
| 2652 | sizeof(*cpi->td.mb.hash_value_buffer[0][0]))); |
| 2653 | |
| 2654 | cpi->td.mb.g_crc_initialized = 0; |
| 2655 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2656 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2657 | (int32_t *)aom_memalign( |
| 2658 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2659 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2660 | av1_set_speed_features_framesize_independent(cpi); |
| 2661 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2662 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2663 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 2664 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2665 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2666 | cpi->fn_ptr[BT].vf = VF; \ |
| 2667 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2668 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2669 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 2670 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2671 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2672 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2673 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2674 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2675 | aom_sad4x16x4d, aom_jnt_sad4x16_avg, aom_jnt_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2676 | |
| 2677 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2678 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2679 | aom_sad16x4x4d, aom_jnt_sad16x4_avg, aom_jnt_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2680 | |
| 2681 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2682 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2683 | aom_sad8x32x4d, aom_jnt_sad8x32_avg, aom_jnt_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2684 | |
| 2685 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2686 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2687 | aom_sad32x8x4d, aom_jnt_sad32x8_avg, aom_jnt_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2688 | |
| 2689 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2690 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2691 | aom_sad16x64x4d, aom_jnt_sad16x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2692 | aom_jnt_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2693 | |
| 2694 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2695 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2696 | aom_sad64x16x4d, aom_jnt_sad64x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2697 | aom_jnt_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2698 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2699 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2700 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2701 | aom_sad128x128x4d, aom_jnt_sad128x128_avg, |
| 2702 | aom_jnt_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2703 | |
| 2704 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2705 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, |
| 2706 | aom_sad128x64x4d, aom_jnt_sad128x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2707 | aom_jnt_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2708 | |
| 2709 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2710 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, |
| 2711 | aom_sad64x128x4d, aom_jnt_sad64x128_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2712 | aom_jnt_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2713 | |
| 2714 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2715 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2716 | aom_sad32x16x4d, aom_jnt_sad32x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2717 | aom_jnt_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2718 | |
| 2719 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2720 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2721 | aom_sad16x32x4d, aom_jnt_sad16x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2722 | aom_jnt_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2723 | |
| 2724 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2725 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2726 | aom_sad64x32x4d, aom_jnt_sad64x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2727 | aom_jnt_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2728 | |
| 2729 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2730 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2731 | aom_sad32x64x4d, aom_jnt_sad32x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2732 | aom_jnt_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2733 | |
| 2734 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2735 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2736 | aom_sad32x32x4d, aom_jnt_sad32x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2737 | aom_jnt_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2738 | |
| 2739 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2740 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2741 | aom_sad64x64x4d, aom_jnt_sad64x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2742 | aom_jnt_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2743 | |
| 2744 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2745 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2746 | aom_sad16x16x4d, aom_jnt_sad16x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2747 | aom_jnt_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2748 | |
| 2749 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2750 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, |
| 2751 | aom_sad16x8x4d, aom_jnt_sad16x8_avg, aom_jnt_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2752 | |
| 2753 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2754 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, |
| 2755 | aom_sad8x16x4d, aom_jnt_sad8x16_avg, aom_jnt_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2756 | |
| 2757 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2758 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x4d, |
| 2759 | aom_jnt_sad8x8_avg, aom_jnt_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2760 | |
| 2761 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2762 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, aom_sad8x4x4d, |
| 2763 | aom_jnt_sad8x4_avg, aom_jnt_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2764 | |
| 2765 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2766 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, aom_sad4x8x4d, |
| 2767 | aom_jnt_sad4x8_avg, aom_jnt_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2768 | |
| 2769 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2770 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x4d, |
| 2771 | aom_jnt_sad4x4_avg, aom_jnt_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2772 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2773 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2774 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2775 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2776 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2777 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2778 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2779 | aom_obmc_sub_pixel_variance128x128) |
| 2780 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2781 | aom_obmc_sub_pixel_variance128x64) |
| 2782 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2783 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2784 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2785 | aom_obmc_sub_pixel_variance64x64) |
| 2786 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2787 | aom_obmc_sub_pixel_variance64x32) |
| 2788 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2789 | aom_obmc_sub_pixel_variance32x64) |
| 2790 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2791 | aom_obmc_sub_pixel_variance32x32) |
| 2792 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2793 | aom_obmc_sub_pixel_variance32x16) |
| 2794 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2795 | aom_obmc_sub_pixel_variance16x32) |
| 2796 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2797 | aom_obmc_sub_pixel_variance16x16) |
| 2798 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2799 | aom_obmc_sub_pixel_variance16x8) |
| 2800 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2801 | aom_obmc_sub_pixel_variance8x16) |
| 2802 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2803 | aom_obmc_sub_pixel_variance8x8) |
| 2804 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2805 | aom_obmc_sub_pixel_variance4x8) |
| 2806 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2807 | aom_obmc_sub_pixel_variance8x4) |
| 2808 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2809 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2810 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2811 | aom_obmc_sub_pixel_variance4x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2812 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2813 | aom_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2814 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2815 | aom_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2816 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2817 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2818 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2819 | aom_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2820 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2821 | aom_obmc_sub_pixel_variance64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2822 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2823 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2824 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2825 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2826 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2827 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2828 | aom_masked_sub_pixel_variance128x128) |
| 2829 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2830 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2831 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2832 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2833 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2834 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2835 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2836 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2837 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2838 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2839 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2840 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2841 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2842 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2843 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2844 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2845 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 2846 | |
| 2847 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 2848 | |
| 2849 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 2850 | |
| 2851 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2852 | |
| 2853 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 2854 | |
| 2855 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2856 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2857 | highbd_set_var_fns(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2858 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2859 | /* av1_init_quantizer() is first called here. Add check in |
| 2860 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2861 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2862 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2863 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2864 | av1_init_quantizer(cpi); |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 2865 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2866 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2867 | av1_loop_filter_init(cm); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 2868 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 2869 | cm->superres_upscaled_width = oxcf->width; |
| 2870 | cm->superres_upscaled_height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2871 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2872 | |
| 2873 | cm->error.setjmp = 0; |
| 2874 | |
| 2875 | return cpi; |
| 2876 | } |
| 2877 | |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2878 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2879 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2880 | |
| 2881 | #define SNPRINT2(H, T, V) \ |
| 2882 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2883 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2884 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2885 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2886 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2887 | unsigned int i; |
| 2888 | int t; |
| 2889 | |
| 2890 | if (!cpi) return; |
| 2891 | |
| 2892 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2893 | const int num_planes = av1_num_planes(cm); |
| 2894 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2895 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2896 | #if CONFIG_ENTROPY_STATS |
| 2897 | if (cpi->oxcf.pass != 1) { |
| 2898 | fprintf(stderr, "Writing counts.stt\n"); |
| 2899 | FILE *f = fopen("counts.stt", "wb"); |
| 2900 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 2901 | fclose(f); |
| 2902 | } |
| 2903 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2904 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2905 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2906 | |
| 2907 | if (cpi->oxcf.pass != 1) { |
| 2908 | char headings[512] = { 0 }; |
| 2909 | char results[512] = { 0 }; |
| 2910 | FILE *f = fopen("opsnr.stt", "a"); |
| 2911 | double time_encoded = |
| 2912 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 2913 | 10000000.000; |
| 2914 | double total_encode_time = |
| 2915 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 2916 | const double dr = |
| 2917 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 2918 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 2919 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 2920 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 2921 | |
| 2922 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2923 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2924 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 2925 | const double total_ssim = |
| 2926 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 2927 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2928 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2929 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 2930 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2931 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2932 | snprintf(results, sizeof(results), |
| 2933 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2934 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 2935 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 2936 | "%7.3f\t%7.3f\t%7.3f", |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 2937 | dr, cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, |
| 2938 | cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, total_ssim, |
| 2939 | total_ssim, cpi->fastssim.stat[STAT_ALL] / cpi->count, |
| 2940 | cpi->psnrhvs.stat[STAT_ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 2941 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 2942 | cpi->psnr.stat[STAT_Y] / cpi->count, |
| 2943 | cpi->psnr.stat[STAT_U] / cpi->count, |
| 2944 | cpi->psnr.stat[STAT_V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2945 | |
| 2946 | if (cpi->b_calculate_blockiness) { |
| 2947 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 2948 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 2949 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 2950 | } |
| 2951 | |
| 2952 | if (cpi->b_calculate_consistency) { |
| 2953 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2954 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2955 | (double)cpi->total_inconsistency); |
| 2956 | |
| 2957 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 2958 | SNPRINT2(results, "\t%7.3f", consistency); |
| 2959 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 2960 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 2961 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 2962 | 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] | 2963 | rate_err, fabs(rate_err)); |
| 2964 | } |
| 2965 | |
| 2966 | fclose(f); |
| 2967 | } |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2968 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2972 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2973 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 2974 | |
| 2975 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2976 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2977 | |
| 2978 | // Deallocate allocated thread data. |
| 2979 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2980 | aom_free(thread_data->td->palette_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2981 | aom_free(thread_data->td->tmp_conv_dst); |
| 2982 | for (int j = 0; j < 2; ++j) { |
| 2983 | aom_free(thread_data->td->tmp_obmc_bufs[j]); |
| 2984 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2985 | aom_free(thread_data->td->above_pred_buf); |
| 2986 | aom_free(thread_data->td->left_pred_buf); |
| 2987 | aom_free(thread_data->td->wsrc_buf); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2988 | for (int x = 0; x < 2; x++) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 2989 | for (int y = 0; y < 2; y++) { |
| 2990 | aom_free(thread_data->td->hash_value_buffer[x][y]); |
| 2991 | thread_data->td->hash_value_buffer[x][y] = NULL; |
| 2992 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2993 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2994 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2995 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2996 | av1_free_pc_tree(thread_data->td, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2997 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2998 | } |
| 2999 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3000 | aom_free(cpi->tile_thr_data); |
| 3001 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3002 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3003 | if (cpi->num_workers > 1) { |
| 3004 | av1_loop_filter_dealloc(&cpi->lf_row_sync); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 3005 | av1_loop_restoration_dealloc(&cpi->lr_row_sync, cpi->num_workers); |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3006 | } |
| 3007 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3008 | dealloc_compressor_data(cpi); |
| 3009 | |
| 3010 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3011 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3012 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | #if CONFIG_FP_MB_STATS |
| 3016 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3017 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3018 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 3019 | } |
| 3020 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3021 | #if CONFIG_INTERNAL_STATS |
| 3022 | aom_free(cpi->ssim_vars); |
| 3023 | cpi->ssim_vars = NULL; |
| 3024 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3025 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3026 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3027 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3028 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 3029 | } |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 3030 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3031 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3032 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3033 | |
| 3034 | #ifdef OUTPUT_YUV_SKINMAP |
| 3035 | fclose(yuv_skinmap_file); |
| 3036 | #endif |
| 3037 | #ifdef OUTPUT_YUV_REC |
| 3038 | fclose(yuv_rec_file); |
| 3039 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3042 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3043 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3044 | int i; |
| 3045 | PSNR_STATS psnr; |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3046 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3047 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3048 | |
| 3049 | for (i = 0; i < 4; ++i) { |
| 3050 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3051 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3052 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3053 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3054 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3055 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3058 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3059 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3060 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 3061 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3062 | return 0; |
| 3063 | } |
| 3064 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 3065 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) { |
| 3066 | cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0; |
| 3067 | cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0; |
| 3068 | cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0; |
| 3069 | cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0; |
| 3070 | 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] | 3071 | cpi->ext_refresh_frame_flags_pending = 1; |
| 3072 | } |
| 3073 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3074 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3075 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3076 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3077 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3078 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3079 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3080 | return 0; |
| 3081 | } else { |
| 3082 | return -1; |
| 3083 | } |
| 3084 | } |
| 3085 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3086 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3087 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3088 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3089 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3090 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3091 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3092 | return 0; |
| 3093 | } else { |
| 3094 | return -1; |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3099 | cpi->ext_refresh_frame_context = update; |
| 3100 | cpi->ext_refresh_frame_context_pending = 1; |
| 3101 | return 0; |
| 3102 | } |
| 3103 | |
| 3104 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3105 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3106 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3107 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3108 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3109 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3110 | uint8_t *src = s->y_buffer; |
| 3111 | int h = s->y_height; |
| 3112 | |
| 3113 | do { |
| 3114 | fwrite(src, s->y_width, 1, f); |
| 3115 | src += s->y_stride; |
| 3116 | } while (--h); |
| 3117 | |
| 3118 | src = s->u_buffer; |
| 3119 | h = s->uv_height; |
| 3120 | |
| 3121 | do { |
| 3122 | fwrite(src, s->uv_width, 1, f); |
| 3123 | src += s->uv_stride; |
| 3124 | } while (--h); |
| 3125 | |
| 3126 | src = s->v_buffer; |
| 3127 | h = s->uv_height; |
| 3128 | |
| 3129 | do { |
| 3130 | fwrite(src, s->uv_width, 1, f); |
| 3131 | src += s->uv_stride; |
| 3132 | } while (--h); |
| 3133 | } |
| 3134 | #endif |
| 3135 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3136 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3137 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3138 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3139 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3140 | gf_group->update_type[gf_group->index]; |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3141 | #if USE_SYMM_MULTI_LAYER |
| 3142 | const int which_arf = (cpi->new_bwdref_update_rule == 1) |
| 3143 | ? gf_group->arf_update_idx[gf_group->index] > 0 |
| 3144 | : gf_group->arf_update_idx[gf_group->index]; |
| 3145 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3146 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3147 | #endif |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3148 | |
| 3149 | if (cm->show_existing_frame == 1) { |
| 3150 | cm->show_existing_frame = 0; |
| 3151 | } else if (cpi->rc.is_last_bipred_frame) { |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3152 | #if USE_SYMM_MULTI_LAYER |
| 3153 | // NOTE: When new structure is used, every bwdref will have one overlay |
| 3154 | // frame. Therefore, there is no need to find out which frame to |
| 3155 | // show in advance. |
| 3156 | if (cpi->new_bwdref_update_rule == 0) { |
| 3157 | #endif |
| 3158 | // NOTE: If the current frame is a last bi-predictive frame, it is |
| 3159 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3160 | // the last_fb_idxes[0] after reference frame buffer update |
| 3161 | cpi->rc.is_last_bipred_frame = 0; |
| 3162 | cm->show_existing_frame = 1; |
| 3163 | cpi->existing_fb_idx_to_show = cpi->ref_fb_idx[0]; |
| 3164 | #if USE_SYMM_MULTI_LAYER |
| 3165 | } |
| 3166 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3167 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3168 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3169 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3170 | #if USE_SYMM_MULTI_LAYER |
| 3171 | const int bwdref_to_show = |
| 3172 | (cpi->new_bwdref_update_rule == 1) ? BWDREF_FRAME : ALTREF2_FRAME; |
| 3173 | #else |
| 3174 | const int bwdref_to_show = ALTREF2_FRAME; |
| 3175 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3176 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3177 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3178 | cm->show_existing_frame = 1; |
| 3179 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3180 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3181 | ? cpi->ref_fb_idx[ALTREF_FRAME - 1] |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3182 | : cpi->ref_fb_idx[bwdref_to_show - 1]; |
| 3183 | #if USE_SYMM_MULTI_LAYER |
| 3184 | if (cpi->new_bwdref_update_rule == 0) |
| 3185 | #endif |
| 3186 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3187 | } |
| 3188 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3189 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3190 | |
| 3191 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3192 | 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] | 3193 | uint8_t *src = s->y_buffer; |
| 3194 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3195 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3196 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3197 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3198 | |
| 3199 | do { |
| 3200 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3201 | src16 += s->y_stride; |
| 3202 | } while (--h); |
| 3203 | |
| 3204 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3205 | h = s->uv_height; |
| 3206 | |
| 3207 | do { |
| 3208 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3209 | src16 += s->uv_stride; |
| 3210 | } while (--h); |
| 3211 | |
| 3212 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3213 | h = s->uv_height; |
| 3214 | |
| 3215 | do { |
| 3216 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3217 | src16 += s->uv_stride; |
| 3218 | } while (--h); |
| 3219 | |
| 3220 | fflush(yuv_rec_file); |
| 3221 | return; |
| 3222 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3223 | |
| 3224 | do { |
| 3225 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3226 | src += s->y_stride; |
| 3227 | } while (--h); |
| 3228 | |
| 3229 | src = s->u_buffer; |
| 3230 | h = s->uv_height; |
| 3231 | |
| 3232 | do { |
| 3233 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3234 | src += s->uv_stride; |
| 3235 | } while (--h); |
| 3236 | |
| 3237 | src = s->v_buffer; |
| 3238 | h = s->uv_height; |
| 3239 | |
| 3240 | do { |
| 3241 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3242 | src += s->uv_stride; |
| 3243 | } while (--h); |
| 3244 | |
| 3245 | fflush(yuv_rec_file); |
| 3246 | } |
| 3247 | #endif // OUTPUT_YUV_REC |
| 3248 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3249 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3250 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3251 | int i; |
| 3252 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3253 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3254 | AV1_COMMON *const cm = &cpi->common; |
| 3255 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3256 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3257 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3258 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3259 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3260 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3261 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3262 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 3263 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 3264 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 3265 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3266 | } |
| 3267 | } |
| 3268 | return recode; |
| 3269 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3270 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3271 | // Function to test for conditions that indicate we should loop |
| 3272 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3273 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3274 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3275 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3276 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3277 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3278 | int force_recode = 0; |
| 3279 | |
| 3280 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3281 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3282 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3283 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3284 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3285 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3286 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3287 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3288 | // Deal with frame undershoot and whether or not we are |
| 3289 | // below the automatically set cq level. |
| 3290 | if (q > oxcf->cq_level && |
| 3291 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3292 | force_recode = 1; |
| 3293 | } |
| 3294 | } |
| 3295 | } |
| 3296 | return force_recode; |
| 3297 | } |
| 3298 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3299 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3300 | |
| 3301 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3302 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3303 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3304 | char *file_name) { |
| 3305 | int h; |
| 3306 | FILE *f_ref = NULL; |
| 3307 | |
| 3308 | if (ref_buf == NULL) { |
| 3309 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3310 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3314 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3315 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | // --- Y --- |
| 3319 | for (h = 0; h < cm->height; ++h) { |
| 3320 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3321 | } |
| 3322 | // --- U --- |
| 3323 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3324 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3325 | f_ref); |
| 3326 | } |
| 3327 | // --- V --- |
| 3328 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3329 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3330 | f_ref); |
| 3331 | } |
| 3332 | |
| 3333 | fclose(f_ref); |
| 3334 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3335 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3336 | } |
| 3337 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3338 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3339 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3340 | MV_REFERENCE_FRAME ref_frame; |
| 3341 | |
| 3342 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3343 | char file_name[256] = ""; |
| 3344 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3345 | cm->current_video_frame, ref_frame); |
| 3346 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3347 | } |
| 3348 | } |
| 3349 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3350 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3351 | // This function is used to shift the virtual indices of last reference frames |
| 3352 | // as follows: |
| 3353 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3354 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3355 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3356 | // TODO(isbs): shift the scaled indices as well |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3357 | int ref_frame; |
| 3358 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3359 | 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] | 3360 | |
| 3361 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3362 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3363 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3364 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3365 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3366 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3367 | } |
| 3368 | } |
| 3369 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3370 | |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3371 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3372 | // This function is used to shift the virtual indices of bwd reference |
| 3373 | // frames as follows: |
| 3374 | // BWD_REF -> ALT2_REF -> EXT_REF |
| 3375 | // to clear a space to store the closest bwdref |
| 3376 | static INLINE void rshift_bwd_ref_frames(AV1_COMP *cpi) { |
| 3377 | // TODO(isbs): shift the scaled indices as well |
| 3378 | static const int ordered_bwd[3] = { BWDREF_FRAME - 1, ALTREF2_FRAME - 1, |
| 3379 | EXTREF_FRAME - 1 }; |
| 3380 | |
| 3381 | for (int i = 2; i > 0; --i) { |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3382 | // [0] is allocated to the current coded frame, i.e. bwdref |
| 3383 | memcpy( |
| 3384 | cpi->interp_filter_selected[ordered_bwd[i] + LAST_FRAME], |
| 3385 | cpi->interp_filter_selected[ordered_bwd[i - 1] + LAST_FRAME], |
| 3386 | sizeof(cpi->interp_filter_selected[ordered_bwd[i - 1] + LAST_FRAME])); |
SmilingWolf | dad2282 | 2018-09-12 15:43:43 -0700 | [diff] [blame] | 3387 | |
| 3388 | cpi->ref_fb_idx[ordered_bwd[i]] = cpi->ref_fb_idx[ordered_bwd[i - 1]]; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | // This function is used to shift the virtual indices of bwd reference |
| 3393 | // frames as follows: |
| 3394 | // BWD_REF <- ALT2_REF <- EXT_REF |
| 3395 | // to update the bwd reference frame for coding the next frame. |
| 3396 | static INLINE void lshift_bwd_ref_frames(AV1_COMP *cpi) { |
| 3397 | // TODO(isbs): shift the scaled indices as well |
| 3398 | static const int ordered_bwd[3] = { BWDREF_FRAME - 1, ALTREF2_FRAME - 1, |
| 3399 | EXTREF_FRAME - 1 }; |
| 3400 | |
| 3401 | for (int i = 0; i < 2; ++i) { |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3402 | // [0] is allocated to the current coded frame, i.e. bwdref |
| 3403 | memcpy( |
| 3404 | cpi->interp_filter_selected[ordered_bwd[i] + LAST_FRAME], |
| 3405 | cpi->interp_filter_selected[ordered_bwd[i + 1] + LAST_FRAME], |
| 3406 | sizeof(cpi->interp_filter_selected[ordered_bwd[i + 1] + LAST_FRAME])); |
SmilingWolf | dad2282 | 2018-09-12 15:43:43 -0700 | [diff] [blame] | 3407 | |
| 3408 | cpi->ref_fb_idx[ordered_bwd[i]] = cpi->ref_fb_idx[ordered_bwd[i + 1]]; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3409 | } |
| 3410 | } |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3411 | #endif // USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3412 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3413 | static void update_reference_frames(AV1_COMP *cpi) { |
| 3414 | AV1_COMMON *const cm = &cpi->common; |
| 3415 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3416 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3417 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3418 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3419 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 3420 | // In the case of show_existing frame, we will not send fresh flag |
| 3421 | // to decoder. Any change in the reference frame buffer can be done by |
| 3422 | // switching the virtual indices. |
| 3423 | if (cm->show_existing_frame) { |
| 3424 | cpi->refresh_last_frame = 0; |
| 3425 | cpi->refresh_golden_frame = 0; |
| 3426 | cpi->refresh_bwd_ref_frame = 0; |
| 3427 | cpi->refresh_alt2_ref_frame = 0; |
| 3428 | cpi->refresh_alt_ref_frame = 0; |
| 3429 | |
| 3430 | cpi->rc.is_bwd_ref_frame = 0; |
| 3431 | cpi->rc.is_last_bipred_frame = 0; |
| 3432 | cpi->rc.is_bipred_frame = 0; |
| 3433 | } |
| 3434 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3435 | BufferPool *const pool = cm->buffer_pool; |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3436 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3437 | // At this point the new frame has been encoded. |
| 3438 | // If any buffer copy / swapping is signaled it should be done here. |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3439 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 3440 | // Only update all of the reference buffers if a KEY_FRAME is also a |
| 3441 | // show_frame. This ensures a fwd keyframe does not update all of the buffers |
| 3442 | if ((cm->frame_type == KEY_FRAME && cm->show_frame) || frame_is_sframe(cm)) { |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3443 | for (int ref_frame = 0; ref_frame < REF_FRAMES; ++ref_frame) { |
| 3444 | ref_cnt_fb(pool->frame_bufs, |
| 3445 | &cm->ref_frame_map[cpi->ref_fb_idx[ref_frame]], |
| 3446 | cm->new_fb_idx); |
| 3447 | } |
| 3448 | return; |
| 3449 | } |
| 3450 | |
| 3451 | if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3452 | // We have decided to preserve the previously existing golden frame as our |
| 3453 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3454 | // 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] | 3455 | // we're updating the GF with the current decoded frame, we save it to the |
| 3456 | // ARF slot instead. |
| 3457 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3458 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3459 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3460 | int tmp; |
| 3461 | |
Wei-Ting Lin | a8c0245 | 2018-08-13 11:04:06 -0700 | [diff] [blame] | 3462 | // ARF in general is a better reference than overlay. We shouldkeep ARF as |
| 3463 | // reference instead of replacing it with overlay. |
| 3464 | |
| 3465 | if (!cpi->preserve_arf_as_gld) { |
| 3466 | ref_cnt_fb(pool->frame_bufs, |
| 3467 | &cm->ref_frame_map[cpi->ref_fb_idx[ALTREF_FRAME - 1]], |
| 3468 | cm->new_fb_idx); |
| 3469 | } |
| 3470 | |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3471 | tmp = cpi->ref_fb_idx[ALTREF_FRAME - 1]; |
| 3472 | cpi->ref_fb_idx[ALTREF_FRAME - 1] = cpi->ref_fb_idx[GOLDEN_FRAME - 1]; |
| 3473 | cpi->ref_fb_idx[GOLDEN_FRAME - 1] = tmp; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3474 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3475 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3476 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3477 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
Wei-Ting Lin | b72453f | 2018-06-26 14:05:38 -0700 | [diff] [blame] | 3478 | #if CONFIG_DEBUG |
| 3479 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3480 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
| 3481 | #endif |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3482 | #if USE_SYMM_MULTI_LAYER |
| 3483 | const int bwdref_to_show = |
| 3484 | (cpi->new_bwdref_update_rule == 1) ? BWDREF_FRAME : ALTREF2_FRAME; |
| 3485 | #else |
| 3486 | const int bwdref_to_show = ALTREF2_FRAME; |
| 3487 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3488 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3489 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3490 | // by updating the virtual indices. |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3491 | const int tmp = cpi->ref_fb_idx[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3492 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3493 | |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3494 | cpi->ref_fb_idx[LAST_FRAME - 1] = cpi->ref_fb_idx[bwdref_to_show - 1]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3495 | |
| 3496 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3497 | cpi->interp_filter_selected[bwdref_to_show], |
| 3498 | sizeof(cpi->interp_filter_selected[bwdref_to_show])); |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3499 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3500 | if (cpi->new_bwdref_update_rule == 1) { |
| 3501 | lshift_bwd_ref_frames(cpi); |
| 3502 | // pass outdated forward reference frame (previous LAST3) to the |
| 3503 | // spared space |
| 3504 | cpi->ref_fb_idx[EXTREF_FRAME - 1] = tmp; |
| 3505 | } else { |
| 3506 | #endif |
| 3507 | cpi->ref_fb_idx[bwdref_to_show - 1] = tmp; |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3508 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3509 | } |
| 3510 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3511 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3512 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3513 | if (cpi->refresh_alt_ref_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3514 | int arf_idx = cpi->ref_fb_idx[ALTREF_FRAME - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3515 | 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] | 3516 | |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 3517 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3518 | cpi->interp_filter_selected[0], |
| 3519 | sizeof(cpi->interp_filter_selected[0])); |
| 3520 | } |
| 3521 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3522 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3523 | if (cpi->refresh_golden_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3524 | ref_cnt_fb(pool->frame_bufs, |
| 3525 | &cm->ref_frame_map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3526 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3527 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3528 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3529 | cpi->interp_filter_selected[0], |
| 3530 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3533 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3534 | if (cpi->refresh_bwd_ref_frame) { |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3535 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3536 | if (cpi->new_bwdref_update_rule) { |
| 3537 | // We shift the backward reference frame as follows: |
| 3538 | // BWDREF -> ALTREF2 -> EXTREF |
| 3539 | // and assign the newly coded frame to BWDREF so that it always |
| 3540 | // keeps the nearest future frame |
| 3541 | int tmp = cpi->ref_fb_idx[EXTREF_FRAME - 1]; |
| 3542 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[tmp], cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3543 | |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3544 | rshift_bwd_ref_frames(cpi); |
| 3545 | cpi->ref_fb_idx[BWDREF_FRAME - 1] = tmp; |
| 3546 | } else { |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3547 | #endif // USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3548 | ref_cnt_fb(pool->frame_bufs, |
| 3549 | &cm->ref_frame_map[cpi->ref_fb_idx[BWDREF_FRAME - 1]], |
| 3550 | cm->new_fb_idx); |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3551 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3552 | } |
| 3553 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3554 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3555 | cpi->interp_filter_selected[0], |
| 3556 | sizeof(cpi->interp_filter_selected[0])); |
| 3557 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3558 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3559 | // === ALTREF2_FRAME === |
| 3560 | if (cpi->refresh_alt2_ref_frame) { |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3561 | ref_cnt_fb(pool->frame_bufs, |
| 3562 | &cm->ref_frame_map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]], |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3563 | cm->new_fb_idx); |
| 3564 | |
| 3565 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3566 | cpi->interp_filter_selected[0], |
| 3567 | sizeof(cpi->interp_filter_selected[0])); |
| 3568 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | if (cpi->refresh_last_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3572 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3573 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3574 | // the virtual index to the reference frame buffer physical index: |
| 3575 | // |
| 3576 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3577 | // | | | |
| 3578 | // v v v |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3579 | // 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] | 3580 | // | | | |
| 3581 | // v v v |
| 3582 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3583 | // |
| 3584 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3585 | // have the other 2 LAST reference frames shifted as follows: |
| 3586 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3587 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3588 | // |
| 3589 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3590 | // |
| 3591 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3592 | // to point to the newly coded frame, i.e. |
| 3593 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3594 | // |
| 3595 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3596 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3597 | // shifted as follows: |
| 3598 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3599 | // | | | |
| 3600 | // v v v |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3601 | // ref_fb_idx[2], ref_fb_idx[0], ref_fb_idx[1] |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3602 | int tmp; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3603 | |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3604 | ref_cnt_fb(pool->frame_bufs, |
| 3605 | &cm->ref_frame_map[cpi->ref_fb_idx[LAST_REF_FRAMES - 1]], |
| 3606 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3607 | |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3608 | tmp = cpi->ref_fb_idx[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3609 | |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3610 | shift_last_ref_frames(cpi); |
| 3611 | cpi->ref_fb_idx[0] = tmp; |
| 3612 | |
| 3613 | assert(cm->show_existing_frame == 0); |
| 3614 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3615 | cpi->interp_filter_selected[0], |
| 3616 | sizeof(cpi->interp_filter_selected[0])); |
| 3617 | |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3618 | // If the new structure is used, we will always have overlay frames coupled |
| 3619 | // with bwdref frames. Therefore, we won't have to perform this update |
| 3620 | // in advance (we do this update when the overlay frame shows up). |
| 3621 | #if USE_SYMM_MULTI_LAYER |
| 3622 | if (cpi->new_bwdref_update_rule == 0 && cpi->rc.is_last_bipred_frame) { |
| 3623 | #else |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3624 | if (cpi->rc.is_last_bipred_frame) { |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3625 | #endif |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3626 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3627 | // LAST3_FRAME by updating the virtual indices. |
| 3628 | // |
| 3629 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3630 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3631 | // virtual index reshuffling for BWDREF, the encoder always |
| 3632 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3633 | // reshuffling job accordingly. |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 3634 | tmp = cpi->ref_fb_idx[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3635 | |
| 3636 | shift_last_ref_frames(cpi); |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3637 | cpi->ref_fb_idx[0] = cpi->ref_fb_idx[BWDREF_FRAME - 1]; |
| 3638 | cpi->ref_fb_idx[BWDREF_FRAME - 1] = tmp; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3639 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3640 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3641 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3642 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3643 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3647 | // Dump out all reference frame images. |
| 3648 | dump_ref_frame_images(cpi); |
| 3649 | #endif // DUMP_REF_FRAME_IMAGES |
| 3650 | } |
| 3651 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3652 | 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] | 3653 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3654 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3655 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3656 | new_fb_ptr->width = cm->width; |
| 3657 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3660 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3661 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3662 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3663 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3664 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3665 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 3666 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3667 | }; |
| 3668 | |
| 3669 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3670 | // 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] | 3671 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3672 | BufferPool *const pool = cm->buffer_pool; |
| 3673 | const YV12_BUFFER_CONFIG *const ref = |
| 3674 | get_ref_frame_buffer(cpi, ref_frame); |
| 3675 | |
| 3676 | if (ref == NULL) { |
| 3677 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3678 | continue; |
| 3679 | } |
| 3680 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3681 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3682 | RefCntBuffer *new_fb_ptr = NULL; |
| 3683 | int force_scaling = 0; |
| 3684 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3685 | if (new_fb == INVALID_IDX) { |
| 3686 | new_fb = get_free_fb(cm); |
| 3687 | force_scaling = 1; |
| 3688 | } |
| 3689 | if (new_fb == INVALID_IDX) return; |
| 3690 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3691 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3692 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3693 | if (aom_realloc_frame_buffer( |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3694 | &new_fb_ptr->buf, cm->width, cm->height, |
| 3695 | cm->seq_params.subsampling_x, cm->seq_params.subsampling_y, |
| 3696 | cm->seq_params.use_highbitdepth, AOM_BORDER_IN_PIXELS, |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3697 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3698 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3699 | "Failed to allocate frame buffer"); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3700 | av1_resize_and_extend_frame( |
| 3701 | ref, &new_fb_ptr->buf, (int)cm->seq_params.bit_depth, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3702 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3703 | alloc_frame_mvs(cm, new_fb); |
| 3704 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3705 | } else { |
| 3706 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3707 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3708 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3709 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3710 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3711 | ++buf->ref_count; |
| 3712 | } |
| 3713 | } else { |
| 3714 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3715 | } |
| 3716 | } |
| 3717 | } |
| 3718 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3719 | static void release_scaled_references(AV1_COMP *cpi) { |
| 3720 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3721 | int i; |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3722 | // TODO(isbs): only refresh the necessary frames, rather than all of them |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 3723 | for (i = 0; i < REF_FRAMES; ++i) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3724 | const int idx = cpi->scaled_ref_idx[i]; |
| 3725 | RefCntBuffer *const buf = |
| 3726 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3727 | if (buf != NULL) { |
| 3728 | --buf->ref_count; |
| 3729 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3730 | } |
| 3731 | } |
| 3732 | } |
| 3733 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3734 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3735 | const AV1_COMMON *const cm = &cpi->common; |
| 3736 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3737 | |
| 3738 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3739 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3740 | |
| 3741 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3742 | if (frame_is_intra_only(cm)) { |
| 3743 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3744 | // after a key/intra-only frame. |
| 3745 | cpi->max_mv_magnitude = max_mv_def; |
| 3746 | } else { |
| 3747 | if (cm->show_frame) { |
| 3748 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3749 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3750 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3751 | cpi->mv_step_param = av1_init_search_range( |
| 3752 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3753 | } |
| 3754 | cpi->max_mv_magnitude = 0; |
| 3755 | } |
| 3756 | } |
| 3757 | } |
| 3758 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3759 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3760 | int i; |
| 3761 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3762 | cpi->common.global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3763 | } |
| 3764 | cpi->global_motion_search_done = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3765 | av1_set_speed_features_framesize_independent(cpi); |
| 3766 | av1_set_rd_speed_thresholds(cpi); |
| 3767 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Urvang Joshi | b55cb5e | 2018-09-12 14:50:21 -0700 | [diff] [blame] | 3768 | cpi->common.interp_filter = SWITCHABLE; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 3769 | cpi->common.switchable_motion_mode = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3770 | } |
| 3771 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3772 | 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] | 3773 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3774 | AV1_COMMON *const cm = &cpi->common; |
| 3775 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3776 | |
| 3777 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3778 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3779 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 3780 | // Decide q and q bounds. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3781 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 3782 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3783 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3784 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3785 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3786 | cpi->common.cur_frame_force_integer_mv); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3787 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3788 | |
| 3789 | // Configure experimental use of segmentation for enhanced coding of |
| 3790 | // static regions if indicated. |
| 3791 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3792 | // lagged coding, and if the relevant speed feature flag is set. |
| 3793 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3794 | configure_static_seg_features(cpi); |
| 3795 | } |
| 3796 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3797 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3798 | int y_stride = cpi->scaled_source.y_stride; |
| 3799 | |
| 3800 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3801 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3802 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3803 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3807 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3808 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 3809 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3810 | (void)width; |
| 3811 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3812 | (void)sx; |
| 3813 | (void)sy; |
| 3814 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3815 | int s = AOMMIN(sx, sy); |
| 3816 | #else |
| 3817 | int s = 0; |
| 3818 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3819 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3820 | if (width * height > 352 * 288) |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3821 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3822 | else |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3823 | rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3824 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 3825 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3826 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3827 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3828 | static void init_ref_frame_bufs(AV1_COMP *cpi) { |
| 3829 | AV1_COMMON *const cm = &cpi->common; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3830 | int i; |
| 3831 | BufferPool *const pool = cm->buffer_pool; |
| 3832 | cm->new_fb_idx = INVALID_IDX; |
| 3833 | for (i = 0; i < REF_FRAMES; ++i) { |
| 3834 | cm->ref_frame_map[i] = INVALID_IDX; |
| 3835 | pool->frame_bufs[i].ref_count = 0; |
| 3836 | } |
RogerZhou | 86902d0 | 2018-02-28 15:29:16 -0800 | [diff] [blame] | 3837 | if (cm->seq_params.force_screen_content_tools) { |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 3838 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3839 | av1_hash_table_init(&pool->frame_bufs[i].hash_table, &cpi->td.mb); |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 3840 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3841 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 3844 | static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3845 | int subsampling_x, int subsampling_y) { |
| 3846 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3847 | SequenceHeader *const seq_params = &cm->seq_params; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3848 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3849 | if (!cpi->initial_width || seq_params->use_highbitdepth != use_highbitdepth || |
| 3850 | seq_params->subsampling_x != subsampling_x || |
| 3851 | seq_params->subsampling_y != subsampling_y) { |
| 3852 | seq_params->subsampling_x = subsampling_x; |
| 3853 | seq_params->subsampling_y = subsampling_y; |
| 3854 | seq_params->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3855 | |
| 3856 | alloc_raw_frame_buffers(cpi); |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3857 | init_ref_frame_bufs(cpi); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3858 | alloc_util_frame_buffers(cpi); |
| 3859 | |
| 3860 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 3861 | |
| 3862 | cpi->initial_width = cm->width; |
| 3863 | cpi->initial_height = cm->height; |
| 3864 | cpi->initial_mbs = cm->MBs; |
| 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | // Returns 1 if the assigned width or height was <= 0. |
| 3869 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 3870 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3871 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3872 | check_initial_width(cpi, cm->seq_params.use_highbitdepth, |
| 3873 | cm->seq_params.subsampling_x, |
| 3874 | cm->seq_params.subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3875 | |
| 3876 | if (width <= 0 || height <= 0) return 1; |
| 3877 | |
| 3878 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3879 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3880 | |
| 3881 | if (cpi->initial_width && cpi->initial_height && |
| 3882 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 3883 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3884 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3885 | alloc_compressor_data(cpi); |
| 3886 | realloc_segmentation_maps(cpi); |
| 3887 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3888 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3889 | update_frame_size(cpi); |
| 3890 | |
| 3891 | return 0; |
| 3892 | } |
| 3893 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3894 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3895 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3896 | const SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3897 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3898 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3899 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3900 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3901 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 3902 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3903 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3904 | set_mv_search_params(cpi); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 3905 | // Recalculate 'all_lossless' in case super-resolution was (un)selected. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 3906 | cm->all_lossless = cm->coded_lossless && !av1_superres_scaled(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3909 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3910 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3911 | } |
| 3912 | |
| 3913 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 3914 | |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 3915 | // Allocate above context buffers |
Cherma Rajan A | f147908 | 2018-05-09 14:26:34 +0530 | [diff] [blame] | 3916 | if (cm->num_allocated_above_context_planes < av1_num_planes(cm) || |
| 3917 | cm->num_allocated_above_context_mi_col < cm->mi_cols || |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 3918 | cm->num_allocated_above_contexts < cm->tile_rows) { |
| 3919 | av1_free_above_context_buffers(cm, cm->num_allocated_above_contexts); |
| 3920 | if (av1_alloc_above_context_buffers(cm, cm->tile_rows)) |
| 3921 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3922 | "Failed to allocate context buffers"); |
| 3923 | } |
| 3924 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3925 | // Reset the frame pointers to the current frame size. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3926 | if (aom_realloc_frame_buffer( |
| 3927 | get_frame_new_buffer(cm), cm->width, cm->height, |
| 3928 | seq_params->subsampling_x, seq_params->subsampling_y, |
| 3929 | seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3930 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3931 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3932 | "Failed to allocate frame buffer"); |
| 3933 | |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3934 | const int frame_width = cm->superres_upscaled_width; |
| 3935 | const int frame_height = cm->superres_upscaled_height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3936 | set_restoration_unit_size(frame_width, frame_height, |
| 3937 | seq_params->subsampling_x, |
| 3938 | seq_params->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3939 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 3940 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3941 | |
| 3942 | av1_alloc_restoration_buffers(cm); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 3943 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3944 | init_motion_estimation(cpi); |
| 3945 | |
| 3946 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3947 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3948 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3949 | |
| 3950 | ref_buf->idx = buf_idx; |
| 3951 | |
| 3952 | if (buf_idx != INVALID_IDX) { |
| 3953 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 3954 | ref_buf->buf = buf; |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 3955 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 3956 | buf->y_crop_height, cm->width, |
| 3957 | cm->height); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3958 | if (av1_is_scaled(&ref_buf->sf)) |
| 3959 | aom_extend_frame_borders(buf, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3960 | } else { |
| 3961 | ref_buf->buf = NULL; |
| 3962 | } |
| 3963 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3964 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 3965 | 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] | 3966 | cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3967 | |
| 3968 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3969 | } |
| 3970 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3971 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 3972 | // Choose an arbitrary random number |
| 3973 | static unsigned int seed = 56789; |
| 3974 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3975 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3976 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3977 | |
Debargha Mukherjee | 2b7c2b3 | 2018-04-10 07:35:28 -0700 | [diff] [blame] | 3978 | if (cpi->common.seq_params.reduced_still_picture_hdr) return SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3979 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3980 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3981 | case RESIZE_FIXED: |
| 3982 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3983 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3984 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3985 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3986 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3987 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3988 | default: assert(0); |
| 3989 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3990 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3993 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 3994 | // Choose an arbitrary random number |
| 3995 | static unsigned int seed = 34567; |
| 3996 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3997 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3998 | uint8_t new_denom = SCALE_NUMERATOR; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3999 | |
| 4000 | // Make sure that superres mode of the frame is consistent with the |
| 4001 | // sequence-level flag. |
| 4002 | assert(IMPLIES(oxcf->superres_mode != SUPERRES_NONE, |
| 4003 | cpi->common.seq_params.enable_superres)); |
| 4004 | assert(IMPLIES(!cpi->common.seq_params.enable_superres, |
| 4005 | oxcf->superres_mode == SUPERRES_NONE)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4006 | |
| 4007 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4008 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4009 | case SUPERRES_FIXED: |
| 4010 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4011 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4012 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4013 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4014 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4015 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4016 | case SUPERRES_QTHRESH: { |
| 4017 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4018 | const RATE_FACTOR_LEVEL rf_level = gf_group->rf_level[gf_group->index]; |
| 4019 | const double rate_factor_delta = rate_factor_deltas[rf_level]; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4020 | const int qthresh = (rate_factor_delta <= 1.0) |
| 4021 | ? oxcf->superres_qthresh |
| 4022 | : oxcf->superres_kf_qthresh; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4023 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4024 | int bottom_index, top_index; |
| 4025 | const int q = av1_rc_pick_q_and_bounds( |
| 4026 | cpi, cpi->oxcf.width, cpi->oxcf.height, &bottom_index, &top_index); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4027 | if (q < qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4028 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4029 | } else { |
Urvang Joshi | 28983f7 | 2017-10-25 14:41:06 -0700 | [diff] [blame] | 4030 | const uint8_t min_denom = SCALE_NUMERATOR + 1; |
| 4031 | const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3; |
Imdad Sardharwalla | f6154fd | 2018-03-02 16:53:41 +0000 | [diff] [blame] | 4032 | |
| 4033 | if (q == qthresh) { |
| 4034 | new_denom = min_denom; |
| 4035 | } else if (denom_step == 0) { |
| 4036 | new_denom = SCALE_NUMERATOR << 1; |
| 4037 | } else { |
| 4038 | const uint8_t additional_denom = (q - qthresh) / denom_step; |
| 4039 | new_denom = |
| 4040 | AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1); |
| 4041 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4042 | } |
| 4043 | break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4044 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4045 | default: assert(0); |
| 4046 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4047 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4050 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4051 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4052 | } |
| 4053 | |
| 4054 | 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] | 4055 | // Only need to check the width, as scaling is horizontal only. |
| 4056 | (void)oheight; |
| 4057 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4060 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4061 | SUPERRES_MODE superres_mode, int owidth, |
| 4062 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4063 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4064 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4067 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4068 | int resize_denom = |
| 4069 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 4070 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 4071 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4072 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4073 | // Alter superres scale as needed to enforce conformity. |
| 4074 | rsz->superres_denom = |
| 4075 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 4076 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4077 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4078 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4079 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4080 | // Alter resize scale as needed to enforce conformity. |
| 4081 | resize_denom = |
| 4082 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4083 | rsz->resize_width = owidth; |
| 4084 | rsz->resize_height = oheight; |
| 4085 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4086 | resize_denom); |
| 4087 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4088 | if (resize_denom > SCALE_NUMERATOR) { |
| 4089 | --resize_denom; |
| 4090 | rsz->resize_width = owidth; |
| 4091 | rsz->resize_height = oheight; |
| 4092 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 4093 | resize_denom); |
| 4094 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4095 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4096 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4097 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4098 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4099 | if (resize_denom > rsz->superres_denom) |
| 4100 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4101 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4102 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4103 | rsz->resize_width = owidth; |
| 4104 | rsz->resize_height = oheight; |
| 4105 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4106 | resize_denom); |
| 4107 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 4108 | (resize_denom > SCALE_NUMERATOR || |
| 4109 | rsz->superres_denom > SCALE_NUMERATOR)); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4110 | } else { // We are allowed to alter neither resize scale nor superres |
| 4111 | // scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4112 | return 0; |
| 4113 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4114 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4115 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4116 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4117 | // Calculates resize and superres params for next frame |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4118 | size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) { |
| 4119 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 4120 | size_params_type rsz = { oxcf->width, oxcf->height, SCALE_NUMERATOR }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4121 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4122 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4123 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 4124 | rsz.resize_width = cpi->resize_pending_width; |
| 4125 | rsz.resize_height = cpi->resize_pending_height; |
| 4126 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 4127 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4128 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4129 | rsz.resize_width = cpi->oxcf.width; |
| 4130 | rsz.resize_height = cpi->oxcf.height; |
| 4131 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4132 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4133 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4134 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4135 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 4136 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4137 | assert(0 && "Invalid scale parameters"); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4138 | return rsz; |
| 4139 | } |
| 4140 | |
| 4141 | 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] | 4142 | int encode_width = rsz->resize_width; |
| 4143 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4144 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4145 | AV1_COMMON *cm = &cpi->common; |
| 4146 | cm->superres_upscaled_width = encode_width; |
| 4147 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4148 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4149 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 4150 | rsz->superres_denom); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4151 | set_frame_size(cpi, encode_width, encode_height); |
| 4152 | } |
| 4153 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4154 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4155 | size_params_type rsz = av1_calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4156 | setup_frame_size_from_params(cpi, &rsz); |
| 4157 | } |
| 4158 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4159 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4160 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4161 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4162 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4163 | if (!av1_superres_scaled(cm)) return; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4164 | |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4165 | assert(cpi->oxcf.enable_superres); |
| 4166 | assert(!is_lossless_requested(&cpi->oxcf)); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4167 | assert(!cm->all_lossless); |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4168 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4169 | av1_superres_upscale(cm, NULL); |
| 4170 | |
| 4171 | // If regular resizing is occurring the source will need to be downscaled to |
| 4172 | // match the upscaled superres resolution. Otherwise the original source is |
| 4173 | // used. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4174 | if (!av1_resize_scaled(cm)) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4175 | cpi->source = cpi->unscaled_source; |
| 4176 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4177 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4178 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4179 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4180 | // Do downscale. cm->(width|height) has been updated by |
| 4181 | // av1_superres_upscale |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4182 | if (aom_realloc_frame_buffer( |
| 4183 | &cpi->scaled_source, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4184 | cm->superres_upscaled_height, cm->seq_params.subsampling_x, |
| 4185 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
| 4186 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4187 | aom_internal_error( |
| 4188 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4189 | "Failed to reallocate scaled source buffer for superres"); |
| 4190 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4191 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4192 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4193 | (int)cm->seq_params.bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4194 | cpi->source = &cpi->scaled_source; |
| 4195 | } |
| 4196 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4197 | |
| 4198 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4199 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4200 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4201 | |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4202 | assert(IMPLIES(is_lossless_requested(&cpi->oxcf), |
| 4203 | cm->coded_lossless && cm->all_lossless)); |
| 4204 | |
| 4205 | const int no_loopfilter = cm->coded_lossless || cm->large_scale_tile; |
| 4206 | const int no_cdef = |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 4207 | !cm->seq_params.enable_cdef || cm->coded_lossless || cm->large_scale_tile; |
| 4208 | const int no_restoration = !cm->seq_params.enable_restoration || |
| 4209 | cm->all_lossless || cm->large_scale_tile; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4210 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4211 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4212 | |
| 4213 | if (no_loopfilter) { |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4214 | lf->filter_level[0] = 0; |
| 4215 | lf->filter_level[1] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4216 | } else { |
| 4217 | struct aom_usec_timer timer; |
| 4218 | |
| 4219 | aom_clear_system_state(); |
| 4220 | |
| 4221 | aom_usec_timer_start(&timer); |
| 4222 | |
| 4223 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4224 | |
| 4225 | aom_usec_timer_mark(&timer); |
| 4226 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4227 | } |
| 4228 | |
Debargha Mukherjee | 2382b14 | 2018-02-26 14:31:32 -0800 | [diff] [blame] | 4229 | if (lf->filter_level[0] || lf->filter_level[1]) { |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 4230 | #if LOOP_FILTER_BITMASK |
| 4231 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, 0, num_planes, 0); |
| 4232 | #else |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 4233 | if (cpi->num_workers > 1) |
| 4234 | av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd, 0, num_planes, 0, |
| 4235 | cpi->workers, cpi->num_workers, |
| 4236 | &cpi->lf_row_sync); |
| 4237 | else |
| 4238 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, 0, num_planes, 0); |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 4239 | #endif |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4240 | } |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4241 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4242 | if (!no_restoration) |
| 4243 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4244 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4245 | if (no_cdef) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4246 | cm->cdef_bits = 0; |
| 4247 | cm->cdef_strengths[0] = 0; |
| 4248 | cm->nb_cdef_strengths = 1; |
Yunqing Wang | dad63d4 | 2017-12-08 12:45:07 -0800 | [diff] [blame] | 4249 | cm->cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4250 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4251 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4252 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
Debargha Mukherjee | d7338aa | 2017-11-04 07:34:50 -0700 | [diff] [blame] | 4253 | cpi->sf.fast_cdef_search); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4254 | |
| 4255 | // Apply the filter |
| 4256 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4257 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4258 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4259 | superres_post_encode(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4260 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4261 | if (no_restoration) { |
| 4262 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4263 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4264 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
| 4265 | } else { |
| 4266 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1); |
| 4267 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4268 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4269 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4270 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4271 | if (cpi->num_workers > 1) |
| 4272 | av1_loop_restoration_filter_frame_mt(cm->frame_to_show, cm, 0, |
| 4273 | cpi->workers, cpi->num_workers, |
| 4274 | &cpi->lr_row_sync, &cpi->lr_ctxt); |
| 4275 | else |
| 4276 | av1_loop_restoration_filter_frame(cm->frame_to_show, cm, 0, |
| 4277 | &cpi->lr_ctxt); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4278 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4279 | } |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4280 | } |
| 4281 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4282 | static int encode_without_recode_loop(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4283 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4284 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4285 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4286 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4287 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4288 | set_size_independent_vars(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4289 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4290 | setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4291 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4292 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4293 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4294 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4295 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4296 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4297 | cpi->source = |
| 4298 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4299 | if (cpi->unscaled_last_source != NULL) |
| 4300 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4301 | &cpi->scaled_last_source); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4302 | cpi->source->buf_8bit_valid = 0; |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4303 | if (frame_is_intra_only(cm) == 0) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4304 | scale_references(cpi); |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4307 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4308 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4309 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4310 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4311 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4312 | // exclusive. |
| 4313 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4314 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4315 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4316 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4317 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4318 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4319 | } |
| 4320 | apply_active_map(cpi); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4321 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4322 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4323 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 4324 | } else { |
| 4325 | calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4326 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4327 | } else { |
| 4328 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4329 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4330 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4331 | |
| 4332 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4333 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4334 | |
| 4335 | // Update some stats from cyclic refresh, and check if we should not update |
| 4336 | // golden reference, for 1 pass CBR. |
| 4337 | 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] | 4338 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4339 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4340 | |
| 4341 | // Update the skip mb flag probabilities based on the distribution |
| 4342 | // seen in the last encoder iteration. |
| 4343 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4344 | aom_clear_system_state(); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4345 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4348 | 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] | 4349 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4350 | RATE_CONTROL *const rc = &cpi->rc; |
| 4351 | int bottom_index, top_index; |
| 4352 | int loop_count = 0; |
| 4353 | int loop_at_this_size = 0; |
| 4354 | int loop = 0; |
| 4355 | int overshoot_seen = 0; |
| 4356 | int undershoot_seen = 0; |
| 4357 | int frame_over_shoot_limit; |
| 4358 | int frame_under_shoot_limit; |
| 4359 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4360 | |
| 4361 | set_size_independent_vars(cpi); |
| 4362 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4363 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4364 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4365 | aom_clear_system_state(); |
| 4366 | setup_frame_size(cpi); |
| 4367 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4368 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4369 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4370 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4371 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4372 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4373 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4374 | set_mv_search_params(cpi); |
| 4375 | |
| 4376 | // Reset the loop state for new frame size. |
| 4377 | overshoot_seen = 0; |
| 4378 | undershoot_seen = 0; |
| 4379 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4380 | q_low = bottom_index; |
| 4381 | q_high = top_index; |
| 4382 | |
| 4383 | loop_at_this_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4384 | |
Urvang Joshi | 2a74cf2 | 2017-12-18 17:21:41 -0800 | [diff] [blame] | 4385 | // Decide frame size bounds first time through. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4386 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4387 | &frame_under_shoot_limit, |
| 4388 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4391 | // if frame was scaled calculate global_motion_search again if already |
| 4392 | // done |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4393 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) |
| 4394 | if (cpi->source->y_crop_width != cm->width || |
| 4395 | cpi->source->y_crop_height != cm->height) |
| 4396 | cpi->global_motion_search_done = 0; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4397 | cpi->source = |
| 4398 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4399 | if (cpi->unscaled_last_source != NULL) |
| 4400 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4401 | &cpi->scaled_last_source); |
| 4402 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4403 | if (frame_is_intra_only(cm) == 0) { |
| 4404 | if (loop_count > 0) { |
| 4405 | release_scaled_references(cpi); |
| 4406 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4407 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4408 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4409 | av1_set_quantizer(cm, q); |
Yaowu Xu | 2e58723 | 2018-05-10 09:30:08 -0700 | [diff] [blame] | 4410 | // printf("Frame %d/%d: q = %d, frame_type = %d\n", cm->current_video_frame, |
| 4411 | // cm->show_frame, q, cm->frame_type); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4412 | |
| 4413 | if (loop_count == 0) setup_frame(cpi); |
| 4414 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4415 | // Base q-index may have changed, so we need to assign proper default coef |
| 4416 | // probs before every iteration. |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 4417 | if (cm->primary_ref_frame == PRIMARY_REF_NONE || |
| 4418 | cm->frame_refs[cm->primary_ref_frame].idx < 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4419 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 4420 | av1_setup_frame_contexts(cm); |
David Barker | fc91b39 | 2018-03-09 15:32:03 +0000 | [diff] [blame] | 4421 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4422 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4423 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4424 | // exclusive. |
| 4425 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4426 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4427 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4428 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4429 | } |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4430 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4431 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4432 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 4433 | } else { |
| 4434 | calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4435 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4436 | } else { |
| 4437 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4438 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4439 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4440 | |
| 4441 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4442 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4443 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4444 | |
| 4445 | // Update the skip mb flag probabilities based on the distribution |
| 4446 | // seen in the last encoder iteration. |
| 4447 | // update_base_skip_probs(cpi); |
| 4448 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4449 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4450 | |
| 4451 | // Dummy pack of the bitstream using up to date stats to get an |
| 4452 | // accurate estimate of output frame size to determine if we need |
| 4453 | // to recode. |
| 4454 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4455 | restore_coding_context(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4456 | |
| 4457 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 4458 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4459 | |
| 4460 | rc->projected_frame_size = (int)(*size) << 3; |
| 4461 | restore_coding_context(cpi); |
| 4462 | |
| 4463 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4464 | } |
| 4465 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4466 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4467 | loop = 0; |
| 4468 | } else { |
| 4469 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4470 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4471 | int last_q = q; |
| 4472 | int64_t kf_err; |
| 4473 | |
| 4474 | int64_t high_err_target = cpi->ambient_err; |
| 4475 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4476 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4477 | if (cm->seq_params.use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4478 | 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] | 4479 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4480 | 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] | 4481 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4482 | // Prevent possible divide by zero error below for perfect KF |
| 4483 | kf_err += !kf_err; |
| 4484 | |
| 4485 | // The key frame is not good enough or we can afford |
| 4486 | // to make it better without undue risk of popping. |
| 4487 | if ((kf_err > high_err_target && |
| 4488 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4489 | (kf_err > low_err_target && |
| 4490 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4491 | // Lower q_high |
| 4492 | q_high = q > q_low ? q - 1 : q_low; |
| 4493 | |
| 4494 | // Adjust Q |
| 4495 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4496 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4497 | } else if (kf_err < low_err_target && |
| 4498 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4499 | // The key frame is much better than the previous frame |
| 4500 | // Raise q_low |
| 4501 | q_low = q < q_high ? q + 1 : q_high; |
| 4502 | |
| 4503 | // Adjust Q |
| 4504 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4505 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | // Clamp Q to upper and lower limits: |
| 4509 | q = clamp(q, q_low, q_high); |
| 4510 | |
| 4511 | loop = q != last_q; |
| 4512 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4513 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4514 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4515 | // Is the projected frame size out of range and are we allowed |
| 4516 | // to attempt to recode. |
| 4517 | int last_q = q; |
| 4518 | int retries = 0; |
| 4519 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4520 | // Frame size out of permitted range: |
| 4521 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4522 | // Frame is too large |
| 4523 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4524 | // Special case if the projected size is > the max allowed. |
| 4525 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4526 | q_high = rc->worst_quality; |
| 4527 | |
| 4528 | // Raise Qlow as to at least the current value |
| 4529 | q_low = q < q_high ? q + 1 : q_high; |
| 4530 | |
| 4531 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4532 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4533 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4534 | |
| 4535 | q = (q_high + q_low + 1) / 2; |
| 4536 | } else { |
| 4537 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4538 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4539 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4540 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4541 | AOMMAX(q_high, top_index), cm->width, |
| 4542 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4543 | |
| 4544 | while (q < q_low && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4545 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4546 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4547 | AOMMAX(q_high, top_index), cm->width, |
| 4548 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4549 | retries++; |
| 4550 | } |
| 4551 | } |
| 4552 | |
| 4553 | overshoot_seen = 1; |
| 4554 | } else { |
| 4555 | // Frame is too small |
| 4556 | q_high = q > q_low ? q - 1 : q_low; |
| 4557 | |
| 4558 | if (overshoot_seen || loop_at_this_size > 1) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4559 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4560 | q = (q_high + q_low) / 2; |
| 4561 | } else { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4562 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4563 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4564 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4565 | // Special case reset for qlow for constrained quality. |
| 4566 | // This should only trigger where there is very substantial |
| 4567 | // undershoot on a frame and the auto cq level is above |
| 4568 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4569 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4570 | q_low = q; |
| 4571 | } |
| 4572 | |
| 4573 | while (q > q_high && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4574 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4575 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4576 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4577 | retries++; |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | undershoot_seen = 1; |
| 4582 | } |
| 4583 | |
| 4584 | // Clamp Q to upper and lower limits: |
| 4585 | q = clamp(q, q_low, q_high); |
| 4586 | |
| 4587 | loop = (q != last_q); |
| 4588 | } else { |
| 4589 | loop = 0; |
| 4590 | } |
| 4591 | } |
| 4592 | |
| 4593 | // Special case for overlay frame. |
| 4594 | if (rc->is_src_frame_alt_ref && |
| 4595 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4596 | loop = 0; |
| 4597 | |
Debargha Mukherjee | 79853eb | 2018-09-13 17:38:02 -0700 | [diff] [blame^] | 4598 | if (!cpi->sf.gm_disable_recode) { |
| 4599 | if (recode_loop_test_global_motion(cpi)) loop = 1; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4600 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4601 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4602 | if (loop) { |
| 4603 | ++loop_count; |
| 4604 | ++loop_at_this_size; |
| 4605 | |
| 4606 | #if CONFIG_INTERNAL_STATS |
| 4607 | ++cpi->tot_recode_hits; |
| 4608 | #endif |
| 4609 | } |
| 4610 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4611 | |
| 4612 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4613 | } |
| 4614 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4615 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4616 | const int *const map = cpi->common.ref_frame_map; |
| 4617 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4618 | // No.1 Priority: LAST_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4619 | const int last2_is_last = map[cpi->ref_fb_idx[1]] == map[cpi->ref_fb_idx[0]]; |
| 4620 | const int last3_is_last = map[cpi->ref_fb_idx[2]] == map[cpi->ref_fb_idx[0]]; |
| 4621 | const int gld_is_last = |
| 4622 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == map[cpi->ref_fb_idx[0]]; |
| 4623 | const int bwd_is_last = |
| 4624 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == map[cpi->ref_fb_idx[0]]; |
| 4625 | const int alt2_is_last = |
| 4626 | map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == map[cpi->ref_fb_idx[0]]; |
| 4627 | const int alt_is_last = |
| 4628 | 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] | 4629 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4630 | // No.2 Priority: ALTREF_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4631 | const int last2_is_alt = |
| 4632 | map[cpi->ref_fb_idx[1]] == map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4633 | const int last3_is_alt = |
| 4634 | map[cpi->ref_fb_idx[2]] == map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4635 | const int gld_is_alt = map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == |
| 4636 | map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4637 | const int bwd_is_alt = map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == |
| 4638 | map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
| 4639 | const int alt2_is_alt = map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == |
| 4640 | map[cpi->ref_fb_idx[ALTREF_FRAME - 1]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4641 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4642 | // No.3 Priority: LAST2_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4643 | const int last3_is_last2 = map[cpi->ref_fb_idx[2]] == map[cpi->ref_fb_idx[1]]; |
| 4644 | const int gld_is_last2 = |
| 4645 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == map[cpi->ref_fb_idx[1]]; |
| 4646 | const int bwd_is_last2 = |
| 4647 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == map[cpi->ref_fb_idx[1]]; |
| 4648 | const int alt2_is_last2 = |
| 4649 | 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] | 4650 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4651 | // No.4 Priority: LAST3_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4652 | const int gld_is_last3 = |
| 4653 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]] == map[cpi->ref_fb_idx[2]]; |
| 4654 | const int bwd_is_last3 = |
| 4655 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == map[cpi->ref_fb_idx[2]]; |
| 4656 | const int alt2_is_last3 = |
| 4657 | 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] | 4658 | |
| 4659 | // No.5 Priority: GOLDEN_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4660 | const int bwd_is_gld = map[cpi->ref_fb_idx[BWDREF_FRAME - 1]] == |
| 4661 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]]; |
| 4662 | const int alt2_is_gld = map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == |
| 4663 | map[cpi->ref_fb_idx[GOLDEN_FRAME - 1]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4664 | |
| 4665 | // No.6 Priority: BWDREF_FRAME |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 4666 | const int alt2_is_bwd = map[cpi->ref_fb_idx[ALTREF2_FRAME - 1]] == |
| 4667 | map[cpi->ref_fb_idx[BWDREF_FRAME - 1]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4668 | |
| 4669 | // No.7 Priority: ALTREF2_FRAME |
| 4670 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 4671 | // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be |
| 4672 | // adjusted according to external encoder flags. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 4673 | int flags = cpi->ext_ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4674 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4675 | 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] | 4676 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4677 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4678 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4679 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4680 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4681 | 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] | 4682 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4683 | if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3) |
| 4684 | flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4685 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4686 | if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 || |
| 4687 | bwd_is_gld) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4688 | (flags & AOM_BWD_FLAG)) |
| 4689 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4690 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4691 | if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 || |
| 4692 | alt2_is_gld || alt2_is_bwd) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4693 | (flags & AOM_ALT2_FLAG)) |
| 4694 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4695 | |
| 4696 | return flags; |
| 4697 | } |
| 4698 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4699 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4700 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4701 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4702 | // Note: The overrides are valid only for the next frame passed |
| 4703 | // to encode_frame_to_data_rate() function |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4704 | if (cpi->ext_use_s_frame) cpi->common.frame_type = S_FRAME; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 4705 | cpi->common.force_primary_ref_none = cpi->ext_use_primary_ref_none; |
Debargha Mukherjee | 52fb047 | 2018-03-29 15:48:11 -0700 | [diff] [blame] | 4706 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4707 | if (cpi->ext_refresh_frame_context_pending) { |
| 4708 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 4709 | cpi->ext_refresh_frame_context_pending = 0; |
| 4710 | } |
| 4711 | if (cpi->ext_refresh_frame_flags_pending) { |
| 4712 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 4713 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 4714 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 4715 | cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame; |
| 4716 | cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4717 | cpi->ext_refresh_frame_flags_pending = 0; |
| 4718 | } |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4719 | cpi->common.allow_ref_frame_mvs = cpi->ext_use_ref_frame_mvs; |
Sarah Parker | 14feea4 | 2018-07-06 16:41:41 -0700 | [diff] [blame] | 4720 | // A keyframe is already error resilient and keyframes with |
| 4721 | // error_resilient_mode interferes with the use of show_existing_frame |
| 4722 | // when forward reference keyframes are enabled. |
| 4723 | cpi->common.error_resilient_mode = |
| 4724 | cpi->ext_use_error_resilient && cpi->common.frame_type != KEY_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4725 | } |
| 4726 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4727 | #define DUMP_RECON_FRAMES 0 |
| 4728 | |
| 4729 | #if DUMP_RECON_FRAMES == 1 |
| 4730 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4731 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4732 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4733 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4734 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4735 | if (recon_buf == NULL) { |
| 4736 | printf("Frame %d is not ready.\n", cm->current_video_frame); |
| 4737 | return; |
| 4738 | } |
| 4739 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 4740 | static const int flag_list[REF_FRAMES] = { 0, |
| 4741 | AOM_LAST_FLAG, |
| 4742 | AOM_LAST2_FLAG, |
| 4743 | AOM_LAST3_FLAG, |
| 4744 | AOM_GOLD_FLAG, |
| 4745 | AOM_BWD_FLAG, |
| 4746 | AOM_ALT2_FLAG, |
| 4747 | AOM_ALT_FLAG }; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4748 | printf( |
| 4749 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 4750 | "show_existing_frame=%d) " |
| 4751 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
| 4752 | cm->current_video_frame, cm->frame_offset, cm->show_frame, |
| 4753 | cm->show_existing_frame); |
| 4754 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4755 | const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 4756 | const int ref_offset = |
| 4757 | (buf_idx >= 0) |
| 4758 | ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset |
| 4759 | : -1; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 4760 | printf( |
| 4761 | " %d(%c-%d-%4.2f)", ref_offset, |
| 4762 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N', |
| 4763 | (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1, |
| 4764 | (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] | 4765 | } |
| 4766 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4767 | |
| 4768 | if (!cm->show_frame) { |
| 4769 | 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] | 4770 | cm->current_video_frame); |
| 4771 | return; |
| 4772 | } |
| 4773 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4774 | int h; |
| 4775 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4776 | FILE *f_recon = NULL; |
| 4777 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4778 | if (cm->current_video_frame == 0) { |
| 4779 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4780 | printf("Unable to open file %s to write.\n", file_name); |
| 4781 | return; |
| 4782 | } |
| 4783 | } else { |
| 4784 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4785 | printf("Unable to open file %s to append.\n", file_name); |
| 4786 | return; |
| 4787 | } |
| 4788 | } |
| 4789 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4790 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 4791 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
| 4792 | "refresh_alt_ref_frame=%d, rf_level=%d, " |
| 4793 | "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] | 4794 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 4795 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4796 | cm->frame_offset, cm->show_frame, cm->show_existing_frame, |
| 4797 | cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame, |
| 4798 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 4799 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4800 | #if 0 |
| 4801 | int ref_frame; |
| 4802 | printf("get_ref_frame_map_idx: ["); |
| 4803 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 4804 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 4805 | printf(" ]\n"); |
| 4806 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 4807 | printf("cm->ref_frame_map = ["); |
| 4808 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4809 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 4810 | } |
| 4811 | printf(" ]\n"); |
| 4812 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4813 | |
| 4814 | // --- Y --- |
| 4815 | for (h = 0; h < cm->height; ++h) { |
| 4816 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4817 | f_recon); |
| 4818 | } |
| 4819 | // --- U --- |
| 4820 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4821 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4822 | f_recon); |
| 4823 | } |
| 4824 | // --- V --- |
| 4825 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4826 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4827 | f_recon); |
| 4828 | } |
| 4829 | |
| 4830 | fclose(f_recon); |
| 4831 | } |
| 4832 | #endif // DUMP_RECON_FRAMES |
| 4833 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 4834 | static INLINE int is_frame_droppable(AV1_COMP *cpi) { |
| 4835 | return !(cpi->refresh_alt_ref_frame || cpi->refresh_alt2_ref_frame || |
| 4836 | cpi->refresh_bwd_ref_frame || cpi->refresh_golden_frame || |
| 4837 | cpi->refresh_last_frame); |
| 4838 | } |
| 4839 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4840 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 4841 | int skip_adapt, |
| 4842 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4843 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4844 | SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4845 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4846 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 4847 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4848 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4849 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4850 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 4851 | // frame type has been decided outside of this function call |
Zoe Liu | d78ce2d | 2018-02-24 05:50:57 -0800 | [diff] [blame] | 4852 | cm->cur_frame->intra_only = frame_is_intra_only(cm); |
Zoe Liu | 2723a9d | 2018-02-22 20:17:00 -0800 | [diff] [blame] | 4853 | cm->cur_frame->frame_type = cm->frame_type; |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 4854 | |
| 4855 | // S_FRAMEs are always error resilient |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4856 | cm->error_resilient_mode |= frame_is_sframe(cm); |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 4857 | |
| 4858 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 4859 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4860 | if (cm->large_scale_tile) seq_params->frame_id_numbers_present_flag = 0; |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 4861 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4862 | cm->allow_ref_frame_mvs &= frame_might_allow_ref_frame_mvs(cm); |
Yunqing Wang | d48fb16 | 2018-06-15 10:55:28 -0700 | [diff] [blame] | 4863 | // cm->allow_ref_frame_mvs needs to be written into the frame header while |
| 4864 | // cm->large_scale_tile is 1, therefore, "cm->large_scale_tile=1" case is |
| 4865 | // separated from frame_might_allow_ref_frame_mvs(). |
| 4866 | cm->allow_ref_frame_mvs &= !cm->large_scale_tile; |
| 4867 | |
Debargha Mukherjee | 1d7217e | 2018-03-26 13:32:13 -0700 | [diff] [blame] | 4868 | cm->allow_warped_motion = |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 4869 | cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4870 | |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 4871 | // Reset the frame packet stamp index. |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 4872 | if (cm->frame_type == KEY_FRAME && cm->show_frame) |
| 4873 | cm->current_video_frame = 0; |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 4874 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4875 | // NOTE: |
| 4876 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 4877 | // determined by the current frame properties; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4878 | // (2) The setup of the ref_frame_flags applies to both |
| 4879 | // show_existing_frame's |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4880 | // and the other cases. |
| 4881 | if (cm->current_video_frame > 0) |
| 4882 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 4883 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 4884 | if (encode_show_existing_frame(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4885 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 4886 | // BWDREF_FRAME in the reference frame buffer. |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 4887 | if (cm->frame_type == KEY_FRAME) { |
| 4888 | cm->reset_decoder_state = 1; |
| 4889 | } else { |
| 4890 | cm->frame_type = INTER_FRAME; |
| 4891 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4892 | cm->show_frame = 1; |
| 4893 | cpi->frame_flags = *frame_flags; |
| 4894 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4895 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4896 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4897 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4898 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 4899 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4900 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4901 | cpi->seq_params_locked = 1; |
| 4902 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4903 | // Set up frame to show to get ready for stats collection. |
| 4904 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 4905 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4906 | // Update current frame offset. |
| 4907 | cm->frame_offset = |
| 4908 | cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4909 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4910 | #if DUMP_RECON_FRAMES == 1 |
| 4911 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4912 | dump_filtered_recon_frames(cpi); |
| 4913 | #endif // DUMP_RECON_FRAMES |
| 4914 | |
| 4915 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4916 | // NOTE: |
| 4917 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 4918 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 4919 | // right before BWDREF_FRAME (in the display order); |
| 4920 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4921 | // update will be done when the following is called, which will |
| 4922 | // exchange |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4923 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4924 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, |
| 4925 | // and |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4926 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4927 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4928 | |
| 4929 | // Update frame flags |
| 4930 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 4931 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 4932 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 4933 | |
| 4934 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 4935 | |
| 4936 | // Update the frame type |
| 4937 | cm->last_frame_type = cm->frame_type; |
| 4938 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4939 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 4940 | // to do post-encoding update accordingly. |
| 4941 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4942 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4943 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4944 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4945 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4946 | ++cm->current_video_frame; |
| 4947 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4948 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4949 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4950 | |
| 4951 | // Set default state for segment based loop filter update flags. |
| 4952 | cm->lf.mode_ref_delta_update = 0; |
| 4953 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4954 | // 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] | 4955 | if (frame_is_intra_only(cm) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4956 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4957 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4958 | |
| 4959 | // If segmentation is enabled force a map update for key frames. |
| 4960 | if (seg->enabled) { |
| 4961 | seg->update_map = 1; |
| 4962 | seg->update_data = 1; |
| 4963 | } |
| 4964 | |
| 4965 | // The alternate reference frame cannot be active for a key frame. |
| 4966 | cpi->rc.source_alt_ref_active = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4967 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4968 | if (cpi->oxcf.mtu == 0) { |
| 4969 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 4970 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 4971 | // Use a default value for the purposes of weighting costs in probability |
| 4972 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4973 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 4974 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4975 | |
| 4976 | // For 1 pass CBR, check if we are dropping this frame. |
| 4977 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4978 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4979 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4980 | if (av1_rc_drop_frame(cpi)) { |
| 4981 | av1_rc_postencode_update_drop_frame(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4982 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4983 | } |
| 4984 | } |
| 4985 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4986 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4987 | |
| 4988 | #if CONFIG_INTERNAL_STATS |
| 4989 | memset(cpi->mode_chosen_counts, 0, |
| 4990 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 4991 | #endif |
| 4992 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4993 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4994 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 4995 | * wraparound) */ |
Sebastien Alaiwan | d418f68 | 2017-10-19 15:06:52 +0200 | [diff] [blame] | 4996 | const int frame_id_length = FRAME_ID_LENGTH; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4997 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4998 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4999 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5000 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5001 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 5002 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5003 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5004 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5005 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5006 | } |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5007 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 5008 | |
| 5009 | // S_frame is meant for stitching different streams of different |
| 5010 | // resolutions together, so current_frame_id must be the |
| 5011 | // same across different streams of the same content current_frame_id |
| 5012 | // should be the same and not random. 0x37 is a chosen number as start |
| 5013 | // point |
| 5014 | if (cpi->oxcf.sframe_enabled) cm->current_frame_id = 0x37; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5015 | } else { |
| 5016 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5017 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 5018 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5019 | } |
| 5020 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5021 | |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5022 | switch (cpi->oxcf.cdf_update_mode) { |
| 5023 | case 0: // No CDF update for any frames(4~6% compression loss). |
| 5024 | cm->disable_cdf_update = 1; |
| 5025 | break; |
| 5026 | case 1: // Enable CDF update for all frames. |
| 5027 | cm->disable_cdf_update = 0; |
| 5028 | break; |
| 5029 | case 2: |
| 5030 | // Strategically determine at which frames to do CDF update. |
| 5031 | // Currently only enable CDF update for all-intra and no-show frames(1.5% |
| 5032 | // compression loss). |
| 5033 | // TODO(huisu@google.com): design schemes for various trade-offs between |
| 5034 | // compression quality and decoding speed. |
Hui Su | b1b76b3 | 2018-02-27 15:24:48 -0800 | [diff] [blame] | 5035 | cm->disable_cdf_update = |
| 5036 | (frame_is_intra_only(cm) || !cm->show_frame) ? 0 : 1; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5037 | break; |
| 5038 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5039 | cm->timing_info_present &= !seq_params->reduced_still_picture_hdr; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5040 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5041 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5042 | 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] | 5043 | } else { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5044 | if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK) |
| 5045 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5048 | cm->last_tile_cols = cm->tile_cols; |
| 5049 | cm->last_tile_rows = cm->tile_rows; |
| 5050 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5051 | #ifdef OUTPUT_YUV_SKINMAP |
| 5052 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5053 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5054 | } |
| 5055 | #endif // OUTPUT_YUV_SKINMAP |
| 5056 | |
| 5057 | // Special case code to reduce pulsing when key frames are forced at a |
| 5058 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5059 | // the force key frame |
| 5060 | if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5061 | if (seq_params->use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5062 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5063 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5064 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5065 | 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] | 5066 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5067 | } |
| 5068 | |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 5069 | // If the encoder forced a KEY_FRAME decision or if frame is an S_FRAME |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5070 | if ((cm->frame_type == KEY_FRAME && cm->show_frame) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5071 | cpi->refresh_last_frame = 1; |
| 5072 | } |
| 5073 | |
| 5074 | cm->frame_to_show = get_frame_new_buffer(cm); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5075 | cm->frame_to_show->color_primaries = seq_params->color_primaries; |
| 5076 | cm->frame_to_show->transfer_characteristics = |
| 5077 | seq_params->transfer_characteristics; |
| 5078 | cm->frame_to_show->matrix_coefficients = seq_params->matrix_coefficients; |
| 5079 | cm->frame_to_show->monochrome = seq_params->monochrome; |
| 5080 | cm->frame_to_show->chroma_sample_position = |
| 5081 | seq_params->chroma_sample_position; |
| 5082 | cm->frame_to_show->color_range = seq_params->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5083 | cm->frame_to_show->render_width = cm->render_width; |
| 5084 | cm->frame_to_show->render_height = cm->render_height; |
| 5085 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5086 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5087 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5088 | |
| 5089 | // Pick the loop filter level for the frame. |
Cheng Chen | 68dc914 | 2018-05-02 17:46:28 -0700 | [diff] [blame] | 5090 | if (!cm->allow_intrabc) { |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5091 | loopfilter_frame(cpi, cm); |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5092 | } else { |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5093 | cm->lf.filter_level[0] = 0; |
| 5094 | cm->lf.filter_level[1] = 0; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5095 | cm->cdef_bits = 0; |
| 5096 | cm->cdef_strengths[0] = 0; |
| 5097 | cm->nb_cdef_strengths = 1; |
| 5098 | cm->cdef_uv_strengths[0] = 0; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5099 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5100 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5101 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5102 | } |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5103 | |
| 5104 | // TODO(debargha): Fix mv search range on encoder side |
| 5105 | // aom_extend_frame_inner_borders(cm->frame_to_show, av1_num_planes(cm)); |
| 5106 | aom_extend_frame_borders(cm->frame_to_show, av1_num_planes(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5107 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5108 | #ifdef OUTPUT_YUV_REC |
| 5109 | aom_write_one_yuv_frame(cm, cm->frame_to_show); |
| 5110 | #endif |
| 5111 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5112 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5113 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 5114 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5115 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5116 | cpi->seq_params_locked = 1; |
| 5117 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5118 | if (skip_adapt) return AOM_CODEC_OK; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5119 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5120 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5121 | int i; |
Zoe Liu | 630a89f | 2018-04-16 09:36:50 -0700 | [diff] [blame] | 5122 | // Update reference frame id values based on the value of refresh_frame_mask |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5123 | for (i = 0; i < REF_FRAMES; i++) { |
Zoe Liu | 630a89f | 2018-04-16 09:36:50 -0700 | [diff] [blame] | 5124 | if ((cpi->refresh_frame_mask >> i) & 1) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5125 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5126 | } |
| 5127 | } |
| 5128 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5129 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5130 | #if DUMP_RECON_FRAMES == 1 |
| 5131 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5132 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5133 | #endif // DUMP_RECON_FRAMES |
| 5134 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5135 | if (cm->seg.enabled) { |
| 5136 | if (cm->seg.update_map) { |
| 5137 | update_reference_segmentation_map(cpi); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 5138 | } else if (cm->last_frame_seg_map) { |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5139 | memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map, |
| 5140 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 5141 | } |
| 5142 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5143 | |
| 5144 | if (frame_is_intra_only(cm) == 0) { |
| 5145 | release_scaled_references(cpi); |
| 5146 | } |
| 5147 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5148 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5149 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5150 | #if CONFIG_ENTROPY_STATS |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 5151 | av1_accumulate_frame_counts(&aggregate_fc, &cpi->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5152 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5153 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5154 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
| 5155 | *cm->fc = cpi->tile_data[cm->largest_tile_id].tctx; |
| 5156 | av1_reset_cdf_symbol_counters(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | if (cpi->refresh_golden_frame == 1) |
| 5160 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 5161 | else |
| 5162 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5163 | |
| 5164 | if (cpi->refresh_alt_ref_frame == 1) |
| 5165 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 5166 | else |
| 5167 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5168 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5169 | if (cpi->refresh_bwd_ref_frame == 1) |
| 5170 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5171 | else |
| 5172 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5173 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5174 | cm->last_frame_type = cm->frame_type; |
| 5175 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5176 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5177 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5178 | if (cm->frame_type == KEY_FRAME) { |
| 5179 | // Tell the caller that the frame was coded as a key frame |
| 5180 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5181 | } else { |
| 5182 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5183 | } |
| 5184 | |
| 5185 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5186 | // filter deltas. |
| 5187 | cm->seg.update_map = 0; |
| 5188 | cm->seg.update_data = 0; |
| 5189 | cm->lf.mode_ref_delta_update = 0; |
| 5190 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 5191 | // A droppable frame might not be shown but it always |
| 5192 | // takes a space in the gf group. Therefore, even when |
| 5193 | // it is not shown, we still need update the count down. |
| 5194 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5195 | if (cm->show_frame) { |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5196 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that |
| 5197 | // are |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5198 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5199 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5200 | // Don't increment frame counters if this was an altref buffer |
| 5201 | // update not a real frame |
Wei-Ting Lin | 96ee0eb | 2018-06-22 15:27:22 -0700 | [diff] [blame] | 5202 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5203 | ++cm->current_video_frame; |
| 5204 | } |
| 5205 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5206 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5207 | if (cm->is_reference_frame) { |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5208 | // keep track of the last coded dimensions |
| 5209 | cm->last_width = cm->width; |
| 5210 | cm->last_height = cm->height; |
| 5211 | |
| 5212 | // reset to normal state now that we are done. |
| 5213 | cm->last_show_frame = cm->show_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5214 | } |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5215 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5216 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5217 | } |
| 5218 | |
Sarah Parker | 3491dd2 | 2018-08-08 18:38:31 -0700 | [diff] [blame] | 5219 | static INLINE void update_keyframe_counters(AV1_COMP *cpi) { |
| 5220 | // TODO(zoeliu): To investigate whether we should treat BWDREF_FRAME |
| 5221 | // differently here for rc->avg_frame_bandwidth. |
| 5222 | if (cpi->common.show_frame || cpi->rc.is_bwd_ref_frame) { |
| 5223 | if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref || |
| 5224 | cpi->common.frame_type == KEY_FRAME) { |
| 5225 | // If this is a show_existing_frame with a source other than altref, |
| 5226 | // or if it is not a displayed forward keyframe, the keyframe update |
| 5227 | // counters were incremented when it was originally encoded. |
| 5228 | cpi->rc.frames_since_key++; |
| 5229 | cpi->rc.frames_to_key--; |
| 5230 | } |
| 5231 | } |
| 5232 | } |
| 5233 | |
| 5234 | static INLINE void update_frames_till_gf_update(AV1_COMP *cpi) { |
| 5235 | // TODO(weitinglin): Updating this counter for is_frame_droppable |
| 5236 | // is a work-around to handle the condition when a frame is drop. |
| 5237 | // We should fix the cpi->common.show_frame flag |
| 5238 | // instead of checking the other condition to update the counter properly. |
| 5239 | if (cpi->common.show_frame || is_frame_droppable(cpi)) { |
| 5240 | // Decrement count down till next gf |
| 5241 | if (cpi->rc.frames_till_gf_update_due > 0) |
| 5242 | cpi->rc.frames_till_gf_update_due--; |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | static INLINE void update_twopass_gf_group_index(AV1_COMP *cpi) { |
| 5247 | // Increment the gf group index ready for the next frame. If this is |
| 5248 | // a show_existing_frame with a source other than altref, or if it is not |
| 5249 | // a displayed forward keyframe, the index was incremented when it was |
| 5250 | // originally encoded. |
| 5251 | if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref || |
| 5252 | cpi->common.frame_type == KEY_FRAME) { |
| 5253 | ++cpi->twopass.gf_group.index; |
| 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | static void update_rc_counts(AV1_COMP *cpi) { |
| 5258 | update_keyframe_counters(cpi); |
| 5259 | update_frames_till_gf_update(cpi); |
| 5260 | if (cpi->oxcf.pass == 2) update_twopass_gf_group_index(cpi); |
| 5261 | } |
| 5262 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5263 | static int Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5264 | int skip_adapt, unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5265 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5266 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5267 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5268 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5269 | } |
Debargha Mukherjee | ff48c09 | 2018-04-04 23:53:40 -0700 | [diff] [blame] | 5270 | if (encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags) != |
| 5271 | AOM_CODEC_OK) { |
| 5272 | return AOM_CODEC_ERROR; |
| 5273 | } |
Sarah Parker | 3491dd2 | 2018-08-08 18:38:31 -0700 | [diff] [blame] | 5274 | update_rc_counts(cpi); |
Debargha Mukherjee | ff48c09 | 2018-04-04 23:53:40 -0700 | [diff] [blame] | 5275 | check_show_existing_frame(cpi); |
| 5276 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5279 | static int Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5280 | unsigned int *frame_flags) { |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 5281 | #if CONFIG_MISMATCH_DEBUG |
| 5282 | mismatch_move_frame_idx_w(); |
| 5283 | #endif |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 5284 | #if TXCOEFF_COST_TIMER |
| 5285 | AV1_COMMON *cm = &cpi->common; |
| 5286 | cm->txcoeff_cost_timer = 0; |
| 5287 | cm->txcoeff_cost_count = 0; |
| 5288 | #endif |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5289 | |
| 5290 | if (encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags) != |
| 5291 | AOM_CODEC_OK) { |
| 5292 | return AOM_CODEC_ERROR; |
| 5293 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5294 | |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 5295 | #if TXCOEFF_COST_TIMER |
| 5296 | cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer; |
| 5297 | fprintf(stderr, |
| 5298 | "\ntxb coeff cost block number: %ld, frame time: %ld, cum time %ld " |
| 5299 | "in us\n", |
| 5300 | cm->txcoeff_cost_count, cm->txcoeff_cost_timer, |
| 5301 | cm->cum_txcoeff_cost_timer); |
| 5302 | #endif |
| 5303 | |
Sarah Parker | 3491dd2 | 2018-08-08 18:38:31 -0700 | [diff] [blame] | 5304 | av1_twopass_postencode_update(cpi); |
| 5305 | update_rc_counts(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5306 | check_show_existing_frame(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5307 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5308 | } |
| 5309 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5310 | #if CONFIG_DENOISE |
| 5311 | static int apply_denoise_2d(AV1_COMP *cpi, YV12_BUFFER_CONFIG *sd, |
| 5312 | int block_size, float noise_level, |
| 5313 | int64_t time_stamp, int64_t end_time) { |
| 5314 | AV1_COMMON *const cm = &cpi->common; |
| 5315 | if (!cpi->denoise_and_model) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5316 | cpi->denoise_and_model = aom_denoise_and_model_alloc( |
| 5317 | cm->seq_params.bit_depth, block_size, noise_level); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5318 | if (!cpi->denoise_and_model) { |
| 5319 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5320 | "Error allocating denoise and model"); |
| 5321 | return -1; |
| 5322 | } |
| 5323 | } |
| 5324 | if (!cpi->film_grain_table) { |
| 5325 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 5326 | if (!cpi->film_grain_table) { |
| 5327 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5328 | "Error allocating grain table"); |
| 5329 | return -1; |
| 5330 | } |
| 5331 | memset(cpi->film_grain_table, 0, sizeof(*cpi->film_grain_table)); |
| 5332 | } |
| 5333 | if (aom_denoise_and_model_run(cpi->denoise_and_model, sd, |
| 5334 | &cm->film_grain_params)) { |
| 5335 | if (cm->film_grain_params.apply_grain) { |
| 5336 | aom_film_grain_table_append(cpi->film_grain_table, time_stamp, end_time, |
| 5337 | &cm->film_grain_params); |
| 5338 | } |
| 5339 | } |
| 5340 | return 0; |
| 5341 | } |
| 5342 | #endif |
| 5343 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5344 | 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] | 5345 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5346 | int64_t end_time) { |
| 5347 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5348 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5349 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5350 | int res = 0; |
| 5351 | const int subsampling_x = sd->subsampling_x; |
| 5352 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5353 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5354 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5355 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5356 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5357 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5358 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5359 | #if CONFIG_DENOISE |
| 5360 | if (cpi->oxcf.noise_level > 0) |
| 5361 | if (apply_denoise_2d(cpi, sd, cpi->oxcf.noise_block_size, |
| 5362 | cpi->oxcf.noise_level, time_stamp, end_time) < 0) |
| 5363 | res = -1; |
| 5364 | #endif // CONFIG_DENOISE |
| 5365 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5366 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5367 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5368 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5369 | aom_usec_timer_mark(&timer); |
| 5370 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5371 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5372 | if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5373 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5374 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5375 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5376 | res = -1; |
| 5377 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5378 | if ((seq_params->profile == PROFILE_1) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5379 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5380 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5381 | "Profile 1 requires 4:4:4 color format"); |
| 5382 | res = -1; |
| 5383 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5384 | if ((seq_params->profile == PROFILE_2) && |
| 5385 | (seq_params->bit_depth <= AOM_BITS_10) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5386 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 5387 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 5388 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5389 | res = -1; |
| 5390 | } |
| 5391 | |
| 5392 | return res; |
| 5393 | } |
| 5394 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5395 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5396 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5397 | |
| 5398 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5399 | cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame || |
| 5400 | cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame || |
| 5401 | !cm->error_resilient_mode || cm->lf.mode_ref_delta_update || |
| 5402 | cm->seg.update_map || cm->seg.update_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5403 | } |
| 5404 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5405 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5406 | const struct lookahead_entry *source) { |
| 5407 | int64_t this_duration; |
| 5408 | int step = 0; |
| 5409 | |
| 5410 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5411 | this_duration = source->ts_end - source->ts_start; |
| 5412 | step = 1; |
| 5413 | } else { |
| 5414 | int64_t last_duration = |
| 5415 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5416 | |
| 5417 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5418 | |
| 5419 | // do a step update if the duration changes by 10% |
| 5420 | if (last_duration) |
| 5421 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5422 | } |
| 5423 | |
| 5424 | if (this_duration) { |
| 5425 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5426 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5427 | } else { |
| 5428 | // Average this frame's rate into the last second's average |
| 5429 | // frame rate. If we haven't seen 1 second yet, then average |
| 5430 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5431 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5432 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5433 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5434 | avg_duration *= (interval - avg_duration + this_duration); |
| 5435 | avg_duration /= interval; |
| 5436 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5437 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5438 | } |
| 5439 | } |
| 5440 | cpi->last_time_stamp_seen = source->ts_start; |
| 5441 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5442 | } |
| 5443 | |
| 5444 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5445 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5446 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5447 | RATE_CONTROL *const rc = &cpi->rc; |
| 5448 | int arf_src_index = 0; |
| 5449 | if (is_altref_enabled(cpi)) { |
| 5450 | if (cpi->oxcf.pass == 2) { |
| 5451 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5452 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5453 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5454 | } |
| 5455 | } else if (rc->source_alt_ref_pending) { |
| 5456 | arf_src_index = rc->frames_till_gf_update_due; |
| 5457 | } |
| 5458 | } |
| 5459 | return arf_src_index; |
| 5460 | } |
| 5461 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5462 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5463 | int brf_src_index = 0; |
| 5464 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5465 | |
| 5466 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5467 | // flag. |
| 5468 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5469 | if (cpi->oxcf.pass == 2) { |
| 5470 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5471 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5472 | } else { |
| 5473 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5474 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | return brf_src_index; |
| 5479 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5480 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5481 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5482 | // used as the arf midpoint. |
| 5483 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5484 | int arf2_src_index = 0; |
| 5485 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5486 | if (cpi->oxcf.pass == 2) { |
| 5487 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5488 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 5489 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5490 | } |
| 5491 | } |
| 5492 | } |
| 5493 | return arf2_src_index; |
| 5494 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5495 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5496 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5497 | const struct lookahead_entry *source) { |
| 5498 | RATE_CONTROL *const rc = &cpi->rc; |
| 5499 | |
| 5500 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5501 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5502 | |
| 5503 | if (cpi->oxcf.pass == 2) { |
| 5504 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5505 | rc->is_src_frame_alt_ref = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5506 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5507 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5508 | rc->is_src_frame_ext_arf = |
| 5509 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5510 | } else { |
| 5511 | rc->is_src_frame_alt_ref = |
| 5512 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5513 | } |
| 5514 | |
| 5515 | if (rc->is_src_frame_alt_ref) { |
| 5516 | // Current frame is an ARF overlay frame. |
| 5517 | cpi->alt_ref_source = NULL; |
| 5518 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5519 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 5520 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 5521 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 5522 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 5523 | cpi->refresh_last_frame = 1; |
| 5524 | } else { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5525 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 5526 | // become the GF so preserve last as an alternative prediction option. |
| 5527 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5528 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5529 | } |
| 5530 | } |
| 5531 | |
| 5532 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5533 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5534 | const unsigned char *img2, int img2_pitch, |
| 5535 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5536 | |
| 5537 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5538 | ImageStat *s) { |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 5539 | s->stat[STAT_Y] += y; |
| 5540 | s->stat[STAT_U] += u; |
| 5541 | s->stat[STAT_V] += v; |
| 5542 | s->stat[STAT_ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5543 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5546 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5547 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5548 | double samples = 0.0; |
| 5549 | uint32_t in_bit_depth = 8; |
| 5550 | uint32_t bit_depth = 8; |
| 5551 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5552 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 5553 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5554 | #endif |
| 5555 | cpi->bytes += frame_bytes; |
| 5556 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5557 | if (cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5558 | in_bit_depth = cpi->oxcf.input_bit_depth; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5559 | bit_depth = cm->seq_params.bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5560 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5561 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5562 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5563 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 5564 | double y, u, v, frame_all; |
| 5565 | |
| 5566 | cpi->count++; |
| 5567 | if (cpi->b_calculate_psnr) { |
| 5568 | PSNR_STATS psnr; |
| 5569 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5570 | aom_clear_system_state(); |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5571 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5572 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5573 | |
| 5574 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5575 | &cpi->psnr); |
| 5576 | cpi->total_sq_error += psnr.sse[0]; |
| 5577 | cpi->total_samples += psnr.samples[0]; |
| 5578 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5579 | // TODO(yaowu): unify these two versions into one. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5580 | if (cm->seq_params.use_highbitdepth) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5581 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5582 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5583 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5584 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5585 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5586 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5587 | cpi->summed_quality += frame_ssim2 * weight; |
| 5588 | cpi->summed_weights += weight; |
| 5589 | |
| 5590 | #if 0 |
| 5591 | { |
| 5592 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 5593 | double y2 = psnr.psnr[1]; |
| 5594 | double u2 = psnr.psnr[2]; |
| 5595 | double v2 = psnr.psnr[3]; |
| 5596 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5597 | 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] | 5598 | cm->current_video_frame, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5599 | frame_psnr2, frame_ssim2); |
| 5600 | fclose(f); |
| 5601 | } |
| 5602 | #endif |
| 5603 | } |
| 5604 | if (cpi->b_calculate_blockiness) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5605 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5606 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5607 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5608 | recon->y_stride, orig->y_width, orig->y_height); |
| 5609 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5610 | cpi->total_blockiness += frame_blockiness; |
| 5611 | } |
| 5612 | |
| 5613 | if (cpi->b_calculate_consistency) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5614 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5615 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5616 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5617 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5618 | |
| 5619 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5620 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5621 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5622 | if (consistency > 0.0) |
| 5623 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5624 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5625 | cpi->total_inconsistency += this_inconsistency; |
| 5626 | } |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5631 | 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] | 5632 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5633 | 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] | 5634 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5635 | } |
| 5636 | } |
| 5637 | #endif // CONFIG_INTERNAL_STATS |
| 5638 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5639 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 5640 | const YV12_BUFFER_CONFIG *last_picture, |
| 5641 | hash_table *last_hash_table) { |
| 5642 | aom_clear_system_state(); |
| 5643 | // check use hash ME |
| 5644 | int k; |
| 5645 | uint32_t hash_value_1; |
| 5646 | uint32_t hash_value_2; |
| 5647 | |
| 5648 | const int block_size = 8; |
| 5649 | const double threshold_current = 0.8; |
| 5650 | const double threshold_average = 0.95; |
| 5651 | const int max_history_size = 32; |
| 5652 | int T = 0; // total block |
| 5653 | int C = 0; // match with collocated block |
| 5654 | int S = 0; // smooth region but not match with collocated block |
| 5655 | int M = 0; // match with other block |
| 5656 | |
| 5657 | const int pic_width = cur_picture->y_width; |
| 5658 | const int pic_height = cur_picture->y_height; |
| 5659 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 5660 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 5661 | const int x_pos = j; |
| 5662 | const int y_pos = i; |
| 5663 | int match = 1; |
| 5664 | T++; |
| 5665 | |
| 5666 | // check whether collocated block match with current |
| 5667 | uint8_t *p_cur = cur_picture->y_buffer; |
| 5668 | uint8_t *p_ref = last_picture->y_buffer; |
| 5669 | int stride_cur = cur_picture->y_stride; |
| 5670 | int stride_ref = last_picture->y_stride; |
| 5671 | p_cur += (y_pos * stride_cur + x_pos); |
| 5672 | p_ref += (y_pos * stride_ref + x_pos); |
| 5673 | |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5674 | if (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5675 | uint16_t *p16_cur = CONVERT_TO_SHORTPTR(p_cur); |
| 5676 | uint16_t *p16_ref = CONVERT_TO_SHORTPTR(p_ref); |
| 5677 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5678 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5679 | if (p16_cur[tmpX] != p16_ref[tmpX]) { |
| 5680 | match = 0; |
| 5681 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5682 | } |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5683 | p16_cur += stride_cur; |
| 5684 | p16_ref += stride_ref; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5685 | } |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5686 | } else { |
| 5687 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5688 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5689 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 5690 | match = 0; |
| 5691 | } |
| 5692 | } |
| 5693 | p_cur += stride_cur; |
| 5694 | p_ref += stride_ref; |
| 5695 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | if (match) { |
| 5699 | C++; |
| 5700 | continue; |
| 5701 | } |
| 5702 | |
| 5703 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 5704 | y_pos) || |
| 5705 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 5706 | S++; |
| 5707 | continue; |
| 5708 | } |
| 5709 | |
| 5710 | av1_get_block_hash_value( |
| 5711 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5712 | block_size, &hash_value_1, &hash_value_2, |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 5713 | (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb); |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5714 | // Hashing does not work for highbitdepth currently. |
| 5715 | // TODO(Roger): Make it work for highbitdepth. |
| 5716 | if (av1_use_hash_me(&cpi->common)) { |
| 5717 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 5718 | M++; |
| 5719 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5720 | } |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | assert(T > 0); |
| 5725 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 5726 | double m_rate = ((double)(M)) / ((double)(T)); |
| 5727 | |
| 5728 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 5729 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 5730 | |
| 5731 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 5732 | cpi->rate_size++; |
| 5733 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 5734 | |
| 5735 | if (csm_rate < threshold_current) { |
| 5736 | return 0; |
| 5737 | } |
| 5738 | |
| 5739 | if (C == T) { |
| 5740 | return 1; |
| 5741 | } |
| 5742 | |
| 5743 | double csm_average = 0.0; |
| 5744 | double m_average = 0.0; |
| 5745 | |
| 5746 | for (k = 0; k < cpi->rate_size; k++) { |
| 5747 | csm_average += cpi->csm_rate_array[k]; |
| 5748 | m_average += cpi->m_rate_array[k]; |
| 5749 | } |
| 5750 | csm_average /= cpi->rate_size; |
| 5751 | m_average /= cpi->rate_size; |
| 5752 | |
| 5753 | if (csm_average < threshold_average) { |
| 5754 | return 0; |
| 5755 | } |
| 5756 | |
| 5757 | if (M > (T - C - S) / 3) { |
| 5758 | return 1; |
| 5759 | } |
| 5760 | |
| 5761 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 5762 | return 1; |
| 5763 | } |
| 5764 | |
| 5765 | if (csm_average + m_average > 1.01) { |
| 5766 | return 1; |
| 5767 | } |
| 5768 | |
| 5769 | return 0; |
| 5770 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5771 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 5772 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 5773 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 5774 | int64_t *time_end, int flush, |
| 5775 | const aom_rational_t *timebase) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5776 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5777 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5778 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5779 | BufferPool *const pool = cm->buffer_pool; |
| 5780 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5781 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5782 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 5783 | struct lookahead_entry *last_source = NULL; |
| 5784 | struct lookahead_entry *source = NULL; |
| 5785 | int arf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5786 | int brf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5787 | int i; |
| 5788 | |
| 5789 | #if CONFIG_BITSTREAM_DEBUG |
| 5790 | assert(cpi->oxcf.max_threads == 0 && |
| 5791 | "bitstream debug tool does not support multithreading"); |
| 5792 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 5793 | 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] | 5794 | #endif |
| 5795 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5796 | cm->showable_frame = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5797 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5798 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5799 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5800 | |
Debargha Mukherjee | ba7b8fe | 2018-03-15 23:10:07 -0700 | [diff] [blame] | 5801 | // Normal defaults |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5802 | cm->refresh_frame_context = oxcf->frame_parallel_decoding_mode |
| 5803 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 5804 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 5805 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 5806 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5807 | |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 5808 | // default reference buffers update config |
| 5809 | av1_configure_buffer_updates_firstpass(cpi, LF_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5810 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5811 | // Initialize fields related to forward keyframes |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 5812 | cpi->no_show_kf = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 5813 | cm->reset_decoder_state = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 5814 | |
Sarah Parker | 7e13da8 | 2018-04-30 17:47:24 -0700 | [diff] [blame] | 5815 | // Don't allow a show_existing_frame to coincide with an error resilient or |
Sarah Parker | 14feea4 | 2018-07-06 16:41:41 -0700 | [diff] [blame] | 5816 | // S-Frame. An exception can be made in the case of a keyframe, since it |
| 5817 | // does not depend on any previous frames. We must make this exception here |
| 5818 | // because of the use of show_existing_frame with forward coded keyframes. |
Sarah Parker | 7e13da8 | 2018-04-30 17:47:24 -0700 | [diff] [blame] | 5819 | struct lookahead_entry *lookahead_src = NULL; |
| 5820 | if (cm->current_video_frame > 0) |
| 5821 | lookahead_src = av1_lookahead_peek(cpi->lookahead, 0); |
Sarah Parker | 349e0bd | 2018-08-03 14:18:05 -0700 | [diff] [blame] | 5822 | |
| 5823 | int use_show_existing = 1; |
| 5824 | if (lookahead_src != NULL) { |
| 5825 | const int is_error_resilient = |
| 5826 | cpi->oxcf.error_resilient_mode || |
| 5827 | (lookahead_src->flags & AOM_EFLAG_ERROR_RESILIENT); |
| 5828 | const int is_s_frame = cpi->oxcf.s_frame_mode || |
| 5829 | (lookahead_src->flags & AOM_EFLAG_SET_S_FRAME); |
| 5830 | const int is_key_frame = |
| 5831 | (rc->frames_to_key == 0) || (cpi->frame_flags & FRAMEFLAGS_KEY); |
| 5832 | use_show_existing = !(is_error_resilient || is_s_frame) || is_key_frame; |
| 5833 | } |
Sarah Parker | 7e13da8 | 2018-04-30 17:47:24 -0700 | [diff] [blame] | 5834 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 5835 | if (oxcf->pass == 2 && cm->show_existing_frame && use_show_existing) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5836 | // Manage the source buffer and flush out the source frame that has been |
| 5837 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5838 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5839 | *size = 0; |
| 5840 | return -1; |
| 5841 | } |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5842 | av1_apply_encoding_flags(cpi, source->flags); |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5843 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5844 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 5845 | // the frame rate. |
| 5846 | *time_stamp = source->ts_start; |
| 5847 | *time_end = source->ts_end; |
| 5848 | |
| 5849 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5850 | 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] | 5851 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5852 | // Find a free buffer for the new frame, releasing the reference |
| 5853 | // previously |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5854 | // held. |
| 5855 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5856 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5857 | } |
| 5858 | cm->new_fb_idx = get_free_fb(cm); |
| 5859 | |
| 5860 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5861 | |
| 5862 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5863 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5864 | |
| 5865 | // Start with a 0 size frame. |
| 5866 | *size = 0; |
| 5867 | |
| 5868 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5869 | 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] | 5870 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5871 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 5872 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5873 | |
| 5874 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 5875 | |
| 5876 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5877 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5878 | #endif // CONFIG_INTERNAL_STATS |
| 5879 | |
| 5880 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5881 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5882 | |
| 5883 | cm->show_existing_frame = 0; |
| 5884 | return 0; |
| 5885 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5886 | |
| 5887 | // Should we encode an arf frame. |
| 5888 | arf_src_index = get_arf_src_index(cpi); |
| 5889 | if (arf_src_index) { |
| 5890 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5891 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5892 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5893 | if (e == NULL) { |
| 5894 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5895 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5896 | arf_src_index = 0; |
| 5897 | flush = 1; |
| 5898 | break; |
| 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
| 5903 | if (arf_src_index) { |
| 5904 | assert(arf_src_index <= rc->frames_to_key); |
| 5905 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5906 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5907 | cm->showable_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5908 | cpi->alt_ref_source = source; |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 5909 | // When arf_src_index == rc->frames_to_key, it indicates a fwd_kf |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5910 | if (arf_src_index == rc->frames_to_key) { |
| 5911 | // Skip temporal filtering and mark as intra_only if we have a fwd_kf |
| 5912 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5913 | int which_arf = gf_group->arf_update_idx[gf_group->index]; |
| 5914 | cpi->is_arf_filter_off[which_arf] = 1; |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 5915 | cpi->no_show_kf = 1; |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5916 | } else { |
| 5917 | if (oxcf->arnr_max_frames > 0) { |
| 5918 | // Produce the filtered ARF frame. |
| 5919 | av1_temporal_filter(cpi, arf_src_index); |
| 5920 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
| 5921 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5922 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5923 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5924 | cm->show_frame = 0; |
| 5925 | cm->intra_only = 0; |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 5926 | |
| 5927 | if (oxcf->pass < 2) { |
| 5928 | // In second pass, the buffer updates configure will be set |
| 5929 | // in the function av1_rc_get_second_pass_params |
| 5930 | av1_configure_buffer_updates_firstpass(cpi, ARF_UPDATE); |
| 5931 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5932 | } |
| 5933 | rc->source_alt_ref_pending = 0; |
| 5934 | } |
| 5935 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5936 | // Should we encode an arf2 frame. |
| 5937 | arf_src_index = get_arf2_src_index(cpi); |
| 5938 | if (arf_src_index) { |
| 5939 | for (i = 0; i <= arf_src_index; ++i) { |
| 5940 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 5941 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5942 | if (e == NULL) { |
| 5943 | break; |
| 5944 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 5945 | arf_src_index = 0; |
| 5946 | flush = 1; |
| 5947 | break; |
| 5948 | } |
| 5949 | } |
| 5950 | } |
| 5951 | |
| 5952 | if (arf_src_index) { |
| 5953 | assert(arf_src_index <= rc->frames_to_key); |
| 5954 | |
| 5955 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5956 | cm->showable_frame = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5957 | cpi->alt_ref_source = source; |
| 5958 | |
| 5959 | if (oxcf->arnr_max_frames > 0) { |
| 5960 | // Produce the filtered ARF frame. |
Sebastien Alaiwan | 6697acf | 2018-02-21 16:59:17 +0100 | [diff] [blame] | 5961 | av1_temporal_filter(cpi, arf_src_index); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5962 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5963 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5964 | } |
| 5965 | |
| 5966 | cm->show_frame = 0; |
| 5967 | cm->intra_only = 0; |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 5968 | |
| 5969 | if (oxcf->pass < 2) { |
| 5970 | // In second pass, the buffer updates configure will be set |
| 5971 | // in the function av1_rc_get_second_pass_params |
| 5972 | av1_configure_buffer_updates_firstpass(cpi, INTNL_ARF_UPDATE); |
| 5973 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5974 | } |
| 5975 | rc->source_alt_ref_pending = 0; |
| 5976 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5977 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5978 | rc->is_bwd_ref_frame = 0; |
| 5979 | brf_src_index = get_brf_src_index(cpi); |
| 5980 | if (brf_src_index) { |
| 5981 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5982 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5983 | cm->showable_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5984 | cm->show_frame = 0; |
| 5985 | cm->intra_only = 0; |
| 5986 | |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 5987 | if (oxcf->pass < 2) { |
| 5988 | // In second pass, the buffer updates configure will be set |
| 5989 | // in the function av1_rc_get_second_pass_params |
| 5990 | av1_configure_buffer_updates_firstpass(cpi, BIPRED_UPDATE); |
| 5991 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5992 | } |
| 5993 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5994 | |
| 5995 | if (!source) { |
| 5996 | // Get last frame source. |
| 5997 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5998 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5999 | return -1; |
| 6000 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6001 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6002 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6003 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6004 | |
| 6005 | if (source != NULL) { |
| 6006 | cm->show_frame = 1; |
| 6007 | cm->intra_only = 0; |
| 6008 | |
| 6009 | // Check to see if the frame should be encoded as an arf overlay. |
| 6010 | check_src_altref(cpi, source); |
| 6011 | } |
| 6012 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6013 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6014 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6015 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6016 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 6017 | |
| 6018 | *time_stamp = source->ts_start; |
| 6019 | *time_end = source->ts_end; |
Sarah Parker | 7355677 | 2018-03-28 18:28:05 -0700 | [diff] [blame] | 6020 | av1_apply_encoding_flags(cpi, source->flags); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6021 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6022 | |
| 6023 | } else { |
| 6024 | *size = 0; |
| 6025 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6026 | av1_end_first_pass(cpi); /* get last stats packet */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6027 | cpi->twopass.first_pass_done = 1; |
| 6028 | } |
| 6029 | return -1; |
| 6030 | } |
| 6031 | |
| 6032 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 6033 | cpi->first_time_stamp_ever = source->ts_start; |
| 6034 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 6035 | } |
| 6036 | |
| 6037 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6038 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6039 | |
| 6040 | // adjust frame rates based on timestamps given |
| 6041 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 6042 | |
| 6043 | // Find a free buffer for the new frame, releasing the reference previously |
| 6044 | // held. |
| 6045 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6046 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6047 | } |
| 6048 | cm->new_fb_idx = get_free_fb(cm); |
| 6049 | |
| 6050 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6051 | |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 6052 | // Retain the RF_LEVEL for the current newly coded frame. |
| 6053 | cpi->frame_rf_level[cm->new_fb_idx] = |
| 6054 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index]; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 6055 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6056 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 6057 | cm->cur_frame->buf.buf_8bit_valid = 0; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 6058 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6059 | if (cpi->film_grain_table) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 6060 | cm->seq_params.film_grain_params_present = aom_film_grain_table_lookup( |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6061 | cpi->film_grain_table, *time_stamp, *time_end, 0 /* =erase */, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 6062 | &cm->film_grain_params); |
| 6063 | } |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 6064 | cm->cur_frame->film_grain_params_present = |
| 6065 | cm->seq_params.film_grain_params_present; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6066 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6067 | // only one operating point supported now |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 6068 | const int64_t pts64 = ticks_to_timebase_units(timebase, *time_stamp); |
| 6069 | if (pts64 < 0 || pts64 > UINT32_MAX) return AOM_CODEC_ERROR; |
| 6070 | cpi->common.frame_presentation_time = (uint32_t)pts64; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6071 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6072 | // Start with a 0 size frame. |
| 6073 | *size = 0; |
| 6074 | |
| 6075 | cpi->frame_flags = *frame_flags; |
| 6076 | |
| 6077 | if (oxcf->pass == 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6078 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6079 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 6080 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6081 | } |
| 6082 | |
| 6083 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 6084 | 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] | 6085 | } |
| 6086 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6087 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 6088 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 6089 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6090 | |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 6091 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6092 | if (*time_stamp == 0) { |
| 6093 | cpi->common.current_frame_id = -1; |
| 6094 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6095 | } |
Zoe Liu | ca0cd3f | 2018-02-26 15:07:50 -0800 | [diff] [blame] | 6096 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6097 | cpi->cur_poc++; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 6098 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools && |
| 6099 | !frame_is_intra_only(cm)) { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 6100 | if (cpi->common.seq_params.force_integer_mv == 2) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6101 | struct lookahead_entry *previous_entry = |
Debargha Mukherjee | a71e3db | 2018-02-28 07:47:17 -0800 | [diff] [blame] | 6102 | av1_lookahead_peek(cpi->lookahead, cpi->previous_index); |
| 6103 | if (!previous_entry) |
| 6104 | cpi->common.cur_frame_force_integer_mv = 0; |
| 6105 | else |
| 6106 | cpi->common.cur_frame_force_integer_mv = is_integer_mv( |
| 6107 | cpi, cpi->source, &previous_entry->img, cpi->previous_hash_table); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6108 | } else { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 6109 | cpi->common.cur_frame_force_integer_mv = |
| 6110 | cpi->common.seq_params.force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6111 | } |
| 6112 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6113 | cpi->common.cur_frame_force_integer_mv = 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6114 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6115 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6116 | if (oxcf->pass == 1) { |
| 6117 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6118 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6119 | } else if (oxcf->pass == 2) { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6120 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 6121 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6122 | } else { |
| 6123 | // One pass encode |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6124 | if (Pass0Encode(cpi, size, dest, 0, frame_flags) != AOM_CODEC_OK) |
| 6125 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6126 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6127 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 6128 | cpi->previous_hash_table = &cm->cur_frame->hash_table; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6129 | { |
| 6130 | int l; |
| 6131 | for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) { |
| 6132 | if ((cpi->lookahead->buf + l) == source) { |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 6133 | cpi->previous_index = l; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6134 | break; |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | if (l == cpi->lookahead->max_sz) { |
| 6139 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6140 | "Failed to find last frame original buffer"); |
| 6141 | } |
| 6142 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6143 | } |
| 6144 | |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 6145 | if (!cm->large_scale_tile) { |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 6146 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 6147 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6148 | |
Yunqing Wang | b041d8a | 2017-11-15 12:31:18 -0800 | [diff] [blame] | 6149 | #define EXT_TILE_DEBUG 0 |
| 6150 | #if EXT_TILE_DEBUG |
| 6151 | if (cm->large_scale_tile && oxcf->pass == 2) { |
| 6152 | char fn[20] = "./fc"; |
| 6153 | fn[4] = cm->current_video_frame / 100 + '0'; |
| 6154 | fn[5] = (cm->current_video_frame % 100) / 10 + '0'; |
| 6155 | fn[6] = (cm->current_video_frame % 10) + '0'; |
| 6156 | fn[7] = '\0'; |
| 6157 | av1_print_frame_contexts(cm->fc, fn); |
| 6158 | } |
| 6159 | #endif // EXT_TILE_DEBUG |
| 6160 | #undef EXT_TILE_DEBUG |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 6161 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6162 | cm->showable_frame = !cm->show_frame && cm->showable_frame; |
Yunqing Wang | b041d8a | 2017-11-15 12:31:18 -0800 | [diff] [blame] | 6163 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6164 | // No frame encoded, or frame was dropped, release scaled references. |
| 6165 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 6166 | release_scaled_references(cpi); |
| 6167 | } |
| 6168 | |
| 6169 | if (*size > 0) { |
| 6170 | cpi->droppable = !frame_is_reference(cpi); |
| 6171 | } |
| 6172 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6173 | aom_usec_timer_mark(&cmptimer); |
| 6174 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6175 | |
| 6176 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 6177 | generate_psnr_packet(cpi); |
| 6178 | |
| 6179 | #if CONFIG_INTERNAL_STATS |
| 6180 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6181 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6182 | } |
| 6183 | #endif // CONFIG_INTERNAL_STATS |
| 6184 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6185 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6186 | |
| 6187 | return 0; |
| 6188 | } |
| 6189 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6190 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6191 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6192 | if (!cm->show_frame) { |
| 6193 | return -1; |
| 6194 | } else { |
| 6195 | int ret; |
| 6196 | if (cm->frame_to_show) { |
| 6197 | *dest = *cm->frame_to_show; |
| 6198 | dest->y_width = cm->width; |
| 6199 | dest->y_height = cm->height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6200 | dest->uv_width = cm->width >> cm->seq_params.subsampling_x; |
| 6201 | dest->uv_height = cm->height >> cm->seq_params.subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6202 | ret = 0; |
| 6203 | } else { |
| 6204 | ret = -1; |
| 6205 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6206 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6207 | return ret; |
| 6208 | } |
| 6209 | } |
| 6210 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6211 | 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] | 6212 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 6213 | |
| 6214 | *frame = |
| 6215 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 6216 | return 0; |
| 6217 | } |
| 6218 | |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6219 | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
| 6220 | const YV12_BUFFER_CONFIG *b) { |
| 6221 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 6222 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
| 6223 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
| 6224 | a->border == b->border && |
| 6225 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
| 6226 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
| 6227 | } |
| 6228 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 6229 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 6230 | YV12_BUFFER_CONFIG *new_frame, |
| 6231 | YV12_BUFFER_CONFIG *sd) { |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6232 | const int num_planes = av1_num_planes(cm); |
| 6233 | if (!equal_dimensions_and_border(new_frame, sd)) |
| 6234 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 6235 | "Incorrect buffer dimensions"); |
| 6236 | else |
| 6237 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
| 6238 | |
| 6239 | return cm->error.error_code; |
| 6240 | } |
| 6241 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6242 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6243 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6244 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6245 | |
| 6246 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6247 | |
| 6248 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6249 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6250 | |
| 6251 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 6252 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6253 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6254 | |
| 6255 | return 0; |
| 6256 | } |
| 6257 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6258 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6259 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6260 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *frame_size) { |
| 6261 | size_t output_size = 0; |
| 6262 | size_t total_bytes_read = 0; |
| 6263 | size_t remaining_size = *frame_size; |
| 6264 | uint8_t *buff_ptr = buffer; |
| 6265 | |
| 6266 | // go through each OBUs |
| 6267 | while (total_bytes_read < *frame_size) { |
| 6268 | uint8_t saved_obu_header[2]; |
| 6269 | uint64_t obu_payload_size; |
| 6270 | size_t length_of_payload_size; |
| 6271 | size_t length_of_obu_size; |
| 6272 | uint32_t obu_header_size = (buff_ptr[0] >> 2) & 0x1 ? 2 : 1; |
| 6273 | size_t obu_bytes_read = obu_header_size; // bytes read for current obu |
| 6274 | |
| 6275 | // save the obu header (1 or 2 bytes) |
| 6276 | memmove(saved_obu_header, buff_ptr, obu_header_size); |
| 6277 | // clear the obu_has_size_field |
| 6278 | saved_obu_header[0] = saved_obu_header[0] & (~0x2); |
| 6279 | |
| 6280 | // get the payload_size and length of payload_size |
| 6281 | if (aom_uleb_decode(buff_ptr + obu_header_size, remaining_size, |
| 6282 | &obu_payload_size, &length_of_payload_size) != 0) { |
| 6283 | return AOM_CODEC_ERROR; |
| 6284 | } |
| 6285 | obu_bytes_read += length_of_payload_size; |
| 6286 | |
| 6287 | // calculate the length of size of the obu header plus payload |
| 6288 | length_of_obu_size = |
| 6289 | aom_uleb_size_in_bytes((uint64_t)(obu_header_size + obu_payload_size)); |
| 6290 | |
| 6291 | // move the rest of data to new location |
| 6292 | memmove(buff_ptr + length_of_obu_size + obu_header_size, |
| 6293 | buff_ptr + obu_bytes_read, remaining_size - obu_bytes_read); |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 6294 | obu_bytes_read += (size_t)obu_payload_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6295 | |
| 6296 | // write the new obu size |
| 6297 | const uint64_t obu_size = obu_header_size + obu_payload_size; |
| 6298 | size_t coded_obu_size; |
| 6299 | if (aom_uleb_encode(obu_size, sizeof(obu_size), buff_ptr, |
| 6300 | &coded_obu_size) != 0) { |
| 6301 | return AOM_CODEC_ERROR; |
| 6302 | } |
| 6303 | |
| 6304 | // write the saved (modified) obu_header following obu size |
| 6305 | memmove(buff_ptr + length_of_obu_size, saved_obu_header, obu_header_size); |
| 6306 | |
| 6307 | total_bytes_read += obu_bytes_read; |
| 6308 | remaining_size -= obu_bytes_read; |
| 6309 | buff_ptr += length_of_obu_size + obu_size; |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 6310 | output_size += length_of_obu_size + (size_t)obu_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | *frame_size = output_size; |
| 6314 | return AOM_CODEC_OK; |
| 6315 | } |
| 6316 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6317 | 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] | 6318 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 6319 | // should be consistent with internal reference frame selection. Need to |
| 6320 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 6321 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
| 6322 | // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be |
| 6323 | // LAST. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6324 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6325 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6326 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 6327 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 6328 | AOM_EFLAG_NO_REF_ARF2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6329 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6330 | cpi->ext_ref_frame_flags = 0; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6331 | } else { |
| 6332 | int ref = AOM_REFFRAME_ALL; |
| 6333 | |
| 6334 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 6335 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 6336 | |
| 6337 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 6338 | |
| 6339 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 6340 | ref ^= AOM_ALT_FLAG; |
| 6341 | ref ^= AOM_BWD_FLAG; |
| 6342 | ref ^= AOM_ALT2_FLAG; |
| 6343 | } else { |
| 6344 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 6345 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
| 6346 | } |
| 6347 | |
| 6348 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6349 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6353 | (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] | 6354 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6355 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6356 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 6357 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6358 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6359 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6360 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6361 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 6362 | upd ^= AOM_ALT_FLAG; |
| 6363 | upd ^= AOM_BWD_FLAG; |
| 6364 | upd ^= AOM_ALT2_FLAG; |
| 6365 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6366 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6367 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6370 | cpi->ext_use_ref_frame_mvs = cpi->oxcf.allow_ref_frame_mvs & |
| 6371 | ((flags & AOM_EFLAG_NO_REF_FRAME_MVS) == 0); |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6372 | cpi->ext_use_error_resilient = cpi->oxcf.error_resilient_mode | |
| 6373 | ((flags & AOM_EFLAG_ERROR_RESILIENT) != 0); |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6374 | cpi->ext_use_s_frame = |
| 6375 | cpi->oxcf.s_frame_mode | ((flags & AOM_EFLAG_SET_S_FRAME) != 0); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 6376 | cpi->ext_use_primary_ref_none = (flags & AOM_EFLAG_SET_PRIMARY_REF_NONE) != 0; |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6377 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6378 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6379 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6380 | } |
| 6381 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6382 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6383 | int64_t timebase_units_to_ticks(const aom_rational_t *timebase, int64_t n) { |
| 6384 | return n * TICKS_PER_SEC * timebase->num / timebase->den; |
| 6385 | } |
| 6386 | |
| 6387 | int64_t ticks_to_timebase_units(const aom_rational_t *timebase, int64_t n) { |
| 6388 | const int64_t round = TICKS_PER_SEC * timebase->num / 2 - 1; |
| 6389 | return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC; |
| 6390 | } |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 6391 | |
| 6392 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi) { |
| 6393 | if (!cpi) return NULL; |
| 6394 | |
| 6395 | uint8_t header_buf[512] = { 0 }; |
| 6396 | const uint32_t sequence_header_size = |
| 6397 | write_sequence_header_obu(cpi, &header_buf[0]); |
| 6398 | assert(sequence_header_size <= sizeof(header_buf)); |
| 6399 | if (sequence_header_size == 0) return NULL; |
| 6400 | |
| 6401 | const size_t obu_header_size = 1; |
| 6402 | const size_t size_field_size = aom_uleb_size_in_bytes(sequence_header_size); |
| 6403 | const size_t payload_offset = obu_header_size + size_field_size; |
| 6404 | |
| 6405 | if (payload_offset + sequence_header_size > sizeof(header_buf)) return NULL; |
| 6406 | memmove(&header_buf[payload_offset], &header_buf[0], sequence_header_size); |
| 6407 | |
| 6408 | if (write_obu_header(OBU_SEQUENCE_HEADER, 0, &header_buf[0]) != |
| 6409 | obu_header_size) { |
| 6410 | return NULL; |
| 6411 | } |
| 6412 | |
| 6413 | size_t coded_size_field_size = 0; |
| 6414 | if (aom_uleb_encode(sequence_header_size, size_field_size, |
| 6415 | &header_buf[obu_header_size], |
| 6416 | &coded_size_field_size) != 0) { |
| 6417 | return NULL; |
| 6418 | } |
| 6419 | assert(coded_size_field_size == size_field_size); |
| 6420 | |
| 6421 | aom_fixed_buf_t *global_headers = |
| 6422 | (aom_fixed_buf_t *)malloc(sizeof(*global_headers)); |
| 6423 | if (!global_headers) return NULL; |
| 6424 | |
| 6425 | const size_t global_header_buf_size = |
| 6426 | obu_header_size + size_field_size + sequence_header_size; |
| 6427 | |
| 6428 | global_headers->buf = malloc(global_header_buf_size); |
| 6429 | if (!global_headers->buf) { |
| 6430 | free(global_headers); |
| 6431 | return NULL; |
| 6432 | } |
| 6433 | |
| 6434 | memcpy(global_headers->buf, &header_buf[0], global_header_buf_size); |
| 6435 | global_headers->sz = global_header_buf_size; |
| 6436 | return global_headers; |
| 6437 | } |