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 | |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 49 | #include "av1/encoder/av1_multi_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 50 | #include "av1/encoder/aq_complexity.h" |
| 51 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 52 | #include "av1/encoder/aq_variance.h" |
| 53 | #include "av1/encoder/bitstream.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 54 | #include "av1/encoder/context_tree.h" |
| 55 | #include "av1/encoder/encodeframe.h" |
| 56 | #include "av1/encoder/encodemv.h" |
| 57 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 58 | #include "av1/encoder/encodetxb.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | #include "av1/encoder/ethread.h" |
| 60 | #include "av1/encoder/firstpass.h" |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 61 | #include "av1/encoder/grain_test_vectors.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 62 | #include "av1/encoder/hash_motion.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | #include "av1/encoder/mbgraph.h" |
| 64 | #include "av1/encoder/picklpf.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | #include "av1/encoder/pickrst.h" |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 66 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | #include "av1/encoder/ratectrl.h" |
| 68 | #include "av1/encoder/rd.h" |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 69 | #include "av1/encoder/rdopt.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 70 | #include "av1/encoder/segmentation.h" |
| 71 | #include "av1/encoder/speed_features.h" |
| 72 | #include "av1/encoder/temporal_filter.h" |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 73 | #include "av1/encoder/reconinter_enc.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 75 | #define DEFAULT_EXPLICIT_ORDER_HINT_BITS 7 |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 76 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 77 | // av1 uses 10,000,000 ticks/second as time stamp |
| 78 | #define TICKS_PER_SEC 10000000LL |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 79 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 80 | #if CONFIG_ENTROPY_STATS |
| 81 | FRAME_COUNTS aggregate_fc; |
| 82 | #endif // CONFIG_ENTROPY_STATS |
| 83 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 85 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 86 | |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 87 | // Whether to use high precision mv for altref computation. |
| 88 | #define ALTREF_HIGH_PRECISION_MV 1 |
| 89 | |
| 90 | // Q threshold for high precision mv. Choose a very high value for now so that |
| 91 | // HIGH_PRECISION is always chosen. |
| 92 | #define HIGH_PRECISION_MV_QTHRESH 200 |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 93 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 94 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 95 | #ifdef OUTPUT_YUV_SKINMAP |
| 96 | FILE *yuv_skinmap_file = NULL; |
| 97 | #endif |
| 98 | #ifdef OUTPUT_YUV_REC |
| 99 | FILE *yuv_rec_file; |
| 100 | #define FILE_NAME_LEN 100 |
| 101 | #endif |
| 102 | |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 103 | // Estimate if the source frame is screen content, based on the portion of |
| 104 | // blocks that have no more than 4 (experimentally selected) luma colors. |
| 105 | static int is_screen_content(const uint8_t *src, int use_hbd, int bd, |
| 106 | int stride, int width, int height) { |
| 107 | assert(src != NULL); |
| 108 | int counts = 0; |
| 109 | const int blk_w = 16; |
| 110 | const int blk_h = 16; |
| 111 | const int limit = 4; |
| 112 | for (int r = 0; r + blk_h <= height; r += blk_h) { |
| 113 | for (int c = 0; c + blk_w <= width; c += blk_w) { |
| 114 | int count_buf[1 << 12]; // Maximum (1 << 12) color levels. |
| 115 | const int n_colors = |
| 116 | use_hbd ? av1_count_colors_highbd(src + r * stride + c, stride, blk_w, |
| 117 | blk_h, bd, count_buf) |
| 118 | : av1_count_colors(src + r * stride + c, stride, blk_w, blk_h, |
| 119 | count_buf); |
| 120 | if (n_colors > 1 && n_colors <= limit) counts++; |
| 121 | } |
| 122 | } |
| 123 | // The threshold is 10%. |
| 124 | return counts * blk_h * blk_w * 10 > width * height; |
| 125 | } |
| 126 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 127 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 128 | switch (mode) { |
| 129 | case NORMAL: |
| 130 | *hr = 1; |
| 131 | *hs = 1; |
| 132 | break; |
| 133 | case FOURFIVE: |
| 134 | *hr = 4; |
| 135 | *hs = 5; |
| 136 | break; |
| 137 | case THREEFIVE: |
| 138 | *hr = 3; |
| 139 | *hs = 5; |
| 140 | break; |
| 141 | case ONETWO: |
| 142 | *hr = 1; |
| 143 | *hs = 2; |
| 144 | break; |
| 145 | default: |
| 146 | *hr = 1; |
| 147 | *hs = 1; |
| 148 | assert(0); |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 154 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 155 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 156 | unsigned char *const seg_map = cpi->segmentation_map; |
| 157 | int i; |
| 158 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 159 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 160 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 161 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 162 | } |
| 163 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 164 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | struct segmentation *const seg = &cpi->common.seg; |
| 166 | unsigned char *const seg_map = cpi->segmentation_map; |
| 167 | const unsigned char *const active_map = cpi->active_map.map; |
| 168 | int i; |
| 169 | |
| 170 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 171 | |
| 172 | if (frame_is_intra_only(&cpi->common)) { |
| 173 | cpi->active_map.enabled = 0; |
| 174 | cpi->active_map.update = 1; |
| 175 | } |
| 176 | |
| 177 | if (cpi->active_map.update) { |
| 178 | if (cpi->active_map.enabled) { |
| 179 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 180 | 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] | 181 | av1_enable_segmentation(seg); |
| 182 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 183 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 184 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 185 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 186 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 187 | |
| 188 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 189 | -MAX_LOOP_FILTER); |
| 190 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 191 | -MAX_LOOP_FILTER); |
| 192 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 193 | -MAX_LOOP_FILTER); |
| 194 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 195 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 197 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 198 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 199 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 200 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 201 | 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] | 202 | if (seg->enabled) { |
| 203 | seg->update_data = 1; |
| 204 | seg->update_map = 1; |
| 205 | } |
| 206 | } |
| 207 | cpi->active_map.update = 0; |
| 208 | } |
| 209 | } |
| 210 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 211 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 212 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 213 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 214 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 215 | const int mi_rows = cpi->common.mi_rows; |
| 216 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 217 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 218 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | cpi->active_map.update = 1; |
| 220 | if (new_map_16x16) { |
| 221 | int r, c; |
| 222 | for (r = 0; r < mi_rows; ++r) { |
| 223 | for (c = 0; c < mi_cols; ++c) { |
| 224 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 225 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | ? AM_SEGMENT_ID_ACTIVE |
| 227 | : AM_SEGMENT_ID_INACTIVE; |
| 228 | } |
| 229 | } |
| 230 | cpi->active_map.enabled = 1; |
| 231 | } else { |
| 232 | cpi->active_map.enabled = 0; |
| 233 | } |
| 234 | return 0; |
| 235 | } else { |
| 236 | return -1; |
| 237 | } |
| 238 | } |
| 239 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 240 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 241 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 242 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 243 | new_map_16x16) { |
| 244 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 245 | const int mi_rows = cpi->common.mi_rows; |
| 246 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 247 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 248 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 249 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 250 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 251 | if (cpi->active_map.enabled) { |
| 252 | int r, c; |
| 253 | for (r = 0; r < mi_rows; ++r) { |
| 254 | for (c = 0; c < mi_cols; ++c) { |
| 255 | // Cyclic refresh segments are considered active despite not having |
| 256 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 257 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 258 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | return 0; |
| 263 | } else { |
| 264 | return -1; |
| 265 | } |
| 266 | } |
| 267 | |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 268 | // Compute the horizontal frequency component energy in a frame |
| 269 | // by calucluating the 16x4 Horizontal DCT. This will be subsequently |
| 270 | // used to decide the superresolution factors. |
| 271 | void analyze_hor_freq(const AV1_COMP *cpi, double *energy) { |
| 272 | uint64_t freq_energy[16] = { 0 }; |
| 273 | const YV12_BUFFER_CONFIG *buf = cpi->source; |
| 274 | const int bd = cpi->td.mb.e_mbd.bd; |
| 275 | const int width = buf->y_crop_width; |
| 276 | const int height = buf->y_crop_height; |
| 277 | int32_t coeff[16 * 4]; |
| 278 | int n = 0; |
| 279 | if (buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 280 | const int16_t *src16 = (const int16_t *)CONVERT_TO_SHORTPTR(buf->y_buffer); |
| 281 | for (int i = 0; i < height - 4; i += 4) { |
| 282 | for (int j = 0; j < width - 16; j += 16) { |
| 283 | av1_fwd_txfm2d_16x4(src16 + i * buf->y_stride + j, coeff, buf->y_stride, |
| 284 | H_DCT, bd); |
| 285 | for (int k = 4; k < 16; ++k) { |
| 286 | const int64_t en = |
| 287 | coeff[k] * coeff[k] + coeff[k + 16] * coeff[k + 16] + |
| 288 | coeff[k + 32] * coeff[k + 32] + coeff[k + 48] * coeff[k + 48]; |
| 289 | freq_energy[k] += ROUND_POWER_OF_TWO(en, 2 * (bd - 8)); |
| 290 | } |
| 291 | n++; |
| 292 | } |
| 293 | } |
| 294 | } else { |
| 295 | int16_t src16[16 * 4]; |
| 296 | for (int i = 0; i < height - 4; i += 4) { |
| 297 | for (int j = 0; j < width - 16; j += 16) { |
| 298 | for (int ii = 0; ii < 4; ++ii) |
| 299 | for (int jj = 0; jj < 16; ++jj) |
| 300 | src16[ii * 16 + jj] = |
| 301 | buf->y_buffer[(i + ii) * buf->y_stride + (j + jj)]; |
| 302 | av1_fwd_txfm2d_16x4(src16, coeff, buf->y_stride, H_DCT, bd); |
| 303 | for (int k = 4; k < 16; ++k) { |
| 304 | const int64_t en = |
| 305 | coeff[k] * coeff[k] + coeff[k + 16] * coeff[k + 16] + |
| 306 | coeff[k + 32] * coeff[k + 32] + coeff[k + 48] * coeff[k + 48]; |
| 307 | freq_energy[k] += ROUND_POWER_OF_TWO(en, 2 * (bd - 8)); |
| 308 | } |
| 309 | n++; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | for (int k = 4; k < 16; ++k) energy[k] = (double)freq_energy[k] / n; |
| 314 | } |
| 315 | |
Yaowu Xu | 45295c3 | 2018-03-29 12:06:10 -0700 | [diff] [blame] | 316 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv, |
| 317 | int cur_frame_force_integer_mv) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 318 | MACROBLOCK *const mb = &cpi->td.mb; |
Hui Su | 5036115 | 2018-03-02 11:01:42 -0800 | [diff] [blame] | 319 | cpi->common.allow_high_precision_mv = |
| 320 | allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 321 | const int copy_hp = |
| 322 | cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 323 | int *(*src)[2] = copy_hp ? &mb->nmvcost_hp : &mb->nmvcost; |
| 324 | mb->mv_cost_stack = *src; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 327 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 328 | const AV1_COMMON *const cm = &cpi->common; |
| 329 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 330 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 331 | return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 332 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 333 | if (cm->options && cm->options->ext_partition) |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 334 | #endif |
| 335 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 336 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 337 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 338 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 340 | // TODO(any): Possibly could improve this with a heuristic. |
| 341 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 342 | if (cm->options && !cm->options->ext_partition) return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 343 | #endif |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 344 | |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 345 | // When superres / resize is on, 'cm->width / height' can change between |
| 346 | // calls, so we don't apply this heuristic there. Also, this heuristic gives |
| 347 | // compression gain for speed >= 2 only. |
| 348 | if (cpi->oxcf.superres_mode == SUPERRES_NONE && |
| 349 | cpi->oxcf.resize_mode == RESIZE_NONE && cpi->oxcf.speed >= 2) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 350 | return (cm->width >= 480 && cm->height >= 360) ? BLOCK_128X128 |
| 351 | : BLOCK_64X64; |
| 352 | } |
| 353 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 354 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 357 | static void setup_frame(AV1_COMP *cpi) { |
| 358 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 359 | // Set up entropy context depending on frame type. The decoder mandates |
| 360 | // the use of the default context, index 0, for keyframes and inter |
| 361 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 362 | // other inter-frames the encoder currently uses only two contexts; |
| 363 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 364 | |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 365 | cm->primary_ref_frame = PRIMARY_REF_NONE; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 366 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 367 | cm->force_primary_ref_none) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 368 | av1_setup_past_independence(cm); |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 369 | for (int i = 0; i < REF_FRAMES; i++) { |
| 370 | cm->fb_of_context_type[i] = -1; |
| 371 | } |
| 372 | cm->fb_of_context_type[REGULAR_FRAME] = |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 373 | cm->show_frame ? get_ref_frame_map_idx(cpi, GOLDEN_FRAME) |
| 374 | : get_ref_frame_map_idx(cpi, ALTREF_FRAME); |
Sarah Parker | 167546f | 2018-04-24 12:14:45 -0700 | [diff] [blame] | 375 | cm->frame_context_idx = REGULAR_FRAME; |
Yunqing Wang | 19aefd1 | 2018-05-14 15:38:57 -0700 | [diff] [blame] | 376 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 378 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 379 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 380 | else if (cpi->refresh_alt_ref_frame) |
| 381 | cm->frame_context_idx = ARF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 382 | else if (cpi->rc.is_src_frame_alt_ref) |
| 383 | cm->frame_context_idx = OVERLAY_FRAME; |
| 384 | else if (cpi->refresh_golden_frame) |
| 385 | cm->frame_context_idx = GLD_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | else if (cpi->refresh_bwd_ref_frame) |
| 387 | cm->frame_context_idx = BRF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 388 | else |
| 389 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 390 | int wanted_fb = cm->fb_of_context_type[cm->frame_context_idx]; |
| 391 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { |
| 392 | int fb = get_ref_frame_map_idx(cpi, ref_frame); |
| 393 | if (fb == wanted_fb) { |
| 394 | cm->primary_ref_frame = ref_frame - LAST_FRAME; |
| 395 | } |
| 396 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 399 | if (cm->frame_type == KEY_FRAME && cm->show_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 400 | cpi->refresh_golden_frame = 1; |
| 401 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 402 | av1_zero(cpi->interp_filter_selected); |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 403 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 404 | set_use_reference_buffer(cm, 0); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 405 | } else if (frame_is_sframe(cm)) { |
| 406 | cpi->refresh_golden_frame = 1; |
| 407 | cpi->refresh_alt_ref_frame = 1; |
| 408 | av1_zero(cpi->interp_filter_selected); |
| 409 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 410 | } else { |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 411 | if (cm->primary_ref_frame == PRIMARY_REF_NONE || |
| 412 | cm->frame_refs[cm->primary_ref_frame].idx < 0) { |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 413 | av1_setup_past_independence(cm); |
| 414 | cm->seg.update_map = 1; |
| 415 | cm->seg.update_data = 1; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 416 | } else { |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 417 | *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] | 418 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 419 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 422 | cm->prev_frame = get_prev_frame(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 423 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 426 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 427 | int i; |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 428 | int mi_rows_sb_aligned = calc_mi_size(cm->mi_rows); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 429 | cm->mi = cm->mip; |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 430 | 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] | 431 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 432 | // Clear top border row |
| 433 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 434 | // Clear left border column |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 435 | for (i = 0; i < mi_rows_sb_aligned; ++i) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 436 | 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] | 437 | cm->mi_grid_visible = cm->mi_grid_base; |
| 438 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 439 | |
| 440 | memset(cm->mi_grid_base, 0, |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 441 | cm->mi_stride * mi_rows_sb_aligned * sizeof(*cm->mi_grid_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 444 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 445 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 446 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 447 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 448 | if (!cm->prev_mip) return 1; |
| 449 | cm->mi_alloc_size = mi_size; |
| 450 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 451 | cm->mi_grid_base = |
| 452 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 453 | if (!cm->mi_grid_base) return 1; |
| 454 | cm->prev_mi_grid_base = |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 455 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 456 | if (!cm->prev_mi_grid_base) return 1; |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 461 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 462 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 463 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 464 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 465 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 466 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 467 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 468 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 469 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 470 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 473 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 474 | // Current mip will be the prev_mip for the next frame. |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 475 | MB_MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 476 | MB_MODE_INFO *temp = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 477 | cm->prev_mip = cm->mip; |
| 478 | cm->mip = temp; |
| 479 | |
| 480 | // Update the upper left visible macroblock ptrs. |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 481 | cm->mi = cm->mip; |
| 482 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 483 | |
| 484 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 485 | cm->mi_grid_base = temp_base; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 486 | cm->mi_grid_visible = cm->mi_grid_base; |
| 487 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 490 | void av1_initialize_enc(void) { |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 491 | av1_rtcd(); |
| 492 | aom_dsp_rtcd(); |
| 493 | aom_scale_rtcd(); |
| 494 | av1_init_intra_predictors(); |
| 495 | av1_init_me_luts(); |
| 496 | av1_rc_init_minq_luts(); |
| 497 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 500 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 501 | if (cpi->mbmi_ext_base) { |
| 502 | aom_free(cpi->mbmi_ext_base); |
| 503 | cpi->mbmi_ext_base = NULL; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 508 | AV1_COMMON *cm = &cpi->common; |
| 509 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 510 | |
| 511 | dealloc_context_buffers_ext(cpi); |
| 512 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 513 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 514 | } |
| 515 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 516 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 517 | const AV1EncoderConfig *oxcf) { |
| 518 | AV1_COMMON *const cm = &cpi->common; |
| 519 | cpi->oxcf = *oxcf; |
| 520 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 521 | if (cpi->film_grain_table) { |
| 522 | aom_film_grain_table_free(cpi->film_grain_table); |
| 523 | aom_free(cpi->film_grain_table); |
| 524 | cpi->film_grain_table = NULL; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 525 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 526 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 527 | if (oxcf->film_grain_test_vector) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 528 | cm->seq_params.film_grain_params_present = 1; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 529 | if (cm->frame_type == KEY_FRAME) { |
| 530 | memcpy(&cm->film_grain_params, |
| 531 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 532 | sizeof(cm->film_grain_params)); |
| 533 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 534 | cm->film_grain_params.bit_depth = cm->seq_params.bit_depth; |
| 535 | if (cm->seq_params.color_range == AOM_CR_FULL_RANGE) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 536 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 537 | } |
| 538 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 539 | } else if (oxcf->film_grain_table_filename) { |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 540 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 541 | memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t)); |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 542 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 543 | aom_film_grain_table_read(cpi->film_grain_table, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 544 | oxcf->film_grain_table_filename, &cm->error); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 545 | } else { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 546 | cm->seq_params.film_grain_params_present = 0; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 547 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 548 | } |
| 549 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 550 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 551 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 552 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 553 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 554 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 555 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 556 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 557 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 558 | cpi->tile_data = NULL; |
| 559 | |
| 560 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 561 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 563 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 564 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 565 | cpi->cyclic_refresh = NULL; |
| 566 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 567 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 568 | cpi->active_map.map = NULL; |
| 569 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 570 | aom_free(cpi->td.mb.above_pred_buf); |
| 571 | cpi->td.mb.above_pred_buf = NULL; |
| 572 | |
| 573 | aom_free(cpi->td.mb.left_pred_buf); |
| 574 | cpi->td.mb.left_pred_buf = NULL; |
| 575 | |
| 576 | aom_free(cpi->td.mb.wsrc_buf); |
| 577 | cpi->td.mb.wsrc_buf = NULL; |
| 578 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 579 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 580 | aom_free(cpi->td.mb.inter_modes_info); |
| 581 | cpi->td.mb.inter_modes_info = NULL; |
| 582 | #endif |
| 583 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 584 | for (int i = 0; i < 2; i++) |
| 585 | for (int j = 0; j < 2; j++) { |
| 586 | aom_free(cpi->td.mb.hash_value_buffer[i][j]); |
| 587 | cpi->td.mb.hash_value_buffer[i][j] = NULL; |
| 588 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 589 | aom_free(cpi->td.mb.mask_buf); |
| 590 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 591 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 592 | aom_free(cm->tpl_mvs); |
| 593 | cm->tpl_mvs = NULL; |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 594 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 595 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 596 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 597 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 598 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 599 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 600 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 601 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 602 | aom_free_frame_buffer(&cpi->scaled_source); |
| 603 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 604 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 605 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 606 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 607 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 608 | cpi->tile_tok[0][0] = 0; |
| 609 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 610 | aom_free(cpi->tplist[0][0]); |
| 611 | cpi->tplist[0][0] = NULL; |
| 612 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 613 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 614 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 615 | aom_free(cpi->td.mb.palette_buffer); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 616 | |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 617 | aom_free(cpi->td.mb.tmp_conv_dst); |
| 618 | for (int j = 0; j < 2; ++j) { |
| 619 | aom_free(cpi->td.mb.tmp_obmc_bufs[j]); |
| 620 | } |
| 621 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 622 | #if CONFIG_DENOISE |
| 623 | if (cpi->denoise_and_model) { |
| 624 | aom_denoise_and_model_free(cpi->denoise_and_model); |
| 625 | cpi->denoise_and_model = NULL; |
| 626 | } |
| 627 | #endif |
| 628 | if (cpi->film_grain_table) { |
| 629 | aom_film_grain_table_free(cpi->film_grain_table); |
| 630 | cpi->film_grain_table = NULL; |
| 631 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 634 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 635 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 636 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 637 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 638 | // Stores a snapshot of key state variables which can subsequently be |
| 639 | // restored with a call to av1_restore_coding_context. These functions are |
| 640 | // intended for use in a re-code loop in av1_compress_frame where the |
| 641 | // quantizer value is adjusted between loop iterations. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 642 | av1_copy(cc->nmv_vec_cost, cpi->td.mb.nmv_vec_cost); |
| 643 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 644 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 645 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 646 | cc->fc = *cm->fc; |
| 647 | } |
| 648 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 649 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 650 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 651 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 652 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 653 | // Restore key state variables to the snapshot state stored in the |
| 654 | // previous call to av1_save_coding_context. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 655 | av1_copy(cpi->td.mb.nmv_vec_cost, cc->nmv_vec_cost); |
| 656 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 657 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 658 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 659 | *cm->fc = cc->fc; |
| 660 | } |
| 661 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 662 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 663 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 664 | const RATE_CONTROL *const rc = &cpi->rc; |
| 665 | struct segmentation *const seg = &cm->seg; |
| 666 | |
| 667 | int high_q = (int)(rc->avg_q > 48.0); |
| 668 | int qi_delta; |
| 669 | |
| 670 | // Disable and clear down for KF |
| 671 | if (cm->frame_type == KEY_FRAME) { |
| 672 | // Clear down the global segmentation map |
| 673 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 674 | seg->update_map = 0; |
| 675 | seg->update_data = 0; |
| 676 | cpi->static_mb_pct = 0; |
| 677 | |
| 678 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 679 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 680 | |
| 681 | // Clear down the segment features. |
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 | } else if (cpi->refresh_alt_ref_frame) { |
| 684 | // If this is an alt ref frame |
| 685 | // Clear down the global segmentation map |
| 686 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 687 | seg->update_map = 0; |
| 688 | seg->update_data = 0; |
| 689 | cpi->static_mb_pct = 0; |
| 690 | |
| 691 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 692 | av1_disable_segmentation(seg); |
| 693 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 694 | |
| 695 | // Scan frames from current to arf frame. |
| 696 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 697 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 698 | |
| 699 | // If segmentation was enabled set those features needed for the |
| 700 | // arf itself. |
| 701 | if (seg->enabled) { |
| 702 | seg->update_map = 1; |
| 703 | seg->update_data = 1; |
| 704 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 705 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, |
| 706 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 707 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 708 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 709 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 710 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 711 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 712 | |
| 713 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 714 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 715 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 716 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 717 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 718 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 719 | } |
| 720 | } else if (seg->enabled) { |
| 721 | // All other frames if segmentation has been enabled |
| 722 | |
| 723 | // First normal frame in a valid gf or alt ref group |
| 724 | if (rc->frames_since_golden == 0) { |
| 725 | // Set up segment features for normal frames in an arf group |
| 726 | if (rc->source_alt_ref_active) { |
| 727 | seg->update_map = 0; |
| 728 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 729 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 730 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, |
| 731 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 732 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 733 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 734 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 735 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 736 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 737 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 738 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 739 | |
| 740 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 741 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 742 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 743 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 744 | |
| 745 | // Segment coding disabled for compred testing |
| 746 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 747 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 748 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 749 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 750 | } |
| 751 | } else { |
| 752 | // Disable segmentation and clear down features if alt ref |
| 753 | // is not active for this group |
| 754 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 755 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 756 | |
| 757 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 758 | |
| 759 | seg->update_map = 0; |
| 760 | seg->update_data = 0; |
| 761 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 762 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 763 | } |
| 764 | } else if (rc->is_src_frame_alt_ref) { |
| 765 | // Special case where we are coding over the top of a previous |
| 766 | // alt ref frame. |
| 767 | // Segment coding disabled for compred testing |
| 768 | |
| 769 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 770 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 771 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 772 | |
| 773 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 774 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 775 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 776 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 777 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 778 | |
| 779 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 780 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 781 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 782 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 783 | } |
| 784 | // Enable data update |
| 785 | seg->update_data = 1; |
| 786 | } else { |
| 787 | // All other frames. |
| 788 | |
| 789 | // No updates.. leave things as they are. |
| 790 | seg->update_map = 0; |
| 791 | seg->update_data = 0; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 796 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 797 | AV1_COMMON *const cm = &cpi->common; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 798 | MB_MODE_INFO **mi_4x4_ptr = cm->mi_grid_visible; |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 799 | uint8_t *cache_ptr = cm->current_frame_seg_map; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 800 | int row, col; |
| 801 | |
| 802 | for (row = 0; row < cm->mi_rows; row++) { |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 803 | MB_MODE_INFO **mi_4x4 = mi_4x4_ptr; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 804 | uint8_t *cache = cache_ptr; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 805 | for (col = 0; col < cm->mi_cols; col++, mi_4x4++, cache++) |
| 806 | cache[0] = mi_4x4[0]->segment_id; |
| 807 | mi_4x4_ptr += cm->mi_stride; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 808 | cache_ptr += cm->mi_cols; |
| 809 | } |
| 810 | } |
| 811 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 812 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 813 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 814 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 815 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 816 | |
| 817 | if (!cpi->lookahead) |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 818 | cpi->lookahead = |
| 819 | av1_lookahead_init(oxcf->width, oxcf->height, seq_params->subsampling_x, |
| 820 | seq_params->subsampling_y, |
| 821 | seq_params->use_highbitdepth, oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 822 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 823 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | "Failed to allocate lag buffers"); |
| 825 | |
| 826 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 827 | if (aom_realloc_frame_buffer( |
| 828 | &cpi->alt_ref_buffer, oxcf->width, oxcf->height, |
| 829 | seq_params->subsampling_x, seq_params->subsampling_y, |
| 830 | seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 831 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 832 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | "Failed to allocate altref buffer"); |
| 834 | } |
| 835 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 836 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 837 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 838 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 839 | if (aom_realloc_frame_buffer( |
| 840 | &cpi->last_frame_uf, cm->width, cm->height, seq_params->subsampling_x, |
| 841 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
| 842 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 843 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 844 | "Failed to allocate last frame buffer"); |
| 845 | |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 846 | if (aom_realloc_frame_buffer( |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 847 | &cpi->trial_frame_rst, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 848 | cm->superres_upscaled_height, seq_params->subsampling_x, |
| 849 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
| 850 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 851 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 852 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 853 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 854 | if (aom_realloc_frame_buffer( |
| 855 | &cpi->scaled_source, cm->width, cm->height, seq_params->subsampling_x, |
| 856 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
| 857 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 858 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 859 | "Failed to allocate scaled source buffer"); |
| 860 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 861 | if (aom_realloc_frame_buffer( |
| 862 | &cpi->scaled_last_source, cm->width, cm->height, |
| 863 | seq_params->subsampling_x, seq_params->subsampling_y, |
| 864 | seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 865 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 866 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 867 | "Failed to allocate scaled last source buffer"); |
| 868 | } |
| 869 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 870 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 871 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 872 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 873 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 874 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 875 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 876 | int mi_rows_aligned_to_sb = |
| 877 | ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 878 | int sb_rows = mi_rows_aligned_to_sb >> cm->seq_params.mib_size_log2; |
| 879 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 880 | av1_alloc_txb_buf(cpi); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 881 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 882 | alloc_context_buffers_ext(cpi); |
| 883 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 884 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 885 | |
| 886 | { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 887 | unsigned int tokens = |
| 888 | 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] | 889 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 890 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 891 | } |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 892 | aom_free(cpi->tplist[0][0]); |
| 893 | |
| 894 | CHECK_MEM_ERROR(cm, cpi->tplist[0][0], |
| 895 | aom_calloc(sb_rows * MAX_TILE_ROWS * MAX_TILE_COLS, |
| 896 | sizeof(*cpi->tplist[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 897 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 898 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 901 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 902 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 903 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Yunqing Wang | 75e20e8 | 2018-06-16 12:10:48 -0700 | [diff] [blame] | 906 | static void set_tile_info(AV1_COMP *cpi) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 907 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 908 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 909 | |
| 910 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 911 | |
| 912 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 913 | 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] | 914 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 915 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 916 | 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] | 917 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 918 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 919 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 920 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 921 | cm->uniform_tile_spacing_flag = 0; |
| 922 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 923 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 924 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 925 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
David Barker | 6cd5a82 | 2018-03-05 16:19:28 +0000 | [diff] [blame] | 926 | start_sb += AOMMIN(size_sb, cm->max_tile_width_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 927 | } |
| 928 | cm->tile_cols = i; |
| 929 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 930 | } |
| 931 | av1_calculate_tile_cols(cm); |
| 932 | |
| 933 | // configure tile rows |
| 934 | if (cm->uniform_tile_spacing_flag) { |
| 935 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 936 | 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] | 937 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 938 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 939 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 940 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 941 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 942 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 943 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 944 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 945 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 946 | } |
| 947 | cm->tile_rows = i; |
| 948 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 949 | } |
| 950 | av1_calculate_tile_rows(cm); |
| 951 | } |
| 952 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 953 | static void update_frame_size(AV1_COMP *cpi) { |
| 954 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 955 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 956 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 957 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 958 | av1_init_context_buffers(cm); |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 959 | av1_init_macroblockd(cm, xd, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 960 | memset(cpi->mbmi_ext_base, 0, |
| 961 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 962 | set_tile_info(cpi); |
| 963 | } |
| 964 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 965 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 966 | int fb_idx; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 967 | for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx) |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 968 | cpi->remapped_ref_idx[fb_idx] = fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 969 | cpi->rate_index = 0; |
| 970 | cpi->rate_size = 0; |
| 971 | cpi->cur_poc = -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 974 | static INLINE int does_level_match(int width, int height, double fps, |
| 975 | int lvl_width, int lvl_height, |
| 976 | double lvl_fps, int lvl_dim_mult) { |
| 977 | const int64_t lvl_luma_pels = lvl_width * lvl_height; |
| 978 | const double lvl_display_sample_rate = lvl_luma_pels * lvl_fps; |
| 979 | const int64_t luma_pels = width * height; |
| 980 | const double display_sample_rate = luma_pels * fps; |
| 981 | return luma_pels <= lvl_luma_pels && |
| 982 | display_sample_rate <= lvl_display_sample_rate && |
| 983 | width <= lvl_width * lvl_dim_mult && |
| 984 | height <= lvl_height * lvl_dim_mult; |
| 985 | } |
| 986 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 987 | static void set_bitstream_level_tier(SequenceHeader *seq, AV1_COMMON *cm, |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 988 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 989 | // TODO(any): This is a placeholder function that only addresses dimensions |
| 990 | // and max display sample rates. |
| 991 | // Need to add checks for max bit rate, max decoded luma sample rate, header |
| 992 | // rate, etc. that are not covered by this function. |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 993 | (void)oxcf; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 994 | BitstreamLevel bl = { 9, 3 }; |
| 995 | if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, 512, |
| 996 | 288, 30.0, 4)) { |
| 997 | bl.major = 2; |
| 998 | bl.minor = 0; |
| 999 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1000 | 704, 396, 30.0, 4)) { |
| 1001 | bl.major = 2; |
| 1002 | bl.minor = 1; |
| 1003 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1004 | 1088, 612, 30.0, 4)) { |
| 1005 | bl.major = 3; |
| 1006 | bl.minor = 0; |
| 1007 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1008 | 1376, 774, 30.0, 4)) { |
| 1009 | bl.major = 3; |
| 1010 | bl.minor = 1; |
| 1011 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1012 | 2048, 1152, 30.0, 3)) { |
| 1013 | bl.major = 4; |
| 1014 | bl.minor = 0; |
| 1015 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1016 | 2048, 1152, 60.0, 3)) { |
| 1017 | bl.major = 4; |
| 1018 | bl.minor = 1; |
| 1019 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1020 | 4096, 2176, 30.0, 2)) { |
| 1021 | bl.major = 5; |
| 1022 | bl.minor = 0; |
| 1023 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1024 | 4096, 2176, 60.0, 2)) { |
| 1025 | bl.major = 5; |
| 1026 | bl.minor = 1; |
| 1027 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1028 | 4096, 2176, 120.0, 2)) { |
| 1029 | bl.major = 5; |
| 1030 | bl.minor = 2; |
| 1031 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1032 | 8192, 4352, 30.0, 2)) { |
| 1033 | bl.major = 6; |
| 1034 | bl.minor = 0; |
| 1035 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1036 | 8192, 4352, 60.0, 2)) { |
| 1037 | bl.major = 6; |
| 1038 | bl.minor = 1; |
| 1039 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1040 | 8192, 4352, 120.0, 2)) { |
| 1041 | bl.major = 6; |
| 1042 | bl.minor = 2; |
| 1043 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1044 | 16384, 8704, 30.0, 2)) { |
| 1045 | bl.major = 7; |
| 1046 | bl.minor = 0; |
| 1047 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1048 | 16384, 8704, 60.0, 2)) { |
| 1049 | bl.major = 7; |
| 1050 | bl.minor = 1; |
| 1051 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1052 | 16384, 8704, 120.0, 2)) { |
| 1053 | bl.major = 7; |
| 1054 | bl.minor = 2; |
| 1055 | } |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1056 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1057 | seq->level[i] = bl; |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 1058 | seq->tier[i] = 0; // setting main tier by default |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1059 | // Set the maximum parameters for bitrate and buffer size for this profile, |
| 1060 | // level, and tier |
| 1061 | cm->op_params[i].bitrate = max_level_bitrate( |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1062 | cm->seq_params.profile, major_minor_to_seq_level_idx(seq->level[i]), |
| 1063 | seq->tier[i]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1064 | // Level with seq_level_idx = 31 returns a high "dummy" bitrate to pass the |
| 1065 | // check |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1066 | if (cm->op_params[i].bitrate == 0) |
| 1067 | aom_internal_error( |
| 1068 | &cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 1069 | "AV1 does not support this combination of profile, level, and tier."); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1070 | // Buffer size in bits/s is bitrate in bits/s * 1 s |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1071 | cm->op_params[i].buffer_size = cm->op_params[i].bitrate; |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1075 | static void init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm, |
| 1076 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1077 | seq->still_picture = (oxcf->limit == 1); |
| 1078 | seq->reduced_still_picture_hdr = seq->still_picture; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 1079 | seq->reduced_still_picture_hdr &= !oxcf->full_still_picture_hdr; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1080 | seq->force_screen_content_tools = 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1081 | seq->force_integer_mv = 2; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1082 | seq->order_hint_info.enable_order_hint = oxcf->enable_order_hint; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1083 | seq->frame_id_numbers_present_flag = oxcf->large_scale_tile; |
| 1084 | if (seq->still_picture && seq->reduced_still_picture_hdr) { |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1085 | seq->order_hint_info.enable_order_hint = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1086 | seq->frame_id_numbers_present_flag = 0; |
| 1087 | seq->force_screen_content_tools = 2; |
| 1088 | seq->force_integer_mv = 2; |
| 1089 | } |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1090 | seq->order_hint_info.order_hint_bits_minus_1 = |
| 1091 | seq->order_hint_info.enable_order_hint |
| 1092 | ? DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1 |
| 1093 | : -1; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1094 | |
| 1095 | seq->enable_dual_filter = oxcf->enable_dual_filter; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1096 | seq->order_hint_info.enable_jnt_comp = oxcf->enable_jnt_comp; |
| 1097 | seq->order_hint_info.enable_jnt_comp &= |
| 1098 | seq->order_hint_info.enable_order_hint; |
| 1099 | seq->order_hint_info.enable_ref_frame_mvs = oxcf->enable_ref_frame_mvs; |
| 1100 | seq->order_hint_info.enable_ref_frame_mvs &= |
| 1101 | seq->order_hint_info.enable_order_hint; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1102 | seq->enable_superres = oxcf->enable_superres; |
| 1103 | seq->enable_cdef = oxcf->enable_cdef; |
| 1104 | seq->enable_restoration = oxcf->enable_restoration; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 1105 | seq->enable_warped_motion = oxcf->enable_warped_motion; |
Debargha Mukherjee | 97095fb | 2018-03-26 07:51:48 -0700 | [diff] [blame] | 1106 | seq->enable_interintra_compound = 1; |
| 1107 | seq->enable_masked_compound = 1; |
Debargha Mukherjee | 365eae8 | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 1108 | seq->enable_intra_edge_filter = 1; |
| 1109 | seq->enable_filter_intra = 1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1110 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1111 | set_bitstream_level_tier(seq, cm, oxcf); |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1112 | |
| 1113 | if (seq->operating_points_cnt_minus_1 == 0) { |
| 1114 | seq->operating_point_idc[0] = 0; |
| 1115 | } else { |
| 1116 | // Set operating_point_idc[] such that for the i-th operating point the |
| 1117 | // first (operating_points_cnt-i) spatial layers and the first temporal |
| 1118 | // layer are decoded Note that highest quality operating point should come |
| 1119 | // first |
| 1120 | for (int i = 0; i < seq->operating_points_cnt_minus_1 + 1; i++) |
| 1121 | seq->operating_point_idc[i] = |
| 1122 | (~(~0u << (seq->operating_points_cnt_minus_1 + 1 - i)) << 8) | 1; |
| 1123 | } |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1126 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1127 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1128 | |
| 1129 | cpi->oxcf = *oxcf; |
| 1130 | cpi->framerate = oxcf->init_framerate; |
| 1131 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1132 | cm->seq_params.profile = oxcf->profile; |
| 1133 | cm->seq_params.bit_depth = oxcf->bit_depth; |
| 1134 | cm->seq_params.use_highbitdepth = oxcf->use_highbitdepth; |
| 1135 | cm->seq_params.color_primaries = oxcf->color_primaries; |
| 1136 | cm->seq_params.transfer_characteristics = oxcf->transfer_characteristics; |
| 1137 | cm->seq_params.matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1138 | cm->seq_params.monochrome = oxcf->monochrome; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1139 | cm->seq_params.chroma_sample_position = oxcf->chroma_sample_position; |
| 1140 | cm->seq_params.color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 1141 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1142 | cm->timing_info.num_units_in_display_tick = |
| 1143 | oxcf->timing_info.num_units_in_display_tick; |
| 1144 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 1145 | cm->timing_info.equal_picture_interval = |
| 1146 | oxcf->timing_info.equal_picture_interval; |
| 1147 | cm->timing_info.num_ticks_per_picture = |
| 1148 | oxcf->timing_info.num_ticks_per_picture; |
| 1149 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1150 | cm->seq_params.display_model_info_present_flag = |
| 1151 | oxcf->display_model_info_present_flag; |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1152 | cm->seq_params.decoder_model_info_present_flag = |
| 1153 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1154 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1155 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1156 | cm->buffer_model.num_units_in_decoding_tick = |
| 1157 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 1158 | cm->buffer_removal_time_present = 1; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1159 | set_aom_dec_model_info(&cm->buffer_model); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1160 | set_dec_model_op_parameters(&cm->op_params[0]); |
| 1161 | } else if (cm->timing_info_present && |
| 1162 | cm->timing_info.equal_picture_interval && |
| 1163 | !cm->seq_params.decoder_model_info_present_flag) { |
| 1164 | // set the decoder model parameters in resource availability mode |
| 1165 | set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1166 | } else { |
| 1167 | cm->op_params[0].initial_display_delay = |
| 1168 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1169 | } |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1170 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1171 | if (cm->seq_params.monochrome) { |
| 1172 | cm->seq_params.subsampling_x = 1; |
| 1173 | cm->seq_params.subsampling_y = 1; |
| 1174 | } else if (cm->seq_params.color_primaries == AOM_CICP_CP_BT_709 && |
| 1175 | cm->seq_params.transfer_characteristics == AOM_CICP_TC_SRGB && |
| 1176 | cm->seq_params.matrix_coefficients == AOM_CICP_MC_IDENTITY) { |
| 1177 | cm->seq_params.subsampling_x = 0; |
| 1178 | cm->seq_params.subsampling_y = 0; |
| 1179 | } else { |
| 1180 | if (cm->seq_params.profile == 0) { |
| 1181 | cm->seq_params.subsampling_x = 1; |
| 1182 | cm->seq_params.subsampling_y = 1; |
| 1183 | } else if (cm->seq_params.profile == 1) { |
| 1184 | cm->seq_params.subsampling_x = 0; |
| 1185 | cm->seq_params.subsampling_y = 0; |
| 1186 | } else { |
| 1187 | if (cm->seq_params.bit_depth == AOM_BITS_12) { |
| 1188 | cm->seq_params.subsampling_x = oxcf->chroma_subsampling_x; |
| 1189 | cm->seq_params.subsampling_y = oxcf->chroma_subsampling_y; |
| 1190 | } else { |
| 1191 | cm->seq_params.subsampling_x = 1; |
| 1192 | cm->seq_params.subsampling_y = 0; |
| 1193 | } |
| 1194 | } |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1197 | cm->width = oxcf->width; |
| 1198 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1199 | set_sb_size(&cm->seq_params, |
| 1200 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1201 | alloc_compressor_data(cpi); |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 1202 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 1203 | update_film_grain_parameters(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1204 | |
| 1205 | // Single thread case: use counts in common. |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 1206 | cpi->td.counts = &cpi->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1207 | |
| 1208 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1209 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1210 | |
| 1211 | cpi->static_mb_pct = 0; |
| 1212 | cpi->ref_frame_flags = 0; |
| 1213 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1214 | // Reset resize pending flags |
| 1215 | cpi->resize_pending_width = 0; |
| 1216 | cpi->resize_pending_height = 0; |
| 1217 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1218 | init_buffer_indices(cpi); |
| 1219 | } |
| 1220 | |
| 1221 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1222 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1223 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1224 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1225 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1226 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1227 | |
| 1228 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1229 | rc->optimal_buffer_level = |
| 1230 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1231 | rc->maximum_buffer_size = |
| 1232 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1233 | } |
| 1234 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1235 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 1236 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1237 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1238 | cpi->fn_ptr[BT].vf = VF; \ |
| 1239 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1240 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1241 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 1242 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1243 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1244 | |
| 1245 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1246 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1247 | int source_stride, \ |
| 1248 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1249 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1250 | } \ |
| 1251 | static unsigned int fnname##_bits10( \ |
| 1252 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1253 | int ref_stride) { \ |
| 1254 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1255 | } \ |
| 1256 | static unsigned int fnname##_bits12( \ |
| 1257 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1258 | int ref_stride) { \ |
| 1259 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1260 | } |
| 1261 | |
| 1262 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1263 | static unsigned int fnname##_bits8( \ |
| 1264 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1265 | int ref_stride, const uint8_t *second_pred) { \ |
| 1266 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1267 | } \ |
| 1268 | static unsigned int fnname##_bits10( \ |
| 1269 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1270 | int ref_stride, const uint8_t *second_pred) { \ |
| 1271 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1272 | 2; \ |
| 1273 | } \ |
| 1274 | static unsigned int fnname##_bits12( \ |
| 1275 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1276 | int ref_stride, const uint8_t *second_pred) { \ |
| 1277 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1278 | 4; \ |
| 1279 | } |
| 1280 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1281 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1282 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1283 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1284 | unsigned int *sad_array) { \ |
| 1285 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1286 | } \ |
| 1287 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1288 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1289 | unsigned int *sad_array) { \ |
| 1290 | int i; \ |
| 1291 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1292 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1293 | } \ |
| 1294 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1295 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1296 | unsigned int *sad_array) { \ |
| 1297 | int i; \ |
| 1298 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1299 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1300 | } |
| 1301 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1302 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1303 | static unsigned int fnname##_bits8( \ |
| 1304 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1305 | int ref_stride, const uint8_t *second_pred, \ |
| 1306 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1307 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1308 | jcp_param); \ |
| 1309 | } \ |
| 1310 | static unsigned int fnname##_bits10( \ |
| 1311 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1312 | int ref_stride, const uint8_t *second_pred, \ |
| 1313 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1314 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1315 | jcp_param) >> \ |
| 1316 | 2; \ |
| 1317 | } \ |
| 1318 | static unsigned int fnname##_bits12( \ |
| 1319 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1320 | int ref_stride, const uint8_t *second_pred, \ |
| 1321 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1322 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1323 | jcp_param) >> \ |
| 1324 | 4; \ |
| 1325 | } |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1326 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1327 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1328 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1329 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1330 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1331 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1332 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1333 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1334 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1335 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1336 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1337 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1338 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1339 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1340 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1341 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1342 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1343 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1344 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1345 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1346 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1347 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1348 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1349 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1350 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1351 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1352 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1353 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1354 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1355 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1356 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1357 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1358 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1359 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1360 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1361 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1362 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1363 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1364 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1365 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1366 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1367 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1368 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1369 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1370 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1371 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1372 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1373 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1374 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1375 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1376 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1377 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1378 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1379 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1380 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1381 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1382 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1383 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1384 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1385 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1386 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1387 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1388 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1389 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1390 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1391 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1392 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1393 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1394 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1395 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x128_avg) |
| 1396 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x64_avg) |
| 1397 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x128_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1398 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x16_avg) |
| 1399 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x32_avg) |
| 1400 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x32_avg) |
| 1401 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x64_avg) |
| 1402 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x32_avg) |
| 1403 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x64_avg) |
| 1404 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x16_avg) |
| 1405 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x8_avg) |
| 1406 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x16_avg) |
| 1407 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x8_avg) |
| 1408 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x4_avg) |
| 1409 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x8_avg) |
| 1410 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x4_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1411 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x16_avg) |
| 1412 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x4_avg) |
| 1413 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x32_avg) |
| 1414 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x8_avg) |
| 1415 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x64_avg) |
| 1416 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x16_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1417 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1418 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1419 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1420 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1421 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1422 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1423 | static unsigned int fnname##_bits8( \ |
| 1424 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1425 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1426 | int m_stride, int invert_mask) { \ |
| 1427 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1428 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1429 | } \ |
| 1430 | static unsigned int fnname##_bits10( \ |
| 1431 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1432 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1433 | int m_stride, int invert_mask) { \ |
| 1434 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1435 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1436 | 2; \ |
| 1437 | } \ |
| 1438 | static unsigned int fnname##_bits12( \ |
| 1439 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1440 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1441 | int m_stride, int invert_mask) { \ |
| 1442 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1443 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1444 | 4; \ |
| 1445 | } |
| 1446 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1447 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1448 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1449 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1450 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1451 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1452 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1453 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1454 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1455 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1456 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1457 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1458 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1459 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1460 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1461 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1462 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1463 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1464 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1465 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1466 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1467 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1468 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1469 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1470 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1471 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1472 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1473 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1474 | |
| 1475 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1476 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1477 | const int32_t *wsrc, \ |
| 1478 | const int32_t *msk) { \ |
| 1479 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1480 | } \ |
| 1481 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1482 | const int32_t *wsrc, \ |
| 1483 | const int32_t *msk) { \ |
| 1484 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1485 | } \ |
| 1486 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1487 | const int32_t *wsrc, \ |
| 1488 | const int32_t *msk) { \ |
| 1489 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1490 | } |
| 1491 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1492 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1493 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1494 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1495 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1496 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1497 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1498 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1499 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1500 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1501 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1502 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1503 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1504 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1505 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1506 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1507 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1508 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1509 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1510 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1511 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1512 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1513 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1514 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1515 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1516 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1517 | if (cm->seq_params.use_highbitdepth) { |
| 1518 | switch (cm->seq_params.bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1519 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1520 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1521 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1522 | aom_highbd_8_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1523 | aom_highbd_8_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1524 | aom_highbd_sad64x16x4d_bits8, |
| 1525 | aom_highbd_jnt_sad64x16_avg_bits8, |
| 1526 | aom_highbd_8_jnt_sub_pixel_avg_variance64x16) |
| 1527 | |
| 1528 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1529 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1530 | aom_highbd_8_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1531 | aom_highbd_8_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1532 | aom_highbd_sad16x64x4d_bits8, |
| 1533 | aom_highbd_jnt_sad16x64_avg_bits8, |
| 1534 | aom_highbd_8_jnt_sub_pixel_avg_variance16x64) |
| 1535 | |
| 1536 | HIGHBD_BFP( |
| 1537 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1538 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1539 | aom_highbd_8_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1540 | aom_highbd_sad32x8x4d_bits8, aom_highbd_jnt_sad32x8_avg_bits8, |
| 1541 | aom_highbd_8_jnt_sub_pixel_avg_variance32x8) |
| 1542 | |
| 1543 | HIGHBD_BFP( |
| 1544 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1545 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1546 | aom_highbd_8_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1547 | aom_highbd_sad8x32x4d_bits8, aom_highbd_jnt_sad8x32_avg_bits8, |
| 1548 | aom_highbd_8_jnt_sub_pixel_avg_variance8x32) |
| 1549 | |
| 1550 | HIGHBD_BFP( |
| 1551 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1552 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1553 | aom_highbd_8_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1554 | aom_highbd_sad16x4x4d_bits8, aom_highbd_jnt_sad16x4_avg_bits8, |
| 1555 | aom_highbd_8_jnt_sub_pixel_avg_variance16x4) |
| 1556 | |
| 1557 | HIGHBD_BFP( |
| 1558 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1559 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1560 | aom_highbd_8_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1561 | aom_highbd_sad4x16x4d_bits8, aom_highbd_jnt_sad4x16_avg_bits8, |
| 1562 | aom_highbd_8_jnt_sub_pixel_avg_variance4x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1563 | |
| 1564 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1565 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1566 | aom_highbd_8_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1567 | aom_highbd_8_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1568 | aom_highbd_sad32x16x4d_bits8, |
| 1569 | aom_highbd_jnt_sad32x16_avg_bits8, |
| 1570 | aom_highbd_8_jnt_sub_pixel_avg_variance32x16) |
| 1571 | |
| 1572 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1573 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1574 | aom_highbd_8_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1575 | aom_highbd_8_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1576 | aom_highbd_sad16x32x4d_bits8, |
| 1577 | aom_highbd_jnt_sad16x32_avg_bits8, |
| 1578 | aom_highbd_8_jnt_sub_pixel_avg_variance16x32) |
| 1579 | |
| 1580 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1581 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1582 | aom_highbd_8_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1583 | aom_highbd_8_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1584 | aom_highbd_sad64x32x4d_bits8, |
| 1585 | aom_highbd_jnt_sad64x32_avg_bits8, |
| 1586 | aom_highbd_8_jnt_sub_pixel_avg_variance64x32) |
| 1587 | |
| 1588 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1589 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1590 | aom_highbd_8_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1591 | aom_highbd_8_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1592 | aom_highbd_sad32x64x4d_bits8, |
| 1593 | aom_highbd_jnt_sad32x64_avg_bits8, |
| 1594 | aom_highbd_8_jnt_sub_pixel_avg_variance32x64) |
| 1595 | |
| 1596 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1597 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1598 | aom_highbd_8_sub_pixel_variance32x32, |
| 1599 | aom_highbd_8_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1600 | aom_highbd_sad32x32x4d_bits8, |
| 1601 | aom_highbd_jnt_sad32x32_avg_bits8, |
| 1602 | aom_highbd_8_jnt_sub_pixel_avg_variance32x32) |
| 1603 | |
| 1604 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1605 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1606 | aom_highbd_8_sub_pixel_variance64x64, |
| 1607 | aom_highbd_8_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1608 | aom_highbd_sad64x64x4d_bits8, |
| 1609 | aom_highbd_jnt_sad64x64_avg_bits8, |
| 1610 | aom_highbd_8_jnt_sub_pixel_avg_variance64x64) |
| 1611 | |
| 1612 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1613 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1614 | aom_highbd_8_sub_pixel_variance16x16, |
| 1615 | aom_highbd_8_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1616 | aom_highbd_sad16x16x4d_bits8, |
| 1617 | aom_highbd_jnt_sad16x16_avg_bits8, |
| 1618 | aom_highbd_8_jnt_sub_pixel_avg_variance16x16) |
| 1619 | |
| 1620 | HIGHBD_BFP( |
| 1621 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1622 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1623 | aom_highbd_8_sub_pixel_avg_variance16x8, |
| 1624 | aom_highbd_sad16x8x4d_bits8, aom_highbd_jnt_sad16x8_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1625 | aom_highbd_8_jnt_sub_pixel_avg_variance16x8) |
| 1626 | |
| 1627 | HIGHBD_BFP( |
| 1628 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1629 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1630 | aom_highbd_8_sub_pixel_avg_variance8x16, |
| 1631 | aom_highbd_sad8x16x4d_bits8, aom_highbd_jnt_sad8x16_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1632 | aom_highbd_8_jnt_sub_pixel_avg_variance8x16) |
| 1633 | |
| 1634 | HIGHBD_BFP(BLOCK_8X8, aom_highbd_sad8x8_bits8, |
| 1635 | aom_highbd_sad8x8_avg_bits8, aom_highbd_8_variance8x8, |
| 1636 | aom_highbd_8_sub_pixel_variance8x8, |
| 1637 | aom_highbd_8_sub_pixel_avg_variance8x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1638 | aom_highbd_sad8x8x4d_bits8, aom_highbd_jnt_sad8x8_avg_bits8, |
| 1639 | aom_highbd_8_jnt_sub_pixel_avg_variance8x8) |
| 1640 | |
| 1641 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1642 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1643 | aom_highbd_8_sub_pixel_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1644 | aom_highbd_8_sub_pixel_avg_variance8x4, |
| 1645 | aom_highbd_sad8x4x4d_bits8, aom_highbd_jnt_sad8x4_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1646 | aom_highbd_8_jnt_sub_pixel_avg_variance8x4) |
| 1647 | |
| 1648 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1649 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1650 | aom_highbd_8_sub_pixel_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1651 | aom_highbd_8_sub_pixel_avg_variance4x8, |
| 1652 | aom_highbd_sad4x8x4d_bits8, aom_highbd_jnt_sad4x8_avg_bits8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1653 | aom_highbd_8_jnt_sub_pixel_avg_variance4x8) |
| 1654 | |
| 1655 | HIGHBD_BFP(BLOCK_4X4, aom_highbd_sad4x4_bits8, |
| 1656 | aom_highbd_sad4x4_avg_bits8, aom_highbd_8_variance4x4, |
| 1657 | aom_highbd_8_sub_pixel_variance4x4, |
| 1658 | aom_highbd_8_sub_pixel_avg_variance4x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1659 | aom_highbd_sad4x4x4d_bits8, aom_highbd_jnt_sad4x4_avg_bits8, |
| 1660 | aom_highbd_8_jnt_sub_pixel_avg_variance4x4) |
| 1661 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1662 | HIGHBD_BFP( |
| 1663 | BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1664 | aom_highbd_sad128x128_avg_bits8, aom_highbd_8_variance128x128, |
| 1665 | aom_highbd_8_sub_pixel_variance128x128, |
| 1666 | aom_highbd_8_sub_pixel_avg_variance128x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1667 | aom_highbd_sad128x128x4d_bits8, aom_highbd_jnt_sad128x128_avg_bits8, |
| 1668 | aom_highbd_8_jnt_sub_pixel_avg_variance128x128) |
| 1669 | |
| 1670 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1671 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1672 | aom_highbd_8_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1673 | aom_highbd_8_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1674 | aom_highbd_sad128x64x4d_bits8, |
| 1675 | aom_highbd_jnt_sad128x64_avg_bits8, |
| 1676 | aom_highbd_8_jnt_sub_pixel_avg_variance128x64) |
| 1677 | |
| 1678 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1679 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1680 | aom_highbd_8_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1681 | aom_highbd_8_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1682 | aom_highbd_sad64x128x4d_bits8, |
| 1683 | aom_highbd_jnt_sad64x128_avg_bits8, |
| 1684 | aom_highbd_8_jnt_sub_pixel_avg_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1685 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1686 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1687 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1688 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1689 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1690 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1691 | aom_highbd_8_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1692 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1693 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1694 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1695 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1696 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1697 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1698 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1699 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1700 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1701 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1702 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1703 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1704 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1705 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1706 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1707 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1708 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1709 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1710 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1711 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1712 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1713 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1714 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1715 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1716 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1717 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1718 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1719 | aom_highbd_8_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1720 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1721 | aom_highbd_8_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1722 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1723 | aom_highbd_8_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1724 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1725 | aom_highbd_8_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1726 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1727 | aom_highbd_8_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1728 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1729 | aom_highbd_8_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1730 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1731 | aom_highbd_obmc_variance128x128, |
| 1732 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1733 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1734 | aom_highbd_obmc_variance128x64, |
| 1735 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1736 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1737 | aom_highbd_obmc_variance64x128, |
| 1738 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1739 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1740 | aom_highbd_obmc_variance64x64, |
| 1741 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1742 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1743 | aom_highbd_obmc_variance64x32, |
| 1744 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1745 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1746 | aom_highbd_obmc_variance32x64, |
| 1747 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1748 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1749 | aom_highbd_obmc_variance32x32, |
| 1750 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1751 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1752 | aom_highbd_obmc_variance32x16, |
| 1753 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1754 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1755 | aom_highbd_obmc_variance16x32, |
| 1756 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1757 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1758 | aom_highbd_obmc_variance16x16, |
| 1759 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1760 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1761 | aom_highbd_obmc_variance8x16, |
| 1762 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1763 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1764 | aom_highbd_obmc_variance16x8, |
| 1765 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1766 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1767 | aom_highbd_obmc_variance8x8, |
| 1768 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1769 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1770 | aom_highbd_obmc_variance4x8, |
| 1771 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1772 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1773 | aom_highbd_obmc_variance8x4, |
| 1774 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1775 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1776 | aom_highbd_obmc_variance4x4, |
| 1777 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1778 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1779 | aom_highbd_obmc_variance64x16, |
| 1780 | aom_highbd_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1781 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1782 | aom_highbd_obmc_variance16x64, |
| 1783 | aom_highbd_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1784 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1785 | aom_highbd_obmc_variance32x8, |
| 1786 | aom_highbd_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1787 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1788 | aom_highbd_obmc_variance8x32, |
| 1789 | aom_highbd_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1790 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1791 | aom_highbd_obmc_variance16x4, |
| 1792 | aom_highbd_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1793 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1794 | aom_highbd_obmc_variance4x16, |
| 1795 | aom_highbd_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1796 | break; |
| 1797 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1798 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1799 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1800 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1801 | aom_highbd_10_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1802 | aom_highbd_10_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1803 | aom_highbd_sad64x16x4d_bits10, |
| 1804 | aom_highbd_jnt_sad64x16_avg_bits10, |
| 1805 | aom_highbd_10_jnt_sub_pixel_avg_variance64x16); |
| 1806 | |
| 1807 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1808 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1809 | aom_highbd_10_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1810 | aom_highbd_10_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1811 | aom_highbd_sad16x64x4d_bits10, |
| 1812 | aom_highbd_jnt_sad16x64_avg_bits10, |
| 1813 | aom_highbd_10_jnt_sub_pixel_avg_variance16x64); |
| 1814 | |
| 1815 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1816 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1817 | aom_highbd_10_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1818 | aom_highbd_10_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1819 | aom_highbd_sad32x8x4d_bits10, |
| 1820 | aom_highbd_jnt_sad32x8_avg_bits10, |
| 1821 | aom_highbd_10_jnt_sub_pixel_avg_variance32x8); |
| 1822 | |
| 1823 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1824 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1825 | aom_highbd_10_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1826 | aom_highbd_10_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1827 | aom_highbd_sad8x32x4d_bits10, |
| 1828 | aom_highbd_jnt_sad8x32_avg_bits10, |
| 1829 | aom_highbd_10_jnt_sub_pixel_avg_variance8x32); |
| 1830 | |
| 1831 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1832 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1833 | aom_highbd_10_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1834 | aom_highbd_10_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1835 | aom_highbd_sad16x4x4d_bits10, |
| 1836 | aom_highbd_jnt_sad16x4_avg_bits10, |
| 1837 | aom_highbd_10_jnt_sub_pixel_avg_variance16x4); |
| 1838 | |
| 1839 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1840 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1841 | aom_highbd_10_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1842 | aom_highbd_10_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1843 | aom_highbd_sad4x16x4d_bits10, |
| 1844 | aom_highbd_jnt_sad4x16_avg_bits10, |
| 1845 | aom_highbd_10_jnt_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1846 | |
| 1847 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1848 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1849 | aom_highbd_10_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1850 | aom_highbd_10_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1851 | aom_highbd_sad32x16x4d_bits10, |
| 1852 | aom_highbd_jnt_sad32x16_avg_bits10, |
| 1853 | aom_highbd_10_jnt_sub_pixel_avg_variance32x16); |
| 1854 | |
| 1855 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1856 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1857 | aom_highbd_10_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1858 | aom_highbd_10_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1859 | aom_highbd_sad16x32x4d_bits10, |
| 1860 | aom_highbd_jnt_sad16x32_avg_bits10, |
| 1861 | aom_highbd_10_jnt_sub_pixel_avg_variance16x32); |
| 1862 | |
| 1863 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1864 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1865 | aom_highbd_10_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1866 | aom_highbd_10_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1867 | aom_highbd_sad64x32x4d_bits10, |
| 1868 | aom_highbd_jnt_sad64x32_avg_bits10, |
| 1869 | aom_highbd_10_jnt_sub_pixel_avg_variance64x32); |
| 1870 | |
| 1871 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1872 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1873 | aom_highbd_10_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1874 | aom_highbd_10_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1875 | aom_highbd_sad32x64x4d_bits10, |
| 1876 | aom_highbd_jnt_sad32x64_avg_bits10, |
| 1877 | aom_highbd_10_jnt_sub_pixel_avg_variance32x64); |
| 1878 | |
| 1879 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1880 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1881 | aom_highbd_10_sub_pixel_variance32x32, |
| 1882 | aom_highbd_10_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1883 | aom_highbd_sad32x32x4d_bits10, |
| 1884 | aom_highbd_jnt_sad32x32_avg_bits10, |
| 1885 | aom_highbd_10_jnt_sub_pixel_avg_variance32x32); |
| 1886 | |
| 1887 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1888 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1889 | aom_highbd_10_sub_pixel_variance64x64, |
| 1890 | aom_highbd_10_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1891 | aom_highbd_sad64x64x4d_bits10, |
| 1892 | aom_highbd_jnt_sad64x64_avg_bits10, |
| 1893 | aom_highbd_10_jnt_sub_pixel_avg_variance64x64); |
| 1894 | |
| 1895 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1896 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1897 | aom_highbd_10_sub_pixel_variance16x16, |
| 1898 | aom_highbd_10_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1899 | aom_highbd_sad16x16x4d_bits10, |
| 1900 | aom_highbd_jnt_sad16x16_avg_bits10, |
| 1901 | aom_highbd_10_jnt_sub_pixel_avg_variance16x16); |
| 1902 | |
| 1903 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1904 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1905 | aom_highbd_10_sub_pixel_variance16x8, |
| 1906 | aom_highbd_10_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1907 | aom_highbd_sad16x8x4d_bits10, |
| 1908 | aom_highbd_jnt_sad16x8_avg_bits10, |
| 1909 | aom_highbd_10_jnt_sub_pixel_avg_variance16x8); |
| 1910 | |
| 1911 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1912 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1913 | aom_highbd_10_sub_pixel_variance8x16, |
| 1914 | aom_highbd_10_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1915 | aom_highbd_sad8x16x4d_bits10, |
| 1916 | aom_highbd_jnt_sad8x16_avg_bits10, |
| 1917 | aom_highbd_10_jnt_sub_pixel_avg_variance8x16); |
| 1918 | |
| 1919 | HIGHBD_BFP( |
| 1920 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1921 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1922 | aom_highbd_10_sub_pixel_avg_variance8x8, |
| 1923 | aom_highbd_sad8x8x4d_bits10, aom_highbd_jnt_sad8x8_avg_bits10, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1924 | aom_highbd_10_jnt_sub_pixel_avg_variance8x8); |
| 1925 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1926 | HIGHBD_BFP( |
| 1927 | BLOCK_8X4, aom_highbd_sad8x4_bits10, aom_highbd_sad8x4_avg_bits10, |
| 1928 | aom_highbd_10_variance8x4, aom_highbd_10_sub_pixel_variance8x4, |
| 1929 | aom_highbd_10_sub_pixel_avg_variance8x4, |
| 1930 | aom_highbd_sad8x4x4d_bits10, aom_highbd_jnt_sad8x4_avg_bits10, |
| 1931 | aom_highbd_10_jnt_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1932 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1933 | HIGHBD_BFP( |
| 1934 | BLOCK_4X8, aom_highbd_sad4x8_bits10, aom_highbd_sad4x8_avg_bits10, |
| 1935 | aom_highbd_10_variance4x8, aom_highbd_10_sub_pixel_variance4x8, |
| 1936 | aom_highbd_10_sub_pixel_avg_variance4x8, |
| 1937 | aom_highbd_sad4x8x4d_bits10, aom_highbd_jnt_sad4x8_avg_bits10, |
| 1938 | aom_highbd_10_jnt_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1939 | |
| 1940 | HIGHBD_BFP( |
| 1941 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1942 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1943 | aom_highbd_10_sub_pixel_avg_variance4x4, |
| 1944 | aom_highbd_sad4x4x4d_bits10, aom_highbd_jnt_sad4x4_avg_bits10, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1945 | aom_highbd_10_jnt_sub_pixel_avg_variance4x4); |
| 1946 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1947 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1948 | aom_highbd_sad128x128_avg_bits10, |
| 1949 | aom_highbd_10_variance128x128, |
| 1950 | aom_highbd_10_sub_pixel_variance128x128, |
| 1951 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1952 | aom_highbd_sad128x128x4d_bits10, |
| 1953 | aom_highbd_jnt_sad128x128_avg_bits10, |
| 1954 | aom_highbd_10_jnt_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1955 | |
| 1956 | HIGHBD_BFP( |
| 1957 | BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1958 | aom_highbd_sad128x64_avg_bits10, aom_highbd_10_variance128x64, |
| 1959 | aom_highbd_10_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1960 | aom_highbd_10_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1961 | aom_highbd_sad128x64x4d_bits10, aom_highbd_jnt_sad128x64_avg_bits10, |
| 1962 | aom_highbd_10_jnt_sub_pixel_avg_variance128x64); |
| 1963 | |
| 1964 | HIGHBD_BFP( |
| 1965 | BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1966 | aom_highbd_sad64x128_avg_bits10, aom_highbd_10_variance64x128, |
| 1967 | aom_highbd_10_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1968 | aom_highbd_10_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1969 | aom_highbd_sad64x128x4d_bits10, aom_highbd_jnt_sad64x128_avg_bits10, |
| 1970 | aom_highbd_10_jnt_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1971 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1972 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1973 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1974 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1975 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1976 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1977 | aom_highbd_10_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1978 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1979 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1980 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1981 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1982 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1983 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1984 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1985 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1986 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1987 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1988 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1989 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1990 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1991 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1992 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1993 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1994 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1995 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1996 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1997 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1998 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1999 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 2000 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 2001 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 2002 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 2003 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2004 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 2005 | aom_highbd_10_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2006 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 2007 | aom_highbd_10_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2008 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 2009 | aom_highbd_10_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2010 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 2011 | aom_highbd_10_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2012 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 2013 | aom_highbd_10_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2014 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 2015 | aom_highbd_10_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2016 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 2017 | aom_highbd_10_obmc_variance128x128, |
| 2018 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 2019 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 2020 | aom_highbd_10_obmc_variance128x64, |
| 2021 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 2022 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 2023 | aom_highbd_10_obmc_variance64x128, |
| 2024 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2025 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 2026 | aom_highbd_10_obmc_variance64x64, |
| 2027 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2028 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2029 | aom_highbd_10_obmc_variance64x32, |
| 2030 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2031 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2032 | aom_highbd_10_obmc_variance32x64, |
| 2033 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2034 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2035 | aom_highbd_10_obmc_variance32x32, |
| 2036 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2037 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2038 | aom_highbd_10_obmc_variance32x16, |
| 2039 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2040 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2041 | aom_highbd_10_obmc_variance16x32, |
| 2042 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2043 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2044 | aom_highbd_10_obmc_variance16x16, |
| 2045 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2046 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2047 | aom_highbd_10_obmc_variance8x16, |
| 2048 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2049 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2050 | aom_highbd_10_obmc_variance16x8, |
| 2051 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2052 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2053 | aom_highbd_10_obmc_variance8x8, |
| 2054 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2055 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2056 | aom_highbd_10_obmc_variance4x8, |
| 2057 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2058 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2059 | aom_highbd_10_obmc_variance8x4, |
| 2060 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2061 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2062 | aom_highbd_10_obmc_variance4x4, |
| 2063 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2064 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2065 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2066 | aom_highbd_10_obmc_variance64x16, |
| 2067 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2068 | |
| 2069 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2070 | aom_highbd_10_obmc_variance16x64, |
| 2071 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2072 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2073 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2074 | aom_highbd_10_obmc_variance32x8, |
| 2075 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2076 | |
| 2077 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2078 | aom_highbd_10_obmc_variance8x32, |
| 2079 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2080 | |
| 2081 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2082 | aom_highbd_10_obmc_variance16x4, |
| 2083 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2084 | |
| 2085 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2086 | aom_highbd_10_obmc_variance4x16, |
| 2087 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2088 | break; |
| 2089 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2090 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2091 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2092 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2093 | aom_highbd_12_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2094 | aom_highbd_12_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2095 | aom_highbd_sad64x16x4d_bits12, |
| 2096 | aom_highbd_jnt_sad64x16_avg_bits12, |
| 2097 | aom_highbd_12_jnt_sub_pixel_avg_variance64x16); |
| 2098 | |
| 2099 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2100 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2101 | aom_highbd_12_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2102 | aom_highbd_12_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2103 | aom_highbd_sad16x64x4d_bits12, |
| 2104 | aom_highbd_jnt_sad16x64_avg_bits12, |
| 2105 | aom_highbd_12_jnt_sub_pixel_avg_variance16x64); |
| 2106 | |
| 2107 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2108 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2109 | aom_highbd_12_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2110 | aom_highbd_12_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2111 | aom_highbd_sad32x8x4d_bits12, |
| 2112 | aom_highbd_jnt_sad32x8_avg_bits12, |
| 2113 | aom_highbd_12_jnt_sub_pixel_avg_variance32x8); |
| 2114 | |
| 2115 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2116 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2117 | aom_highbd_12_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2118 | aom_highbd_12_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2119 | aom_highbd_sad8x32x4d_bits12, |
| 2120 | aom_highbd_jnt_sad8x32_avg_bits12, |
| 2121 | aom_highbd_12_jnt_sub_pixel_avg_variance8x32); |
| 2122 | |
| 2123 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2124 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2125 | aom_highbd_12_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2126 | aom_highbd_12_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2127 | aom_highbd_sad16x4x4d_bits12, |
| 2128 | aom_highbd_jnt_sad16x4_avg_bits12, |
| 2129 | aom_highbd_12_jnt_sub_pixel_avg_variance16x4); |
| 2130 | |
| 2131 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2132 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2133 | aom_highbd_12_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2134 | aom_highbd_12_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2135 | aom_highbd_sad4x16x4d_bits12, |
| 2136 | aom_highbd_jnt_sad4x16_avg_bits12, |
| 2137 | aom_highbd_12_jnt_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2138 | |
| 2139 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2140 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2141 | aom_highbd_12_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2142 | aom_highbd_12_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2143 | aom_highbd_sad32x16x4d_bits12, |
| 2144 | aom_highbd_jnt_sad32x16_avg_bits12, |
| 2145 | aom_highbd_12_jnt_sub_pixel_avg_variance32x16); |
| 2146 | |
| 2147 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2148 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2149 | aom_highbd_12_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2150 | aom_highbd_12_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2151 | aom_highbd_sad16x32x4d_bits12, |
| 2152 | aom_highbd_jnt_sad16x32_avg_bits12, |
| 2153 | aom_highbd_12_jnt_sub_pixel_avg_variance16x32); |
| 2154 | |
| 2155 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2156 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2157 | aom_highbd_12_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2158 | aom_highbd_12_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2159 | aom_highbd_sad64x32x4d_bits12, |
| 2160 | aom_highbd_jnt_sad64x32_avg_bits12, |
| 2161 | aom_highbd_12_jnt_sub_pixel_avg_variance64x32); |
| 2162 | |
| 2163 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2164 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2165 | aom_highbd_12_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2166 | aom_highbd_12_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2167 | aom_highbd_sad32x64x4d_bits12, |
| 2168 | aom_highbd_jnt_sad32x64_avg_bits12, |
| 2169 | aom_highbd_12_jnt_sub_pixel_avg_variance32x64); |
| 2170 | |
| 2171 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2172 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2173 | aom_highbd_12_sub_pixel_variance32x32, |
| 2174 | aom_highbd_12_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2175 | aom_highbd_sad32x32x4d_bits12, |
| 2176 | aom_highbd_jnt_sad32x32_avg_bits12, |
| 2177 | aom_highbd_12_jnt_sub_pixel_avg_variance32x32); |
| 2178 | |
| 2179 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2180 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2181 | aom_highbd_12_sub_pixel_variance64x64, |
| 2182 | aom_highbd_12_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2183 | aom_highbd_sad64x64x4d_bits12, |
| 2184 | aom_highbd_jnt_sad64x64_avg_bits12, |
| 2185 | aom_highbd_12_jnt_sub_pixel_avg_variance64x64); |
| 2186 | |
| 2187 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2188 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2189 | aom_highbd_12_sub_pixel_variance16x16, |
| 2190 | aom_highbd_12_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2191 | aom_highbd_sad16x16x4d_bits12, |
| 2192 | aom_highbd_jnt_sad16x16_avg_bits12, |
| 2193 | aom_highbd_12_jnt_sub_pixel_avg_variance16x16); |
| 2194 | |
| 2195 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2196 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2197 | aom_highbd_12_sub_pixel_variance16x8, |
| 2198 | aom_highbd_12_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2199 | aom_highbd_sad16x8x4d_bits12, |
| 2200 | aom_highbd_jnt_sad16x8_avg_bits12, |
| 2201 | aom_highbd_12_jnt_sub_pixel_avg_variance16x8); |
| 2202 | |
| 2203 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2204 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2205 | aom_highbd_12_sub_pixel_variance8x16, |
| 2206 | aom_highbd_12_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2207 | aom_highbd_sad8x16x4d_bits12, |
| 2208 | aom_highbd_jnt_sad8x16_avg_bits12, |
| 2209 | aom_highbd_12_jnt_sub_pixel_avg_variance8x16); |
| 2210 | |
| 2211 | HIGHBD_BFP( |
| 2212 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2213 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2214 | aom_highbd_12_sub_pixel_avg_variance8x8, |
| 2215 | aom_highbd_sad8x8x4d_bits12, aom_highbd_jnt_sad8x8_avg_bits12, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2216 | aom_highbd_12_jnt_sub_pixel_avg_variance8x8); |
| 2217 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2218 | HIGHBD_BFP( |
| 2219 | BLOCK_8X4, aom_highbd_sad8x4_bits12, aom_highbd_sad8x4_avg_bits12, |
| 2220 | aom_highbd_12_variance8x4, aom_highbd_12_sub_pixel_variance8x4, |
| 2221 | aom_highbd_12_sub_pixel_avg_variance8x4, |
| 2222 | aom_highbd_sad8x4x4d_bits12, aom_highbd_jnt_sad8x4_avg_bits12, |
| 2223 | aom_highbd_12_jnt_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2224 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2225 | HIGHBD_BFP( |
| 2226 | BLOCK_4X8, aom_highbd_sad4x8_bits12, aom_highbd_sad4x8_avg_bits12, |
| 2227 | aom_highbd_12_variance4x8, aom_highbd_12_sub_pixel_variance4x8, |
| 2228 | aom_highbd_12_sub_pixel_avg_variance4x8, |
| 2229 | aom_highbd_sad4x8x4d_bits12, aom_highbd_jnt_sad4x8_avg_bits12, |
| 2230 | aom_highbd_12_jnt_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2231 | |
| 2232 | HIGHBD_BFP( |
| 2233 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2234 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2235 | aom_highbd_12_sub_pixel_avg_variance4x4, |
| 2236 | aom_highbd_sad4x4x4d_bits12, aom_highbd_jnt_sad4x4_avg_bits12, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2237 | aom_highbd_12_jnt_sub_pixel_avg_variance4x4); |
| 2238 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2239 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2240 | aom_highbd_sad128x128_avg_bits12, |
| 2241 | aom_highbd_12_variance128x128, |
| 2242 | aom_highbd_12_sub_pixel_variance128x128, |
| 2243 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2244 | aom_highbd_sad128x128x4d_bits12, |
| 2245 | aom_highbd_jnt_sad128x128_avg_bits12, |
| 2246 | aom_highbd_12_jnt_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2247 | |
| 2248 | HIGHBD_BFP( |
| 2249 | BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2250 | aom_highbd_sad128x64_avg_bits12, aom_highbd_12_variance128x64, |
| 2251 | aom_highbd_12_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2252 | aom_highbd_12_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2253 | aom_highbd_sad128x64x4d_bits12, aom_highbd_jnt_sad128x64_avg_bits12, |
| 2254 | aom_highbd_12_jnt_sub_pixel_avg_variance128x64); |
| 2255 | |
| 2256 | HIGHBD_BFP( |
| 2257 | BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2258 | aom_highbd_sad64x128_avg_bits12, aom_highbd_12_variance64x128, |
| 2259 | aom_highbd_12_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2260 | aom_highbd_12_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2261 | aom_highbd_sad64x128x4d_bits12, aom_highbd_jnt_sad64x128_avg_bits12, |
| 2262 | aom_highbd_12_jnt_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2263 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2264 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2265 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2266 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2267 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2268 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2269 | aom_highbd_12_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2270 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2271 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2272 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2273 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2274 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2275 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2276 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2277 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2278 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2279 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2280 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2281 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2282 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2283 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2284 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2285 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2286 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2287 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2288 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2289 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2290 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2291 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2292 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2293 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2294 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2295 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2296 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2297 | aom_highbd_12_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2298 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2299 | aom_highbd_12_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2300 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2301 | aom_highbd_12_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2302 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2303 | aom_highbd_12_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2304 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2305 | aom_highbd_12_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2306 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2307 | aom_highbd_12_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2308 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2309 | aom_highbd_12_obmc_variance128x128, |
| 2310 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2311 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2312 | aom_highbd_12_obmc_variance128x64, |
| 2313 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2314 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2315 | aom_highbd_12_obmc_variance64x128, |
| 2316 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2317 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2318 | aom_highbd_12_obmc_variance64x64, |
| 2319 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2320 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2321 | aom_highbd_12_obmc_variance64x32, |
| 2322 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2323 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2324 | aom_highbd_12_obmc_variance32x64, |
| 2325 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2326 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2327 | aom_highbd_12_obmc_variance32x32, |
| 2328 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2329 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2330 | aom_highbd_12_obmc_variance32x16, |
| 2331 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2332 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2333 | aom_highbd_12_obmc_variance16x32, |
| 2334 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2335 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2336 | aom_highbd_12_obmc_variance16x16, |
| 2337 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2338 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2339 | aom_highbd_12_obmc_variance8x16, |
| 2340 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2341 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2342 | aom_highbd_12_obmc_variance16x8, |
| 2343 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2344 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2345 | aom_highbd_12_obmc_variance8x8, |
| 2346 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2347 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2348 | aom_highbd_12_obmc_variance4x8, |
| 2349 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2350 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2351 | aom_highbd_12_obmc_variance8x4, |
| 2352 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2353 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2354 | aom_highbd_12_obmc_variance4x4, |
| 2355 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2356 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2357 | aom_highbd_12_obmc_variance64x16, |
| 2358 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2359 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2360 | aom_highbd_12_obmc_variance16x64, |
| 2361 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2362 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2363 | aom_highbd_12_obmc_variance32x8, |
| 2364 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2365 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2366 | aom_highbd_12_obmc_variance8x32, |
| 2367 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2368 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2369 | aom_highbd_12_obmc_variance16x4, |
| 2370 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2371 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2372 | aom_highbd_12_obmc_variance4x16, |
| 2373 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2374 | break; |
| 2375 | |
| 2376 | default: |
| 2377 | assert(0 && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2378 | "cm->seq_params.bit_depth should be AOM_BITS_8, " |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2379 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2383 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2384 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2385 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2386 | |
| 2387 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2388 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2389 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2390 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2391 | |
| 2392 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2393 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2394 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2395 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2396 | |
| 2397 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2398 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2399 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2400 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2403 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2404 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2405 | SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2406 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2407 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2408 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2409 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2410 | if (seq_params->profile != oxcf->profile) seq_params->profile = oxcf->profile; |
| 2411 | seq_params->bit_depth = oxcf->bit_depth; |
| 2412 | seq_params->color_primaries = oxcf->color_primaries; |
| 2413 | seq_params->transfer_characteristics = oxcf->transfer_characteristics; |
| 2414 | seq_params->matrix_coefficients = oxcf->matrix_coefficients; |
| 2415 | seq_params->monochrome = oxcf->monochrome; |
| 2416 | seq_params->chroma_sample_position = oxcf->chroma_sample_position; |
| 2417 | seq_params->color_range = oxcf->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2418 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2419 | assert(IMPLIES(seq_params->profile <= PROFILE_1, |
| 2420 | seq_params->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2421 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2422 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2423 | cm->timing_info.num_units_in_display_tick = |
| 2424 | oxcf->timing_info.num_units_in_display_tick; |
| 2425 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 2426 | cm->timing_info.equal_picture_interval = |
| 2427 | oxcf->timing_info.equal_picture_interval; |
| 2428 | cm->timing_info.num_ticks_per_picture = |
| 2429 | oxcf->timing_info.num_ticks_per_picture; |
| 2430 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2431 | seq_params->display_model_info_present_flag = |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2432 | oxcf->display_model_info_present_flag; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2433 | seq_params->decoder_model_info_present_flag = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2434 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2435 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2436 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2437 | cm->buffer_model.num_units_in_decoding_tick = |
| 2438 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 2439 | cm->buffer_removal_time_present = 1; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2440 | set_aom_dec_model_info(&cm->buffer_model); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2441 | set_dec_model_op_parameters(&cm->op_params[0]); |
| 2442 | } else if (cm->timing_info_present && |
| 2443 | cm->timing_info.equal_picture_interval && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2444 | !seq_params->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2445 | // set the decoder model parameters in resource availability mode |
| 2446 | set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 2447 | } else { |
| 2448 | cm->op_params[0].initial_display_delay = |
| 2449 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2450 | } |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2451 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2452 | update_film_grain_parameters(cpi, oxcf); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2453 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2454 | cpi->oxcf = *oxcf; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 2455 | cpi->common.options = oxcf->cfg; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2456 | x->e_mbd.bd = (int)seq_params->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2457 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2458 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2459 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2460 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2461 | } else { |
| 2462 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2463 | } |
| 2464 | |
| 2465 | cpi->refresh_last_frame = 1; |
| 2466 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2467 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2468 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2469 | |
Debargha Mukherjee | 229fdc8 | 2018-03-10 07:45:33 -0800 | [diff] [blame] | 2470 | cm->refresh_frame_context = (oxcf->frame_parallel_decoding_mode) |
| 2471 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 2472 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2473 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 2474 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2475 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2476 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2477 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2478 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2479 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2480 | |
| 2481 | if (x->tmp_conv_dst == NULL) { |
| 2482 | CHECK_MEM_ERROR( |
| 2483 | cm, x->tmp_conv_dst, |
| 2484 | 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] | 2485 | x->e_mbd.tmp_conv_dst = x->tmp_conv_dst; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2486 | } |
| 2487 | for (int i = 0; i < 2; ++i) { |
| 2488 | if (x->tmp_obmc_bufs[i] == NULL) { |
| 2489 | CHECK_MEM_ERROR(cm, x->tmp_obmc_bufs[i], |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 2490 | aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE * |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2491 | sizeof(*x->tmp_obmc_bufs[i]))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2492 | x->e_mbd.tmp_obmc_bufs[i] = x->tmp_obmc_bufs[i]; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2493 | } |
| 2494 | } |
| 2495 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2496 | av1_reset_segment_features(cm); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2497 | set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2498 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2499 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2500 | |
| 2501 | // Under a configuration change, where maximum_buffer_size may change, |
| 2502 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2503 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2504 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2505 | |
| 2506 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2507 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2508 | |
| 2509 | // Set absolute upper and lower quality limits |
| 2510 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2511 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2512 | |
Urvang Joshi | b55cb5e | 2018-09-12 14:50:21 -0700 | [diff] [blame] | 2513 | cm->interp_filter = oxcf->large_scale_tile ? EIGHTTAP_REGULAR : SWITCHABLE; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 2514 | cm->switchable_motion_mode = 1; |
| 2515 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2516 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2517 | cm->render_width = cpi->oxcf.render_width; |
| 2518 | cm->render_height = cpi->oxcf.render_height; |
| 2519 | } else { |
| 2520 | cm->render_width = cpi->oxcf.width; |
| 2521 | cm->render_height = cpi->oxcf.height; |
| 2522 | } |
| 2523 | cm->width = cpi->oxcf.width; |
| 2524 | cm->height = cpi->oxcf.height; |
| 2525 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2526 | int sb_size = seq_params->sb_size; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2527 | // Superblock size should not be updated after the first key frame. |
| 2528 | if (!cpi->seq_params_locked) { |
| 2529 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
| 2530 | } |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2531 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2532 | if (cpi->initial_width || sb_size != seq_params->sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2533 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2534 | seq_params->sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2535 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2536 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2537 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2538 | realloc_segmentation_maps(cpi); |
| 2539 | cpi->initial_width = cpi->initial_height = 0; |
| 2540 | } |
| 2541 | } |
| 2542 | update_frame_size(cpi); |
| 2543 | |
| 2544 | cpi->alt_ref_source = NULL; |
| 2545 | rc->is_src_frame_alt_ref = 0; |
| 2546 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2547 | rc->is_bwd_ref_frame = 0; |
| 2548 | rc->is_last_bipred_frame = 0; |
| 2549 | rc->is_bipred_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2550 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2551 | set_tile_info(cpi); |
| 2552 | |
| 2553 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2554 | cpi->ext_refresh_frame_context_pending = 0; |
| 2555 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2556 | highbd_set_var_fns(cpi); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 2557 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 2558 | // Init sequence level coding tools |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2559 | // This should not be called after the first key frame. |
| 2560 | if (!cpi->seq_params_locked) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2561 | seq_params->operating_points_cnt_minus_1 = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2562 | cm->number_spatial_layers > 1 ? cm->number_spatial_layers - 1 : 0; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2563 | init_seq_coding_tools(&cm->seq_params, cm, oxcf); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2564 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2567 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2568 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2569 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2570 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2571 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2572 | |
| 2573 | if (!cm) return NULL; |
| 2574 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2575 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2576 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 2577 | // The jmp_buf is valid only for the duration of the function that calls |
| 2578 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 2579 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2580 | if (setjmp(cm->error.jmp)) { |
| 2581 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2582 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2583 | return 0; |
| 2584 | } |
| 2585 | |
| 2586 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2587 | cm->alloc_mi = enc_alloc_mi; |
| 2588 | cm->free_mi = enc_free_mi; |
| 2589 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2590 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2591 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2592 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2593 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2594 | (FRAME_CONTEXT *)aom_memalign( |
| 2595 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2596 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2597 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2598 | |
| 2599 | cpi->resize_state = 0; |
| 2600 | cpi->resize_avg_qp = 0; |
| 2601 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2602 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2603 | cpi->common.buffer_pool = pool; |
| 2604 | |
| 2605 | init_config(cpi, oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2606 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2607 | |
| 2608 | cm->current_video_frame = 0; |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2609 | cpi->seq_params_locked = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2610 | cpi->partition_search_skippable_frame = 0; |
| 2611 | cpi->tile_data = NULL; |
| 2612 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2613 | realloc_segmentation_maps(cpi); |
| 2614 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2615 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2616 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2617 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2618 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2619 | i++) { |
| 2620 | CHECK_MEM_ERROR( |
| 2621 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2622 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | #if CONFIG_FP_MB_STATS |
| 2626 | cpi->use_fp_mb_stats = 0; |
| 2627 | if (cpi->use_fp_mb_stats) { |
| 2628 | // a place holder used to store the first pass mb stats in the first pass |
| 2629 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2630 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2631 | } else { |
| 2632 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2633 | } |
| 2634 | #endif |
| 2635 | |
| 2636 | cpi->refresh_alt_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2637 | |
| 2638 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2639 | #if CONFIG_INTERNAL_STATS |
| 2640 | cpi->b_calculate_blockiness = 1; |
| 2641 | cpi->b_calculate_consistency = 1; |
| 2642 | cpi->total_inconsistency = 0; |
| 2643 | cpi->psnr.worst = 100.0; |
| 2644 | cpi->worst_ssim = 100.0; |
| 2645 | |
| 2646 | cpi->count = 0; |
| 2647 | cpi->bytes = 0; |
| 2648 | |
| 2649 | if (cpi->b_calculate_psnr) { |
| 2650 | cpi->total_sq_error = 0; |
| 2651 | cpi->total_samples = 0; |
| 2652 | cpi->tot_recode_hits = 0; |
| 2653 | cpi->summed_quality = 0; |
| 2654 | cpi->summed_weights = 0; |
| 2655 | } |
| 2656 | |
| 2657 | cpi->fastssim.worst = 100.0; |
| 2658 | cpi->psnrhvs.worst = 100.0; |
| 2659 | |
| 2660 | if (cpi->b_calculate_blockiness) { |
| 2661 | cpi->total_blockiness = 0; |
| 2662 | cpi->worst_blockiness = 0.0; |
| 2663 | } |
| 2664 | |
| 2665 | if (cpi->b_calculate_consistency) { |
| 2666 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2667 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2668 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2669 | cpi->worst_consistency = 100.0; |
| 2670 | } |
| 2671 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2672 | #if CONFIG_ENTROPY_STATS |
| 2673 | av1_zero(aggregate_fc); |
| 2674 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2675 | |
| 2676 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2677 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2678 | cpi->td.mb.nmvcost[0] = &cpi->nmv_costs[0][MV_MAX]; |
| 2679 | cpi->td.mb.nmvcost[1] = &cpi->nmv_costs[1][MV_MAX]; |
| 2680 | cpi->td.mb.nmvcost_hp[0] = &cpi->nmv_costs_hp[0][MV_MAX]; |
| 2681 | 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] | 2682 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2683 | #ifdef OUTPUT_YUV_SKINMAP |
| 2684 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2685 | #endif |
| 2686 | #ifdef OUTPUT_YUV_REC |
| 2687 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2688 | #endif |
| 2689 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2690 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2691 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2692 | } else if (oxcf->pass == 2) { |
| 2693 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2694 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2695 | |
| 2696 | #if CONFIG_FP_MB_STATS |
| 2697 | if (cpi->use_fp_mb_stats) { |
| 2698 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2699 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2700 | |
| 2701 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2702 | oxcf->firstpass_mb_stats_in.buf; |
| 2703 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2704 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2705 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2706 | } |
| 2707 | #endif |
| 2708 | |
| 2709 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2710 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2711 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2712 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2713 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2716 | CHECK_MEM_ERROR( |
| 2717 | cm, cpi->td.mb.above_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2718 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2719 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2720 | CHECK_MEM_ERROR( |
| 2721 | cm, cpi->td.mb.left_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2722 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2723 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2724 | |
| 2725 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2726 | (int32_t *)aom_memalign( |
| 2727 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2728 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 2729 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 2730 | CHECK_MEM_ERROR( |
| 2731 | cm, cpi->td.mb.inter_modes_info, |
| 2732 | (InterModesInfo *)aom_malloc(sizeof(*cpi->td.mb.inter_modes_info))); |
| 2733 | #endif |
| 2734 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 2735 | for (int x = 0; x < 2; x++) |
| 2736 | for (int y = 0; y < 2; y++) |
| 2737 | CHECK_MEM_ERROR( |
| 2738 | cm, cpi->td.mb.hash_value_buffer[x][y], |
| 2739 | (uint32_t *)aom_malloc(AOM_BUFFER_SIZE_FOR_BLOCK_HASH * |
| 2740 | sizeof(*cpi->td.mb.hash_value_buffer[0][0]))); |
| 2741 | |
| 2742 | cpi->td.mb.g_crc_initialized = 0; |
| 2743 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2744 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2745 | (int32_t *)aom_memalign( |
| 2746 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2747 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2748 | av1_set_speed_features_framesize_independent(cpi); |
| 2749 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2750 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 2751 | for (int frame = 0; frame < MAX_LAG_BUFFERS; ++frame) { |
| 2752 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 2753 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 2754 | |
| 2755 | CHECK_MEM_ERROR(cm, cpi->tpl_stats[frame].tpl_stats_ptr, |
| 2756 | aom_calloc(mi_rows * mi_cols, |
| 2757 | sizeof(*cpi->tpl_stats[frame].tpl_stats_ptr))); |
| 2758 | cpi->tpl_stats[frame].is_valid = 0; |
| 2759 | cpi->tpl_stats[frame].width = mi_cols; |
| 2760 | cpi->tpl_stats[frame].height = mi_rows; |
| 2761 | cpi->tpl_stats[frame].stride = mi_cols; |
| 2762 | cpi->tpl_stats[frame].mi_rows = cm->mi_rows; |
| 2763 | cpi->tpl_stats[frame].mi_cols = cm->mi_cols; |
| 2764 | } |
| 2765 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2766 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 2767 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2768 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2769 | cpi->fn_ptr[BT].vf = VF; \ |
| 2770 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2771 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2772 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 2773 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2774 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2775 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2776 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2777 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2778 | aom_sad4x16x4d, aom_jnt_sad4x16_avg, aom_jnt_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2779 | |
| 2780 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2781 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2782 | aom_sad16x4x4d, aom_jnt_sad16x4_avg, aom_jnt_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2783 | |
| 2784 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2785 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2786 | aom_sad8x32x4d, aom_jnt_sad8x32_avg, aom_jnt_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2787 | |
| 2788 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2789 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2790 | aom_sad32x8x4d, aom_jnt_sad32x8_avg, aom_jnt_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2791 | |
| 2792 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2793 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2794 | aom_sad16x64x4d, aom_jnt_sad16x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2795 | aom_jnt_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2796 | |
| 2797 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2798 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2799 | aom_sad64x16x4d, aom_jnt_sad64x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2800 | aom_jnt_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2801 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2802 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2803 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2804 | aom_sad128x128x4d, aom_jnt_sad128x128_avg, |
| 2805 | aom_jnt_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2806 | |
| 2807 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2808 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, |
| 2809 | aom_sad128x64x4d, aom_jnt_sad128x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2810 | aom_jnt_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2811 | |
| 2812 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2813 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, |
| 2814 | aom_sad64x128x4d, aom_jnt_sad64x128_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2815 | aom_jnt_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2816 | |
| 2817 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2818 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2819 | aom_sad32x16x4d, aom_jnt_sad32x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2820 | aom_jnt_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2821 | |
| 2822 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2823 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2824 | aom_sad16x32x4d, aom_jnt_sad16x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2825 | aom_jnt_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2826 | |
| 2827 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2828 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2829 | aom_sad64x32x4d, aom_jnt_sad64x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2830 | aom_jnt_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2831 | |
| 2832 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2833 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 2834 | aom_sad32x64x4d, aom_jnt_sad32x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2835 | aom_jnt_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2836 | |
| 2837 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2838 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2839 | aom_sad32x32x4d, aom_jnt_sad32x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2840 | aom_jnt_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2841 | |
| 2842 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2843 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2844 | aom_sad64x64x4d, aom_jnt_sad64x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2845 | aom_jnt_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2846 | |
| 2847 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2848 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2849 | aom_sad16x16x4d, aom_jnt_sad16x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 2850 | aom_jnt_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2851 | |
| 2852 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2853 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, |
| 2854 | aom_sad16x8x4d, aom_jnt_sad16x8_avg, aom_jnt_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2855 | |
| 2856 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2857 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, |
| 2858 | aom_sad8x16x4d, aom_jnt_sad8x16_avg, aom_jnt_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2859 | |
| 2860 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2861 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x4d, |
| 2862 | aom_jnt_sad8x8_avg, aom_jnt_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2863 | |
| 2864 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2865 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, aom_sad8x4x4d, |
| 2866 | aom_jnt_sad8x4_avg, aom_jnt_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2867 | |
| 2868 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2869 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, aom_sad4x8x4d, |
| 2870 | aom_jnt_sad4x8_avg, aom_jnt_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2871 | |
| 2872 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2873 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x4d, |
| 2874 | aom_jnt_sad4x4_avg, aom_jnt_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2875 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2876 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2877 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2878 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2879 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2880 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2881 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2882 | aom_obmc_sub_pixel_variance128x128) |
| 2883 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2884 | aom_obmc_sub_pixel_variance128x64) |
| 2885 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2886 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2887 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2888 | aom_obmc_sub_pixel_variance64x64) |
| 2889 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2890 | aom_obmc_sub_pixel_variance64x32) |
| 2891 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2892 | aom_obmc_sub_pixel_variance32x64) |
| 2893 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2894 | aom_obmc_sub_pixel_variance32x32) |
| 2895 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2896 | aom_obmc_sub_pixel_variance32x16) |
| 2897 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2898 | aom_obmc_sub_pixel_variance16x32) |
| 2899 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2900 | aom_obmc_sub_pixel_variance16x16) |
| 2901 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2902 | aom_obmc_sub_pixel_variance16x8) |
| 2903 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2904 | aom_obmc_sub_pixel_variance8x16) |
| 2905 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2906 | aom_obmc_sub_pixel_variance8x8) |
| 2907 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2908 | aom_obmc_sub_pixel_variance4x8) |
| 2909 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2910 | aom_obmc_sub_pixel_variance8x4) |
| 2911 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2912 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2913 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2914 | aom_obmc_sub_pixel_variance4x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2915 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2916 | aom_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2917 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2918 | aom_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2919 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2920 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2921 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2922 | aom_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2923 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2924 | aom_obmc_sub_pixel_variance64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2925 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2926 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2927 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2928 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2929 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2930 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2931 | aom_masked_sub_pixel_variance128x128) |
| 2932 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2933 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2934 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2935 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2936 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2937 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2938 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2939 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2940 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2941 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2942 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2943 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2944 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2945 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2946 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2947 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2948 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 2949 | |
| 2950 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 2951 | |
| 2952 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 2953 | |
| 2954 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2955 | |
| 2956 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 2957 | |
| 2958 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2959 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2960 | highbd_set_var_fns(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2961 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2962 | /* av1_init_quantizer() is first called here. Add check in |
| 2963 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2964 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2965 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2966 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2967 | av1_init_quantizer(cpi); |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 2968 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2969 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2970 | av1_loop_filter_init(cm); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 2971 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 2972 | cm->superres_upscaled_width = oxcf->width; |
| 2973 | cm->superres_upscaled_height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2974 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2975 | |
| 2976 | cm->error.setjmp = 0; |
| 2977 | |
| 2978 | return cpi; |
| 2979 | } |
| 2980 | |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2981 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2982 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2983 | |
| 2984 | #define SNPRINT2(H, T, V) \ |
| 2985 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2986 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2987 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2988 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2989 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2990 | unsigned int i; |
| 2991 | int t; |
| 2992 | |
| 2993 | if (!cpi) return; |
| 2994 | |
| 2995 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2996 | const int num_planes = av1_num_planes(cm); |
| 2997 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2998 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2999 | #if CONFIG_ENTROPY_STATS |
| 3000 | if (cpi->oxcf.pass != 1) { |
| 3001 | fprintf(stderr, "Writing counts.stt\n"); |
| 3002 | FILE *f = fopen("counts.stt", "wb"); |
| 3003 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 3004 | fclose(f); |
| 3005 | } |
| 3006 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3007 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3008 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3009 | |
| 3010 | if (cpi->oxcf.pass != 1) { |
| 3011 | char headings[512] = { 0 }; |
| 3012 | char results[512] = { 0 }; |
| 3013 | FILE *f = fopen("opsnr.stt", "a"); |
| 3014 | double time_encoded = |
| 3015 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3016 | 10000000.000; |
| 3017 | double total_encode_time = |
| 3018 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3019 | const double dr = |
| 3020 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3021 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3022 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3023 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3024 | |
| 3025 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3026 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3027 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3028 | const double total_ssim = |
| 3029 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3030 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3031 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3032 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3033 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3034 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3035 | snprintf(results, sizeof(results), |
| 3036 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3037 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3038 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3039 | "%7.3f\t%7.3f\t%7.3f", |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3040 | dr, cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, |
| 3041 | cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, total_ssim, |
| 3042 | total_ssim, cpi->fastssim.stat[STAT_ALL] / cpi->count, |
| 3043 | cpi->psnrhvs.stat[STAT_ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3044 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3045 | cpi->psnr.stat[STAT_Y] / cpi->count, |
| 3046 | cpi->psnr.stat[STAT_U] / cpi->count, |
| 3047 | cpi->psnr.stat[STAT_V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3048 | |
| 3049 | if (cpi->b_calculate_blockiness) { |
| 3050 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3051 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3052 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3053 | } |
| 3054 | |
| 3055 | if (cpi->b_calculate_consistency) { |
| 3056 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3057 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3058 | (double)cpi->total_inconsistency); |
| 3059 | |
| 3060 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3061 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3062 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3063 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 3064 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 3065 | 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] | 3066 | rate_err, fabs(rate_err)); |
| 3067 | } |
| 3068 | |
| 3069 | fclose(f); |
| 3070 | } |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3071 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3074 | for (int frame = 0; frame < MAX_LAG_BUFFERS; ++frame) { |
| 3075 | aom_free(cpi->tpl_stats[frame].tpl_stats_ptr); |
| 3076 | cpi->tpl_stats[frame].is_valid = 0; |
| 3077 | } |
| 3078 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3079 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3080 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3081 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3082 | |
| 3083 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3084 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3085 | |
| 3086 | // Deallocate allocated thread data. |
Ravi Chaudhary | 1cf7d16 | 2018-10-09 17:00:43 +0530 | [diff] [blame] | 3087 | if (cpi->row_mt == 1) aom_free(thread_data->td->tctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3088 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3089 | aom_free(thread_data->td->palette_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3090 | aom_free(thread_data->td->tmp_conv_dst); |
| 3091 | for (int j = 0; j < 2; ++j) { |
| 3092 | aom_free(thread_data->td->tmp_obmc_bufs[j]); |
| 3093 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3094 | aom_free(thread_data->td->above_pred_buf); |
| 3095 | aom_free(thread_data->td->left_pred_buf); |
| 3096 | aom_free(thread_data->td->wsrc_buf); |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 3097 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3098 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 3099 | aom_free(thread_data->td->inter_modes_info); |
| 3100 | #endif |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3101 | for (int x = 0; x < 2; x++) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3102 | for (int y = 0; y < 2; y++) { |
| 3103 | aom_free(thread_data->td->hash_value_buffer[x][y]); |
| 3104 | thread_data->td->hash_value_buffer[x][y] = NULL; |
| 3105 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3106 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3107 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3108 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3109 | av1_free_pc_tree(thread_data->td, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3110 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3111 | } |
| 3112 | } |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 3113 | #if CONFIG_MULTITHREAD |
| 3114 | if (cpi->row_mt == 1) { |
| 3115 | if (cpi->row_mt_mutex_ != NULL) { |
| 3116 | pthread_mutex_destroy(cpi->row_mt_mutex_); |
| 3117 | aom_free(cpi->row_mt_mutex_); |
| 3118 | } |
| 3119 | } |
| 3120 | #endif |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 3121 | av1_row_mt_mem_dealloc(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3122 | aom_free(cpi->tile_thr_data); |
| 3123 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3124 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3125 | if (cpi->num_workers > 1) { |
| 3126 | av1_loop_filter_dealloc(&cpi->lf_row_sync); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 3127 | av1_loop_restoration_dealloc(&cpi->lr_row_sync, cpi->num_workers); |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3128 | } |
| 3129 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3130 | dealloc_compressor_data(cpi); |
| 3131 | |
| 3132 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3133 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3134 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | #if CONFIG_FP_MB_STATS |
| 3138 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3139 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3140 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 3141 | } |
| 3142 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3143 | #if CONFIG_INTERNAL_STATS |
| 3144 | aom_free(cpi->ssim_vars); |
| 3145 | cpi->ssim_vars = NULL; |
| 3146 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3147 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3148 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3149 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3150 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 3151 | } |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 3152 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3153 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3154 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3155 | |
| 3156 | #ifdef OUTPUT_YUV_SKINMAP |
| 3157 | fclose(yuv_skinmap_file); |
| 3158 | #endif |
| 3159 | #ifdef OUTPUT_YUV_REC |
| 3160 | fclose(yuv_rec_file); |
| 3161 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3164 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3165 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3166 | int i; |
| 3167 | PSNR_STATS psnr; |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3168 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3169 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3170 | |
| 3171 | for (i = 0; i < 4; ++i) { |
| 3172 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3173 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3174 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3175 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3176 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3177 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3180 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3181 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3182 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 3183 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3184 | return 0; |
| 3185 | } |
| 3186 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 3187 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) { |
| 3188 | cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0; |
| 3189 | cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0; |
| 3190 | cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0; |
| 3191 | cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0; |
| 3192 | 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] | 3193 | cpi->ext_refresh_frame_flags_pending = 1; |
| 3194 | } |
| 3195 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3196 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3197 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3198 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3199 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3200 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3201 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3202 | return 0; |
| 3203 | } else { |
| 3204 | return -1; |
| 3205 | } |
| 3206 | } |
| 3207 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3208 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3209 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3210 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3211 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3212 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3213 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3214 | return 0; |
| 3215 | } else { |
| 3216 | return -1; |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3221 | cpi->ext_refresh_frame_context = update; |
| 3222 | cpi->ext_refresh_frame_context_pending = 1; |
| 3223 | return 0; |
| 3224 | } |
| 3225 | |
| 3226 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3227 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3228 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3229 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3230 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3231 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3232 | uint8_t *src = s->y_buffer; |
| 3233 | int h = s->y_height; |
| 3234 | |
| 3235 | do { |
| 3236 | fwrite(src, s->y_width, 1, f); |
| 3237 | src += s->y_stride; |
| 3238 | } while (--h); |
| 3239 | |
| 3240 | src = s->u_buffer; |
| 3241 | h = s->uv_height; |
| 3242 | |
| 3243 | do { |
| 3244 | fwrite(src, s->uv_width, 1, f); |
| 3245 | src += s->uv_stride; |
| 3246 | } while (--h); |
| 3247 | |
| 3248 | src = s->v_buffer; |
| 3249 | h = s->uv_height; |
| 3250 | |
| 3251 | do { |
| 3252 | fwrite(src, s->uv_width, 1, f); |
| 3253 | src += s->uv_stride; |
| 3254 | } while (--h); |
| 3255 | } |
| 3256 | #endif |
| 3257 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3258 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3259 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3260 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3261 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3262 | gf_group->update_type[gf_group->index]; |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3263 | #if USE_SYMM_MULTI_LAYER |
| 3264 | const int which_arf = (cpi->new_bwdref_update_rule == 1) |
| 3265 | ? gf_group->arf_update_idx[gf_group->index] > 0 |
| 3266 | : gf_group->arf_update_idx[gf_group->index]; |
| 3267 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3268 | 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] | 3269 | #endif |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3270 | |
| 3271 | if (cm->show_existing_frame == 1) { |
| 3272 | cm->show_existing_frame = 0; |
| 3273 | } else if (cpi->rc.is_last_bipred_frame) { |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3274 | #if USE_SYMM_MULTI_LAYER |
| 3275 | // NOTE: When new structure is used, every bwdref will have one overlay |
| 3276 | // frame. Therefore, there is no need to find out which frame to |
| 3277 | // show in advance. |
| 3278 | if (cpi->new_bwdref_update_rule == 0) { |
| 3279 | #endif |
| 3280 | // NOTE: If the current frame is a last bi-predictive frame, it is |
| 3281 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3282 | // the last_fb_idxes[0] after reference frame buffer update |
| 3283 | cpi->rc.is_last_bipred_frame = 0; |
| 3284 | cm->show_existing_frame = 1; |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3285 | cpi->existing_fb_idx_to_show = cpi->remapped_ref_idx[0]; |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3286 | #if USE_SYMM_MULTI_LAYER |
| 3287 | } |
| 3288 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3289 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3290 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3291 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3292 | #if USE_SYMM_MULTI_LAYER |
| 3293 | const int bwdref_to_show = |
| 3294 | (cpi->new_bwdref_update_rule == 1) ? BWDREF_FRAME : ALTREF2_FRAME; |
| 3295 | #else |
| 3296 | const int bwdref_to_show = ALTREF2_FRAME; |
| 3297 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3298 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3299 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3300 | cm->show_existing_frame = 1; |
| 3301 | cpi->rc.is_src_frame_alt_ref = 1; |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3302 | cpi->existing_fb_idx_to_show = |
| 3303 | (next_frame_update_type == OVERLAY_UPDATE) |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3304 | ? get_ref_frame_map_idx(cpi, ALTREF_FRAME) |
| 3305 | : get_ref_frame_map_idx(cpi, bwdref_to_show); |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3306 | #if USE_SYMM_MULTI_LAYER |
| 3307 | if (cpi->new_bwdref_update_rule == 0) |
| 3308 | #endif |
| 3309 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3310 | } |
| 3311 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3312 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3313 | |
| 3314 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3315 | 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] | 3316 | uint8_t *src = s->y_buffer; |
| 3317 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3318 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3319 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3320 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3321 | |
| 3322 | do { |
| 3323 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3324 | src16 += s->y_stride; |
| 3325 | } while (--h); |
| 3326 | |
| 3327 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3328 | h = s->uv_height; |
| 3329 | |
| 3330 | do { |
| 3331 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3332 | src16 += s->uv_stride; |
| 3333 | } while (--h); |
| 3334 | |
| 3335 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3336 | h = s->uv_height; |
| 3337 | |
| 3338 | do { |
| 3339 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3340 | src16 += s->uv_stride; |
| 3341 | } while (--h); |
| 3342 | |
| 3343 | fflush(yuv_rec_file); |
| 3344 | return; |
| 3345 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3346 | |
| 3347 | do { |
| 3348 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3349 | src += s->y_stride; |
| 3350 | } while (--h); |
| 3351 | |
| 3352 | src = s->u_buffer; |
| 3353 | h = s->uv_height; |
| 3354 | |
| 3355 | do { |
| 3356 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3357 | src += s->uv_stride; |
| 3358 | } while (--h); |
| 3359 | |
| 3360 | src = s->v_buffer; |
| 3361 | h = s->uv_height; |
| 3362 | |
| 3363 | do { |
| 3364 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3365 | src += s->uv_stride; |
| 3366 | } while (--h); |
| 3367 | |
| 3368 | fflush(yuv_rec_file); |
| 3369 | } |
| 3370 | #endif // OUTPUT_YUV_REC |
| 3371 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3372 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3373 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3374 | int i; |
| 3375 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3376 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3377 | AV1_COMMON *const cm = &cpi->common; |
| 3378 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3379 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3380 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3381 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3382 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3383 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3384 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3385 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 3386 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 3387 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 3388 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | return recode; |
| 3392 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3393 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3394 | // Function to test for conditions that indicate we should loop |
| 3395 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3396 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3397 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3398 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3399 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3400 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3401 | int force_recode = 0; |
| 3402 | |
| 3403 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3404 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3405 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3406 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3407 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3408 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3409 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3410 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3411 | // Deal with frame undershoot and whether or not we are |
| 3412 | // below the automatically set cq level. |
| 3413 | if (q > oxcf->cq_level && |
| 3414 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3415 | force_recode = 1; |
| 3416 | } |
| 3417 | } |
| 3418 | } |
| 3419 | return force_recode; |
| 3420 | } |
| 3421 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3422 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3423 | |
| 3424 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3425 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3426 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3427 | char *file_name) { |
| 3428 | int h; |
| 3429 | FILE *f_ref = NULL; |
| 3430 | |
| 3431 | if (ref_buf == NULL) { |
| 3432 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3433 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3437 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3438 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | // --- Y --- |
| 3442 | for (h = 0; h < cm->height; ++h) { |
| 3443 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3444 | } |
| 3445 | // --- U --- |
| 3446 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3447 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3448 | f_ref); |
| 3449 | } |
| 3450 | // --- V --- |
| 3451 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3452 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3453 | f_ref); |
| 3454 | } |
| 3455 | |
| 3456 | fclose(f_ref); |
| 3457 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3458 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3459 | } |
| 3460 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3461 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3462 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3463 | MV_REFERENCE_FRAME ref_frame; |
| 3464 | |
| 3465 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3466 | char file_name[256] = ""; |
| 3467 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3468 | cm->current_video_frame, ref_frame); |
| 3469 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3470 | } |
| 3471 | } |
| 3472 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3473 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3474 | // This function is used to shift the virtual indices of last reference frames |
| 3475 | // as follows: |
| 3476 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3477 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3478 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3479 | // TODO(isbs): shift the scaled indices as well |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 3480 | for (int ref_frame = LAST3_FRAME; ref_frame > LAST_FRAME; --ref_frame) { |
| 3481 | const int ref_idx = ref_frame - LAST_FRAME; |
| 3482 | cpi->remapped_ref_idx[ref_idx] = cpi->remapped_ref_idx[ref_idx - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3483 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3484 | if (!cpi->rc.is_src_frame_alt_ref) { |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 3485 | memcpy(cpi->interp_filter_selected[ref_frame], |
| 3486 | cpi->interp_filter_selected[ref_frame - 1], |
| 3487 | sizeof(cpi->interp_filter_selected[ref_frame - 1])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3491 | |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3492 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3493 | // This function is used to shift the virtual indices of bwd reference |
| 3494 | // frames as follows: |
| 3495 | // BWD_REF -> ALT2_REF -> EXT_REF |
| 3496 | // to clear a space to store the closest bwdref |
| 3497 | static INLINE void rshift_bwd_ref_frames(AV1_COMP *cpi) { |
| 3498 | // TODO(isbs): shift the scaled indices as well |
Urvang Joshi | 03d8ebe | 2018-11-08 17:13:44 -0800 | [diff] [blame] | 3499 | static const int ordered_bwd[3] = { BWDREF_FRAME, ALTREF2_FRAME, |
| 3500 | EXTREF_FRAME }; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3501 | |
| 3502 | for (int i = 2; i > 0; --i) { |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3503 | // [0] is allocated to the current coded frame, i.e. bwdref |
Urvang Joshi | 03d8ebe | 2018-11-08 17:13:44 -0800 | [diff] [blame] | 3504 | memcpy(cpi->interp_filter_selected[ordered_bwd[i]], |
| 3505 | cpi->interp_filter_selected[ordered_bwd[i - 1]], |
| 3506 | sizeof(cpi->interp_filter_selected[ordered_bwd[i - 1]])); |
SmilingWolf | dad2282 | 2018-09-12 15:43:43 -0700 | [diff] [blame] | 3507 | |
Urvang Joshi | 03d8ebe | 2018-11-08 17:13:44 -0800 | [diff] [blame] | 3508 | cpi->remapped_ref_idx[ordered_bwd[i] - LAST_FRAME] = |
| 3509 | cpi->remapped_ref_idx[ordered_bwd[i - 1] - LAST_FRAME]; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | // This function is used to shift the virtual indices of bwd reference |
| 3514 | // frames as follows: |
| 3515 | // BWD_REF <- ALT2_REF <- EXT_REF |
| 3516 | // to update the bwd reference frame for coding the next frame. |
| 3517 | static INLINE void lshift_bwd_ref_frames(AV1_COMP *cpi) { |
| 3518 | // TODO(isbs): shift the scaled indices as well |
Urvang Joshi | 03d8ebe | 2018-11-08 17:13:44 -0800 | [diff] [blame] | 3519 | static const int ordered_bwd[3] = { BWDREF_FRAME, ALTREF2_FRAME, |
| 3520 | EXTREF_FRAME }; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3521 | |
| 3522 | for (int i = 0; i < 2; ++i) { |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3523 | // [0] is allocated to the current coded frame, i.e. bwdref |
Urvang Joshi | 03d8ebe | 2018-11-08 17:13:44 -0800 | [diff] [blame] | 3524 | memcpy(cpi->interp_filter_selected[ordered_bwd[i]], |
| 3525 | cpi->interp_filter_selected[ordered_bwd[i + 1]], |
| 3526 | sizeof(cpi->interp_filter_selected[ordered_bwd[i + 1]])); |
SmilingWolf | dad2282 | 2018-09-12 15:43:43 -0700 | [diff] [blame] | 3527 | |
Urvang Joshi | 03d8ebe | 2018-11-08 17:13:44 -0800 | [diff] [blame] | 3528 | cpi->remapped_ref_idx[ordered_bwd[i] - LAST_FRAME] = |
| 3529 | cpi->remapped_ref_idx[ordered_bwd[i + 1] - LAST_FRAME]; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3530 | } |
| 3531 | } |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3532 | #endif // USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3533 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3534 | static void update_reference_frames(AV1_COMP *cpi) { |
| 3535 | AV1_COMMON *const cm = &cpi->common; |
| 3536 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3537 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3538 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3539 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3540 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 3541 | // In the case of show_existing frame, we will not send fresh flag |
| 3542 | // to decoder. Any change in the reference frame buffer can be done by |
| 3543 | // switching the virtual indices. |
| 3544 | if (cm->show_existing_frame) { |
Sarah Parker | 29147cf | 2018-10-16 20:34:51 -0700 | [diff] [blame] | 3545 | // If we are not indicating to the decoder that this frame is |
| 3546 | // a show_existing_frame, which occurs in error_resilient mode, |
Sarah Parker | a9e1905 | 2018-10-18 17:49:26 -0700 | [diff] [blame] | 3547 | // we still want to refresh the LAST_FRAME when the current frame |
| 3548 | // was the source of an ext_arf. |
| 3549 | cpi->refresh_last_frame = |
| 3550 | !encode_show_existing_frame(cm) && cpi->rc.is_src_frame_ext_arf; |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 3551 | cpi->refresh_golden_frame = 0; |
| 3552 | cpi->refresh_bwd_ref_frame = 0; |
| 3553 | cpi->refresh_alt2_ref_frame = 0; |
| 3554 | cpi->refresh_alt_ref_frame = 0; |
| 3555 | |
| 3556 | cpi->rc.is_bwd_ref_frame = 0; |
| 3557 | cpi->rc.is_last_bipred_frame = 0; |
| 3558 | cpi->rc.is_bipred_frame = 0; |
| 3559 | } |
| 3560 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3561 | BufferPool *const pool = cm->buffer_pool; |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3562 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3563 | // At this point the new frame has been encoded. |
| 3564 | // If any buffer copy / swapping is signaled it should be done here. |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3565 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 3566 | // Only update all of the reference buffers if a KEY_FRAME is also a |
| 3567 | // show_frame. This ensures a fwd keyframe does not update all of the buffers |
| 3568 | 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] | 3569 | for (int ref_frame = 0; ref_frame < REF_FRAMES; ++ref_frame) { |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3570 | assign_frame_buffer(pool->frame_bufs, |
| 3571 | &cm->ref_frame_map[cpi->remapped_ref_idx[ref_frame]], |
| 3572 | cm->new_fb_idx); |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3573 | } |
| 3574 | return; |
| 3575 | } |
| 3576 | |
| 3577 | if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3578 | // We have decided to preserve the previously existing golden frame as our |
| 3579 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3580 | // 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] | 3581 | // we're updating the GF with the current decoded frame, we save it to the |
| 3582 | // ARF slot instead. |
| 3583 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3584 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3585 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3586 | int tmp; |
| 3587 | |
Wei-Ting Lin | a8c0245 | 2018-08-13 11:04:06 -0700 | [diff] [blame] | 3588 | // ARF in general is a better reference than overlay. We shouldkeep ARF as |
| 3589 | // reference instead of replacing it with overlay. |
| 3590 | |
| 3591 | if (!cpi->preserve_arf_as_gld) { |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3592 | assign_frame_buffer( |
| 3593 | pool->frame_bufs, |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3594 | &cm->ref_frame_map[get_ref_frame_map_idx(cpi, ALTREF_FRAME)], |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3595 | cm->new_fb_idx); |
Wei-Ting Lin | a8c0245 | 2018-08-13 11:04:06 -0700 | [diff] [blame] | 3596 | } |
| 3597 | |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3598 | tmp = get_ref_frame_map_idx(cpi, ALTREF_FRAME); |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3599 | cpi->remapped_ref_idx[ALTREF_FRAME - 1] = |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3600 | get_ref_frame_map_idx(cpi, GOLDEN_FRAME); |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3601 | cpi->remapped_ref_idx[GOLDEN_FRAME - 1] = tmp; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3602 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3603 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3604 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
Sarah Parker | 7a9bb78 | 2018-10-11 14:52:42 -0700 | [diff] [blame] | 3605 | } else if (cpi->rc.is_src_frame_ext_arf && encode_show_existing_frame(cm)) { |
Wei-Ting Lin | b72453f | 2018-06-26 14:05:38 -0700 | [diff] [blame] | 3606 | #if CONFIG_DEBUG |
| 3607 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3608 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
| 3609 | #endif |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3610 | #if USE_SYMM_MULTI_LAYER |
| 3611 | const int bwdref_to_show = |
| 3612 | (cpi->new_bwdref_update_rule == 1) ? BWDREF_FRAME : ALTREF2_FRAME; |
| 3613 | #else |
| 3614 | const int bwdref_to_show = ALTREF2_FRAME; |
| 3615 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3616 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3617 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3618 | // by updating the virtual indices. |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3619 | const int last3_remapped_idx = get_ref_frame_map_idx(cpi, LAST3_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3620 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3621 | |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3622 | cpi->remapped_ref_idx[LAST_FRAME - 1] = |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3623 | get_ref_frame_map_idx(cpi, bwdref_to_show); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3624 | |
| 3625 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3626 | cpi->interp_filter_selected[bwdref_to_show], |
| 3627 | sizeof(cpi->interp_filter_selected[bwdref_to_show])); |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3628 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3629 | if (cpi->new_bwdref_update_rule == 1) { |
| 3630 | lshift_bwd_ref_frames(cpi); |
| 3631 | // pass outdated forward reference frame (previous LAST3) to the |
| 3632 | // spared space |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 3633 | cpi->remapped_ref_idx[EXTREF_FRAME - 1] = last3_remapped_idx; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3634 | } else { |
| 3635 | #endif |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 3636 | cpi->remapped_ref_idx[bwdref_to_show - 1] = last3_remapped_idx; |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3637 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3638 | } |
| 3639 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3640 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3641 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3642 | if (cpi->refresh_alt_ref_frame) { |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3643 | int arf_idx = get_ref_frame_map_idx(cpi, ALTREF_FRAME); |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3644 | assign_frame_buffer(pool->frame_bufs, &cm->ref_frame_map[arf_idx], |
| 3645 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3646 | |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 3647 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3648 | cpi->interp_filter_selected[0], |
| 3649 | sizeof(cpi->interp_filter_selected[0])); |
| 3650 | } |
| 3651 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3652 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3653 | if (cpi->refresh_golden_frame) { |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3654 | assign_frame_buffer( |
| 3655 | pool->frame_bufs, |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3656 | &cm->ref_frame_map[get_ref_frame_map_idx(cpi, GOLDEN_FRAME)], |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3657 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3658 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3659 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3660 | cpi->interp_filter_selected[0], |
| 3661 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3664 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3665 | if (cpi->refresh_bwd_ref_frame) { |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3666 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3667 | if (cpi->new_bwdref_update_rule) { |
| 3668 | // We shift the backward reference frame as follows: |
| 3669 | // BWDREF -> ALTREF2 -> EXTREF |
| 3670 | // and assign the newly coded frame to BWDREF so that it always |
| 3671 | // keeps the nearest future frame |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3672 | int tmp = get_ref_frame_map_idx(cpi, EXTREF_FRAME); |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3673 | assign_frame_buffer(pool->frame_bufs, &cm->ref_frame_map[tmp], |
| 3674 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3675 | |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3676 | rshift_bwd_ref_frames(cpi); |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3677 | cpi->remapped_ref_idx[BWDREF_FRAME - 1] = tmp; |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3678 | } else { |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3679 | #endif // USE_SYMM_MULTI_LAYER |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3680 | assign_frame_buffer( |
| 3681 | pool->frame_bufs, |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3682 | &cm->ref_frame_map[get_ref_frame_map_idx(cpi, BWDREF_FRAME)], |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3683 | cm->new_fb_idx); |
Wei-Ting Lin | 240d9b4 | 2018-07-12 11:48:02 -0700 | [diff] [blame] | 3684 | #if USE_SYMM_MULTI_LAYER |
Wei-Ting Lin | cc75ca7 | 2018-07-10 15:36:32 -0700 | [diff] [blame] | 3685 | } |
| 3686 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3687 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3688 | cpi->interp_filter_selected[0], |
| 3689 | sizeof(cpi->interp_filter_selected[0])); |
| 3690 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3691 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3692 | // === ALTREF2_FRAME === |
| 3693 | if (cpi->refresh_alt2_ref_frame) { |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3694 | assign_frame_buffer( |
| 3695 | pool->frame_bufs, |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3696 | &cm->ref_frame_map[get_ref_frame_map_idx(cpi, ALTREF2_FRAME)], |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3697 | cm->new_fb_idx); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3698 | |
| 3699 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3700 | cpi->interp_filter_selected[0], |
| 3701 | sizeof(cpi->interp_filter_selected[0])); |
| 3702 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | if (cpi->refresh_last_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3706 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3707 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3708 | // the virtual index to the reference frame buffer physical index: |
| 3709 | // |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3710 | // LAST_FRAME, ..., EXTREF_FRAME |
| 3711 | // | | |
| 3712 | // v v |
| 3713 | // remapped_ref_idx[LAST_FRAME - 1], ..., remapped_ref_idx[EXTREF_FRAME - 1] |
| 3714 | // | | |
| 3715 | // v v |
| 3716 | // ref_frame_map[], ..., ref_frame_map[] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3717 | // |
| 3718 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3719 | // have the other 2 LAST reference frames shifted as follows: |
| 3720 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3721 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3722 | // |
| 3723 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3724 | // |
| 3725 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3726 | // to point to the newly coded frame, i.e. |
| 3727 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3728 | // |
| 3729 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3730 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3731 | // shifted as follows: |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 3732 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3733 | // | | | |
| 3734 | // v v v |
| 3735 | // remapped_ref_idx[2], remapped_ref_idx[0], remapped_ref_idx[1] |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3736 | assign_frame_buffer( |
| 3737 | pool->frame_bufs, |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3738 | &cm->ref_frame_map[get_ref_frame_map_idx(cpi, LAST3_FRAME)], |
Urvang Joshi | df802ee | 2018-11-05 16:43:26 -0800 | [diff] [blame] | 3739 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3740 | |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3741 | int last3_remapped_idx = get_ref_frame_map_idx(cpi, LAST3_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3742 | |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3743 | shift_last_ref_frames(cpi); |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 3744 | cpi->remapped_ref_idx[LAST_FRAME - 1] = last3_remapped_idx; |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3745 | |
Sarah Parker | 5336b9c | 2018-10-18 11:34:20 -0700 | [diff] [blame] | 3746 | assert(!encode_show_existing_frame(cm)); |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3747 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3748 | cpi->interp_filter_selected[0], |
| 3749 | sizeof(cpi->interp_filter_selected[0])); |
| 3750 | |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3751 | // If the new structure is used, we will always have overlay frames coupled |
| 3752 | // with bwdref frames. Therefore, we won't have to perform this update |
| 3753 | // in advance (we do this update when the overlay frame shows up). |
| 3754 | #if USE_SYMM_MULTI_LAYER |
| 3755 | if (cpi->new_bwdref_update_rule == 0 && cpi->rc.is_last_bipred_frame) { |
| 3756 | #else |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3757 | if (cpi->rc.is_last_bipred_frame) { |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 3758 | #endif |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3759 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3760 | // LAST3_FRAME by updating the virtual indices. |
| 3761 | // |
| 3762 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3763 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3764 | // virtual index reshuffling for BWDREF, the encoder always |
| 3765 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3766 | // reshuffling job accordingly. |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3767 | last3_remapped_idx = get_ref_frame_map_idx(cpi, LAST3_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3768 | |
| 3769 | shift_last_ref_frames(cpi); |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 3770 | cpi->remapped_ref_idx[LAST_FRAME - 1] = |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 3771 | get_ref_frame_map_idx(cpi, BWDREF_FRAME); |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 3772 | cpi->remapped_ref_idx[BWDREF_FRAME - 1] = last3_remapped_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3773 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3774 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
Zoe Liu | bcef1e6 | 2018-04-06 20:56:11 -0700 | [diff] [blame] | 3775 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3776 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3777 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3781 | // Dump out all reference frame images. |
| 3782 | dump_ref_frame_images(cpi); |
| 3783 | #endif // DUMP_REF_FRAME_IMAGES |
| 3784 | } |
| 3785 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3786 | 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] | 3787 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3788 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3789 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3790 | new_fb_ptr->width = cm->width; |
| 3791 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3794 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3795 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3796 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3797 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3798 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3799 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 3800 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3801 | }; |
| 3802 | |
| 3803 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3804 | // 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] | 3805 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3806 | BufferPool *const pool = cm->buffer_pool; |
| 3807 | const YV12_BUFFER_CONFIG *const ref = |
| 3808 | get_ref_frame_buffer(cpi, ref_frame); |
| 3809 | |
| 3810 | if (ref == NULL) { |
| 3811 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3812 | continue; |
| 3813 | } |
| 3814 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3815 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3816 | RefCntBuffer *new_fb_ptr = NULL; |
| 3817 | int force_scaling = 0; |
| 3818 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3819 | if (new_fb == INVALID_IDX) { |
| 3820 | new_fb = get_free_fb(cm); |
Wan-Teh Chang | 4a8c004 | 2018-10-05 09:41:52 -0700 | [diff] [blame] | 3821 | if (new_fb == INVALID_IDX) |
| 3822 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3823 | "Unable to find free frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3824 | force_scaling = 1; |
| 3825 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3826 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3827 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3828 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3829 | if (aom_realloc_frame_buffer( |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3830 | &new_fb_ptr->buf, cm->width, cm->height, |
| 3831 | cm->seq_params.subsampling_x, cm->seq_params.subsampling_y, |
| 3832 | cm->seq_params.use_highbitdepth, AOM_BORDER_IN_PIXELS, |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3833 | cm->byte_alignment, NULL, NULL, NULL)) { |
| 3834 | if (force_scaling) { |
| 3835 | // Release the reference acquired in the get_free_fb() call above. |
| 3836 | --new_fb_ptr->ref_count; |
| 3837 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3838 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3839 | "Failed to allocate frame buffer"); |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3840 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3841 | av1_resize_and_extend_frame( |
| 3842 | 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] | 3843 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3844 | alloc_frame_mvs(cm, new_fb); |
| 3845 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3846 | } else { |
| 3847 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3848 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3849 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3850 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3851 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3852 | ++buf->ref_count; |
| 3853 | } |
| 3854 | } else { |
| 3855 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3856 | } |
| 3857 | } |
| 3858 | } |
| 3859 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3860 | static void release_scaled_references(AV1_COMP *cpi) { |
| 3861 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3862 | int i; |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3863 | // TODO(isbs): only refresh the necessary frames, rather than all of them |
Wan-Teh Chang | bb6a3d2 | 2018-10-05 11:22:48 -0700 | [diff] [blame] | 3864 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3865 | const int idx = cpi->scaled_ref_idx[i]; |
Wan-Teh Chang | d05e033 | 2018-10-03 12:00:43 -0700 | [diff] [blame] | 3866 | if (idx != INVALID_IDX) { |
| 3867 | RefCntBuffer *const buf = &cm->buffer_pool->frame_bufs[idx]; |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3868 | --buf->ref_count; |
| 3869 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3870 | } |
| 3871 | } |
| 3872 | } |
| 3873 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3874 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3875 | const AV1_COMMON *const cm = &cpi->common; |
| 3876 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3877 | |
| 3878 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3879 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3880 | |
| 3881 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3882 | if (frame_is_intra_only(cm)) { |
| 3883 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3884 | // after a key/intra-only frame. |
| 3885 | cpi->max_mv_magnitude = max_mv_def; |
| 3886 | } else { |
| 3887 | if (cm->show_frame) { |
| 3888 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3889 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3890 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3891 | cpi->mv_step_param = av1_init_search_range( |
| 3892 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3893 | } |
| 3894 | cpi->max_mv_magnitude = 0; |
| 3895 | } |
| 3896 | } |
| 3897 | } |
| 3898 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3899 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3900 | int i; |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3901 | AV1_COMMON *cm = &cpi->common; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3902 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3903 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3904 | } |
| 3905 | cpi->global_motion_search_done = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3906 | av1_set_speed_features_framesize_independent(cpi); |
| 3907 | av1_set_rd_speed_thresholds(cpi); |
| 3908 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3909 | cm->interp_filter = SWITCHABLE; |
| 3910 | cm->switchable_motion_mode = 1; |
| 3911 | |
| 3912 | if (frame_is_intra_only(cm)) { |
| 3913 | if (cm->seq_params.force_screen_content_tools == 2) { |
| 3914 | cm->allow_screen_content_tools = |
| 3915 | cpi->oxcf.content == AOM_CONTENT_SCREEN || |
| 3916 | is_screen_content(cpi->source->y_buffer, |
| 3917 | cpi->source->flags & YV12_FLAG_HIGHBITDEPTH, |
| 3918 | cm->seq_params.bit_depth, cpi->source->y_stride, |
| 3919 | cpi->source->y_width, cpi->source->y_height); |
| 3920 | } else { |
| 3921 | cm->allow_screen_content_tools = |
| 3922 | cm->seq_params.force_screen_content_tools; |
| 3923 | } |
| 3924 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3927 | 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] | 3928 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3929 | AV1_COMMON *const cm = &cpi->common; |
| 3930 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3931 | |
| 3932 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3933 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3934 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 3935 | // Decide q and q bounds. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3936 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 3937 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3938 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3939 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3940 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3941 | cpi->common.cur_frame_force_integer_mv); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3942 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3943 | |
| 3944 | // Configure experimental use of segmentation for enhanced coding of |
| 3945 | // static regions if indicated. |
| 3946 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3947 | // lagged coding, and if the relevant speed feature flag is set. |
| 3948 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3949 | configure_static_seg_features(cpi); |
| 3950 | } |
| 3951 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3952 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3953 | int y_stride = cpi->scaled_source.y_stride; |
| 3954 | |
| 3955 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3956 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3957 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3958 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3962 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3963 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 3964 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3965 | (void)width; |
| 3966 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3967 | (void)sx; |
| 3968 | (void)sy; |
| 3969 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3970 | int s = AOMMIN(sx, sy); |
| 3971 | #else |
| 3972 | int s = 0; |
| 3973 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3974 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3975 | if (width * height > 352 * 288) |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3976 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3977 | else |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3978 | rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3979 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 3980 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3981 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3982 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3983 | static void init_ref_frame_bufs(AV1_COMP *cpi) { |
| 3984 | AV1_COMMON *const cm = &cpi->common; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3985 | int i; |
| 3986 | BufferPool *const pool = cm->buffer_pool; |
| 3987 | cm->new_fb_idx = INVALID_IDX; |
| 3988 | for (i = 0; i < REF_FRAMES; ++i) { |
| 3989 | cm->ref_frame_map[i] = INVALID_IDX; |
Wan-Teh Chang | d05e033 | 2018-10-03 12:00:43 -0700 | [diff] [blame] | 3990 | } |
| 3991 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3992 | pool->frame_bufs[i].ref_count = 0; |
| 3993 | } |
RogerZhou | 86902d0 | 2018-02-28 15:29:16 -0800 | [diff] [blame] | 3994 | if (cm->seq_params.force_screen_content_tools) { |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 3995 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3996 | 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] | 3997 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3998 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4001 | static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4002 | int subsampling_x, int subsampling_y) { |
| 4003 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4004 | SequenceHeader *const seq_params = &cm->seq_params; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4005 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4006 | if (!cpi->initial_width || seq_params->use_highbitdepth != use_highbitdepth || |
| 4007 | seq_params->subsampling_x != subsampling_x || |
| 4008 | seq_params->subsampling_y != subsampling_y) { |
| 4009 | seq_params->subsampling_x = subsampling_x; |
| 4010 | seq_params->subsampling_y = subsampling_y; |
| 4011 | seq_params->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4012 | |
| 4013 | alloc_raw_frame_buffers(cpi); |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 4014 | init_ref_frame_bufs(cpi); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4015 | alloc_util_frame_buffers(cpi); |
| 4016 | |
| 4017 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 4018 | |
| 4019 | cpi->initial_width = cm->width; |
| 4020 | cpi->initial_height = cm->height; |
| 4021 | cpi->initial_mbs = cm->MBs; |
| 4022 | } |
| 4023 | } |
| 4024 | |
| 4025 | // Returns 1 if the assigned width or height was <= 0. |
| 4026 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 4027 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4028 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4029 | check_initial_width(cpi, cm->seq_params.use_highbitdepth, |
| 4030 | cm->seq_params.subsampling_x, |
| 4031 | cm->seq_params.subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4032 | |
| 4033 | if (width <= 0 || height <= 0) return 1; |
| 4034 | |
| 4035 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4036 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4037 | |
| 4038 | if (cpi->initial_width && cpi->initial_height && |
| 4039 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 4040 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4041 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4042 | alloc_compressor_data(cpi); |
| 4043 | realloc_segmentation_maps(cpi); |
| 4044 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4045 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4046 | update_frame_size(cpi); |
| 4047 | |
| 4048 | return 0; |
| 4049 | } |
| 4050 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4051 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4052 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4053 | const SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4054 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4055 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4056 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4057 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4058 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 4059 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4060 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4061 | set_mv_search_params(cpi); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4062 | // Recalculate 'all_lossless' in case super-resolution was (un)selected. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4063 | cm->all_lossless = cm->coded_lossless && !av1_superres_scaled(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4066 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4067 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 4071 | |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 4072 | // Allocate above context buffers |
Cherma Rajan A | f147908 | 2018-05-09 14:26:34 +0530 | [diff] [blame] | 4073 | if (cm->num_allocated_above_context_planes < av1_num_planes(cm) || |
| 4074 | cm->num_allocated_above_context_mi_col < cm->mi_cols || |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 4075 | cm->num_allocated_above_contexts < cm->tile_rows) { |
| 4076 | av1_free_above_context_buffers(cm, cm->num_allocated_above_contexts); |
| 4077 | if (av1_alloc_above_context_buffers(cm, cm->tile_rows)) |
| 4078 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 4079 | "Failed to allocate context buffers"); |
| 4080 | } |
| 4081 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4082 | // Reset the frame pointers to the current frame size. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4083 | if (aom_realloc_frame_buffer( |
| 4084 | get_frame_new_buffer(cm), cm->width, cm->height, |
| 4085 | seq_params->subsampling_x, seq_params->subsampling_y, |
| 4086 | seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 4087 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4088 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4089 | "Failed to allocate frame buffer"); |
| 4090 | |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4091 | const int frame_width = cm->superres_upscaled_width; |
| 4092 | const int frame_height = cm->superres_upscaled_height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4093 | set_restoration_unit_size(frame_width, frame_height, |
| 4094 | seq_params->subsampling_x, |
| 4095 | seq_params->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4096 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 4097 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4098 | |
| 4099 | av1_alloc_restoration_buffers(cm); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4100 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4101 | init_motion_estimation(cpi); |
| 4102 | |
| 4103 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4104 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 4105 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4106 | |
| 4107 | ref_buf->idx = buf_idx; |
| 4108 | |
| 4109 | if (buf_idx != INVALID_IDX) { |
| 4110 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 4111 | ref_buf->buf = buf; |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 4112 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 4113 | buf->y_crop_height, cm->width, |
| 4114 | cm->height); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4115 | if (av1_is_scaled(&ref_buf->sf)) |
| 4116 | aom_extend_frame_borders(buf, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4117 | } else { |
| 4118 | ref_buf->buf = NULL; |
| 4119 | } |
| 4120 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4121 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 4122 | 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] | 4123 | cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4124 | |
| 4125 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4126 | } |
| 4127 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4128 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 4129 | // Choose an arbitrary random number |
| 4130 | static unsigned int seed = 56789; |
| 4131 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4132 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4133 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4134 | |
Debargha Mukherjee | 2b7c2b3 | 2018-04-10 07:35:28 -0700 | [diff] [blame] | 4135 | if (cpi->common.seq_params.reduced_still_picture_hdr) return SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4136 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4137 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4138 | case RESIZE_FIXED: |
| 4139 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4140 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4141 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4142 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4143 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4144 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4145 | default: assert(0); |
| 4146 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4147 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4150 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 4151 | // Choose an arbitrary random number |
| 4152 | static unsigned int seed = 34567; |
| 4153 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4154 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4155 | uint8_t new_denom = SCALE_NUMERATOR; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4156 | |
| 4157 | // Make sure that superres mode of the frame is consistent with the |
| 4158 | // sequence-level flag. |
| 4159 | assert(IMPLIES(oxcf->superres_mode != SUPERRES_NONE, |
| 4160 | cpi->common.seq_params.enable_superres)); |
| 4161 | assert(IMPLIES(!cpi->common.seq_params.enable_superres, |
| 4162 | oxcf->superres_mode == SUPERRES_NONE)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4163 | |
| 4164 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4165 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4166 | case SUPERRES_FIXED: |
| 4167 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4168 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4169 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4170 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4171 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4172 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4173 | case SUPERRES_QTHRESH: { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 4174 | // Do not use superres when screen content tools are used. |
| 4175 | if (cpi->common.allow_screen_content_tools) break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4176 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4177 | const RATE_FACTOR_LEVEL rf_level = gf_group->rf_level[gf_group->index]; |
| 4178 | const double rate_factor_delta = rate_factor_deltas[rf_level]; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4179 | const int qthresh = (rate_factor_delta <= 1.0) |
| 4180 | ? oxcf->superres_qthresh |
| 4181 | : oxcf->superres_kf_qthresh; |
Debargha Mukherjee | 2b2c5fd | 2018-11-14 13:21:24 -0800 | [diff] [blame^] | 4182 | if (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) |
| 4183 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4184 | int bottom_index, top_index; |
| 4185 | const int q = av1_rc_pick_q_and_bounds( |
| 4186 | cpi, cpi->oxcf.width, cpi->oxcf.height, &bottom_index, &top_index); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4187 | if (q < qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4188 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4189 | } else { |
Urvang Joshi | 28983f7 | 2017-10-25 14:41:06 -0700 | [diff] [blame] | 4190 | const uint8_t min_denom = SCALE_NUMERATOR + 1; |
Debargha Mukherjee | 2b2c5fd | 2018-11-14 13:21:24 -0800 | [diff] [blame^] | 4191 | const uint8_t denom_step = (MAXQ - qthresh + 4) >> 3; |
Imdad Sardharwalla | f6154fd | 2018-03-02 16:53:41 +0000 | [diff] [blame] | 4192 | |
| 4193 | if (q == qthresh) { |
| 4194 | new_denom = min_denom; |
| 4195 | } else if (denom_step == 0) { |
| 4196 | new_denom = SCALE_NUMERATOR << 1; |
| 4197 | } else { |
| 4198 | const uint8_t additional_denom = (q - qthresh) / denom_step; |
| 4199 | new_denom = |
| 4200 | AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1); |
| 4201 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4202 | } |
| 4203 | break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4204 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4205 | default: assert(0); |
| 4206 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4207 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4210 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4211 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4212 | } |
| 4213 | |
| 4214 | 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] | 4215 | // Only need to check the width, as scaling is horizontal only. |
| 4216 | (void)oheight; |
| 4217 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4220 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4221 | SUPERRES_MODE superres_mode, int owidth, |
| 4222 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4223 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4224 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4227 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4228 | int resize_denom = |
| 4229 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 4230 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 4231 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4232 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4233 | // Alter superres scale as needed to enforce conformity. |
| 4234 | rsz->superres_denom = |
| 4235 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 4236 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4237 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4238 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4239 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4240 | // Alter resize scale as needed to enforce conformity. |
| 4241 | resize_denom = |
| 4242 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4243 | rsz->resize_width = owidth; |
| 4244 | rsz->resize_height = oheight; |
| 4245 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4246 | resize_denom); |
| 4247 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4248 | if (resize_denom > SCALE_NUMERATOR) { |
| 4249 | --resize_denom; |
| 4250 | rsz->resize_width = owidth; |
| 4251 | rsz->resize_height = oheight; |
| 4252 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 4253 | resize_denom); |
| 4254 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4255 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4256 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4257 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4258 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4259 | if (resize_denom > rsz->superres_denom) |
| 4260 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4261 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4262 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4263 | rsz->resize_width = owidth; |
| 4264 | rsz->resize_height = oheight; |
| 4265 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4266 | resize_denom); |
| 4267 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 4268 | (resize_denom > SCALE_NUMERATOR || |
| 4269 | rsz->superres_denom > SCALE_NUMERATOR)); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4270 | } else { // We are allowed to alter neither resize scale nor superres |
| 4271 | // scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4272 | return 0; |
| 4273 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4274 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4275 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4276 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4277 | // Calculates resize and superres params for next frame |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4278 | size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) { |
| 4279 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 4280 | size_params_type rsz = { oxcf->width, oxcf->height, SCALE_NUMERATOR }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4281 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4282 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4283 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 4284 | rsz.resize_width = cpi->resize_pending_width; |
| 4285 | rsz.resize_height = cpi->resize_pending_height; |
| 4286 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 4287 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4288 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4289 | rsz.resize_width = cpi->oxcf.width; |
| 4290 | rsz.resize_height = cpi->oxcf.height; |
| 4291 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4292 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4293 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4294 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4295 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 4296 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4297 | assert(0 && "Invalid scale parameters"); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4298 | return rsz; |
| 4299 | } |
| 4300 | |
| 4301 | 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] | 4302 | int encode_width = rsz->resize_width; |
| 4303 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4304 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4305 | AV1_COMMON *cm = &cpi->common; |
| 4306 | cm->superres_upscaled_width = encode_width; |
| 4307 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4308 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4309 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 4310 | rsz->superres_denom); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4311 | set_frame_size(cpi, encode_width, encode_height); |
| 4312 | } |
| 4313 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4314 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4315 | size_params_type rsz = av1_calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4316 | setup_frame_size_from_params(cpi, &rsz); |
| 4317 | } |
| 4318 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4319 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4320 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4321 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4322 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4323 | if (!av1_superres_scaled(cm)) return; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4324 | |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4325 | assert(cpi->oxcf.enable_superres); |
| 4326 | assert(!is_lossless_requested(&cpi->oxcf)); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4327 | assert(!cm->all_lossless); |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4328 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4329 | av1_superres_upscale(cm, NULL); |
| 4330 | |
| 4331 | // If regular resizing is occurring the source will need to be downscaled to |
| 4332 | // match the upscaled superres resolution. Otherwise the original source is |
| 4333 | // used. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4334 | if (!av1_resize_scaled(cm)) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4335 | cpi->source = cpi->unscaled_source; |
| 4336 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4337 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4338 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4339 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4340 | // Do downscale. cm->(width|height) has been updated by |
| 4341 | // av1_superres_upscale |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4342 | if (aom_realloc_frame_buffer( |
| 4343 | &cpi->scaled_source, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4344 | cm->superres_upscaled_height, cm->seq_params.subsampling_x, |
| 4345 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
| 4346 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4347 | aom_internal_error( |
| 4348 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4349 | "Failed to reallocate scaled source buffer for superres"); |
| 4350 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4351 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4352 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4353 | (int)cm->seq_params.bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4354 | cpi->source = &cpi->scaled_source; |
| 4355 | } |
| 4356 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4357 | |
| 4358 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4359 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4360 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4361 | |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4362 | assert(IMPLIES(is_lossless_requested(&cpi->oxcf), |
| 4363 | cm->coded_lossless && cm->all_lossless)); |
| 4364 | |
| 4365 | const int no_loopfilter = cm->coded_lossless || cm->large_scale_tile; |
| 4366 | const int no_cdef = |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 4367 | !cm->seq_params.enable_cdef || cm->coded_lossless || cm->large_scale_tile; |
| 4368 | const int no_restoration = !cm->seq_params.enable_restoration || |
| 4369 | cm->all_lossless || cm->large_scale_tile; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4370 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4371 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4372 | |
| 4373 | if (no_loopfilter) { |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4374 | lf->filter_level[0] = 0; |
| 4375 | lf->filter_level[1] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4376 | } else { |
| 4377 | struct aom_usec_timer timer; |
| 4378 | |
| 4379 | aom_clear_system_state(); |
| 4380 | |
| 4381 | aom_usec_timer_start(&timer); |
| 4382 | |
| 4383 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4384 | |
| 4385 | aom_usec_timer_mark(&timer); |
| 4386 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4387 | } |
| 4388 | |
Debargha Mukherjee | 2382b14 | 2018-02-26 14:31:32 -0800 | [diff] [blame] | 4389 | if (lf->filter_level[0] || lf->filter_level[1]) { |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 4390 | if (cpi->num_workers > 1) |
| 4391 | av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd, 0, num_planes, 0, |
Cheng Chen | e3600cd | 2018-09-21 18:45:42 -0700 | [diff] [blame] | 4392 | #if LOOP_FILTER_BITMASK |
| 4393 | 0, |
| 4394 | #endif |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 4395 | cpi->workers, cpi->num_workers, |
| 4396 | &cpi->lf_row_sync); |
| 4397 | else |
Cheng Chen | 84b0993 | 2018-08-12 17:35:13 -0700 | [diff] [blame] | 4398 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, |
| 4399 | #if LOOP_FILTER_BITMASK |
| 4400 | 0, |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 4401 | #endif |
Cheng Chen | 84b0993 | 2018-08-12 17:35:13 -0700 | [diff] [blame] | 4402 | 0, num_planes, 0); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4403 | } |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4404 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4405 | if (!no_restoration) |
| 4406 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4407 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4408 | if (no_cdef) { |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4409 | cm->cdef_info.cdef_bits = 0; |
| 4410 | cm->cdef_info.cdef_strengths[0] = 0; |
| 4411 | cm->cdef_info.nb_cdef_strengths = 1; |
| 4412 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4413 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4414 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4415 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
Debargha Mukherjee | d7338aa | 2017-11-04 07:34:50 -0700 | [diff] [blame] | 4416 | cpi->sf.fast_cdef_search); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4417 | |
| 4418 | // Apply the filter |
| 4419 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4420 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4421 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4422 | superres_post_encode(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4423 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4424 | if (no_restoration) { |
| 4425 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4426 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4427 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
| 4428 | } else { |
| 4429 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1); |
| 4430 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4431 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4432 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4433 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4434 | if (cpi->num_workers > 1) |
| 4435 | av1_loop_restoration_filter_frame_mt(cm->frame_to_show, cm, 0, |
| 4436 | cpi->workers, cpi->num_workers, |
| 4437 | &cpi->lr_row_sync, &cpi->lr_ctxt); |
| 4438 | else |
| 4439 | av1_loop_restoration_filter_frame(cm->frame_to_show, cm, 0, |
| 4440 | &cpi->lr_ctxt); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4441 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4442 | } |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4443 | } |
| 4444 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4445 | static int encode_without_recode_loop(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4446 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4447 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 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 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4451 | set_size_independent_vars(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4452 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4453 | setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4454 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4455 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4456 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4457 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4458 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4459 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4460 | cpi->source = |
| 4461 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4462 | if (cpi->unscaled_last_source != NULL) |
| 4463 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4464 | &cpi->scaled_last_source); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4465 | cpi->source->buf_8bit_valid = 0; |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4466 | if (frame_is_intra_only(cm) == 0) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4467 | scale_references(cpi); |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4470 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4471 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4472 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4473 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4474 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4475 | // exclusive. |
| 4476 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4477 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4478 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4479 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4480 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4481 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4482 | } |
| 4483 | apply_active_map(cpi); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4484 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4485 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4486 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 4487 | } else { |
| 4488 | calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4489 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4490 | } else { |
| 4491 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4492 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4493 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4494 | |
| 4495 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4496 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4497 | |
| 4498 | // Update some stats from cyclic refresh, and check if we should not update |
| 4499 | // golden reference, for 1 pass CBR. |
| 4500 | 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] | 4501 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4502 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4503 | |
| 4504 | // Update the skip mb flag probabilities based on the distribution |
| 4505 | // seen in the last encoder iteration. |
| 4506 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4507 | aom_clear_system_state(); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4508 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4511 | 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] | 4512 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4513 | RATE_CONTROL *const rc = &cpi->rc; |
| 4514 | int bottom_index, top_index; |
| 4515 | int loop_count = 0; |
| 4516 | int loop_at_this_size = 0; |
| 4517 | int loop = 0; |
| 4518 | int overshoot_seen = 0; |
| 4519 | int undershoot_seen = 0; |
| 4520 | int frame_over_shoot_limit; |
| 4521 | int frame_under_shoot_limit; |
| 4522 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4523 | |
| 4524 | set_size_independent_vars(cpi); |
| 4525 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4526 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4527 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4528 | aom_clear_system_state(); |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 4529 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4530 | setup_frame_size(cpi); |
| 4531 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4532 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4533 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4534 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4535 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4536 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4537 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4538 | set_mv_search_params(cpi); |
| 4539 | |
| 4540 | // Reset the loop state for new frame size. |
| 4541 | overshoot_seen = 0; |
| 4542 | undershoot_seen = 0; |
| 4543 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4544 | q_low = bottom_index; |
| 4545 | q_high = top_index; |
| 4546 | |
| 4547 | loop_at_this_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4548 | |
Urvang Joshi | 2a74cf2 | 2017-12-18 17:21:41 -0800 | [diff] [blame] | 4549 | // Decide frame size bounds first time through. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4550 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4551 | &frame_under_shoot_limit, |
| 4552 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4553 | } |
| 4554 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4555 | // if frame was scaled calculate global_motion_search again if already |
| 4556 | // done |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4557 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) |
| 4558 | if (cpi->source->y_crop_width != cm->width || |
| 4559 | cpi->source->y_crop_height != cm->height) |
| 4560 | cpi->global_motion_search_done = 0; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4561 | cpi->source = |
| 4562 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4563 | if (cpi->unscaled_last_source != NULL) |
| 4564 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4565 | &cpi->scaled_last_source); |
| 4566 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4567 | if (frame_is_intra_only(cm) == 0) { |
| 4568 | if (loop_count > 0) { |
| 4569 | release_scaled_references(cpi); |
| 4570 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4571 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4572 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4573 | av1_set_quantizer(cm, q); |
Yaowu Xu | 2e58723 | 2018-05-10 09:30:08 -0700 | [diff] [blame] | 4574 | // printf("Frame %d/%d: q = %d, frame_type = %d\n", cm->current_video_frame, |
| 4575 | // cm->show_frame, q, cm->frame_type); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4576 | |
| 4577 | if (loop_count == 0) setup_frame(cpi); |
| 4578 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4579 | // Base q-index may have changed, so we need to assign proper default coef |
| 4580 | // probs before every iteration. |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 4581 | if (cm->primary_ref_frame == PRIMARY_REF_NONE || |
| 4582 | cm->frame_refs[cm->primary_ref_frame].idx < 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4583 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 4584 | av1_setup_frame_contexts(cm); |
David Barker | fc91b39 | 2018-03-09 15:32:03 +0000 | [diff] [blame] | 4585 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4586 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4587 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4588 | // exclusive. |
| 4589 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4590 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4591 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4592 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4593 | } |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4594 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4595 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4596 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 4597 | } else { |
| 4598 | calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4599 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4600 | } else { |
| 4601 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4602 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4603 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4604 | |
| 4605 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4606 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4607 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4608 | |
| 4609 | // Update the skip mb flag probabilities based on the distribution |
| 4610 | // seen in the last encoder iteration. |
| 4611 | // update_base_skip_probs(cpi); |
| 4612 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4613 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4614 | |
| 4615 | // Dummy pack of the bitstream using up to date stats to get an |
| 4616 | // accurate estimate of output frame size to determine if we need |
| 4617 | // to recode. |
| 4618 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4619 | restore_coding_context(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4620 | |
| 4621 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 4622 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4623 | |
| 4624 | rc->projected_frame_size = (int)(*size) << 3; |
| 4625 | restore_coding_context(cpi); |
| 4626 | |
| 4627 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4628 | } |
| 4629 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4630 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4631 | loop = 0; |
| 4632 | } else { |
| 4633 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4634 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4635 | int last_q = q; |
| 4636 | int64_t kf_err; |
| 4637 | |
| 4638 | int64_t high_err_target = cpi->ambient_err; |
| 4639 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4640 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4641 | if (cm->seq_params.use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4642 | 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] | 4643 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4644 | 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] | 4645 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4646 | // Prevent possible divide by zero error below for perfect KF |
| 4647 | kf_err += !kf_err; |
| 4648 | |
| 4649 | // The key frame is not good enough or we can afford |
| 4650 | // to make it better without undue risk of popping. |
| 4651 | if ((kf_err > high_err_target && |
| 4652 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4653 | (kf_err > low_err_target && |
| 4654 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4655 | // Lower q_high |
| 4656 | q_high = q > q_low ? q - 1 : q_low; |
| 4657 | |
| 4658 | // Adjust Q |
| 4659 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4660 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4661 | } else if (kf_err < low_err_target && |
| 4662 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4663 | // The key frame is much better than the previous frame |
| 4664 | // Raise q_low |
| 4665 | q_low = q < q_high ? q + 1 : q_high; |
| 4666 | |
| 4667 | // Adjust Q |
| 4668 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4669 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | // Clamp Q to upper and lower limits: |
| 4673 | q = clamp(q, q_low, q_high); |
| 4674 | |
| 4675 | loop = q != last_q; |
| 4676 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4677 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4678 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4679 | // Is the projected frame size out of range and are we allowed |
| 4680 | // to attempt to recode. |
| 4681 | int last_q = q; |
| 4682 | int retries = 0; |
| 4683 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4684 | // Frame size out of permitted range: |
| 4685 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4686 | // Frame is too large |
| 4687 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4688 | // Special case if the projected size is > the max allowed. |
| 4689 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4690 | q_high = rc->worst_quality; |
| 4691 | |
| 4692 | // Raise Qlow as to at least the current value |
| 4693 | q_low = q < q_high ? q + 1 : q_high; |
| 4694 | |
| 4695 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4696 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4697 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4698 | |
| 4699 | q = (q_high + q_low + 1) / 2; |
| 4700 | } else { |
| 4701 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4702 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4703 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4704 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4705 | AOMMAX(q_high, top_index), cm->width, |
| 4706 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4707 | |
| 4708 | while (q < q_low && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4709 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4710 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4711 | AOMMAX(q_high, top_index), cm->width, |
| 4712 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4713 | retries++; |
| 4714 | } |
| 4715 | } |
| 4716 | |
| 4717 | overshoot_seen = 1; |
| 4718 | } else { |
| 4719 | // Frame is too small |
| 4720 | q_high = q > q_low ? q - 1 : q_low; |
| 4721 | |
| 4722 | if (overshoot_seen || loop_at_this_size > 1) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4723 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4724 | q = (q_high + q_low) / 2; |
| 4725 | } else { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4726 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4727 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4728 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4729 | // Special case reset for qlow for constrained quality. |
| 4730 | // This should only trigger where there is very substantial |
| 4731 | // undershoot on a frame and the auto cq level is above |
| 4732 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4733 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4734 | q_low = q; |
| 4735 | } |
| 4736 | |
| 4737 | while (q > q_high && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4738 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4739 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4740 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4741 | retries++; |
| 4742 | } |
| 4743 | } |
| 4744 | |
| 4745 | undershoot_seen = 1; |
| 4746 | } |
| 4747 | |
| 4748 | // Clamp Q to upper and lower limits: |
| 4749 | q = clamp(q, q_low, q_high); |
| 4750 | |
| 4751 | loop = (q != last_q); |
| 4752 | } else { |
| 4753 | loop = 0; |
| 4754 | } |
| 4755 | } |
| 4756 | |
| 4757 | // Special case for overlay frame. |
| 4758 | if (rc->is_src_frame_alt_ref && |
| 4759 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4760 | loop = 0; |
| 4761 | |
Debargha Mukherjee | 79853eb | 2018-09-13 17:38:02 -0700 | [diff] [blame] | 4762 | if (!cpi->sf.gm_disable_recode) { |
| 4763 | if (recode_loop_test_global_motion(cpi)) loop = 1; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4764 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4765 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4766 | if (loop) { |
| 4767 | ++loop_count; |
| 4768 | ++loop_at_this_size; |
| 4769 | |
| 4770 | #if CONFIG_INTERNAL_STATS |
| 4771 | ++cpi->tot_recode_hits; |
| 4772 | #endif |
| 4773 | } |
| 4774 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4775 | |
| 4776 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4779 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4780 | const int *const map = cpi->common.ref_frame_map; |
| 4781 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4782 | // No.1 Priority: LAST_FRAME |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4783 | const int last2_is_last = |
| 4784 | map[cpi->remapped_ref_idx[1]] == map[cpi->remapped_ref_idx[0]]; |
| 4785 | const int last3_is_last = |
| 4786 | map[cpi->remapped_ref_idx[2]] == map[cpi->remapped_ref_idx[0]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4787 | const int gld_is_last = map[get_ref_frame_map_idx(cpi, GOLDEN_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4788 | map[cpi->remapped_ref_idx[0]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4789 | const int bwd_is_last = map[get_ref_frame_map_idx(cpi, BWDREF_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4790 | map[cpi->remapped_ref_idx[0]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4791 | const int alt2_is_last = map[get_ref_frame_map_idx(cpi, ALTREF2_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4792 | map[cpi->remapped_ref_idx[0]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4793 | const int alt_is_last = map[get_ref_frame_map_idx(cpi, ALTREF_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4794 | map[cpi->remapped_ref_idx[0]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4795 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4796 | // No.2 Priority: ALTREF_FRAME |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4797 | const int last2_is_alt = map[cpi->remapped_ref_idx[1]] == |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4798 | map[get_ref_frame_map_idx(cpi, ALTREF_FRAME)]; |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4799 | const int last3_is_alt = map[cpi->remapped_ref_idx[2]] == |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4800 | map[get_ref_frame_map_idx(cpi, ALTREF_FRAME)]; |
| 4801 | const int gld_is_alt = map[get_ref_frame_map_idx(cpi, GOLDEN_FRAME)] == |
| 4802 | map[get_ref_frame_map_idx(cpi, ALTREF_FRAME)]; |
| 4803 | const int bwd_is_alt = map[get_ref_frame_map_idx(cpi, BWDREF_FRAME)] == |
| 4804 | map[get_ref_frame_map_idx(cpi, ALTREF_FRAME)]; |
| 4805 | const int alt2_is_alt = map[get_ref_frame_map_idx(cpi, ALTREF2_FRAME)] == |
| 4806 | map[get_ref_frame_map_idx(cpi, ALTREF_FRAME)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4807 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4808 | // No.3 Priority: LAST2_FRAME |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4809 | const int last3_is_last2 = |
| 4810 | map[cpi->remapped_ref_idx[2]] == map[cpi->remapped_ref_idx[1]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4811 | const int gld_is_last2 = map[get_ref_frame_map_idx(cpi, GOLDEN_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4812 | map[cpi->remapped_ref_idx[1]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4813 | const int bwd_is_last2 = map[get_ref_frame_map_idx(cpi, BWDREF_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4814 | map[cpi->remapped_ref_idx[1]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4815 | const int alt2_is_last2 = map[get_ref_frame_map_idx(cpi, ALTREF2_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4816 | map[cpi->remapped_ref_idx[1]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4817 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4818 | // No.4 Priority: LAST3_FRAME |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4819 | const int gld_is_last3 = map[get_ref_frame_map_idx(cpi, GOLDEN_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4820 | map[cpi->remapped_ref_idx[2]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4821 | const int bwd_is_last3 = map[get_ref_frame_map_idx(cpi, BWDREF_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4822 | map[cpi->remapped_ref_idx[2]]; |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4823 | const int alt2_is_last3 = map[get_ref_frame_map_idx(cpi, ALTREF2_FRAME)] == |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 4824 | map[cpi->remapped_ref_idx[2]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4825 | |
| 4826 | // No.5 Priority: GOLDEN_FRAME |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4827 | const int bwd_is_gld = map[get_ref_frame_map_idx(cpi, BWDREF_FRAME)] == |
| 4828 | map[get_ref_frame_map_idx(cpi, GOLDEN_FRAME)]; |
| 4829 | const int alt2_is_gld = map[get_ref_frame_map_idx(cpi, ALTREF2_FRAME)] == |
| 4830 | map[get_ref_frame_map_idx(cpi, GOLDEN_FRAME)]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4831 | |
| 4832 | // No.6 Priority: BWDREF_FRAME |
Urvang Joshi | 3958582 | 2018-11-07 17:47:32 -0800 | [diff] [blame] | 4833 | const int alt2_is_bwd = map[get_ref_frame_map_idx(cpi, ALTREF2_FRAME)] == |
| 4834 | map[get_ref_frame_map_idx(cpi, BWDREF_FRAME)]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4835 | |
| 4836 | // No.7 Priority: ALTREF2_FRAME |
| 4837 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 4838 | // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be |
| 4839 | // adjusted according to external encoder flags. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 4840 | int flags = cpi->ext_ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4841 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4842 | 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] | 4843 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4844 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4845 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4846 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4847 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4848 | 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] | 4849 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4850 | if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3) |
| 4851 | flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4852 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4853 | if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 || |
| 4854 | bwd_is_gld) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4855 | (flags & AOM_BWD_FLAG)) |
| 4856 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4857 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4858 | if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 || |
| 4859 | alt2_is_gld || alt2_is_bwd) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4860 | (flags & AOM_ALT2_FLAG)) |
| 4861 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4862 | |
| 4863 | return flags; |
| 4864 | } |
| 4865 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4866 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4867 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4868 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4869 | // Note: The overrides are valid only for the next frame passed |
| 4870 | // to encode_frame_to_data_rate() function |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4871 | if (cpi->ext_use_s_frame) cpi->common.frame_type = S_FRAME; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 4872 | cpi->common.force_primary_ref_none = cpi->ext_use_primary_ref_none; |
Debargha Mukherjee | 52fb047 | 2018-03-29 15:48:11 -0700 | [diff] [blame] | 4873 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4874 | if (cpi->ext_refresh_frame_context_pending) { |
| 4875 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 4876 | cpi->ext_refresh_frame_context_pending = 0; |
| 4877 | } |
| 4878 | if (cpi->ext_refresh_frame_flags_pending) { |
| 4879 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 4880 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 4881 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 4882 | cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame; |
| 4883 | cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4884 | cpi->ext_refresh_frame_flags_pending = 0; |
| 4885 | } |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4886 | cpi->common.allow_ref_frame_mvs = cpi->ext_use_ref_frame_mvs; |
Sarah Parker | 14feea4 | 2018-07-06 16:41:41 -0700 | [diff] [blame] | 4887 | // A keyframe is already error resilient and keyframes with |
| 4888 | // error_resilient_mode interferes with the use of show_existing_frame |
| 4889 | // when forward reference keyframes are enabled. |
| 4890 | cpi->common.error_resilient_mode = |
| 4891 | cpi->ext_use_error_resilient && cpi->common.frame_type != KEY_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4892 | } |
| 4893 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4894 | #define DUMP_RECON_FRAMES 0 |
| 4895 | |
| 4896 | #if DUMP_RECON_FRAMES == 1 |
| 4897 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4898 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4899 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4900 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4901 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4902 | if (recon_buf == NULL) { |
| 4903 | printf("Frame %d is not ready.\n", cm->current_video_frame); |
| 4904 | return; |
| 4905 | } |
| 4906 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 4907 | static const int flag_list[REF_FRAMES] = { 0, |
| 4908 | AOM_LAST_FLAG, |
| 4909 | AOM_LAST2_FLAG, |
| 4910 | AOM_LAST3_FLAG, |
| 4911 | AOM_GOLD_FLAG, |
| 4912 | AOM_BWD_FLAG, |
| 4913 | AOM_ALT2_FLAG, |
| 4914 | AOM_ALT_FLAG }; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4915 | printf( |
| 4916 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 4917 | "show_existing_frame=%d) " |
| 4918 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
| 4919 | cm->current_video_frame, cm->frame_offset, cm->show_frame, |
| 4920 | cm->show_existing_frame); |
| 4921 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4922 | const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 4923 | const int ref_offset = |
| 4924 | (buf_idx >= 0) |
| 4925 | ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset |
| 4926 | : -1; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 4927 | printf( |
| 4928 | " %d(%c-%d-%4.2f)", ref_offset, |
| 4929 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N', |
| 4930 | (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1, |
| 4931 | (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] | 4932 | } |
| 4933 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4934 | |
| 4935 | if (!cm->show_frame) { |
| 4936 | 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] | 4937 | cm->current_video_frame); |
| 4938 | return; |
| 4939 | } |
| 4940 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4941 | int h; |
| 4942 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4943 | FILE *f_recon = NULL; |
| 4944 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4945 | if (cm->current_video_frame == 0) { |
| 4946 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4947 | printf("Unable to open file %s to write.\n", file_name); |
| 4948 | return; |
| 4949 | } |
| 4950 | } else { |
| 4951 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4952 | printf("Unable to open file %s to append.\n", file_name); |
| 4953 | return; |
| 4954 | } |
| 4955 | } |
| 4956 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4957 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 4958 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
| 4959 | "refresh_alt_ref_frame=%d, rf_level=%d, " |
| 4960 | "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] | 4961 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 4962 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4963 | cm->frame_offset, cm->show_frame, cm->show_existing_frame, |
| 4964 | cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame, |
| 4965 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 4966 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4967 | #if 0 |
| 4968 | int ref_frame; |
| 4969 | printf("get_ref_frame_map_idx: ["); |
| 4970 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 4971 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 4972 | printf(" ]\n"); |
| 4973 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 4974 | printf("cm->ref_frame_map = ["); |
| 4975 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4976 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 4977 | } |
| 4978 | printf(" ]\n"); |
| 4979 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4980 | |
| 4981 | // --- Y --- |
| 4982 | for (h = 0; h < cm->height; ++h) { |
| 4983 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4984 | f_recon); |
| 4985 | } |
| 4986 | // --- U --- |
| 4987 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4988 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4989 | f_recon); |
| 4990 | } |
| 4991 | // --- V --- |
| 4992 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4993 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4994 | f_recon); |
| 4995 | } |
| 4996 | |
| 4997 | fclose(f_recon); |
| 4998 | } |
| 4999 | #endif // DUMP_RECON_FRAMES |
| 5000 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 5001 | static INLINE int is_frame_droppable(AV1_COMP *cpi) { |
| 5002 | return !(cpi->refresh_alt_ref_frame || cpi->refresh_alt2_ref_frame || |
| 5003 | cpi->refresh_bwd_ref_frame || cpi->refresh_golden_frame || |
| 5004 | cpi->refresh_last_frame); |
| 5005 | } |
| 5006 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5007 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5008 | int skip_adapt, |
| 5009 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5010 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5011 | SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5012 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5013 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5014 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5015 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5016 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5017 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5018 | // frame type has been decided outside of this function call |
Zoe Liu | d78ce2d | 2018-02-24 05:50:57 -0800 | [diff] [blame] | 5019 | cm->cur_frame->intra_only = frame_is_intra_only(cm); |
Zoe Liu | 2723a9d | 2018-02-22 20:17:00 -0800 | [diff] [blame] | 5020 | cm->cur_frame->frame_type = cm->frame_type; |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 5021 | |
| 5022 | // S_FRAMEs are always error resilient |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5023 | cm->error_resilient_mode |= frame_is_sframe(cm); |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 5024 | |
| 5025 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 5026 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5027 | 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] | 5028 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5029 | cm->allow_ref_frame_mvs &= frame_might_allow_ref_frame_mvs(cm); |
Yunqing Wang | d48fb16 | 2018-06-15 10:55:28 -0700 | [diff] [blame] | 5030 | // cm->allow_ref_frame_mvs needs to be written into the frame header while |
| 5031 | // cm->large_scale_tile is 1, therefore, "cm->large_scale_tile=1" case is |
| 5032 | // separated from frame_might_allow_ref_frame_mvs(). |
| 5033 | cm->allow_ref_frame_mvs &= !cm->large_scale_tile; |
| 5034 | |
Debargha Mukherjee | 1d7217e | 2018-03-26 13:32:13 -0700 | [diff] [blame] | 5035 | cm->allow_warped_motion = |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 5036 | cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5037 | |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 5038 | // Reset the frame packet stamp index. |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5039 | if (cm->frame_type == KEY_FRAME && cm->show_frame) |
| 5040 | cm->current_video_frame = 0; |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 5041 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5042 | // NOTE: |
| 5043 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 5044 | // determined by the current frame properties; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5045 | // (2) The setup of the ref_frame_flags applies to both |
| 5046 | // show_existing_frame's |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5047 | // and the other cases. |
| 5048 | if (cm->current_video_frame > 0) |
| 5049 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5050 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 5051 | if (encode_show_existing_frame(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5052 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 5053 | // BWDREF_FRAME in the reference frame buffer. |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5054 | if (cm->frame_type == KEY_FRAME) { |
| 5055 | cm->reset_decoder_state = 1; |
| 5056 | } else { |
| 5057 | cm->frame_type = INTER_FRAME; |
| 5058 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5059 | cm->show_frame = 1; |
| 5060 | cpi->frame_flags = *frame_flags; |
| 5061 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 5062 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5063 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5064 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5065 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 5066 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5067 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5068 | cpi->seq_params_locked = 1; |
| 5069 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5070 | // Set up frame to show to get ready for stats collection. |
| 5071 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5072 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5073 | // Update current frame offset. |
| 5074 | cm->frame_offset = |
| 5075 | cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5076 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5077 | #if DUMP_RECON_FRAMES == 1 |
| 5078 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5079 | dump_filtered_recon_frames(cpi); |
| 5080 | #endif // DUMP_RECON_FRAMES |
| 5081 | |
| 5082 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5083 | // NOTE: |
| 5084 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 5085 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 5086 | // right before BWDREF_FRAME (in the display order); |
| 5087 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5088 | // update will be done when the following is called, which will |
| 5089 | // exchange |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5090 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5091 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, |
| 5092 | // and |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5093 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5094 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5095 | |
| 5096 | // Update frame flags |
| 5097 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5098 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5099 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5100 | |
| 5101 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5102 | |
| 5103 | // Update the frame type |
| 5104 | cm->last_frame_type = cm->frame_type; |
| 5105 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5106 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 5107 | // to do post-encoding update accordingly. |
| 5108 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5109 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5110 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5111 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5112 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5113 | ++cm->current_video_frame; |
| 5114 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5115 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5116 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5117 | |
| 5118 | // Set default state for segment based loop filter update flags. |
| 5119 | cm->lf.mode_ref_delta_update = 0; |
| 5120 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5121 | // 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] | 5122 | if (frame_is_intra_only(cm) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5123 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5124 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5125 | |
| 5126 | // If segmentation is enabled force a map update for key frames. |
| 5127 | if (seg->enabled) { |
| 5128 | seg->update_map = 1; |
| 5129 | seg->update_data = 1; |
| 5130 | } |
| 5131 | |
| 5132 | // The alternate reference frame cannot be active for a key frame. |
| 5133 | cpi->rc.source_alt_ref_active = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5134 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5135 | if (cpi->oxcf.mtu == 0) { |
| 5136 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 5137 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 5138 | // Use a default value for the purposes of weighting costs in probability |
| 5139 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5140 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 5141 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5142 | |
| 5143 | // For 1 pass CBR, check if we are dropping this frame. |
| 5144 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5145 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5146 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5147 | if (av1_rc_drop_frame(cpi)) { |
| 5148 | av1_rc_postencode_update_drop_frame(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5149 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5150 | } |
| 5151 | } |
| 5152 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5153 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5154 | |
| 5155 | #if CONFIG_INTERNAL_STATS |
| 5156 | memset(cpi->mode_chosen_counts, 0, |
| 5157 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 5158 | #endif |
| 5159 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5160 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5161 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 5162 | * wraparound) */ |
Sebastien Alaiwan | d418f68 | 2017-10-19 15:06:52 +0200 | [diff] [blame] | 5163 | const int frame_id_length = FRAME_ID_LENGTH; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5164 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5165 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5166 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5167 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5168 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 5169 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5170 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5171 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5172 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5173 | } |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5174 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 5175 | |
| 5176 | // S_frame is meant for stitching different streams of different |
| 5177 | // resolutions together, so current_frame_id must be the |
| 5178 | // same across different streams of the same content current_frame_id |
| 5179 | // should be the same and not random. 0x37 is a chosen number as start |
| 5180 | // point |
| 5181 | if (cpi->oxcf.sframe_enabled) cm->current_frame_id = 0x37; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5182 | } else { |
| 5183 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5184 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 5185 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5186 | } |
| 5187 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5188 | |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5189 | switch (cpi->oxcf.cdf_update_mode) { |
| 5190 | case 0: // No CDF update for any frames(4~6% compression loss). |
| 5191 | cm->disable_cdf_update = 1; |
| 5192 | break; |
| 5193 | case 1: // Enable CDF update for all frames. |
| 5194 | cm->disable_cdf_update = 0; |
| 5195 | break; |
| 5196 | case 2: |
| 5197 | // Strategically determine at which frames to do CDF update. |
| 5198 | // Currently only enable CDF update for all-intra and no-show frames(1.5% |
| 5199 | // compression loss). |
| 5200 | // TODO(huisu@google.com): design schemes for various trade-offs between |
| 5201 | // compression quality and decoding speed. |
Hui Su | b1b76b3 | 2018-02-27 15:24:48 -0800 | [diff] [blame] | 5202 | cm->disable_cdf_update = |
| 5203 | (frame_is_intra_only(cm) || !cm->show_frame) ? 0 : 1; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5204 | break; |
| 5205 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5206 | cm->timing_info_present &= !seq_params->reduced_still_picture_hdr; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5207 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5208 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5209 | 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] | 5210 | } else { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5211 | if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK) |
| 5212 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5215 | cm->last_tile_cols = cm->tile_cols; |
| 5216 | cm->last_tile_rows = cm->tile_rows; |
| 5217 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5218 | #ifdef OUTPUT_YUV_SKINMAP |
| 5219 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5220 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5221 | } |
| 5222 | #endif // OUTPUT_YUV_SKINMAP |
| 5223 | |
| 5224 | // Special case code to reduce pulsing when key frames are forced at a |
| 5225 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5226 | // the force key frame |
| 5227 | 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] | 5228 | if (seq_params->use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5229 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5230 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5231 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5232 | 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] | 5233 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5234 | } |
| 5235 | |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 5236 | // 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] | 5237 | 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] | 5238 | cpi->refresh_last_frame = 1; |
| 5239 | } |
| 5240 | |
| 5241 | cm->frame_to_show = get_frame_new_buffer(cm); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5242 | cm->frame_to_show->color_primaries = seq_params->color_primaries; |
| 5243 | cm->frame_to_show->transfer_characteristics = |
| 5244 | seq_params->transfer_characteristics; |
| 5245 | cm->frame_to_show->matrix_coefficients = seq_params->matrix_coefficients; |
| 5246 | cm->frame_to_show->monochrome = seq_params->monochrome; |
| 5247 | cm->frame_to_show->chroma_sample_position = |
| 5248 | seq_params->chroma_sample_position; |
| 5249 | cm->frame_to_show->color_range = seq_params->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5250 | cm->frame_to_show->render_width = cm->render_width; |
| 5251 | cm->frame_to_show->render_height = cm->render_height; |
| 5252 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5253 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5254 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5255 | |
| 5256 | // Pick the loop filter level for the frame. |
Cheng Chen | 68dc914 | 2018-05-02 17:46:28 -0700 | [diff] [blame] | 5257 | if (!cm->allow_intrabc) { |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5258 | loopfilter_frame(cpi, cm); |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5259 | } else { |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5260 | cm->lf.filter_level[0] = 0; |
| 5261 | cm->lf.filter_level[1] = 0; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5262 | cm->cdef_info.cdef_bits = 0; |
| 5263 | cm->cdef_info.cdef_strengths[0] = 0; |
| 5264 | cm->cdef_info.nb_cdef_strengths = 1; |
| 5265 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5266 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5267 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5268 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5269 | } |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5270 | |
| 5271 | // TODO(debargha): Fix mv search range on encoder side |
| 5272 | // aom_extend_frame_inner_borders(cm->frame_to_show, av1_num_planes(cm)); |
| 5273 | aom_extend_frame_borders(cm->frame_to_show, av1_num_planes(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5274 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5275 | #ifdef OUTPUT_YUV_REC |
| 5276 | aom_write_one_yuv_frame(cm, cm->frame_to_show); |
| 5277 | #endif |
| 5278 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5279 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5280 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 5281 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5282 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5283 | cpi->seq_params_locked = 1; |
| 5284 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5285 | if (skip_adapt) return AOM_CODEC_OK; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5286 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5287 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5288 | int i; |
Zoe Liu | 630a89f | 2018-04-16 09:36:50 -0700 | [diff] [blame] | 5289 | // 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] | 5290 | for (i = 0; i < REF_FRAMES; i++) { |
Zoe Liu | 630a89f | 2018-04-16 09:36:50 -0700 | [diff] [blame] | 5291 | if ((cpi->refresh_frame_mask >> i) & 1) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5292 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5293 | } |
| 5294 | } |
| 5295 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5296 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5297 | #if DUMP_RECON_FRAMES == 1 |
| 5298 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5299 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5300 | #endif // DUMP_RECON_FRAMES |
| 5301 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5302 | if (cm->seg.enabled) { |
| 5303 | if (cm->seg.update_map) { |
| 5304 | update_reference_segmentation_map(cpi); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 5305 | } else if (cm->last_frame_seg_map) { |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5306 | memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map, |
| 5307 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 5308 | } |
| 5309 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5310 | |
| 5311 | if (frame_is_intra_only(cm) == 0) { |
| 5312 | release_scaled_references(cpi); |
| 5313 | } |
| 5314 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5315 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5316 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5317 | #if CONFIG_ENTROPY_STATS |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 5318 | av1_accumulate_frame_counts(&aggregate_fc, &cpi->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5319 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5320 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5321 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
| 5322 | *cm->fc = cpi->tile_data[cm->largest_tile_id].tctx; |
| 5323 | av1_reset_cdf_symbol_counters(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | if (cpi->refresh_golden_frame == 1) |
| 5327 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 5328 | else |
| 5329 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5330 | |
| 5331 | if (cpi->refresh_alt_ref_frame == 1) |
| 5332 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 5333 | else |
| 5334 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5335 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5336 | if (cpi->refresh_bwd_ref_frame == 1) |
| 5337 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5338 | else |
| 5339 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5340 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5341 | cm->last_frame_type = cm->frame_type; |
| 5342 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5343 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5344 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5345 | if (cm->frame_type == KEY_FRAME) { |
| 5346 | // Tell the caller that the frame was coded as a key frame |
| 5347 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5348 | } else { |
| 5349 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5350 | } |
| 5351 | |
| 5352 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5353 | // filter deltas. |
| 5354 | cm->seg.update_map = 0; |
| 5355 | cm->seg.update_data = 0; |
| 5356 | cm->lf.mode_ref_delta_update = 0; |
| 5357 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 5358 | // A droppable frame might not be shown but it always |
| 5359 | // takes a space in the gf group. Therefore, even when |
| 5360 | // it is not shown, we still need update the count down. |
| 5361 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5362 | if (cm->show_frame) { |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5363 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that |
| 5364 | // are |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5365 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5366 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5367 | // Don't increment frame counters if this was an altref buffer |
| 5368 | // update not a real frame |
Wei-Ting Lin | 96ee0eb | 2018-06-22 15:27:22 -0700 | [diff] [blame] | 5369 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5370 | ++cm->current_video_frame; |
| 5371 | } |
| 5372 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5373 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5374 | if (cm->is_reference_frame) { |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5375 | // keep track of the last coded dimensions |
| 5376 | cm->last_width = cm->width; |
| 5377 | cm->last_height = cm->height; |
| 5378 | |
| 5379 | // reset to normal state now that we are done. |
| 5380 | cm->last_show_frame = cm->show_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5381 | } |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5382 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5383 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5384 | } |
| 5385 | |
Sarah Parker | 3491dd2 | 2018-08-08 18:38:31 -0700 | [diff] [blame] | 5386 | static INLINE void update_keyframe_counters(AV1_COMP *cpi) { |
| 5387 | // TODO(zoeliu): To investigate whether we should treat BWDREF_FRAME |
| 5388 | // differently here for rc->avg_frame_bandwidth. |
| 5389 | if (cpi->common.show_frame || cpi->rc.is_bwd_ref_frame) { |
| 5390 | if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref || |
| 5391 | cpi->common.frame_type == KEY_FRAME) { |
| 5392 | // If this is a show_existing_frame with a source other than altref, |
| 5393 | // or if it is not a displayed forward keyframe, the keyframe update |
| 5394 | // counters were incremented when it was originally encoded. |
| 5395 | cpi->rc.frames_since_key++; |
| 5396 | cpi->rc.frames_to_key--; |
| 5397 | } |
| 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | static INLINE void update_frames_till_gf_update(AV1_COMP *cpi) { |
| 5402 | // TODO(weitinglin): Updating this counter for is_frame_droppable |
| 5403 | // is a work-around to handle the condition when a frame is drop. |
| 5404 | // We should fix the cpi->common.show_frame flag |
| 5405 | // instead of checking the other condition to update the counter properly. |
| 5406 | if (cpi->common.show_frame || is_frame_droppable(cpi)) { |
| 5407 | // Decrement count down till next gf |
| 5408 | if (cpi->rc.frames_till_gf_update_due > 0) |
| 5409 | cpi->rc.frames_till_gf_update_due--; |
| 5410 | } |
| 5411 | } |
| 5412 | |
| 5413 | static INLINE void update_twopass_gf_group_index(AV1_COMP *cpi) { |
| 5414 | // Increment the gf group index ready for the next frame. If this is |
| 5415 | // a show_existing_frame with a source other than altref, or if it is not |
| 5416 | // a displayed forward keyframe, the index was incremented when it was |
| 5417 | // originally encoded. |
| 5418 | if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref || |
| 5419 | cpi->common.frame_type == KEY_FRAME) { |
| 5420 | ++cpi->twopass.gf_group.index; |
| 5421 | } |
| 5422 | } |
| 5423 | |
| 5424 | static void update_rc_counts(AV1_COMP *cpi) { |
| 5425 | update_keyframe_counters(cpi); |
| 5426 | update_frames_till_gf_update(cpi); |
| 5427 | if (cpi->oxcf.pass == 2) update_twopass_gf_group_index(cpi); |
| 5428 | } |
| 5429 | |
Debargha Mukherjee | 5737825 | 2018-09-21 18:29:37 -0700 | [diff] [blame] | 5430 | static void set_additional_frame_flags(AV1_COMMON *const cm, |
| 5431 | unsigned int *frame_flags) { |
| 5432 | if (frame_is_intra_only(cm)) *frame_flags |= FRAMEFLAGS_INTRAONLY; |
| 5433 | if (frame_is_sframe(cm)) *frame_flags |= FRAMEFLAGS_SWITCH; |
| 5434 | if (cm->error_resilient_mode) *frame_flags |= FRAMEFLAGS_ERROR_RESILIENT; |
| 5435 | } |
| 5436 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5437 | static int Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5438 | int skip_adapt, unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5439 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5440 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5441 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5442 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5443 | } |
Debargha Mukherjee | ff48c09 | 2018-04-04 23:53:40 -0700 | [diff] [blame] | 5444 | if (encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags) != |
| 5445 | AOM_CODEC_OK) { |
| 5446 | return AOM_CODEC_ERROR; |
| 5447 | } |
Debargha Mukherjee | 5737825 | 2018-09-21 18:29:37 -0700 | [diff] [blame] | 5448 | set_additional_frame_flags(&cpi->common, frame_flags); |
| 5449 | |
Sarah Parker | 3491dd2 | 2018-08-08 18:38:31 -0700 | [diff] [blame] | 5450 | update_rc_counts(cpi); |
Debargha Mukherjee | ff48c09 | 2018-04-04 23:53:40 -0700 | [diff] [blame] | 5451 | check_show_existing_frame(cpi); |
| 5452 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5453 | } |
| 5454 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5455 | static int Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5456 | unsigned int *frame_flags) { |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 5457 | #if CONFIG_MISMATCH_DEBUG |
| 5458 | mismatch_move_frame_idx_w(); |
| 5459 | #endif |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 5460 | #if TXCOEFF_COST_TIMER |
| 5461 | AV1_COMMON *cm = &cpi->common; |
| 5462 | cm->txcoeff_cost_timer = 0; |
| 5463 | cm->txcoeff_cost_count = 0; |
| 5464 | #endif |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5465 | |
| 5466 | if (encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags) != |
| 5467 | AOM_CODEC_OK) { |
| 5468 | return AOM_CODEC_ERROR; |
| 5469 | } |
Debargha Mukherjee | 5737825 | 2018-09-21 18:29:37 -0700 | [diff] [blame] | 5470 | set_additional_frame_flags(&cpi->common, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5471 | |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 5472 | #if TXCOEFF_COST_TIMER |
| 5473 | cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer; |
| 5474 | fprintf(stderr, |
| 5475 | "\ntxb coeff cost block number: %ld, frame time: %ld, cum time %ld " |
| 5476 | "in us\n", |
| 5477 | cm->txcoeff_cost_count, cm->txcoeff_cost_timer, |
| 5478 | cm->cum_txcoeff_cost_timer); |
| 5479 | #endif |
| 5480 | |
Sarah Parker | 3491dd2 | 2018-08-08 18:38:31 -0700 | [diff] [blame] | 5481 | av1_twopass_postencode_update(cpi); |
| 5482 | update_rc_counts(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5483 | check_show_existing_frame(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5484 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5485 | } |
| 5486 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5487 | #if CONFIG_DENOISE |
| 5488 | static int apply_denoise_2d(AV1_COMP *cpi, YV12_BUFFER_CONFIG *sd, |
| 5489 | int block_size, float noise_level, |
| 5490 | int64_t time_stamp, int64_t end_time) { |
| 5491 | AV1_COMMON *const cm = &cpi->common; |
| 5492 | if (!cpi->denoise_and_model) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5493 | cpi->denoise_and_model = aom_denoise_and_model_alloc( |
| 5494 | cm->seq_params.bit_depth, block_size, noise_level); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5495 | if (!cpi->denoise_and_model) { |
| 5496 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5497 | "Error allocating denoise and model"); |
| 5498 | return -1; |
| 5499 | } |
| 5500 | } |
| 5501 | if (!cpi->film_grain_table) { |
| 5502 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 5503 | if (!cpi->film_grain_table) { |
| 5504 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5505 | "Error allocating grain table"); |
| 5506 | return -1; |
| 5507 | } |
| 5508 | memset(cpi->film_grain_table, 0, sizeof(*cpi->film_grain_table)); |
| 5509 | } |
| 5510 | if (aom_denoise_and_model_run(cpi->denoise_and_model, sd, |
| 5511 | &cm->film_grain_params)) { |
| 5512 | if (cm->film_grain_params.apply_grain) { |
| 5513 | aom_film_grain_table_append(cpi->film_grain_table, time_stamp, end_time, |
| 5514 | &cm->film_grain_params); |
| 5515 | } |
| 5516 | } |
| 5517 | return 0; |
| 5518 | } |
| 5519 | #endif |
| 5520 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5521 | 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] | 5522 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5523 | int64_t end_time) { |
| 5524 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5525 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5526 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5527 | int res = 0; |
| 5528 | const int subsampling_x = sd->subsampling_x; |
| 5529 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5530 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5531 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5532 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5533 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5534 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5535 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5536 | #if CONFIG_DENOISE |
| 5537 | if (cpi->oxcf.noise_level > 0) |
| 5538 | if (apply_denoise_2d(cpi, sd, cpi->oxcf.noise_block_size, |
| 5539 | cpi->oxcf.noise_level, time_stamp, end_time) < 0) |
| 5540 | res = -1; |
| 5541 | #endif // CONFIG_DENOISE |
| 5542 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5543 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5544 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5545 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5546 | aom_usec_timer_mark(&timer); |
| 5547 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5548 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5549 | if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5550 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5551 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5552 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5553 | res = -1; |
| 5554 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5555 | if ((seq_params->profile == PROFILE_1) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5556 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5557 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5558 | "Profile 1 requires 4:4:4 color format"); |
| 5559 | res = -1; |
| 5560 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5561 | if ((seq_params->profile == PROFILE_2) && |
| 5562 | (seq_params->bit_depth <= AOM_BITS_10) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5563 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 5564 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 5565 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5566 | res = -1; |
| 5567 | } |
| 5568 | |
| 5569 | return res; |
| 5570 | } |
| 5571 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5572 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5573 | const struct lookahead_entry *source) { |
| 5574 | int64_t this_duration; |
| 5575 | int step = 0; |
| 5576 | |
| 5577 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5578 | this_duration = source->ts_end - source->ts_start; |
| 5579 | step = 1; |
| 5580 | } else { |
| 5581 | int64_t last_duration = |
| 5582 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5583 | |
| 5584 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5585 | |
| 5586 | // do a step update if the duration changes by 10% |
| 5587 | if (last_duration) |
| 5588 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5589 | } |
| 5590 | |
| 5591 | if (this_duration) { |
| 5592 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5593 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5594 | } else { |
| 5595 | // Average this frame's rate into the last second's average |
| 5596 | // frame rate. If we haven't seen 1 second yet, then average |
| 5597 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5598 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5599 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5600 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5601 | avg_duration *= (interval - avg_duration + this_duration); |
| 5602 | avg_duration /= interval; |
| 5603 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5604 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5605 | } |
| 5606 | } |
| 5607 | cpi->last_time_stamp_seen = source->ts_start; |
| 5608 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5609 | } |
| 5610 | |
| 5611 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5612 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5613 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5614 | RATE_CONTROL *const rc = &cpi->rc; |
| 5615 | int arf_src_index = 0; |
| 5616 | if (is_altref_enabled(cpi)) { |
| 5617 | if (cpi->oxcf.pass == 2) { |
| 5618 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5619 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5620 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5621 | } |
| 5622 | } else if (rc->source_alt_ref_pending) { |
| 5623 | arf_src_index = rc->frames_till_gf_update_due; |
| 5624 | } |
| 5625 | } |
| 5626 | return arf_src_index; |
| 5627 | } |
| 5628 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5629 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5630 | int brf_src_index = 0; |
| 5631 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5632 | |
| 5633 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5634 | // flag. |
| 5635 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5636 | if (cpi->oxcf.pass == 2) { |
| 5637 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5638 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5639 | } else { |
| 5640 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5641 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | return brf_src_index; |
| 5646 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5647 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5648 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5649 | // used as the arf midpoint. |
| 5650 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5651 | int arf2_src_index = 0; |
| 5652 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5653 | if (cpi->oxcf.pass == 2) { |
| 5654 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5655 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 5656 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5657 | } |
| 5658 | } |
| 5659 | } |
| 5660 | return arf2_src_index; |
| 5661 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5662 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5663 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5664 | const struct lookahead_entry *source) { |
| 5665 | RATE_CONTROL *const rc = &cpi->rc; |
| 5666 | |
| 5667 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5668 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5669 | |
| 5670 | if (cpi->oxcf.pass == 2) { |
| 5671 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5672 | rc->is_src_frame_alt_ref = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5673 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5674 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5675 | rc->is_src_frame_ext_arf = |
| 5676 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5677 | } else { |
| 5678 | rc->is_src_frame_alt_ref = |
| 5679 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5680 | } |
| 5681 | |
| 5682 | if (rc->is_src_frame_alt_ref) { |
| 5683 | // Current frame is an ARF overlay frame. |
| 5684 | cpi->alt_ref_source = NULL; |
| 5685 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5686 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 5687 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 5688 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 5689 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 5690 | cpi->refresh_last_frame = 1; |
| 5691 | } else { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5692 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 5693 | // become the GF so preserve last as an alternative prediction option. |
| 5694 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5695 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5700 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5701 | const unsigned char *img2, int img2_pitch, |
| 5702 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5703 | |
| 5704 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5705 | ImageStat *s) { |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 5706 | s->stat[STAT_Y] += y; |
| 5707 | s->stat[STAT_U] += u; |
| 5708 | s->stat[STAT_V] += v; |
| 5709 | s->stat[STAT_ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5710 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5711 | } |
| 5712 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5713 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5714 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5715 | double samples = 0.0; |
| 5716 | uint32_t in_bit_depth = 8; |
| 5717 | uint32_t bit_depth = 8; |
| 5718 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5719 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 5720 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5721 | #endif |
| 5722 | cpi->bytes += frame_bytes; |
| 5723 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5724 | if (cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5725 | in_bit_depth = cpi->oxcf.input_bit_depth; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5726 | bit_depth = cm->seq_params.bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5727 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5728 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5729 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5730 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 5731 | double y, u, v, frame_all; |
| 5732 | |
| 5733 | cpi->count++; |
| 5734 | if (cpi->b_calculate_psnr) { |
| 5735 | PSNR_STATS psnr; |
| 5736 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5737 | aom_clear_system_state(); |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5738 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5739 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5740 | |
| 5741 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5742 | &cpi->psnr); |
| 5743 | cpi->total_sq_error += psnr.sse[0]; |
| 5744 | cpi->total_samples += psnr.samples[0]; |
| 5745 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5746 | // TODO(yaowu): unify these two versions into one. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5747 | if (cm->seq_params.use_highbitdepth) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5748 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5749 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5750 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5751 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5752 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5753 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5754 | cpi->summed_quality += frame_ssim2 * weight; |
| 5755 | cpi->summed_weights += weight; |
| 5756 | |
| 5757 | #if 0 |
| 5758 | { |
| 5759 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 5760 | double y2 = psnr.psnr[1]; |
| 5761 | double u2 = psnr.psnr[2]; |
| 5762 | double v2 = psnr.psnr[3]; |
| 5763 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5764 | 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] | 5765 | cm->current_video_frame, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5766 | frame_psnr2, frame_ssim2); |
| 5767 | fclose(f); |
| 5768 | } |
| 5769 | #endif |
| 5770 | } |
| 5771 | if (cpi->b_calculate_blockiness) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5772 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5773 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5774 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5775 | recon->y_stride, orig->y_width, orig->y_height); |
| 5776 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5777 | cpi->total_blockiness += frame_blockiness; |
| 5778 | } |
| 5779 | |
| 5780 | if (cpi->b_calculate_consistency) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5781 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5782 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5783 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5784 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5785 | |
| 5786 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5787 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5788 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5789 | if (consistency > 0.0) |
| 5790 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5791 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5792 | cpi->total_inconsistency += this_inconsistency; |
| 5793 | } |
| 5794 | } |
| 5795 | } |
| 5796 | |
| 5797 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5798 | 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] | 5799 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5800 | 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] | 5801 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5802 | } |
| 5803 | } |
| 5804 | #endif // CONFIG_INTERNAL_STATS |
| 5805 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5806 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 5807 | const YV12_BUFFER_CONFIG *last_picture, |
| 5808 | hash_table *last_hash_table) { |
| 5809 | aom_clear_system_state(); |
| 5810 | // check use hash ME |
| 5811 | int k; |
| 5812 | uint32_t hash_value_1; |
| 5813 | uint32_t hash_value_2; |
| 5814 | |
| 5815 | const int block_size = 8; |
| 5816 | const double threshold_current = 0.8; |
| 5817 | const double threshold_average = 0.95; |
| 5818 | const int max_history_size = 32; |
| 5819 | int T = 0; // total block |
| 5820 | int C = 0; // match with collocated block |
| 5821 | int S = 0; // smooth region but not match with collocated block |
| 5822 | int M = 0; // match with other block |
| 5823 | |
| 5824 | const int pic_width = cur_picture->y_width; |
| 5825 | const int pic_height = cur_picture->y_height; |
| 5826 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 5827 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 5828 | const int x_pos = j; |
| 5829 | const int y_pos = i; |
| 5830 | int match = 1; |
| 5831 | T++; |
| 5832 | |
| 5833 | // check whether collocated block match with current |
| 5834 | uint8_t *p_cur = cur_picture->y_buffer; |
| 5835 | uint8_t *p_ref = last_picture->y_buffer; |
| 5836 | int stride_cur = cur_picture->y_stride; |
| 5837 | int stride_ref = last_picture->y_stride; |
| 5838 | p_cur += (y_pos * stride_cur + x_pos); |
| 5839 | p_ref += (y_pos * stride_ref + x_pos); |
| 5840 | |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5841 | if (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5842 | uint16_t *p16_cur = CONVERT_TO_SHORTPTR(p_cur); |
| 5843 | uint16_t *p16_ref = CONVERT_TO_SHORTPTR(p_ref); |
| 5844 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5845 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5846 | if (p16_cur[tmpX] != p16_ref[tmpX]) { |
| 5847 | match = 0; |
| 5848 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5849 | } |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5850 | p16_cur += stride_cur; |
| 5851 | p16_ref += stride_ref; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5852 | } |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5853 | } else { |
| 5854 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5855 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5856 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 5857 | match = 0; |
| 5858 | } |
| 5859 | } |
| 5860 | p_cur += stride_cur; |
| 5861 | p_ref += stride_ref; |
| 5862 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | if (match) { |
| 5866 | C++; |
| 5867 | continue; |
| 5868 | } |
| 5869 | |
| 5870 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 5871 | y_pos) || |
| 5872 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 5873 | S++; |
| 5874 | continue; |
| 5875 | } |
| 5876 | |
| 5877 | av1_get_block_hash_value( |
| 5878 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5879 | block_size, &hash_value_1, &hash_value_2, |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 5880 | (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb); |
Debargha Mukherjee | 1c58301 | 2018-02-28 22:16:16 -0800 | [diff] [blame] | 5881 | // Hashing does not work for highbitdepth currently. |
| 5882 | // TODO(Roger): Make it work for highbitdepth. |
| 5883 | if (av1_use_hash_me(&cpi->common)) { |
| 5884 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 5885 | M++; |
| 5886 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5887 | } |
| 5888 | } |
| 5889 | } |
| 5890 | |
| 5891 | assert(T > 0); |
| 5892 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 5893 | double m_rate = ((double)(M)) / ((double)(T)); |
| 5894 | |
| 5895 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 5896 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 5897 | |
| 5898 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 5899 | cpi->rate_size++; |
| 5900 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 5901 | |
| 5902 | if (csm_rate < threshold_current) { |
| 5903 | return 0; |
| 5904 | } |
| 5905 | |
| 5906 | if (C == T) { |
| 5907 | return 1; |
| 5908 | } |
| 5909 | |
| 5910 | double csm_average = 0.0; |
| 5911 | double m_average = 0.0; |
| 5912 | |
| 5913 | for (k = 0; k < cpi->rate_size; k++) { |
| 5914 | csm_average += cpi->csm_rate_array[k]; |
| 5915 | m_average += cpi->m_rate_array[k]; |
| 5916 | } |
| 5917 | csm_average /= cpi->rate_size; |
| 5918 | m_average /= cpi->rate_size; |
| 5919 | |
| 5920 | if (csm_average < threshold_average) { |
| 5921 | return 0; |
| 5922 | } |
| 5923 | |
| 5924 | if (M > (T - C - S) / 3) { |
| 5925 | return 1; |
| 5926 | } |
| 5927 | |
| 5928 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 5929 | return 1; |
| 5930 | } |
| 5931 | |
| 5932 | if (csm_average + m_average > 1.01) { |
| 5933 | return 1; |
| 5934 | } |
| 5935 | |
| 5936 | return 0; |
| 5937 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5938 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 5939 | // Code for temporal dependency model |
| 5940 | typedef struct GF_PICTURE { |
| 5941 | YV12_BUFFER_CONFIG *frame; |
| 5942 | int ref_frame[7]; |
| 5943 | } GF_PICTURE; |
| 5944 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 5945 | static void init_gop_frames(AV1_COMP *cpi, GF_PICTURE *gf_picture, |
| 5946 | const GF_GROUP *gf_group, int *tpl_group_frames) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 5947 | AV1_COMMON *cm = &cpi->common; |
| 5948 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 5949 | int frame_idx = 0; |
| 5950 | int i; |
| 5951 | int gld_index = -1; |
| 5952 | int alt_index = -1; |
| 5953 | int lst_index = -1; |
| 5954 | int extend_frame_count = 0; |
| 5955 | int pframe_qindex = cpi->tpl_stats[2].base_qindex; |
| 5956 | |
| 5957 | RefCntBuffer *frame_bufs = cm->buffer_pool->frame_bufs; |
| 5958 | int recon_frame_index[INTER_REFS_PER_FRAME + 1] = { -1, -1, -1, -1, |
| 5959 | -1, -1, -1, -1 }; |
| 5960 | |
| 5961 | // TODO(jingning): To be used later for gf frame type parsing. |
| 5962 | (void)gf_group; |
| 5963 | |
| 5964 | for (i = 0; i < FRAME_BUFFERS && frame_idx < INTER_REFS_PER_FRAME + 1; ++i) { |
| 5965 | if (frame_bufs[i].ref_count == 0) { |
| 5966 | alloc_frame_mvs(cm, i); |
| 5967 | if (aom_realloc_frame_buffer( |
| 5968 | &frame_bufs[i].buf, cm->width, cm->height, |
| 5969 | seq_params->subsampling_x, seq_params->subsampling_y, |
| 5970 | seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 5971 | cm->byte_alignment, NULL, NULL, NULL)) |
| 5972 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5973 | "Failed to allocate frame buffer"); |
| 5974 | |
| 5975 | recon_frame_index[frame_idx] = i; |
| 5976 | ++frame_idx; |
| 5977 | } |
| 5978 | } |
| 5979 | |
| 5980 | for (i = 0; i < INTER_REFS_PER_FRAME + 1; ++i) { |
| 5981 | assert(recon_frame_index[i] >= 0); |
| 5982 | cpi->tpl_recon_frames[i] = &frame_bufs[recon_frame_index[i]].buf; |
| 5983 | } |
| 5984 | |
| 5985 | *tpl_group_frames = 0; |
| 5986 | |
| 5987 | // Initialize Golden reference frame. |
| 5988 | gf_picture[0].frame = get_ref_frame_buffer(cpi, GOLDEN_FRAME); |
| 5989 | for (i = 0; i < 7; ++i) gf_picture[0].ref_frame[i] = -1; |
| 5990 | gld_index = 0; |
| 5991 | ++*tpl_group_frames; |
| 5992 | |
| 5993 | // Initialize ARF frame |
| 5994 | gf_picture[1].frame = cpi->source; |
| 5995 | gf_picture[1].ref_frame[0] = gld_index; |
| 5996 | gf_picture[1].ref_frame[1] = lst_index; |
| 5997 | gf_picture[1].ref_frame[2] = alt_index; |
| 5998 | // TODO(yuec) Need o figure out full AV1 reference model |
| 5999 | for (i = 3; i < 7; ++i) gf_picture[1].ref_frame[i] = -1; |
| 6000 | alt_index = 1; |
| 6001 | ++*tpl_group_frames; |
| 6002 | |
| 6003 | // Initialize P frames |
| 6004 | for (frame_idx = 2; frame_idx < MAX_LAG_BUFFERS; ++frame_idx) { |
| 6005 | struct lookahead_entry *buf = |
| 6006 | av1_lookahead_peek(cpi->lookahead, frame_idx - 2); |
| 6007 | |
| 6008 | if (buf == NULL) break; |
| 6009 | |
| 6010 | gf_picture[frame_idx].frame = &buf->img; |
| 6011 | gf_picture[frame_idx].ref_frame[0] = gld_index; |
| 6012 | gf_picture[frame_idx].ref_frame[1] = lst_index; |
| 6013 | gf_picture[frame_idx].ref_frame[2] = alt_index; |
| 6014 | for (i = 3; i < 7; ++i) gf_picture[frame_idx].ref_frame[i] = -1; |
| 6015 | |
| 6016 | ++*tpl_group_frames; |
| 6017 | lst_index = frame_idx; |
| 6018 | |
| 6019 | if (frame_idx == cpi->rc.baseline_gf_interval + 1) break; |
| 6020 | } |
| 6021 | |
| 6022 | gld_index = frame_idx; |
| 6023 | lst_index = AOMMAX(0, frame_idx - 1); |
| 6024 | alt_index = -1; |
| 6025 | ++frame_idx; |
| 6026 | |
| 6027 | // Extend two frames outside the current gf group. |
| 6028 | for (; frame_idx < MAX_LAG_BUFFERS && extend_frame_count < 2; ++frame_idx) { |
| 6029 | struct lookahead_entry *buf = |
| 6030 | av1_lookahead_peek(cpi->lookahead, frame_idx - 2); |
| 6031 | |
| 6032 | if (buf == NULL) break; |
| 6033 | |
| 6034 | cpi->tpl_stats[frame_idx].base_qindex = pframe_qindex; |
| 6035 | |
| 6036 | gf_picture[frame_idx].frame = &buf->img; |
| 6037 | gf_picture[frame_idx].ref_frame[0] = gld_index; |
| 6038 | gf_picture[frame_idx].ref_frame[1] = lst_index; |
| 6039 | gf_picture[frame_idx].ref_frame[2] = alt_index; |
| 6040 | for (i = 3; i < 7; ++i) gf_picture[frame_idx].ref_frame[i] = -1; |
| 6041 | lst_index = frame_idx; |
| 6042 | ++*tpl_group_frames; |
| 6043 | ++extend_frame_count; |
| 6044 | } |
| 6045 | } |
| 6046 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6047 | static void init_tpl_stats(AV1_COMP *cpi) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6048 | int frame_idx; |
| 6049 | for (frame_idx = 0; frame_idx < MAX_LAG_BUFFERS; ++frame_idx) { |
| 6050 | TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; |
| 6051 | memset(tpl_frame->tpl_stats_ptr, 0, |
| 6052 | tpl_frame->height * tpl_frame->width * |
| 6053 | sizeof(*tpl_frame->tpl_stats_ptr)); |
| 6054 | tpl_frame->is_valid = 0; |
| 6055 | } |
| 6056 | } |
| 6057 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6058 | static uint32_t motion_compensated_prediction(AV1_COMP *cpi, ThreadData *td, |
| 6059 | uint8_t *cur_frame_buf, |
| 6060 | uint8_t *ref_frame_buf, |
| 6061 | int stride, BLOCK_SIZE bsize, |
| 6062 | int mi_row, int mi_col) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6063 | AV1_COMMON *cm = &cpi->common; |
| 6064 | MACROBLOCK *const x = &td->mb; |
| 6065 | MACROBLOCKD *const xd = &x->e_mbd; |
| 6066 | MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; |
| 6067 | const SEARCH_METHODS search_method = NSTEP; |
| 6068 | int step_param; |
| 6069 | int sadpb = x->sadperbit16; |
| 6070 | uint32_t bestsme = UINT_MAX; |
| 6071 | int distortion; |
| 6072 | uint32_t sse; |
| 6073 | int cost_list[5]; |
| 6074 | const MvLimits tmp_mv_limits = x->mv_limits; |
| 6075 | |
| 6076 | MV best_ref_mv1 = { 0, 0 }; |
| 6077 | MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ |
| 6078 | |
| 6079 | best_ref_mv1_full.col = best_ref_mv1.col >> 3; |
| 6080 | best_ref_mv1_full.row = best_ref_mv1.row >> 3; |
| 6081 | |
| 6082 | // Setup frame pointers |
| 6083 | x->plane[0].src.buf = cur_frame_buf; |
| 6084 | x->plane[0].src.stride = stride; |
| 6085 | xd->plane[0].pre[0].buf = ref_frame_buf; |
| 6086 | xd->plane[0].pre[0].stride = stride; |
| 6087 | |
| 6088 | step_param = mv_sf->reduce_first_step_size; |
| 6089 | step_param = AOMMIN(step_param, MAX_MVSEARCH_STEPS - 2); |
| 6090 | |
| 6091 | av1_set_mv_search_range(&x->mv_limits, &best_ref_mv1); |
| 6092 | |
| 6093 | av1_full_pixel_search(cpi, x, bsize, &best_ref_mv1_full, step_param, |
| 6094 | search_method, 0, sadpb, cond_cost_list(cpi, cost_list), |
| 6095 | &best_ref_mv1, INT_MAX, 0, (MI_SIZE * mi_col), |
| 6096 | (MI_SIZE * mi_row), 0); |
| 6097 | |
| 6098 | /* restore UMV window */ |
| 6099 | x->mv_limits = tmp_mv_limits; |
| 6100 | |
| 6101 | const int pw = block_size_wide[bsize]; |
| 6102 | const int ph = block_size_high[bsize]; |
| 6103 | bestsme = cpi->find_fractional_mv_step( |
| 6104 | x, cm, mi_row, mi_col, &best_ref_mv1, cpi->common.allow_high_precision_mv, |
| 6105 | x->errorperbit, &cpi->fn_ptr[bsize], 0, mv_sf->subpel_iters_per_step, |
| 6106 | cond_cost_list(cpi, cost_list), NULL, NULL, &distortion, &sse, NULL, NULL, |
| 6107 | 0, 0, pw, ph, 1, 1); |
| 6108 | |
| 6109 | return bestsme; |
| 6110 | } |
| 6111 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6112 | static int get_overlap_area(int grid_pos_row, int grid_pos_col, int ref_pos_row, |
| 6113 | int ref_pos_col, int block, BLOCK_SIZE bsize) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6114 | int width = 0, height = 0; |
| 6115 | int bw = 4 << mi_size_wide_log2[bsize]; |
| 6116 | int bh = 4 << mi_size_high_log2[bsize]; |
| 6117 | |
| 6118 | switch (block) { |
| 6119 | case 0: |
| 6120 | width = grid_pos_col + bw - ref_pos_col; |
| 6121 | height = grid_pos_row + bh - ref_pos_row; |
| 6122 | break; |
| 6123 | case 1: |
| 6124 | width = ref_pos_col + bw - grid_pos_col; |
| 6125 | height = grid_pos_row + bh - ref_pos_row; |
| 6126 | break; |
| 6127 | case 2: |
| 6128 | width = grid_pos_col + bw - ref_pos_col; |
| 6129 | height = ref_pos_row + bh - grid_pos_row; |
| 6130 | break; |
| 6131 | case 3: |
| 6132 | width = ref_pos_col + bw - grid_pos_col; |
| 6133 | height = ref_pos_row + bh - grid_pos_row; |
| 6134 | break; |
| 6135 | default: assert(0); |
| 6136 | } |
| 6137 | |
| 6138 | return width * height; |
| 6139 | } |
| 6140 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6141 | static int round_floor(int ref_pos, int bsize_pix) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6142 | int round; |
| 6143 | if (ref_pos < 0) |
| 6144 | round = -(1 + (-ref_pos - 1) / bsize_pix); |
| 6145 | else |
| 6146 | round = ref_pos / bsize_pix; |
| 6147 | |
| 6148 | return round; |
| 6149 | } |
| 6150 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6151 | static void tpl_model_store(TplDepStats *tpl_stats, int mi_row, int mi_col, |
| 6152 | BLOCK_SIZE bsize, int stride, |
| 6153 | const TplDepStats *src_stats) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6154 | const int mi_height = mi_size_high[bsize]; |
| 6155 | const int mi_width = mi_size_wide[bsize]; |
| 6156 | int idx, idy; |
| 6157 | |
| 6158 | int64_t intra_cost = src_stats->intra_cost / (mi_height * mi_width); |
| 6159 | int64_t inter_cost = src_stats->inter_cost / (mi_height * mi_width); |
| 6160 | |
| 6161 | TplDepStats *tpl_ptr; |
| 6162 | |
| 6163 | intra_cost = AOMMAX(1, intra_cost); |
| 6164 | inter_cost = AOMMAX(1, inter_cost); |
| 6165 | |
| 6166 | for (idy = 0; idy < mi_height; ++idy) { |
| 6167 | tpl_ptr = &tpl_stats[(mi_row + idy) * stride + mi_col]; |
| 6168 | for (idx = 0; idx < mi_width; ++idx) { |
| 6169 | tpl_ptr->intra_cost = intra_cost; |
| 6170 | tpl_ptr->inter_cost = inter_cost; |
| 6171 | tpl_ptr->mc_dep_cost = tpl_ptr->intra_cost + tpl_ptr->mc_flow; |
| 6172 | tpl_ptr->ref_frame_index = src_stats->ref_frame_index; |
| 6173 | tpl_ptr->mv.as_int = src_stats->mv.as_int; |
| 6174 | ++tpl_ptr; |
| 6175 | } |
| 6176 | } |
| 6177 | } |
| 6178 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6179 | static void tpl_model_update_b(TplDepFrame *tpl_frame, TplDepStats *tpl_stats, |
| 6180 | int mi_row, int mi_col, const BLOCK_SIZE bsize) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6181 | TplDepFrame *ref_tpl_frame = &tpl_frame[tpl_stats->ref_frame_index]; |
| 6182 | TplDepStats *ref_stats = ref_tpl_frame->tpl_stats_ptr; |
| 6183 | MV mv = tpl_stats->mv.as_mv; |
| 6184 | int mv_row = mv.row >> 3; |
| 6185 | int mv_col = mv.col >> 3; |
| 6186 | |
| 6187 | int ref_pos_row = mi_row * MI_SIZE + mv_row; |
| 6188 | int ref_pos_col = mi_col * MI_SIZE + mv_col; |
| 6189 | |
| 6190 | const int bw = 4 << mi_size_wide_log2[bsize]; |
| 6191 | const int bh = 4 << mi_size_high_log2[bsize]; |
| 6192 | const int mi_height = mi_size_high[bsize]; |
| 6193 | const int mi_width = mi_size_wide[bsize]; |
| 6194 | const int pix_num = bw * bh; |
| 6195 | |
| 6196 | // top-left on grid block location in pixel |
| 6197 | int grid_pos_row_base = round_floor(ref_pos_row, bh) * bh; |
| 6198 | int grid_pos_col_base = round_floor(ref_pos_col, bw) * bw; |
| 6199 | int block; |
| 6200 | |
| 6201 | for (block = 0; block < 4; ++block) { |
| 6202 | int grid_pos_row = grid_pos_row_base + bh * (block >> 1); |
| 6203 | int grid_pos_col = grid_pos_col_base + bw * (block & 0x01); |
| 6204 | |
| 6205 | if (grid_pos_row >= 0 && grid_pos_row < ref_tpl_frame->mi_rows * MI_SIZE && |
| 6206 | grid_pos_col >= 0 && grid_pos_col < ref_tpl_frame->mi_cols * MI_SIZE) { |
| 6207 | int overlap_area = get_overlap_area( |
| 6208 | grid_pos_row, grid_pos_col, ref_pos_row, ref_pos_col, block, bsize); |
| 6209 | int ref_mi_row = round_floor(grid_pos_row, bh) * mi_height; |
| 6210 | int ref_mi_col = round_floor(grid_pos_col, bw) * mi_width; |
| 6211 | |
| 6212 | int64_t mc_flow = tpl_stats->mc_dep_cost - |
| 6213 | (tpl_stats->mc_dep_cost * tpl_stats->inter_cost) / |
| 6214 | tpl_stats->intra_cost; |
| 6215 | |
| 6216 | int idx, idy; |
| 6217 | |
| 6218 | for (idy = 0; idy < mi_height; ++idy) { |
| 6219 | for (idx = 0; idx < mi_width; ++idx) { |
| 6220 | TplDepStats *des_stats = |
| 6221 | &ref_stats[(ref_mi_row + idy) * ref_tpl_frame->stride + |
| 6222 | (ref_mi_col + idx)]; |
| 6223 | |
| 6224 | des_stats->mc_flow += (mc_flow * overlap_area) / pix_num; |
| 6225 | des_stats->mc_ref_cost += |
| 6226 | ((tpl_stats->intra_cost - tpl_stats->inter_cost) * overlap_area) / |
| 6227 | pix_num; |
| 6228 | assert(overlap_area >= 0); |
| 6229 | } |
| 6230 | } |
| 6231 | } |
| 6232 | } |
| 6233 | } |
| 6234 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6235 | static void tpl_model_update(TplDepFrame *tpl_frame, TplDepStats *tpl_stats, |
| 6236 | int mi_row, int mi_col, const BLOCK_SIZE bsize) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6237 | int idx, idy; |
| 6238 | const int mi_height = mi_size_high[bsize]; |
| 6239 | const int mi_width = mi_size_wide[bsize]; |
| 6240 | |
| 6241 | for (idy = 0; idy < mi_height; ++idy) { |
| 6242 | for (idx = 0; idx < mi_width; ++idx) { |
| 6243 | TplDepStats *tpl_ptr = |
| 6244 | &tpl_stats[(mi_row + idy) * tpl_frame->stride + (mi_col + idx)]; |
| 6245 | tpl_model_update_b(tpl_frame, tpl_ptr, mi_row + idy, mi_col + idx, |
| 6246 | BLOCK_4X4); |
| 6247 | } |
| 6248 | } |
| 6249 | } |
| 6250 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6251 | static void get_quantize_error(MACROBLOCK *x, int plane, tran_low_t *coeff, |
| 6252 | tran_low_t *qcoeff, tran_low_t *dqcoeff, |
| 6253 | TX_SIZE tx_size, int64_t *recon_error, |
| 6254 | int64_t *sse) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6255 | const struct macroblock_plane *const p = &x->plane[plane]; |
| 6256 | const SCAN_ORDER *const scan_order = &av1_default_scan_orders[tx_size]; |
| 6257 | uint16_t eob; |
| 6258 | int pix_num = 1 << num_pels_log2_lookup[txsize_to_bsize[tx_size]]; |
| 6259 | const int shift = tx_size == TX_32X32 ? 0 : 2; |
| 6260 | |
| 6261 | av1_quantize_fp_32x32(coeff, pix_num, p->zbin_QTX, p->round_fp_QTX, |
| 6262 | p->quant_fp_QTX, p->quant_shift_QTX, qcoeff, dqcoeff, |
| 6263 | p->dequant_QTX, &eob, scan_order->scan, |
| 6264 | scan_order->iscan); |
| 6265 | |
| 6266 | *recon_error = av1_block_error(coeff, dqcoeff, pix_num, sse) >> shift; |
| 6267 | *recon_error = AOMMAX(*recon_error, 1); |
| 6268 | |
| 6269 | *sse = (*sse) >> shift; |
| 6270 | *sse = AOMMAX(*sse, 1); |
| 6271 | } |
| 6272 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6273 | static void wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, |
| 6274 | TX_SIZE tx_size) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6275 | switch (tx_size) { |
| 6276 | case TX_8X8: aom_hadamard_8x8(src_diff, bw, coeff); break; |
| 6277 | case TX_16X16: aom_hadamard_16x16(src_diff, bw, coeff); break; |
| 6278 | case TX_32X32: aom_hadamard_32x32(src_diff, bw, coeff); break; |
| 6279 | default: assert(0); |
| 6280 | } |
| 6281 | } |
| 6282 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6283 | static void mode_estimation(AV1_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, |
| 6284 | struct scale_factors *sf, GF_PICTURE *gf_picture, |
| 6285 | int frame_idx, int16_t *src_diff, tran_low_t *coeff, |
| 6286 | tran_low_t *qcoeff, tran_low_t *dqcoeff, int mi_row, |
| 6287 | int mi_col, BLOCK_SIZE bsize, TX_SIZE tx_size, |
| 6288 | YV12_BUFFER_CONFIG *ref_frame[], uint8_t *predictor, |
| 6289 | int64_t *recon_error, int64_t *sse, |
| 6290 | TplDepStats *tpl_stats) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6291 | AV1_COMMON *cm = &cpi->common; |
| 6292 | ThreadData *td = &cpi->td; |
| 6293 | |
| 6294 | const int bw = 4 << mi_size_wide_log2[bsize]; |
| 6295 | const int bh = 4 << mi_size_high_log2[bsize]; |
| 6296 | const int pix_num = bw * bh; |
| 6297 | int best_rf_idx = -1; |
| 6298 | int_mv best_mv; |
| 6299 | int64_t best_inter_cost = INT64_MAX; |
| 6300 | int64_t inter_cost; |
| 6301 | int rf_idx; |
| 6302 | const InterpFilters kernel = |
| 6303 | av1_make_interp_filters(EIGHTTAP_REGULAR, EIGHTTAP_REGULAR); |
| 6304 | |
| 6305 | int64_t best_intra_cost = INT64_MAX; |
| 6306 | int64_t intra_cost; |
| 6307 | PREDICTION_MODE mode; |
| 6308 | int mb_y_offset = mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE; |
| 6309 | MB_MODE_INFO mi_above, mi_left; |
| 6310 | |
| 6311 | memset(tpl_stats, 0, sizeof(*tpl_stats)); |
| 6312 | |
| 6313 | xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8); |
| 6314 | xd->mb_to_bottom_edge = ((cm->mi_rows - 1 - mi_row) * MI_SIZE) * 8; |
| 6315 | xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8); |
| 6316 | xd->mb_to_right_edge = ((cm->mi_cols - 1 - mi_col) * MI_SIZE) * 8; |
| 6317 | xd->above_mbmi = (mi_row > 0) ? &mi_above : NULL; |
| 6318 | xd->left_mbmi = (mi_col > 0) ? &mi_left : NULL; |
| 6319 | |
| 6320 | // Intra prediction search |
| 6321 | for (mode = DC_PRED; mode <= PAETH_PRED; ++mode) { |
| 6322 | uint8_t *src, *dst; |
| 6323 | int src_stride, dst_stride; |
| 6324 | |
| 6325 | src = xd->cur_buf->y_buffer + mb_y_offset; |
| 6326 | src_stride = xd->cur_buf->y_stride; |
| 6327 | |
| 6328 | dst = &predictor[0]; |
| 6329 | dst_stride = bw; |
| 6330 | |
| 6331 | xd->mi[0]->sb_type = bsize; |
| 6332 | xd->mi[0]->ref_frame[0] = INTRA_FRAME; |
| 6333 | |
| 6334 | av1_predict_intra_block( |
| 6335 | cm, xd, block_size_wide[bsize], block_size_high[bsize], tx_size, mode, |
| 6336 | 0, 0, FILTER_INTRA_MODES, src, src_stride, dst, dst_stride, 0, 0, 0); |
| 6337 | |
| 6338 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 6339 | aom_highbd_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, |
| 6340 | dst_stride, xd->bd); |
| 6341 | } else { |
| 6342 | aom_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, |
| 6343 | dst_stride); |
| 6344 | } |
| 6345 | |
| 6346 | wht_fwd_txfm(src_diff, bw, coeff, tx_size); |
| 6347 | |
| 6348 | intra_cost = aom_satd(coeff, pix_num); |
| 6349 | |
| 6350 | if (intra_cost < best_intra_cost) best_intra_cost = intra_cost; |
| 6351 | } |
| 6352 | |
| 6353 | // Motion compensated prediction |
| 6354 | best_mv.as_int = 0; |
| 6355 | |
| 6356 | (void)mb_y_offset; |
| 6357 | // Motion estimation column boundary |
| 6358 | x->mv_limits.col_min = -((mi_col * MI_SIZE) + (17 - 2 * AOM_INTERP_EXTEND)); |
| 6359 | x->mv_limits.col_max = |
| 6360 | ((cm->mi_cols - 1 - mi_col) * MI_SIZE) + (17 - 2 * AOM_INTERP_EXTEND); |
| 6361 | |
| 6362 | for (rf_idx = 0; rf_idx < 7; ++rf_idx) { |
| 6363 | if (ref_frame[rf_idx] == NULL) continue; |
| 6364 | |
| 6365 | motion_compensated_prediction(cpi, td, xd->cur_buf->y_buffer + mb_y_offset, |
| 6366 | ref_frame[rf_idx]->y_buffer + mb_y_offset, |
| 6367 | xd->cur_buf->y_stride, bsize, mi_row, mi_col); |
| 6368 | |
| 6369 | // TODO(jingning): Not yet support high bit-depth in the next three |
| 6370 | // steps. |
| 6371 | ConvolveParams conv_params = get_conv_params(0, 0, xd->bd); |
| 6372 | WarpTypesAllowed warp_types; |
| 6373 | memset(&warp_types, 0, sizeof(WarpTypesAllowed)); |
| 6374 | |
| 6375 | av1_build_inter_predictor( |
| 6376 | ref_frame[rf_idx]->y_buffer + mb_y_offset, ref_frame[rf_idx]->y_stride, |
| 6377 | &predictor[0], bw, &x->best_mv.as_mv, sf, bw, bh, &conv_params, kernel, |
| 6378 | &warp_types, mi_col * MI_SIZE, mi_row * MI_SIZE, 0, 0, MV_PRECISION_Q3, |
| 6379 | mi_col * MI_SIZE, mi_row * MI_SIZE, xd, 0); |
| 6380 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 6381 | aom_highbd_subtract_block( |
| 6382 | bh, bw, src_diff, bw, xd->cur_buf->y_buffer + mb_y_offset, |
| 6383 | xd->cur_buf->y_stride, &predictor[0], bw, xd->bd); |
| 6384 | } else { |
| 6385 | aom_subtract_block(bh, bw, src_diff, bw, |
| 6386 | xd->cur_buf->y_buffer + mb_y_offset, |
| 6387 | xd->cur_buf->y_stride, &predictor[0], bw); |
| 6388 | } |
| 6389 | wht_fwd_txfm(src_diff, bw, coeff, tx_size); |
| 6390 | |
| 6391 | inter_cost = aom_satd(coeff, pix_num); |
| 6392 | if (inter_cost < best_inter_cost) { |
| 6393 | best_rf_idx = rf_idx; |
| 6394 | best_inter_cost = inter_cost; |
| 6395 | best_mv.as_int = x->best_mv.as_int; |
| 6396 | get_quantize_error(x, 0, coeff, qcoeff, dqcoeff, tx_size, recon_error, |
| 6397 | sse); |
| 6398 | } |
| 6399 | } |
| 6400 | best_intra_cost = AOMMAX(best_intra_cost, 1); |
| 6401 | best_inter_cost = AOMMIN(best_intra_cost, best_inter_cost); |
| 6402 | tpl_stats->inter_cost = best_inter_cost << TPL_DEP_COST_SCALE_LOG2; |
| 6403 | tpl_stats->intra_cost = best_intra_cost << TPL_DEP_COST_SCALE_LOG2; |
| 6404 | tpl_stats->mc_dep_cost = tpl_stats->intra_cost + tpl_stats->mc_flow; |
| 6405 | |
| 6406 | tpl_stats->ref_frame_index = gf_picture[frame_idx].ref_frame[best_rf_idx]; |
| 6407 | tpl_stats->mv.as_int = best_mv.as_int; |
| 6408 | } |
| 6409 | |
Sarah Parker | cf64444 | 2018-10-11 15:23:44 -0700 | [diff] [blame] | 6410 | static void mc_flow_dispenser(AV1_COMP *cpi, GF_PICTURE *gf_picture, |
| 6411 | int frame_idx) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6412 | TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; |
| 6413 | YV12_BUFFER_CONFIG *this_frame = gf_picture[frame_idx].frame; |
| 6414 | YV12_BUFFER_CONFIG *ref_frame[7] = { |
| 6415 | NULL, NULL, NULL, NULL, NULL, NULL, NULL |
| 6416 | }; |
| 6417 | |
| 6418 | AV1_COMMON *cm = &cpi->common; |
| 6419 | struct scale_factors sf; |
| 6420 | int rdmult, idx; |
| 6421 | ThreadData *td = &cpi->td; |
| 6422 | MACROBLOCK *x = &td->mb; |
| 6423 | MACROBLOCKD *xd = &x->e_mbd; |
| 6424 | int mi_row, mi_col; |
| 6425 | |
| 6426 | DECLARE_ALIGNED(16, uint16_t, predictor16[32 * 32 * 3]); |
| 6427 | DECLARE_ALIGNED(16, uint8_t, predictor8[32 * 32 * 3]); |
| 6428 | uint8_t *predictor; |
| 6429 | DECLARE_ALIGNED(16, int16_t, src_diff[32 * 32]); |
| 6430 | DECLARE_ALIGNED(16, tran_low_t, coeff[32 * 32]); |
| 6431 | DECLARE_ALIGNED(16, tran_low_t, qcoeff[32 * 32]); |
| 6432 | DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]); |
| 6433 | |
| 6434 | const BLOCK_SIZE bsize = BLOCK_32X32; |
| 6435 | const TX_SIZE tx_size = max_txsize_lookup[bsize]; |
| 6436 | const int mi_height = mi_size_high[bsize]; |
| 6437 | const int mi_width = mi_size_wide[bsize]; |
| 6438 | int64_t recon_error, sse; |
| 6439 | |
| 6440 | // Setup scaling factor |
| 6441 | av1_setup_scale_factors_for_frame( |
| 6442 | &sf, this_frame->y_crop_width, this_frame->y_crop_height, |
| 6443 | this_frame->y_crop_width, this_frame->y_crop_height); |
| 6444 | |
| 6445 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) |
| 6446 | predictor = CONVERT_TO_BYTEPTR(predictor16); |
| 6447 | else |
| 6448 | predictor = predictor8; |
| 6449 | |
| 6450 | // Prepare reference frame pointers. If any reference frame slot is |
| 6451 | // unavailable, the pointer will be set to Null. |
| 6452 | for (idx = 0; idx < 7; ++idx) { |
| 6453 | int rf_idx = gf_picture[frame_idx].ref_frame[idx]; |
| 6454 | if (rf_idx != -1) ref_frame[idx] = gf_picture[rf_idx].frame; |
| 6455 | } |
| 6456 | |
| 6457 | xd->mi = cm->mi_grid_visible; |
| 6458 | xd->mi[0] = cm->mi; |
| 6459 | xd->cur_buf = this_frame; |
| 6460 | |
| 6461 | // Get rd multiplier set up. |
| 6462 | rdmult = (int)av1_compute_rd_mult(cpi, tpl_frame->base_qindex); |
| 6463 | if (rdmult < 1) rdmult = 1; |
| 6464 | set_error_per_bit(&cpi->td.mb, rdmult); |
| 6465 | av1_initialize_me_consts(cpi, &cpi->td.mb, tpl_frame->base_qindex); |
| 6466 | |
| 6467 | tpl_frame->is_valid = 1; |
| 6468 | |
| 6469 | cm->base_qindex = tpl_frame->base_qindex; |
| 6470 | av1_frame_init_quantizer(cpi); |
| 6471 | |
| 6472 | for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { |
| 6473 | // Motion estimation row boundary |
| 6474 | x->mv_limits.row_min = -((mi_row * MI_SIZE) + (17 - 2 * AOM_INTERP_EXTEND)); |
| 6475 | x->mv_limits.row_max = |
| 6476 | (cm->mi_rows - 1 - mi_row) * MI_SIZE + (17 - 2 * AOM_INTERP_EXTEND); |
| 6477 | for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) { |
| 6478 | TplDepStats tpl_stats; |
| 6479 | mode_estimation(cpi, x, xd, &sf, gf_picture, frame_idx, src_diff, coeff, |
| 6480 | qcoeff, dqcoeff, mi_row, mi_col, bsize, tx_size, |
| 6481 | ref_frame, predictor, &recon_error, &sse, &tpl_stats); |
| 6482 | |
| 6483 | // Motion flow dependency dispenser. |
| 6484 | tpl_model_store(tpl_frame->tpl_stats_ptr, mi_row, mi_col, bsize, |
| 6485 | tpl_frame->stride, &tpl_stats); |
| 6486 | |
| 6487 | tpl_model_update(cpi->tpl_stats, tpl_frame->tpl_stats_ptr, mi_row, mi_col, |
| 6488 | bsize); |
| 6489 | } |
| 6490 | } |
| 6491 | } |
| 6492 | |
| 6493 | static void setup_tpl_stats(AV1_COMP *cpi) { |
| 6494 | GF_PICTURE gf_picture[MAX_LAG_BUFFERS]; |
| 6495 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
| 6496 | int tpl_group_frames = 0; |
| 6497 | int frame_idx; |
| 6498 | |
| 6499 | init_gop_frames(cpi, gf_picture, gf_group, &tpl_group_frames); |
| 6500 | |
| 6501 | init_tpl_stats(cpi); |
| 6502 | |
| 6503 | // Backward propagation from tpl_group_frames to 1. |
| 6504 | for (frame_idx = tpl_group_frames - 1; frame_idx > 0; --frame_idx) |
| 6505 | mc_flow_dispenser(cpi, gf_picture, frame_idx); |
| 6506 | } |
| 6507 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6508 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 6509 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 6510 | int64_t *time_end, int flush, |
| 6511 | const aom_rational_t *timebase) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6512 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 6513 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 6514 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6515 | BufferPool *const pool = cm->buffer_pool; |
| 6516 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6517 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6518 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 6519 | struct lookahead_entry *last_source = NULL; |
| 6520 | struct lookahead_entry *source = NULL; |
| 6521 | int arf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6522 | int brf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6523 | int i; |
| 6524 | |
| 6525 | #if CONFIG_BITSTREAM_DEBUG |
| 6526 | assert(cpi->oxcf.max_threads == 0 && |
| 6527 | "bitstream debug tool does not support multithreading"); |
| 6528 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 6529 | 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] | 6530 | #endif |
| 6531 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6532 | cm->showable_frame = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6533 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6534 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6535 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6536 | |
Debargha Mukherjee | ba7b8fe | 2018-03-15 23:10:07 -0700 | [diff] [blame] | 6537 | // Normal defaults |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6538 | cm->refresh_frame_context = oxcf->frame_parallel_decoding_mode |
| 6539 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 6540 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 6541 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 6542 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6543 | |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 6544 | // default reference buffers update config |
| 6545 | av1_configure_buffer_updates_firstpass(cpi, LF_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6546 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 6547 | // Initialize fields related to forward keyframes |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 6548 | cpi->no_show_kf = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 6549 | cm->reset_decoder_state = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 6550 | |
Sarah Parker | 7e13da8 | 2018-04-30 17:47:24 -0700 | [diff] [blame] | 6551 | // 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] | 6552 | // S-Frame. An exception can be made in the case of a keyframe, since it |
| 6553 | // does not depend on any previous frames. We must make this exception here |
| 6554 | // because of the use of show_existing_frame with forward coded keyframes. |
Sarah Parker | 7e13da8 | 2018-04-30 17:47:24 -0700 | [diff] [blame] | 6555 | struct lookahead_entry *lookahead_src = NULL; |
| 6556 | if (cm->current_video_frame > 0) |
| 6557 | lookahead_src = av1_lookahead_peek(cpi->lookahead, 0); |
Sarah Parker | 349e0bd | 2018-08-03 14:18:05 -0700 | [diff] [blame] | 6558 | |
| 6559 | int use_show_existing = 1; |
| 6560 | if (lookahead_src != NULL) { |
| 6561 | const int is_error_resilient = |
| 6562 | cpi->oxcf.error_resilient_mode || |
| 6563 | (lookahead_src->flags & AOM_EFLAG_ERROR_RESILIENT); |
| 6564 | const int is_s_frame = cpi->oxcf.s_frame_mode || |
| 6565 | (lookahead_src->flags & AOM_EFLAG_SET_S_FRAME); |
| 6566 | const int is_key_frame = |
| 6567 | (rc->frames_to_key == 0) || (cpi->frame_flags & FRAMEFLAGS_KEY); |
| 6568 | use_show_existing = !(is_error_resilient || is_s_frame) || is_key_frame; |
| 6569 | } |
Sarah Parker | 7e13da8 | 2018-04-30 17:47:24 -0700 | [diff] [blame] | 6570 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 6571 | if (oxcf->pass == 2 && cm->show_existing_frame && use_show_existing) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6572 | // Manage the source buffer and flush out the source frame that has been |
| 6573 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6574 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6575 | *size = 0; |
| 6576 | return -1; |
| 6577 | } |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6578 | av1_apply_encoding_flags(cpi, source->flags); |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6579 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6580 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 6581 | // the frame rate. |
| 6582 | *time_stamp = source->ts_start; |
| 6583 | *time_end = source->ts_end; |
| 6584 | |
| 6585 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6586 | 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] | 6587 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 6588 | // Find a free buffer for the new frame, releasing the reference |
Wan-Teh Chang | d05e033 | 2018-10-03 12:00:43 -0700 | [diff] [blame] | 6589 | // previously held. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6590 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6591 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6592 | } |
| 6593 | cm->new_fb_idx = get_free_fb(cm); |
| 6594 | |
Wan-Teh Chang | 4a8c004 | 2018-10-05 09:41:52 -0700 | [diff] [blame] | 6595 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6596 | |
| 6597 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6598 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6599 | |
| 6600 | // Start with a 0 size frame. |
| 6601 | *size = 0; |
| 6602 | |
| 6603 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6604 | 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] | 6605 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6606 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 6607 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6608 | |
| 6609 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 6610 | |
| 6611 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6612 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6613 | #endif // CONFIG_INTERNAL_STATS |
| 6614 | |
| 6615 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6616 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6617 | |
| 6618 | cm->show_existing_frame = 0; |
| 6619 | return 0; |
| 6620 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6621 | |
| 6622 | // Should we encode an arf frame. |
| 6623 | arf_src_index = get_arf_src_index(cpi); |
| 6624 | if (arf_src_index) { |
| 6625 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6626 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6627 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6628 | if (e == NULL) { |
| 6629 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6630 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6631 | arf_src_index = 0; |
| 6632 | flush = 1; |
| 6633 | break; |
| 6634 | } |
| 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | if (arf_src_index) { |
| 6639 | assert(arf_src_index <= rc->frames_to_key); |
| 6640 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6641 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6642 | cm->showable_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6643 | cpi->alt_ref_source = source; |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 6644 | // 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] | 6645 | if (arf_src_index == rc->frames_to_key) { |
| 6646 | // Skip temporal filtering and mark as intra_only if we have a fwd_kf |
| 6647 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6648 | int which_arf = gf_group->arf_update_idx[gf_group->index]; |
| 6649 | cpi->is_arf_filter_off[which_arf] = 1; |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 6650 | cpi->no_show_kf = 1; |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 6651 | } else { |
| 6652 | if (oxcf->arnr_max_frames > 0) { |
| 6653 | // Produce the filtered ARF frame. |
| 6654 | av1_temporal_filter(cpi, arf_src_index); |
| 6655 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
| 6656 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6657 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6658 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6659 | cm->show_frame = 0; |
| 6660 | cm->intra_only = 0; |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 6661 | |
| 6662 | if (oxcf->pass < 2) { |
| 6663 | // In second pass, the buffer updates configure will be set |
| 6664 | // in the function av1_rc_get_second_pass_params |
| 6665 | av1_configure_buffer_updates_firstpass(cpi, ARF_UPDATE); |
| 6666 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6667 | } |
| 6668 | rc->source_alt_ref_pending = 0; |
| 6669 | } |
| 6670 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6671 | // Should we encode an arf2 frame. |
| 6672 | arf_src_index = get_arf2_src_index(cpi); |
| 6673 | if (arf_src_index) { |
| 6674 | for (i = 0; i <= arf_src_index; ++i) { |
| 6675 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 6676 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6677 | if (e == NULL) { |
| 6678 | break; |
| 6679 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 6680 | arf_src_index = 0; |
| 6681 | flush = 1; |
| 6682 | break; |
| 6683 | } |
| 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | if (arf_src_index) { |
| 6688 | assert(arf_src_index <= rc->frames_to_key); |
| 6689 | |
| 6690 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6691 | cm->showable_frame = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6692 | cpi->alt_ref_source = source; |
| 6693 | |
| 6694 | if (oxcf->arnr_max_frames > 0) { |
| 6695 | // Produce the filtered ARF frame. |
Sebastien Alaiwan | 6697acf | 2018-02-21 16:59:17 +0100 | [diff] [blame] | 6696 | av1_temporal_filter(cpi, arf_src_index); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 6697 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6698 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6699 | } |
| 6700 | |
| 6701 | cm->show_frame = 0; |
| 6702 | cm->intra_only = 0; |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 6703 | |
| 6704 | if (oxcf->pass < 2) { |
| 6705 | // In second pass, the buffer updates configure will be set |
| 6706 | // in the function av1_rc_get_second_pass_params |
| 6707 | av1_configure_buffer_updates_firstpass(cpi, INTNL_ARF_UPDATE); |
| 6708 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6709 | } |
| 6710 | rc->source_alt_ref_pending = 0; |
| 6711 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6712 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6713 | rc->is_bwd_ref_frame = 0; |
| 6714 | brf_src_index = get_brf_src_index(cpi); |
| 6715 | if (brf_src_index) { |
| 6716 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6717 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6718 | cm->showable_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6719 | cm->show_frame = 0; |
| 6720 | cm->intra_only = 0; |
| 6721 | |
Wei-Ting Lin | 2e8d045 | 2018-06-27 09:32:39 -0700 | [diff] [blame] | 6722 | if (oxcf->pass < 2) { |
| 6723 | // In second pass, the buffer updates configure will be set |
| 6724 | // in the function av1_rc_get_second_pass_params |
| 6725 | av1_configure_buffer_updates_firstpass(cpi, BIPRED_UPDATE); |
| 6726 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6727 | } |
| 6728 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6729 | |
| 6730 | if (!source) { |
| 6731 | // Get last frame source. |
| 6732 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6733 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6734 | return -1; |
| 6735 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6736 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6737 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6738 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6739 | |
| 6740 | if (source != NULL) { |
| 6741 | cm->show_frame = 1; |
| 6742 | cm->intra_only = 0; |
| 6743 | |
| 6744 | // Check to see if the frame should be encoded as an arf overlay. |
| 6745 | check_src_altref(cpi, source); |
| 6746 | } |
| 6747 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6748 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6749 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6750 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6751 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 6752 | |
| 6753 | *time_stamp = source->ts_start; |
| 6754 | *time_end = source->ts_end; |
Sarah Parker | 7355677 | 2018-03-28 18:28:05 -0700 | [diff] [blame] | 6755 | av1_apply_encoding_flags(cpi, source->flags); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6756 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6757 | |
| 6758 | } else { |
| 6759 | *size = 0; |
| 6760 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6761 | av1_end_first_pass(cpi); /* get last stats packet */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6762 | cpi->twopass.first_pass_done = 1; |
| 6763 | } |
| 6764 | return -1; |
| 6765 | } |
| 6766 | |
| 6767 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 6768 | cpi->first_time_stamp_ever = source->ts_start; |
| 6769 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 6770 | } |
| 6771 | |
| 6772 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6773 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6774 | |
| 6775 | // adjust frame rates based on timestamps given |
| 6776 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 6777 | |
| 6778 | // Find a free buffer for the new frame, releasing the reference previously |
| 6779 | // held. |
| 6780 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6781 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6782 | } |
| 6783 | cm->new_fb_idx = get_free_fb(cm); |
| 6784 | |
Wan-Teh Chang | 4a8c004 | 2018-10-05 09:41:52 -0700 | [diff] [blame] | 6785 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6786 | |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 6787 | // Retain the RF_LEVEL for the current newly coded frame. |
| 6788 | cpi->frame_rf_level[cm->new_fb_idx] = |
| 6789 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index]; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 6790 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6791 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 6792 | cm->cur_frame->buf.buf_8bit_valid = 0; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 6793 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6794 | if (cpi->film_grain_table) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 6795 | cm->seq_params.film_grain_params_present = aom_film_grain_table_lookup( |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6796 | cpi->film_grain_table, *time_stamp, *time_end, 0 /* =erase */, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 6797 | &cm->film_grain_params); |
| 6798 | } |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 6799 | cm->cur_frame->film_grain_params_present = |
| 6800 | cm->seq_params.film_grain_params_present; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6801 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6802 | // only one operating point supported now |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 6803 | const int64_t pts64 = ticks_to_timebase_units(timebase, *time_stamp); |
| 6804 | if (pts64 < 0 || pts64 > UINT32_MAX) return AOM_CODEC_ERROR; |
| 6805 | cpi->common.frame_presentation_time = (uint32_t)pts64; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6806 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6807 | // Start with a 0 size frame. |
| 6808 | *size = 0; |
| 6809 | |
| 6810 | cpi->frame_flags = *frame_flags; |
| 6811 | |
| 6812 | if (oxcf->pass == 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6813 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6814 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 6815 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6816 | } |
| 6817 | |
| 6818 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
Wan-Teh Chang | bb6a3d2 | 2018-10-05 11:22:48 -0700 | [diff] [blame] | 6819 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) |
| 6820 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6821 | } |
| 6822 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6823 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 6824 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 6825 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6826 | |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 6827 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6828 | if (*time_stamp == 0) { |
| 6829 | cpi->common.current_frame_id = -1; |
| 6830 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6831 | } |
Zoe Liu | ca0cd3f | 2018-02-26 15:07:50 -0800 | [diff] [blame] | 6832 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6833 | cpi->cur_poc++; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 6834 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools && |
| 6835 | !frame_is_intra_only(cm)) { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 6836 | if (cpi->common.seq_params.force_integer_mv == 2) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6837 | struct lookahead_entry *previous_entry = |
Debargha Mukherjee | a71e3db | 2018-02-28 07:47:17 -0800 | [diff] [blame] | 6838 | av1_lookahead_peek(cpi->lookahead, cpi->previous_index); |
| 6839 | if (!previous_entry) |
| 6840 | cpi->common.cur_frame_force_integer_mv = 0; |
| 6841 | else |
| 6842 | cpi->common.cur_frame_force_integer_mv = is_integer_mv( |
| 6843 | cpi, cpi->source, &previous_entry->img, cpi->previous_hash_table); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6844 | } else { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 6845 | cpi->common.cur_frame_force_integer_mv = |
| 6846 | cpi->common.seq_params.force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6847 | } |
| 6848 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6849 | cpi->common.cur_frame_force_integer_mv = 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6850 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6851 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 6852 | if (cpi->twopass.gf_group.index == 1 && cpi->oxcf.enable_tpl_model) { |
| 6853 | set_frame_size(cpi, cm->width, cm->height); |
| 6854 | setup_tpl_stats(cpi); |
| 6855 | } |
| 6856 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6857 | if (oxcf->pass == 1) { |
| 6858 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6859 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6860 | } else if (oxcf->pass == 2) { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6861 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 6862 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6863 | } else { |
| 6864 | // One pass encode |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6865 | if (Pass0Encode(cpi, size, dest, 0, frame_flags) != AOM_CODEC_OK) |
| 6866 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6867 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6868 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 6869 | cpi->previous_hash_table = &cm->cur_frame->hash_table; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6870 | { |
| 6871 | int l; |
| 6872 | for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) { |
| 6873 | if ((cpi->lookahead->buf + l) == source) { |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 6874 | cpi->previous_index = l; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6875 | break; |
| 6876 | } |
| 6877 | } |
| 6878 | |
| 6879 | if (l == cpi->lookahead->max_sz) { |
| 6880 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6881 | "Failed to find last frame original buffer"); |
| 6882 | } |
| 6883 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6884 | } |
| 6885 | |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 6886 | if (!cm->large_scale_tile) { |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 6887 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 6888 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6889 | |
Yunqing Wang | b041d8a | 2017-11-15 12:31:18 -0800 | [diff] [blame] | 6890 | #define EXT_TILE_DEBUG 0 |
| 6891 | #if EXT_TILE_DEBUG |
| 6892 | if (cm->large_scale_tile && oxcf->pass == 2) { |
| 6893 | char fn[20] = "./fc"; |
| 6894 | fn[4] = cm->current_video_frame / 100 + '0'; |
| 6895 | fn[5] = (cm->current_video_frame % 100) / 10 + '0'; |
| 6896 | fn[6] = (cm->current_video_frame % 10) + '0'; |
| 6897 | fn[7] = '\0'; |
| 6898 | av1_print_frame_contexts(cm->fc, fn); |
| 6899 | } |
| 6900 | #endif // EXT_TILE_DEBUG |
| 6901 | #undef EXT_TILE_DEBUG |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 6902 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6903 | cm->showable_frame = !cm->show_frame && cm->showable_frame; |
Yunqing Wang | b041d8a | 2017-11-15 12:31:18 -0800 | [diff] [blame] | 6904 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6905 | // No frame encoded, or frame was dropped, release scaled references. |
| 6906 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 6907 | release_scaled_references(cpi); |
| 6908 | } |
| 6909 | |
| 6910 | if (*size > 0) { |
Debargha Mukherjee | 8adee10 | 2018-09-25 11:01:00 -0700 | [diff] [blame] | 6911 | cpi->droppable = is_frame_droppable(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6912 | } |
| 6913 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6914 | aom_usec_timer_mark(&cmptimer); |
| 6915 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6916 | |
| 6917 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 6918 | generate_psnr_packet(cpi); |
| 6919 | |
| 6920 | #if CONFIG_INTERNAL_STATS |
| 6921 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6922 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6923 | } |
| 6924 | #endif // CONFIG_INTERNAL_STATS |
| 6925 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6926 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6927 | |
| 6928 | return 0; |
| 6929 | } |
| 6930 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6931 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6932 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6933 | if (!cm->show_frame) { |
| 6934 | return -1; |
| 6935 | } else { |
| 6936 | int ret; |
| 6937 | if (cm->frame_to_show) { |
| 6938 | *dest = *cm->frame_to_show; |
| 6939 | dest->y_width = cm->width; |
| 6940 | dest->y_height = cm->height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6941 | dest->uv_width = cm->width >> cm->seq_params.subsampling_x; |
| 6942 | dest->uv_height = cm->height >> cm->seq_params.subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6943 | ret = 0; |
| 6944 | } else { |
| 6945 | ret = -1; |
| 6946 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6947 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6948 | return ret; |
| 6949 | } |
| 6950 | } |
| 6951 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6952 | 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] | 6953 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 6954 | |
| 6955 | *frame = |
| 6956 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 6957 | return 0; |
| 6958 | } |
| 6959 | |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6960 | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
| 6961 | const YV12_BUFFER_CONFIG *b) { |
| 6962 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 6963 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
| 6964 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
| 6965 | a->border == b->border && |
| 6966 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
| 6967 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
| 6968 | } |
| 6969 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 6970 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 6971 | YV12_BUFFER_CONFIG *new_frame, |
| 6972 | YV12_BUFFER_CONFIG *sd) { |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6973 | const int num_planes = av1_num_planes(cm); |
| 6974 | if (!equal_dimensions_and_border(new_frame, sd)) |
| 6975 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 6976 | "Incorrect buffer dimensions"); |
| 6977 | else |
| 6978 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
| 6979 | |
| 6980 | return cm->error.error_code; |
| 6981 | } |
| 6982 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6983 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6984 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6985 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6986 | |
| 6987 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6988 | |
| 6989 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6990 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6991 | |
| 6992 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 6993 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6994 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6995 | |
| 6996 | return 0; |
| 6997 | } |
| 6998 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6999 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7000 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 7001 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *frame_size) { |
| 7002 | size_t output_size = 0; |
| 7003 | size_t total_bytes_read = 0; |
| 7004 | size_t remaining_size = *frame_size; |
| 7005 | uint8_t *buff_ptr = buffer; |
| 7006 | |
| 7007 | // go through each OBUs |
| 7008 | while (total_bytes_read < *frame_size) { |
| 7009 | uint8_t saved_obu_header[2]; |
| 7010 | uint64_t obu_payload_size; |
| 7011 | size_t length_of_payload_size; |
| 7012 | size_t length_of_obu_size; |
| 7013 | uint32_t obu_header_size = (buff_ptr[0] >> 2) & 0x1 ? 2 : 1; |
| 7014 | size_t obu_bytes_read = obu_header_size; // bytes read for current obu |
| 7015 | |
| 7016 | // save the obu header (1 or 2 bytes) |
| 7017 | memmove(saved_obu_header, buff_ptr, obu_header_size); |
| 7018 | // clear the obu_has_size_field |
| 7019 | saved_obu_header[0] = saved_obu_header[0] & (~0x2); |
| 7020 | |
| 7021 | // get the payload_size and length of payload_size |
| 7022 | if (aom_uleb_decode(buff_ptr + obu_header_size, remaining_size, |
| 7023 | &obu_payload_size, &length_of_payload_size) != 0) { |
| 7024 | return AOM_CODEC_ERROR; |
| 7025 | } |
| 7026 | obu_bytes_read += length_of_payload_size; |
| 7027 | |
| 7028 | // calculate the length of size of the obu header plus payload |
| 7029 | length_of_obu_size = |
| 7030 | aom_uleb_size_in_bytes((uint64_t)(obu_header_size + obu_payload_size)); |
| 7031 | |
| 7032 | // move the rest of data to new location |
| 7033 | memmove(buff_ptr + length_of_obu_size + obu_header_size, |
| 7034 | buff_ptr + obu_bytes_read, remaining_size - obu_bytes_read); |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 7035 | obu_bytes_read += (size_t)obu_payload_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 7036 | |
| 7037 | // write the new obu size |
| 7038 | const uint64_t obu_size = obu_header_size + obu_payload_size; |
| 7039 | size_t coded_obu_size; |
| 7040 | if (aom_uleb_encode(obu_size, sizeof(obu_size), buff_ptr, |
| 7041 | &coded_obu_size) != 0) { |
| 7042 | return AOM_CODEC_ERROR; |
| 7043 | } |
| 7044 | |
| 7045 | // write the saved (modified) obu_header following obu size |
| 7046 | memmove(buff_ptr + length_of_obu_size, saved_obu_header, obu_header_size); |
| 7047 | |
| 7048 | total_bytes_read += obu_bytes_read; |
| 7049 | remaining_size -= obu_bytes_read; |
| 7050 | buff_ptr += length_of_obu_size + obu_size; |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 7051 | output_size += length_of_obu_size + (size_t)obu_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | *frame_size = output_size; |
| 7055 | return AOM_CODEC_OK; |
| 7056 | } |
| 7057 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7058 | 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] | 7059 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 7060 | // should be consistent with internal reference frame selection. Need to |
| 7061 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 7062 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
| 7063 | // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be |
| 7064 | // LAST. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 7065 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7066 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7067 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 7068 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 7069 | AOM_EFLAG_NO_REF_ARF2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7070 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 7071 | cpi->ext_ref_frame_flags = 0; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7072 | } else { |
| 7073 | int ref = AOM_REFFRAME_ALL; |
| 7074 | |
| 7075 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 7076 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 7077 | |
| 7078 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 7079 | |
| 7080 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 7081 | ref ^= AOM_ALT_FLAG; |
| 7082 | ref ^= AOM_BWD_FLAG; |
| 7083 | ref ^= AOM_ALT2_FLAG; |
| 7084 | } else { |
| 7085 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 7086 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
| 7087 | } |
| 7088 | |
| 7089 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7090 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7091 | } |
| 7092 | |
| 7093 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7094 | (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] | 7095 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7096 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7097 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 7098 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7099 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7100 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7101 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7102 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 7103 | upd ^= AOM_ALT_FLAG; |
| 7104 | upd ^= AOM_BWD_FLAG; |
| 7105 | upd ^= AOM_ALT2_FLAG; |
| 7106 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7107 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7108 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7109 | } |
| 7110 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 7111 | cpi->ext_use_ref_frame_mvs = cpi->oxcf.allow_ref_frame_mvs & |
| 7112 | ((flags & AOM_EFLAG_NO_REF_FRAME_MVS) == 0); |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 7113 | cpi->ext_use_error_resilient = cpi->oxcf.error_resilient_mode | |
| 7114 | ((flags & AOM_EFLAG_ERROR_RESILIENT) != 0); |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 7115 | cpi->ext_use_s_frame = |
| 7116 | cpi->oxcf.s_frame_mode | ((flags & AOM_EFLAG_SET_S_FRAME) != 0); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 7117 | 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] | 7118 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7119 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 7120 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7121 | } |
| 7122 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 7123 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 7124 | int64_t timebase_units_to_ticks(const aom_rational_t *timebase, int64_t n) { |
| 7125 | return n * TICKS_PER_SEC * timebase->num / timebase->den; |
| 7126 | } |
| 7127 | |
| 7128 | int64_t ticks_to_timebase_units(const aom_rational_t *timebase, int64_t n) { |
| 7129 | const int64_t round = TICKS_PER_SEC * timebase->num / 2 - 1; |
| 7130 | return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC; |
| 7131 | } |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 7132 | |
| 7133 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi) { |
| 7134 | if (!cpi) return NULL; |
| 7135 | |
| 7136 | uint8_t header_buf[512] = { 0 }; |
| 7137 | const uint32_t sequence_header_size = |
| 7138 | write_sequence_header_obu(cpi, &header_buf[0]); |
| 7139 | assert(sequence_header_size <= sizeof(header_buf)); |
| 7140 | if (sequence_header_size == 0) return NULL; |
| 7141 | |
| 7142 | const size_t obu_header_size = 1; |
| 7143 | const size_t size_field_size = aom_uleb_size_in_bytes(sequence_header_size); |
| 7144 | const size_t payload_offset = obu_header_size + size_field_size; |
| 7145 | |
| 7146 | if (payload_offset + sequence_header_size > sizeof(header_buf)) return NULL; |
| 7147 | memmove(&header_buf[payload_offset], &header_buf[0], sequence_header_size); |
| 7148 | |
| 7149 | if (write_obu_header(OBU_SEQUENCE_HEADER, 0, &header_buf[0]) != |
| 7150 | obu_header_size) { |
| 7151 | return NULL; |
| 7152 | } |
| 7153 | |
| 7154 | size_t coded_size_field_size = 0; |
| 7155 | if (aom_uleb_encode(sequence_header_size, size_field_size, |
| 7156 | &header_buf[obu_header_size], |
| 7157 | &coded_size_field_size) != 0) { |
| 7158 | return NULL; |
| 7159 | } |
| 7160 | assert(coded_size_field_size == size_field_size); |
| 7161 | |
| 7162 | aom_fixed_buf_t *global_headers = |
| 7163 | (aom_fixed_buf_t *)malloc(sizeof(*global_headers)); |
| 7164 | if (!global_headers) return NULL; |
| 7165 | |
| 7166 | const size_t global_header_buf_size = |
| 7167 | obu_header_size + size_field_size + sequence_header_size; |
| 7168 | |
| 7169 | global_headers->buf = malloc(global_header_buf_size); |
| 7170 | if (!global_headers->buf) { |
| 7171 | free(global_headers); |
| 7172 | return NULL; |
| 7173 | } |
| 7174 | |
| 7175 | memcpy(global_headers->buf, &header_buf[0], global_header_buf_size); |
| 7176 | global_headers->sz = global_header_buf_size; |
| 7177 | return global_headers; |
| 7178 | } |