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