blob: c177d94a4a950c0fb4b8e62ba4b5e8c5e9558d67 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Urvang Joshi8a02d762016-07-28 15:51:12 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Urvang Joshi8a02d762016-07-28 15:51:12 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <limits.h>
13#include <math.h>
14#include <stdio.h>
15
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070017
18#include "av1/common/alloccommon.h"
Steinar Midtskogena9d41e82017-03-17 12:48:15 +010019#include "av1/common/cdef.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070020#include "av1/common/filter.h"
21#include "av1/common/idct.h"
22#include "av1/common/reconinter.h"
23#include "av1/common/reconintra.h"
Fergus Simpsond0565002017-03-27 16:51:52 -070024#include "av1/common/resize.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070025#include "av1/common/tile_common.h"
26
27#include "av1/encoder/aq_complexity.h"
28#include "av1/encoder/aq_cyclicrefresh.h"
29#include "av1/encoder/aq_variance.h"
30#include "av1/encoder/bitstream.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070031#include "av1/encoder/context_tree.h"
32#include "av1/encoder/encodeframe.h"
33#include "av1/encoder/encodemv.h"
34#include "av1/encoder/encoder.h"
Angie Chiangf0fbf9d2017-03-15 15:01:22 -070035#include "av1/encoder/encodetxb.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070036#include "av1/encoder/ethread.h"
37#include "av1/encoder/firstpass.h"
RogerZhoucc5d35d2017-08-07 22:20:15 -070038#if CONFIG_HASH_ME
39#include "av1/encoder/hash_motion.h"
40#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070041#include "av1/encoder/mbgraph.h"
42#include "av1/encoder/picklpf.h"
43#if CONFIG_LOOP_RESTORATION
44#include "av1/encoder/pickrst.h"
45#endif // CONFIG_LOOP_RESTORATION
Debargha Mukherjee7166f222017-09-05 21:32:42 -070046#include "av1/encoder/random.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070047#include "av1/encoder/ratectrl.h"
48#include "av1/encoder/rd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070049#include "av1/encoder/segmentation.h"
50#include "av1/encoder/speed_features.h"
51#include "av1/encoder/temporal_filter.h"
52
Yaowu Xuf883b422016-08-30 14:01:10 -070053#include "./av1_rtcd.h"
54#include "./aom_dsp_rtcd.h"
55#include "./aom_scale_rtcd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070056#include "aom_dsp/psnr.h"
57#if CONFIG_INTERNAL_STATS
58#include "aom_dsp/ssim.h"
59#endif
Andrey Norkin6f1c2f72018-01-15 20:08:52 -080060#if CONFIG_FILM_GRAIN
61#include "av1/encoder/grain_test_vectors.h"
62#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070063#include "aom_dsp/aom_dsp_common.h"
64#include "aom_dsp/aom_filter.h"
Jingning Han1aab8182016-06-03 11:09:06 -070065#include "aom_ports/aom_timer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070066#include "aom_ports/mem.h"
67#include "aom_ports/system_state.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070068#include "aom_scale/aom_scale.h"
Angie Chiang5b5f4df2017-12-06 10:41:12 -080069#if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -070070#include "aom_util/debug_util.h"
Angie Chiang5b5f4df2017-12-06 10:41:12 -080071#endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -070072
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -080073#if CONFIG_ENTROPY_STATS
74FRAME_COUNTS aggregate_fc;
Zoe Liua56f9162017-06-21 22:49:57 -070075// Aggregate frame counts per frame context type
76FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS];
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -080077#endif // CONFIG_ENTROPY_STATS
78
Yaowu Xuc27fc142016-08-22 16:08:15 -070079#define AM_SEGMENT_ID_INACTIVE 7
80#define AM_SEGMENT_ID_ACTIVE 0
81
Johannb0ef6ff2018-02-08 14:32:21 -080082// Whether to use high precision mv for altref computation.
83#define ALTREF_HIGH_PRECISION_MV 1
84
85// Q threshold for high precision mv. Choose a very high value for now so that
86// HIGH_PRECISION is always chosen.
87#define HIGH_PRECISION_MV_QTHRESH 200
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -070088
Yaowu Xuc27fc142016-08-22 16:08:15 -070089// #define OUTPUT_YUV_REC
Yaowu Xuc27fc142016-08-22 16:08:15 -070090#ifdef OUTPUT_YUV_SKINMAP
91FILE *yuv_skinmap_file = NULL;
92#endif
93#ifdef OUTPUT_YUV_REC
94FILE *yuv_rec_file;
95#define FILE_NAME_LEN 100
96#endif
97
98#if 0
99FILE *framepsnr;
100FILE *kf_list;
101FILE *keyfile;
102#endif
103
Urvang Joshib5ed3502016-10-17 16:38:05 -0700104#if CONFIG_INTERNAL_STATS
105typedef enum { Y, U, V, ALL } STAT_TYPE;
106#endif // CONFIG_INTERNAL_STATS
107
Yaowu Xuf883b422016-08-30 14:01:10 -0700108static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109 switch (mode) {
110 case NORMAL:
111 *hr = 1;
112 *hs = 1;
113 break;
114 case FOURFIVE:
115 *hr = 4;
116 *hs = 5;
117 break;
118 case THREEFIVE:
119 *hr = 3;
120 *hs = 5;
121 break;
122 case ONETWO:
123 *hr = 1;
124 *hs = 2;
125 break;
126 default:
127 *hr = 1;
128 *hs = 1;
129 assert(0);
130 break;
131 }
132}
133
134// Mark all inactive blocks as active. Other segmentation features may be set
135// so memset cannot be used, instead only inactive blocks should be reset.
Yaowu Xuf883b422016-08-30 14:01:10 -0700136static void suppress_active_map(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 unsigned char *const seg_map = cpi->segmentation_map;
138 int i;
139 if (cpi->active_map.enabled || cpi->active_map.update)
140 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
141 if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
142 seg_map[i] = AM_SEGMENT_ID_ACTIVE;
143}
144
Yaowu Xuf883b422016-08-30 14:01:10 -0700145static void apply_active_map(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700146 struct segmentation *const seg = &cpi->common.seg;
147 unsigned char *const seg_map = cpi->segmentation_map;
148 const unsigned char *const active_map = cpi->active_map.map;
149 int i;
150
151 assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE);
152
153 if (frame_is_intra_only(&cpi->common)) {
154 cpi->active_map.enabled = 0;
155 cpi->active_map.update = 1;
156 }
157
158 if (cpi->active_map.update) {
159 if (cpi->active_map.enabled) {
160 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
161 if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i];
Yaowu Xuf883b422016-08-30 14:01:10 -0700162 av1_enable_segmentation(seg);
163 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
Cheng Chend8184da2017-09-26 18:15:22 -0700164#if CONFIG_LOOPFILTER_LEVEL
165 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H);
166 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V);
167 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U);
168 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V);
169
170 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H,
171 -MAX_LOOP_FILTER);
172 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V,
173 -MAX_LOOP_FILTER);
174 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U,
175 -MAX_LOOP_FILTER);
176 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V,
177 -MAX_LOOP_FILTER);
178#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700179 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700180 // Setting the data to -MAX_LOOP_FILTER will result in the computed loop
Yushin Chod728c212017-11-03 12:30:24 -0700181 // filter level being zero.
Yaowu Xuf883b422016-08-30 14:01:10 -0700182 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF,
183 -MAX_LOOP_FILTER);
Cheng Chend8184da2017-09-26 18:15:22 -0700184#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700185 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700186 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
Cheng Chend8184da2017-09-26 18:15:22 -0700187#if CONFIG_LOOPFILTER_LEVEL
188 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H);
189 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V);
190 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U);
191 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V);
192#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700193 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
Cheng Chend8184da2017-09-26 18:15:22 -0700194#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700195 if (seg->enabled) {
196 seg->update_data = 1;
197 seg->update_map = 1;
198 }
199 }
200 cpi->active_map.update = 0;
201 }
202}
203
Yaowu Xuf883b422016-08-30 14:01:10 -0700204int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows,
205 int cols) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700206 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
207 unsigned char *const active_map_8x8 = cpi->active_map.map;
208 const int mi_rows = cpi->common.mi_rows;
209 const int mi_cols = cpi->common.mi_cols;
Jingning Han9d533022017-04-07 10:14:42 -0700210 const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2;
211 const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 cpi->active_map.update = 1;
213 if (new_map_16x16) {
214 int r, c;
215 for (r = 0; r < mi_rows; ++r) {
216 for (c = 0; c < mi_cols; ++c) {
217 active_map_8x8[r * mi_cols + c] =
Jingning Han9d533022017-04-07 10:14:42 -0700218 new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)]
Yaowu Xuc27fc142016-08-22 16:08:15 -0700219 ? AM_SEGMENT_ID_ACTIVE
220 : AM_SEGMENT_ID_INACTIVE;
221 }
222 }
223 cpi->active_map.enabled = 1;
224 } else {
225 cpi->active_map.enabled = 0;
226 }
227 return 0;
228 } else {
229 return -1;
230 }
231}
232
Yaowu Xuf883b422016-08-30 14:01:10 -0700233int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows,
234 int cols) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700235 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols &&
236 new_map_16x16) {
237 unsigned char *const seg_map_8x8 = cpi->segmentation_map;
238 const int mi_rows = cpi->common.mi_rows;
239 const int mi_cols = cpi->common.mi_cols;
Jingning Han9d533022017-04-07 10:14:42 -0700240 const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2;
241 const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2;
242
Yaowu Xuc27fc142016-08-22 16:08:15 -0700243 memset(new_map_16x16, !cpi->active_map.enabled, rows * cols);
244 if (cpi->active_map.enabled) {
245 int r, c;
246 for (r = 0; r < mi_rows; ++r) {
247 for (c = 0; c < mi_cols; ++c) {
248 // Cyclic refresh segments are considered active despite not having
249 // AM_SEGMENT_ID_ACTIVE
Jingning Han9d533022017-04-07 10:14:42 -0700250 new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |=
Yaowu Xuc27fc142016-08-22 16:08:15 -0700251 seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE;
252 }
253 }
254 }
255 return 0;
256 } else {
257 return -1;
258 }
259}
260
RogerZhou3b635242017-09-19 10:06:46 -0700261static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv
262#if CONFIG_AMVR
263 ,
RogerZhou10a03802017-10-26 11:49:48 -0700264 int cur_frame_force_integer_mv
RogerZhou3b635242017-09-19 10:06:46 -0700265#endif
Johannb0ef6ff2018-02-08 14:32:21 -0800266) {
James Zern01a9d702017-08-25 19:09:33 +0000267 MACROBLOCK *const mb = &cpi->td.mb;
268 cpi->common.allow_high_precision_mv = allow_high_precision_mv;
269
RogerZhou3b635242017-09-19 10:06:46 -0700270#if CONFIG_AMVR
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000271 const int copy_hp =
272 cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0;
RogerZhou3b635242017-09-19 10:06:46 -0700273#else
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000274 const int copy_hp = cpi->common.allow_high_precision_mv;
RogerZhou3b635242017-09-19 10:06:46 -0700275#endif
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000276 int *(*src)[2] = copy_hp ? mb->nmvcost_hp : mb->nmvcost;
277 for (int i = 0; i < NMV_CONTEXTS; ++i) {
278 mb->mv_cost_stack[i] = src[i];
James Zern01a9d702017-08-25 19:09:33 +0000279 }
280}
281
Yaowu Xuf883b422016-08-30 14:01:10 -0700282static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700283#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700284 if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285 return BLOCK_64X64;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100286#if CONFIG_FILEOPTIONS
287 if (cpi->common.options && cpi->common.options->ext_partition)
288#endif
289 if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128)
290 return BLOCK_128X128;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700291
Yaowu Xuf883b422016-08-30 14:01:10 -0700292 assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700293
Dominic Symes917d6c02017-10-11 18:00:52 +0200294#if !CONFIG_MAX_TILE
295 // for the max_tile experiment there is no common tile_width, tile_height
296 // max_tile assumes tile dimensions are in superblocks (not 64x64 units)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700297 assert(IMPLIES(cpi->common.tile_cols > 1,
298 cpi->common.tile_width % MAX_MIB_SIZE == 0));
299 assert(IMPLIES(cpi->common.tile_rows > 1,
300 cpi->common.tile_height % MAX_MIB_SIZE == 0));
Dominic Symes917d6c02017-10-11 18:00:52 +0200301#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700302
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100303// TODO(any): Possibly could improve this with a heuristic.
304#if CONFIG_FILEOPTIONS
305 if (cpi->common.options && !cpi->common.options->ext_partition)
306 return BLOCK_64X64;
307#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700308 return BLOCK_128X128;
309#else
310 (void)cpi;
311 return BLOCK_64X64;
312#endif // CONFIG_EXT_PARTITION
313}
314
Yaowu Xuf883b422016-08-30 14:01:10 -0700315static void setup_frame(AV1_COMP *cpi) {
316 AV1_COMMON *const cm = &cpi->common;
Johannb0ef6ff2018-02-08 14:32:21 -0800317 // Set up entropy context depending on frame type. The decoder mandates
318 // the use of the default context, index 0, for keyframes and inter
319 // frames where the error_resilient_mode or intra_only flag is set. For
320 // other inter-frames the encoder currently uses only two contexts;
321 // context 1 for ALTREF frames and context 0 for the others.
Soo-Chul Han85e8c792018-01-21 01:58:15 -0500322
323#if CONFIG_SEGMENT_PRED_LAST
324 if (cm->prev_frame) cm->last_frame_seg_map = cm->prev_frame->seg_map;
325 cm->current_frame_seg_map = cm->cur_frame->seg_map;
326#endif
327
Yaowu Xuc27fc142016-08-22 16:08:15 -0700328 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700329 av1_setup_past_independence(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700330 } else {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700331#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
332// Just use frame context from first signaled reference frame.
333// This will always be LAST_FRAME for now.
334#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700335 const GF_GROUP *gf_group = &cpi->twopass.gf_group;
Zoe Liue9b15e22017-07-19 15:53:01 -0700336 if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700337 cm->frame_context_idx = EXT_ARF_FRAME;
338 else if (cpi->refresh_alt_ref_frame)
339 cm->frame_context_idx = ARF_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340 else if (cpi->rc.is_src_frame_alt_ref)
341 cm->frame_context_idx = OVERLAY_FRAME;
342 else if (cpi->refresh_golden_frame)
343 cm->frame_context_idx = GLD_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700344 else if (cpi->refresh_bwd_ref_frame)
345 cm->frame_context_idx = BRF_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700346 else
347 cm->frame_context_idx = REGULAR_FRAME;
Thomas Daededa4d8b92017-06-05 15:44:14 -0700348#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700349 }
350
351 if (cm->frame_type == KEY_FRAME) {
352 cpi->refresh_golden_frame = 1;
353 cpi->refresh_alt_ref_frame = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700354 av1_zero(cpi->interp_filter_selected);
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000355 set_sb_size(&cm->seq_params, select_sb_size(cpi));
Debargha Mukherjee778023d2017-09-26 17:50:27 -0700356#if CONFIG_REFERENCE_BUFFER
357 set_use_reference_buffer(cm, 0);
358#endif // CONFIG_REFERENCE_BUFFER
David Barker11eac7b2017-12-07 12:22:36 +0000359#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
360 cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
361#else
362 cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx];
363#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700364 } else {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700365#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
David Barker11eac7b2017-12-07 12:22:36 +0000366 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700367 *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
David Barker11eac7b2017-12-07 12:22:36 +0000368 cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700369 } else {
David Barker11eac7b2017-12-07 12:22:36 +0000370 assert(cm->frame_refs[0].idx >= 0);
Thomas Daededa4d8b92017-06-05 15:44:14 -0700371 *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx];
David Barker11eac7b2017-12-07 12:22:36 +0000372 cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700373 }
374#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700375 *cm->fc = cm->frame_contexts[cm->frame_context_idx];
David Barker11eac7b2017-12-07 12:22:36 +0000376 cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700377#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuf883b422016-08-30 14:01:10 -0700378 av1_zero(cpi->interp_filter_selected[0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700379 }
Zoe Liuc01dddb2017-11-07 08:44:06 -0800380#if !CONFIG_EXT_COMP_REFS // No change to bitstream
Arild Fuldseth (arilfuld)3f429082017-04-28 15:54:28 +0200381 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
382 cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame;
383 cpi->rc.is_bipred_frame = 1;
384 }
Zoe Liuc01dddb2017-11-07 08:44:06 -0800385#endif // !CONFIG_EXT_COMP_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700386
387 cpi->vaq_refresh = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700388}
389
Cheng Chen46f30c72017-09-07 11:13:33 -0700390static void enc_setup_mi(AV1_COMMON *cm) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700391 int i;
Yunqing Wang19b9f722018-02-20 16:22:01 -0800392 cm->mi = cm->mip;
393 memset(cm->mip, 0, cm->mi_stride * cm->mi_rows * sizeof(*cm->mip));
394 cm->prev_mi = cm->prev_mip;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700395 // Clear top border row
396 memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride);
397 // Clear left border column
Yunqing Wang19b9f722018-02-20 16:22:01 -0800398 for (i = 0; i < cm->mi_rows; ++i)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700399 memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip));
Yunqing Wang19b9f722018-02-20 16:22:01 -0800400 cm->mi_grid_visible = cm->mi_grid_base;
401 cm->prev_mi_grid_visible = cm->prev_mi_grid_base;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700402
403 memset(cm->mi_grid_base, 0,
Yunqing Wang19b9f722018-02-20 16:22:01 -0800404 cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base));
Frank Bossen4ef06b52018-01-18 19:51:15 -0500405
406 memset(cm->boundary_info, 0,
407 cm->boundary_info_alloc_size * sizeof(*cm->boundary_info));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700408}
409
Cheng Chen46f30c72017-09-07 11:13:33 -0700410static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700411 cm->mip = aom_calloc(mi_size, sizeof(*cm->mip));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700412 if (!cm->mip) return 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700413 cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700414 if (!cm->prev_mip) return 1;
415 cm->mi_alloc_size = mi_size;
416
Yaowu Xuf883b422016-08-30 14:01:10 -0700417 cm->mi_grid_base = (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700418 if (!cm->mi_grid_base) return 1;
419 cm->prev_mi_grid_base =
Yaowu Xuf883b422016-08-30 14:01:10 -0700420 (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700421 if (!cm->prev_mi_grid_base) return 1;
422
423 return 0;
424}
425
Cheng Chen46f30c72017-09-07 11:13:33 -0700426static void enc_free_mi(AV1_COMMON *cm) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700427 aom_free(cm->mip);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700428 cm->mip = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700429 aom_free(cm->prev_mip);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700430 cm->prev_mip = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700431 aom_free(cm->mi_grid_base);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700432 cm->mi_grid_base = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700433 aom_free(cm->prev_mi_grid_base);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700434 cm->prev_mi_grid_base = NULL;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700435 cm->mi_alloc_size = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700436}
437
Cheng Chen46f30c72017-09-07 11:13:33 -0700438static void swap_mi_and_prev_mi(AV1_COMMON *cm) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700439 // Current mip will be the prev_mip for the next frame.
440 MODE_INFO **temp_base = cm->prev_mi_grid_base;
441 MODE_INFO *temp = cm->prev_mip;
442 cm->prev_mip = cm->mip;
443 cm->mip = temp;
444
445 // Update the upper left visible macroblock ptrs.
Yunqing Wang19b9f722018-02-20 16:22:01 -0800446 cm->mi = cm->mip;
447 cm->prev_mi = cm->prev_mip;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700448
449 cm->prev_mi_grid_base = cm->mi_grid_base;
450 cm->mi_grid_base = temp_base;
Yunqing Wang19b9f722018-02-20 16:22:01 -0800451 cm->mi_grid_visible = cm->mi_grid_base;
452 cm->prev_mi_grid_visible = cm->prev_mi_grid_base;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700453}
454
Yaowu Xuf883b422016-08-30 14:01:10 -0700455void av1_initialize_enc(void) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700456 static volatile int init_done = 0;
457
458 if (!init_done) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700459 av1_rtcd();
460 aom_dsp_rtcd();
461 aom_scale_rtcd();
462 av1_init_intra_predictors();
463 av1_init_me_luts();
464 av1_rc_init_minq_luts();
Yaowu Xuf883b422016-08-30 14:01:10 -0700465 av1_init_wedge_masks();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700466 init_done = 1;
467 }
468}
469
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700470static void dealloc_context_buffers_ext(AV1_COMP *cpi) {
471 if (cpi->mbmi_ext_base) {
472 aom_free(cpi->mbmi_ext_base);
473 cpi->mbmi_ext_base = NULL;
474 }
475}
476
477static void alloc_context_buffers_ext(AV1_COMP *cpi) {
478 AV1_COMMON *cm = &cpi->common;
479 int mi_size = cm->mi_cols * cm->mi_rows;
480
481 dealloc_context_buffers_ext(cpi);
482 CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base,
483 aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base)));
484}
485
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800486#if CONFIG_FILM_GRAIN
487static void update_film_grain_parameters(struct AV1_COMP *cpi,
488 const AV1EncoderConfig *oxcf) {
489 AV1_COMMON *const cm = &cpi->common;
490 cpi->oxcf = *oxcf;
491
492 if (oxcf->film_grain_test_vector) {
493 cm->film_grain_params_present = 1;
494 if (cm->frame_type == KEY_FRAME) {
495 memcpy(&cm->film_grain_params,
496 film_grain_test_vectors + oxcf->film_grain_test_vector - 1,
497 sizeof(cm->film_grain_params));
498
499 cm->film_grain_params.bit_depth = cm->bit_depth;
500 if (cm->color_range == AOM_CR_FULL_RANGE) {
501 cm->film_grain_params.clip_to_restricted_range = 0;
502 }
503 }
504 } else {
505 cm->film_grain_params_present = 0;
506 memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params));
507 }
508}
509#endif
510
Yaowu Xuf883b422016-08-30 14:01:10 -0700511static void dealloc_compressor_data(AV1_COMP *cpi) {
512 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000513 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700514
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700515 dealloc_context_buffers_ext(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700516
Yaowu Xuf883b422016-08-30 14:01:10 -0700517 aom_free(cpi->tile_data);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700518 cpi->tile_data = NULL;
519
520 // Delete sementation map
Yaowu Xuf883b422016-08-30 14:01:10 -0700521 aom_free(cpi->segmentation_map);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700522 cpi->segmentation_map = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700523
Yaowu Xuf883b422016-08-30 14:01:10 -0700524 av1_cyclic_refresh_free(cpi->cyclic_refresh);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700525 cpi->cyclic_refresh = NULL;
526
Yaowu Xuf883b422016-08-30 14:01:10 -0700527 aom_free(cpi->active_map.map);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700528 cpi->active_map.map = NULL;
529
Yue Chen19d76012018-02-16 15:13:40 -0800530#if CONFIG_OBMC_HIGH_PREC_BLENDING
531 aom_free(cpi->td.mb.above_pred_hp_buf);
532 cpi->td.mb.above_pred_hp_buf = NULL;
533
534 aom_free(cpi->td.mb.left_pred_hp_buf);
535 cpi->td.mb.left_pred_hp_buf = NULL;
536#else
Jingning Hand064cf02017-06-01 10:00:39 -0700537 aom_free(cpi->td.mb.above_pred_buf);
538 cpi->td.mb.above_pred_buf = NULL;
539
540 aom_free(cpi->td.mb.left_pred_buf);
541 cpi->td.mb.left_pred_buf = NULL;
Yue Chen19d76012018-02-16 15:13:40 -0800542#endif
Jingning Hand064cf02017-06-01 10:00:39 -0700543
544 aom_free(cpi->td.mb.wsrc_buf);
545 cpi->td.mb.wsrc_buf = NULL;
546
547 aom_free(cpi->td.mb.mask_buf);
548 cpi->td.mb.mask_buf = NULL;
Jingning Hand064cf02017-06-01 10:00:39 -0700549
Jingning Han6cc1fd32017-10-13 09:05:36 -0700550#if CONFIG_MFMV
551 aom_free(cm->tpl_mvs);
552 cm->tpl_mvs = NULL;
553#endif
554
Yaowu Xuf883b422016-08-30 14:01:10 -0700555 av1_free_ref_frame_buffers(cm->buffer_pool);
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700556 av1_free_txb_buf(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -0700557 av1_free_context_buffers(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700558
Yaowu Xuf883b422016-08-30 14:01:10 -0700559 aom_free_frame_buffer(&cpi->last_frame_uf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700560#if CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -0700561 av1_free_restoration_buffers(cm);
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800562 aom_free_frame_buffer(&cpi->trial_frame_rst);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700563#endif // CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -0700564 aom_free_frame_buffer(&cpi->scaled_source);
565 aom_free_frame_buffer(&cpi->scaled_last_source);
566 aom_free_frame_buffer(&cpi->alt_ref_buffer);
567 av1_lookahead_destroy(cpi->lookahead);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700568
Yaowu Xuf883b422016-08-30 14:01:10 -0700569 aom_free(cpi->tile_tok[0][0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700570 cpi->tile_tok[0][0] = 0;
571
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000572 av1_free_pc_tree(&cpi->td, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700573
hui sud9a812b2017-07-06 14:34:37 -0700574 aom_free(cpi->td.mb.palette_buffer);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700575}
576
Yaowu Xuf883b422016-08-30 14:01:10 -0700577static void save_coding_context(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700578 CODING_CONTEXT *const cc = &cpi->coding_context;
Yaowu Xuf883b422016-08-30 14:01:10 -0700579 AV1_COMMON *cm = &cpi->common;
James Zern01a9d702017-08-25 19:09:33 +0000580 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700581
Sebastien Alaiwane140c502017-04-27 09:52:34 +0200582 // Stores a snapshot of key state variables which can subsequently be
583 // restored with a call to av1_restore_coding_context. These functions are
584 // intended for use in a re-code loop in av1_compress_frame where the
585 // quantizer value is adjusted between loop iterations.
James Zern01a9d702017-08-25 19:09:33 +0000586 for (i = 0; i < NMV_CONTEXTS; ++i) {
587 av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]);
588 av1_copy(cc->nmv_costs, cpi->nmv_costs);
589 av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp);
590 }
591
Yaowu Xuf883b422016-08-30 14:01:10 -0700592 av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas);
593 av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700594
595 cc->fc = *cm->fc;
596}
597
Yaowu Xuf883b422016-08-30 14:01:10 -0700598static void restore_coding_context(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700599 CODING_CONTEXT *const cc = &cpi->coding_context;
Yaowu Xuf883b422016-08-30 14:01:10 -0700600 AV1_COMMON *cm = &cpi->common;
James Zern01a9d702017-08-25 19:09:33 +0000601 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700602
Sebastien Alaiwane140c502017-04-27 09:52:34 +0200603 // Restore key state variables to the snapshot state stored in the
604 // previous call to av1_save_coding_context.
James Zern01a9d702017-08-25 19:09:33 +0000605 for (i = 0; i < NMV_CONTEXTS; ++i) {
606 av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]);
607 av1_copy(cpi->nmv_costs, cc->nmv_costs);
608 av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp);
609 }
610
Yaowu Xuf883b422016-08-30 14:01:10 -0700611 av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas);
612 av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700613
614 *cm->fc = cc->fc;
615}
616
Yaowu Xuf883b422016-08-30 14:01:10 -0700617static void configure_static_seg_features(AV1_COMP *cpi) {
618 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700619 const RATE_CONTROL *const rc = &cpi->rc;
620 struct segmentation *const seg = &cm->seg;
621
622 int high_q = (int)(rc->avg_q > 48.0);
623 int qi_delta;
624
625 // Disable and clear down for KF
626 if (cm->frame_type == KEY_FRAME) {
627 // Clear down the global segmentation map
628 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
629 seg->update_map = 0;
630 seg->update_data = 0;
631 cpi->static_mb_pct = 0;
632
633 // Disable segmentation
Yaowu Xuf883b422016-08-30 14:01:10 -0700634 av1_disable_segmentation(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700635
636 // Clear down the segment features.
Yaowu Xuf883b422016-08-30 14:01:10 -0700637 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700638 } else if (cpi->refresh_alt_ref_frame) {
639 // If this is an alt ref frame
640 // Clear down the global segmentation map
641 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
642 seg->update_map = 0;
643 seg->update_data = 0;
644 cpi->static_mb_pct = 0;
645
646 // Disable segmentation and individual segment features by default
Yaowu Xuf883b422016-08-30 14:01:10 -0700647 av1_disable_segmentation(seg);
648 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700649
650 // Scan frames from current to arf frame.
651 // This function re-enables segmentation if appropriate.
Yaowu Xuf883b422016-08-30 14:01:10 -0700652 av1_update_mbgraph_stats(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700653
654 // If segmentation was enabled set those features needed for the
655 // arf itself.
656 if (seg->enabled) {
657 seg->update_map = 1;
658 seg->update_data = 1;
659
660 qi_delta =
Yaowu Xuf883b422016-08-30 14:01:10 -0700661 av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth);
662 av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2);
Cheng Chend8184da2017-09-26 18:15:22 -0700663#if CONFIG_LOOPFILTER_LEVEL
664 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2);
665 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2);
666 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2);
667 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2);
668
669 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H);
670 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V);
671 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U);
672 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V);
673#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700674 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
Cheng Chend8184da2017-09-26 18:15:22 -0700675 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
676#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700677
Yaowu Xuf883b422016-08-30 14:01:10 -0700678 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700679 }
680 } else if (seg->enabled) {
681 // All other frames if segmentation has been enabled
682
683 // First normal frame in a valid gf or alt ref group
684 if (rc->frames_since_golden == 0) {
685 // Set up segment features for normal frames in an arf group
686 if (rc->source_alt_ref_active) {
687 seg->update_map = 0;
688 seg->update_data = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700689
Yaowu Xuf883b422016-08-30 14:01:10 -0700690 qi_delta =
691 av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth);
692 av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2);
693 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700694
Cheng Chend8184da2017-09-26 18:15:22 -0700695#if CONFIG_LOOPFILTER_LEVEL
696 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2);
697 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2);
698 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2);
699 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2);
700
701 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H);
702 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V);
703 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U);
704 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V);
705#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700706 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
707 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
Cheng Chend8184da2017-09-26 18:15:22 -0700708#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700709
710 // Segment coding disabled for compred testing
711 if (high_q || (cpi->static_mb_pct == 100)) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700712 av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
713 av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
714 av1_enable_segfeature(seg, 1, SEG_LVL_SKIP);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700715 }
716 } else {
717 // Disable segmentation and clear down features if alt ref
718 // is not active for this group
719
Yaowu Xuf883b422016-08-30 14:01:10 -0700720 av1_disable_segmentation(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700721
722 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
723
724 seg->update_map = 0;
725 seg->update_data = 0;
726
Yaowu Xuf883b422016-08-30 14:01:10 -0700727 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700728 }
729 } else if (rc->is_src_frame_alt_ref) {
730 // Special case where we are coding over the top of a previous
731 // alt ref frame.
732 // Segment coding disabled for compred testing
733
734 // Enable ref frame features for segment 0 as well
Yaowu Xuf883b422016-08-30 14:01:10 -0700735 av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME);
736 av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700737
738 // All mbs should use ALTREF_FRAME
Yaowu Xuf883b422016-08-30 14:01:10 -0700739 av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME);
740 av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
741 av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME);
742 av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700743
744 // Skip all MBs if high Q (0,0 mv and skip coeffs)
745 if (high_q) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700746 av1_enable_segfeature(seg, 0, SEG_LVL_SKIP);
747 av1_enable_segfeature(seg, 1, SEG_LVL_SKIP);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700748 }
749 // Enable data update
750 seg->update_data = 1;
751 } else {
752 // All other frames.
753
754 // No updates.. leave things as they are.
755 seg->update_map = 0;
756 seg->update_data = 0;
757 }
758 }
759}
760
Yaowu Xuf883b422016-08-30 14:01:10 -0700761static void update_reference_segmentation_map(AV1_COMP *cpi) {
762 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700763 MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible;
Soo-Chul Han934af352017-10-15 15:21:51 -0400764#if CONFIG_SEGMENT_PRED_LAST
765 uint8_t *cache_ptr = cm->current_frame_seg_map;
766#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700767 uint8_t *cache_ptr = cm->last_frame_seg_map;
Soo-Chul Han934af352017-10-15 15:21:51 -0400768#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700769 int row, col;
770
771 for (row = 0; row < cm->mi_rows; row++) {
772 MODE_INFO **mi_8x8 = mi_8x8_ptr;
773 uint8_t *cache = cache_ptr;
774 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++)
775 cache[0] = mi_8x8[0]->mbmi.segment_id;
776 mi_8x8_ptr += cm->mi_stride;
777 cache_ptr += cm->mi_cols;
778 }
779}
780
Yaowu Xuf883b422016-08-30 14:01:10 -0700781static void alloc_raw_frame_buffers(AV1_COMP *cpi) {
782 AV1_COMMON *cm = &cpi->common;
783 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700784
785 if (!cpi->lookahead)
Yaowu Xud3e7c682017-12-21 14:08:25 -0800786 cpi->lookahead = av1_lookahead_init(
787 oxcf->width, oxcf->height, cm->subsampling_x, cm->subsampling_y,
788 cm->use_highbitdepth, oxcf->lag_in_frames);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700789 if (!cpi->lookahead)
Yaowu Xuf883b422016-08-30 14:01:10 -0700790 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700791 "Failed to allocate lag buffers");
792
793 // TODO(agrange) Check if ARF is enabled and skip allocation if not.
Yaowu Xuf883b422016-08-30 14:01:10 -0700794 if (aom_realloc_frame_buffer(&cpi->alt_ref_buffer, oxcf->width, oxcf->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700795 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800796 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
797 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700798 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700799 "Failed to allocate altref buffer");
800}
801
Yaowu Xuf883b422016-08-30 14:01:10 -0700802static void alloc_util_frame_buffers(AV1_COMP *cpi) {
803 AV1_COMMON *const cm = &cpi->common;
804 if (aom_realloc_frame_buffer(&cpi->last_frame_uf, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700805 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800806 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
807 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700808 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700809 "Failed to allocate last frame buffer");
810
811#if CONFIG_LOOP_RESTORATION
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700812 if (aom_realloc_frame_buffer(
813 &cpi->trial_frame_rst,
Urvang Joshi94ad3702017-12-06 11:38:08 -0800814#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700815 cm->superres_upscaled_width, cm->superres_upscaled_height,
816#else
817 cm->width, cm->height,
Urvang Joshi94ad3702017-12-06 11:38:08 -0800818#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Yaowu Xud3e7c682017-12-21 14:08:25 -0800819 cm->subsampling_x, cm->subsampling_y, cm->use_highbitdepth,
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700820 AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL))
Debargha Mukherjee874d36d2016-12-14 16:53:17 -0800821 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800822 "Failed to allocate trial restored frame buffer");
Yaowu Xuc27fc142016-08-22 16:08:15 -0700823#endif // CONFIG_LOOP_RESTORATION
824
Yaowu Xuf883b422016-08-30 14:01:10 -0700825 if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700826 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800827 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
828 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700829 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700830 "Failed to allocate scaled source buffer");
831
Yaowu Xuf883b422016-08-30 14:01:10 -0700832 if (aom_realloc_frame_buffer(&cpi->scaled_last_source, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700833 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800834 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
835 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700836 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700837 "Failed to allocate scaled last source buffer");
838}
839
Cheng Chen46f30c72017-09-07 11:13:33 -0700840static void alloc_compressor_data(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700841 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000842 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700843
Yaowu Xuf883b422016-08-30 14:01:10 -0700844 av1_alloc_context_buffers(cm, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700845
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700846 av1_alloc_txb_buf(cpi);
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700847
Yaowu Xuc27fc142016-08-22 16:08:15 -0700848 alloc_context_buffers_ext(cpi);
849
Yaowu Xuf883b422016-08-30 14:01:10 -0700850 aom_free(cpi->tile_tok[0][0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700851
852 {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000853 unsigned int tokens =
854 get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700855 CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0],
Yaowu Xuf883b422016-08-30 14:01:10 -0700856 aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0])));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700857 }
858
Yaowu Xuf883b422016-08-30 14:01:10 -0700859 av1_setup_pc_tree(&cpi->common, &cpi->td);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700860}
861
Yaowu Xuf883b422016-08-30 14:01:10 -0700862void av1_new_framerate(AV1_COMP *cpi, double framerate) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700863 cpi->framerate = framerate < 0.1 ? 30 : framerate;
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700864 av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700865}
866
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200867#if CONFIG_MAX_TILE
868
869static void set_tile_info_max_tile(AV1_COMP *cpi) {
870 AV1_COMMON *const cm = &cpi->common;
Dominic Symesf58f1112017-09-25 12:47:40 +0200871 int i, start_sb;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200872
873 av1_get_tile_limits(cm);
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200874
875 // configure tile columns
Dominic Symes26ad0b22017-10-01 16:35:13 +0200876 if (cpi->oxcf.tile_width_count == 0 || cpi->oxcf.tile_height_count == 0) {
Dominic Symesf58f1112017-09-25 12:47:40 +0200877 cm->uniform_tile_spacing_flag = 1;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200878 cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols);
879 cm->log2_tile_cols = AOMMIN(cm->log2_tile_cols, cm->max_log2_tile_cols);
Dominic Symesf58f1112017-09-25 12:47:40 +0200880 } else {
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000881 int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2);
882 int sb_cols = mi_cols >> cm->seq_params.mib_size_log2;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200883 int size_sb, j = 0;
Dominic Symesf58f1112017-09-25 12:47:40 +0200884 cm->uniform_tile_spacing_flag = 0;
885 for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) {
886 cm->tile_col_start_sb[i] = start_sb;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200887 size_sb = cpi->oxcf.tile_widths[j++];
888 if (j >= cpi->oxcf.tile_width_count) j = 0;
889 start_sb += AOMMIN(size_sb, MAX_TILE_WIDTH_SB);
Dominic Symesf58f1112017-09-25 12:47:40 +0200890 }
891 cm->tile_cols = i;
892 cm->tile_col_start_sb[i] = sb_cols;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200893 }
894 av1_calculate_tile_cols(cm);
895
896 // configure tile rows
897 if (cm->uniform_tile_spacing_flag) {
898 cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows);
899 cm->log2_tile_rows = AOMMIN(cm->log2_tile_rows, cm->max_log2_tile_rows);
Dominic Symesf58f1112017-09-25 12:47:40 +0200900 } else {
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000901 int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2);
902 int sb_rows = mi_rows >> cm->seq_params.mib_size_log2;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200903 int size_sb, j = 0;
Dominic Symesf58f1112017-09-25 12:47:40 +0200904 for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) {
905 cm->tile_row_start_sb[i] = start_sb;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200906 size_sb = cpi->oxcf.tile_heights[j++];
907 if (j >= cpi->oxcf.tile_height_count) j = 0;
908 start_sb += AOMMIN(size_sb, cm->max_tile_height_sb);
Dominic Symesf58f1112017-09-25 12:47:40 +0200909 }
910 cm->tile_rows = i;
911 cm->tile_row_start_sb[i] = sb_rows;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200912 }
913 av1_calculate_tile_rows(cm);
914}
915
916#endif
917
Yaowu Xuf883b422016-08-30 14:01:10 -0700918static void set_tile_info(AV1_COMP *cpi) {
919 AV1_COMMON *const cm = &cpi->common;
Yue Chen4eba69b2017-11-09 22:37:35 -0800920 (void)cm;
Thomas Daviesb25ba502017-07-18 10:18:24 +0100921#if CONFIG_DEPENDENT_HORZTILES
Fangwen Fu73126c02017-02-08 22:37:47 -0800922 int tile_row, tile_col, num_tiles_in_tg;
923 int tg_row_start, tg_col_start;
924#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700925#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700926 if (cpi->oxcf.large_scale_tile) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700927#if CONFIG_EXT_PARTITION
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700928 if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) {
929 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32);
930 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32);
931 cm->tile_width <<= MAX_MIB_SIZE_LOG2;
932 cm->tile_height <<= MAX_MIB_SIZE_LOG2;
933 } else {
934 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64);
935 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64);
936 cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1;
937 cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1;
938 }
939#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700940 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64);
941 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700942 cm->tile_width <<= MAX_MIB_SIZE_LOG2;
943 cm->tile_height <<= MAX_MIB_SIZE_LOG2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700944#endif // CONFIG_EXT_PARTITION
945
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700946 cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols);
947 cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700948
Yaowu Xu8d0039c2017-10-13 07:51:46 -0700949 assert(cm->tile_width >> MAX_MIB_SIZE_LOG2 <= 32);
950 assert(cm->tile_height >> MAX_MIB_SIZE_LOG2 <= 32);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700951
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700952 // Get the number of tiles
953 cm->tile_cols = 1;
954 while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700955
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700956 cm->tile_rows = 1;
957 while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows;
Dominic Symes917d6c02017-10-11 18:00:52 +0200958#if CONFIG_MAX_TILE
959 int i;
960 for (i = 0; i <= cm->tile_cols; i++) {
961 cm->tile_col_start_sb[i] =
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000962 ((i * cm->tile_width - 1) >> cm->seq_params.mib_size_log2) + 1;
Dominic Symes917d6c02017-10-11 18:00:52 +0200963 }
964 for (i = 0; i <= cm->tile_rows; i++) {
965 cm->tile_row_start_sb[i] =
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000966 ((i * cm->tile_height - 1) >> cm->seq_params.mib_size_log2) + 1;
Dominic Symes917d6c02017-10-11 18:00:52 +0200967 }
968#endif // CONFIG_MAX_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700969 } else {
970#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700971
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200972#if CONFIG_MAX_TILE
973 set_tile_info_max_tile(cpi);
Sebastien Alaiwan619f4172017-11-13 17:13:42 +0100974 (void)cm;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200975#else
976 int min_log2_tile_cols, max_log2_tile_cols;
977 av1_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700978
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200979 cm->log2_tile_cols =
980 clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols);
981 cm->log2_tile_rows = cpi->oxcf.tile_rows;
Rupert Swarbrick940942b2017-09-01 12:05:55 +0100982
Rupert Swarbrick5a010aa2017-09-26 16:16:48 +0100983 cm->tile_width =
984 get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols);
985 cm->tile_height =
986 get_tile_size(cm->mi_rows, cm->log2_tile_rows, &cm->tile_rows);
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200987#endif // CONFIG_MAX_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700988#if CONFIG_EXT_TILE
989 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700990#endif // CONFIG_EXT_TILE
Ryan Lei7386eda2016-12-08 21:08:31 -0800991
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800992#if CONFIG_DEPENDENT_HORZTILES
993 cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles;
Fangwen Fu70bcb892017-05-06 17:05:19 -0700994#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700995 if (cm->large_scale_tile) {
996 // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted.
997 cm->dependent_horz_tiles = 0;
Fangwen Fu73126c02017-02-08 22:37:47 -0800998 } else {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700999#endif // CONFIG_EXT_TILE
1000 if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0;
1001#if CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001002 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001003#endif // CONFIG_EXT_TILE
1004
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001005#if CONFIG_EXT_TILE
1006 if (!cm->large_scale_tile) {
1007#endif // CONFIG_EXT_TILE
1008 if (cpi->oxcf.mtu == 0) {
1009 cm->num_tg = cpi->oxcf.num_tile_groups;
1010 } else {
1011 // Use a default value for the purposes of weighting costs in probability
1012 // updates
1013 cm->num_tg = DEFAULT_MAX_NUM_TG;
Fangwen Fu73126c02017-02-08 22:37:47 -08001014 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001015 num_tiles_in_tg =
1016 (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg;
1017 tg_row_start = 0;
1018 tg_col_start = 0;
1019 for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) {
1020 for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) {
1021 if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) {
1022 tg_row_start = tile_row;
1023 tg_col_start = tile_col;
1024 }
1025 cm->tile_group_start_row[tile_row][tile_col] = tg_row_start;
1026 cm->tile_group_start_col[tile_row][tile_col] = tg_col_start;
1027 }
1028 }
1029#if CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001030 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001031#endif // CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001032#endif
Fangwen Fu7b9f2b32017-01-17 14:01:52 -08001033
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001034#if CONFIG_LOOPFILTERING_ACROSS_TILES
Lei7bb501d2017-12-13 15:10:34 -08001035#if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
1036 cm->loop_filter_across_tiles_v_enabled =
1037 cpi->oxcf.loop_filter_across_tiles_v_enabled;
1038 cm->loop_filter_across_tiles_h_enabled =
1039 cpi->oxcf.loop_filter_across_tiles_h_enabled;
1040#else
Ryan Lei7386eda2016-12-08 21:08:31 -08001041 cm->loop_filter_across_tiles_enabled =
1042 cpi->oxcf.loop_filter_across_tiles_enabled;
Lei7bb501d2017-12-13 15:10:34 -08001043#endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001044#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001045}
1046
Yaowu Xuf883b422016-08-30 14:01:10 -07001047static void update_frame_size(AV1_COMP *cpi) {
1048 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001049 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
1050
Yaowu Xuf883b422016-08-30 14:01:10 -07001051 av1_set_mb_mi(cm, cm->width, cm->height);
1052 av1_init_context_buffers(cm);
Luc Trudeau1e84af52017-11-25 15:00:28 -05001053 av1_init_macroblockd(cm, xd, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001054 memset(cpi->mbmi_ext_base, 0,
1055 cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001056 set_tile_info(cpi);
1057}
1058
Yaowu Xuf883b422016-08-30 14:01:10 -07001059static void init_buffer_indices(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001060 int fb_idx;
1061 for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx)
1062 cpi->lst_fb_idxes[fb_idx] = fb_idx;
1063 cpi->gld_fb_idx = LAST_REF_FRAMES;
1064 cpi->bwd_fb_idx = LAST_REF_FRAMES + 1;
Zoe Liue9b15e22017-07-19 15:53:01 -07001065 cpi->alt2_fb_idx = LAST_REF_FRAMES + 2;
1066 cpi->alt_fb_idx = LAST_REF_FRAMES + 3;
Zoe Liu8dd1c982017-09-11 10:14:35 -07001067 cpi->ext_fb_idx = LAST_REF_FRAMES + 4;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001068 for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx)
1069 cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx;
RogerZhou3b635242017-09-19 10:06:46 -07001070#if CONFIG_AMVR
1071 cpi->rate_index = 0;
1072 cpi->rate_size = 0;
1073 cpi->cur_poc = -1;
1074#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001075}
1076
Yaowu Xuf883b422016-08-30 14:01:10 -07001077static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) {
1078 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001079
1080 cpi->oxcf = *oxcf;
1081 cpi->framerate = oxcf->init_framerate;
1082
1083 cm->profile = oxcf->profile;
1084 cm->bit_depth = oxcf->bit_depth;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001085 cm->use_highbitdepth = oxcf->use_highbitdepth;
Andrey Norkin9e694632017-12-21 18:50:57 -08001086#if CONFIG_CICP
1087 cm->color_primaries = oxcf->color_primaries;
1088 cm->transfer_characteristics = oxcf->transfer_characteristics;
1089 cm->matrix_coefficients = oxcf->matrix_coefficients;
1090#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001091 cm->color_space = oxcf->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08001092#endif // CONFIG_CICP
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08001093#if CONFIG_MONO_VIDEO
1094 cm->seq_params.monochrome = oxcf->monochrome;
1095#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07001096#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08001097#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07001098 cm->transfer_function = oxcf->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08001099#endif
anorkin76fb1262017-03-22 15:12:12 -07001100 cm->chroma_sample_position = oxcf->chroma_sample_position;
1101#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001102 cm->color_range = oxcf->color_range;
Andrey Norkin28e9ce22018-01-08 10:11:21 -08001103#if CONFIG_TIMING_INFO_IN_SEQ_HEADERS
1104 cm->timing_info_present = oxcf->timing_info_present;
1105 cm->num_units_in_tick = oxcf->num_units_in_tick;
1106 cm->time_scale = oxcf->time_scale;
1107 cm->equal_picture_interval = oxcf->equal_picture_interval;
1108 cm->num_ticks_per_picture = oxcf->num_ticks_per_picture;
1109#endif
Jingning Hana446f552018-02-22 15:42:12 -08001110 cm->seq_params.enable_dual_filter = oxcf->enable_dual_filter;
Cheng Chene0c918a2018-02-22 19:38:31 -08001111#if CONFIG_JNT_COMP
1112 cm->seq_params.enable_jnt_comp = oxcf->enable_jnt_comp;
1113#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001114 cm->width = oxcf->width;
1115 cm->height = oxcf->height;
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00001116 set_sb_size(&cm->seq_params,
1117 select_sb_size(cpi)); // set sb size before allocations
Cheng Chen46f30c72017-09-07 11:13:33 -07001118 alloc_compressor_data(cpi);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -08001119#if CONFIG_FILM_GRAIN
1120 update_film_grain_parameters(cpi, oxcf);
1121#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001122
1123 // Single thread case: use counts in common.
1124 cpi->td.counts = &cm->counts;
1125
1126 // change includes all joint functionality
Yaowu Xuf883b422016-08-30 14:01:10 -07001127 av1_change_config(cpi, oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001128
1129 cpi->static_mb_pct = 0;
1130 cpi->ref_frame_flags = 0;
1131
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07001132 // Reset resize pending flags
1133 cpi->resize_pending_width = 0;
1134 cpi->resize_pending_height = 0;
1135
Yaowu Xuc27fc142016-08-22 16:08:15 -07001136 init_buffer_indices(cpi);
1137}
1138
1139static void set_rc_buffer_sizes(RATE_CONTROL *rc,
Yaowu Xuf883b422016-08-30 14:01:10 -07001140 const AV1EncoderConfig *oxcf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001141 const int64_t bandwidth = oxcf->target_bandwidth;
1142 const int64_t starting = oxcf->starting_buffer_level_ms;
1143 const int64_t optimal = oxcf->optimal_buffer_level_ms;
1144 const int64_t maximum = oxcf->maximum_buffer_size_ms;
1145
1146 rc->starting_buffer_level = starting * bandwidth / 1000;
1147 rc->optimal_buffer_level =
1148 (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000;
1149 rc->maximum_buffer_size =
1150 (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000;
1151}
1152
Cheng Chenbf3d4962017-11-01 14:48:52 -07001153#if CONFIG_JNT_COMP
1154#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, \
1155 JSVAF) \
1156 cpi->fn_ptr[BT].sdf = SDF; \
1157 cpi->fn_ptr[BT].sdaf = SDAF; \
1158 cpi->fn_ptr[BT].vf = VF; \
1159 cpi->fn_ptr[BT].svf = SVF; \
1160 cpi->fn_ptr[BT].svaf = SVAF; \
1161 cpi->fn_ptr[BT].sdx3f = SDX3F; \
1162 cpi->fn_ptr[BT].sdx8f = SDX8F; \
1163 cpi->fn_ptr[BT].sdx4df = SDX4DF; \
1164 cpi->fn_ptr[BT].jsdaf = JSDAF; \
1165 cpi->fn_ptr[BT].jsvaf = JSVAF;
1166#else // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001167#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
1168 cpi->fn_ptr[BT].sdf = SDF; \
1169 cpi->fn_ptr[BT].sdaf = SDAF; \
1170 cpi->fn_ptr[BT].vf = VF; \
1171 cpi->fn_ptr[BT].svf = SVF; \
1172 cpi->fn_ptr[BT].svaf = SVAF; \
1173 cpi->fn_ptr[BT].sdx3f = SDX3F; \
1174 cpi->fn_ptr[BT].sdx8f = SDX8F; \
1175 cpi->fn_ptr[BT].sdx4df = SDX4DF;
Cheng Chenbf3d4962017-11-01 14:48:52 -07001176#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001177
1178#define MAKE_BFP_SAD_WRAPPER(fnname) \
1179 static unsigned int fnname##_bits8(const uint8_t *src_ptr, \
1180 int source_stride, \
1181 const uint8_t *ref_ptr, int ref_stride) { \
1182 return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \
1183 } \
1184 static unsigned int fnname##_bits10( \
1185 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1186 int ref_stride) { \
1187 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \
1188 } \
1189 static unsigned int fnname##_bits12( \
1190 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1191 int ref_stride) { \
1192 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \
1193 }
1194
1195#define MAKE_BFP_SADAVG_WRAPPER(fnname) \
1196 static unsigned int fnname##_bits8( \
1197 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1198 int ref_stride, const uint8_t *second_pred) { \
1199 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \
1200 } \
1201 static unsigned int fnname##_bits10( \
1202 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1203 int ref_stride, const uint8_t *second_pred) { \
1204 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
1205 2; \
1206 } \
1207 static unsigned int fnname##_bits12( \
1208 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1209 int ref_stride, const uint8_t *second_pred) { \
1210 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
1211 4; \
1212 }
1213
1214#define MAKE_BFP_SAD3_WRAPPER(fnname) \
1215 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1216 const uint8_t *ref_ptr, int ref_stride, \
1217 unsigned int *sad_array) { \
1218 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1219 } \
1220 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1221 const uint8_t *ref_ptr, int ref_stride, \
1222 unsigned int *sad_array) { \
1223 int i; \
1224 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1225 for (i = 0; i < 3; i++) sad_array[i] >>= 2; \
1226 } \
1227 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1228 const uint8_t *ref_ptr, int ref_stride, \
1229 unsigned int *sad_array) { \
1230 int i; \
1231 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1232 for (i = 0; i < 3; i++) sad_array[i] >>= 4; \
1233 }
1234
1235#define MAKE_BFP_SAD8_WRAPPER(fnname) \
1236 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1237 const uint8_t *ref_ptr, int ref_stride, \
1238 unsigned int *sad_array) { \
1239 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1240 } \
1241 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1242 const uint8_t *ref_ptr, int ref_stride, \
1243 unsigned int *sad_array) { \
1244 int i; \
1245 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1246 for (i = 0; i < 8; i++) sad_array[i] >>= 2; \
1247 } \
1248 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1249 const uint8_t *ref_ptr, int ref_stride, \
1250 unsigned int *sad_array) { \
1251 int i; \
1252 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1253 for (i = 0; i < 8; i++) sad_array[i] >>= 4; \
1254 }
1255#define MAKE_BFP_SAD4D_WRAPPER(fnname) \
1256 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1257 const uint8_t *const ref_ptr[], int ref_stride, \
1258 unsigned int *sad_array) { \
1259 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1260 } \
1261 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1262 const uint8_t *const ref_ptr[], int ref_stride, \
1263 unsigned int *sad_array) { \
1264 int i; \
1265 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1266 for (i = 0; i < 4; i++) sad_array[i] >>= 2; \
1267 } \
1268 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1269 const uint8_t *const ref_ptr[], int ref_stride, \
1270 unsigned int *sad_array) { \
1271 int i; \
1272 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1273 for (i = 0; i < 4; i++) sad_array[i] >>= 4; \
1274 }
1275
Cheng Chenbf3d4962017-11-01 14:48:52 -07001276#if CONFIG_JNT_COMP
1277#define MAKE_BFP_JSADAVG_WRAPPER(fnname) \
1278 static unsigned int fnname##_bits8( \
1279 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1280 int ref_stride, const uint8_t *second_pred, \
1281 const JNT_COMP_PARAMS *jcp_param) { \
1282 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1283 jcp_param); \
1284 } \
1285 static unsigned int fnname##_bits10( \
1286 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1287 int ref_stride, const uint8_t *second_pred, \
1288 const JNT_COMP_PARAMS *jcp_param) { \
1289 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1290 jcp_param) >> \
1291 2; \
1292 } \
1293 static unsigned int fnname##_bits12( \
1294 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1295 int ref_stride, const uint8_t *second_pred, \
1296 const JNT_COMP_PARAMS *jcp_param) { \
1297 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1298 jcp_param) >> \
1299 4; \
1300 }
1301#endif // CONFIG_JNT_COMP
1302
Yaowu Xuc27fc142016-08-22 16:08:15 -07001303#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001304MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128)
1305MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)
1306MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3)
1307MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8)
1308MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d)
1309MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64)
1310MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg)
1311MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d)
1312MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128)
1313MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg)
1314MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001315#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001316MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16)
1317MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg)
1318MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d)
1319MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32)
1320MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg)
1321MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d)
1322MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32)
1323MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg)
1324MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d)
1325MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64)
1326MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg)
1327MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d)
1328MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32)
1329MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg)
1330MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3)
1331MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8)
1332MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d)
1333MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64)
1334MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg)
1335MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3)
1336MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8)
1337MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d)
1338MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16)
1339MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg)
1340MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3)
1341MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8)
1342MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d)
1343MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8)
1344MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg)
1345MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3)
1346MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8)
1347MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d)
1348MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16)
1349MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg)
1350MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3)
1351MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8)
1352MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d)
1353MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8)
1354MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg)
1355MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3)
1356MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8)
1357MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d)
1358MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4)
1359MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg)
1360MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8)
1361MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d)
1362MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8)
1363MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg)
1364MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8)
1365MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d)
1366MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4)
1367MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg)
1368MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3)
1369MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8)
1370MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001371
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001372#if CONFIG_EXT_PARTITION_TYPES
1373MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16)
1374MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg)
1375MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d)
1376MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4)
1377MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg)
1378MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d)
1379MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32)
1380MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg)
1381MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d)
1382MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8)
1383MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg)
1384MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001385MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64)
1386MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg)
1387MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d)
1388MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16)
1389MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg)
1390MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001391#if CONFIG_EXT_PARTITION
1392MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x128)
1393MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x128_avg)
1394MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x128x4d)
1395MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x32)
1396MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x32_avg)
1397MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x32x4d)
1398#endif // CONFIG_EXT_PARTITION
1399#endif // CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001400
Cheng Chenbf3d4962017-11-01 14:48:52 -07001401#if CONFIG_JNT_COMP
1402#if CONFIG_EXT_PARTITION
1403MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x128_avg)
1404MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x64_avg)
1405MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x128_avg)
1406#endif // CONFIG_EXT_PARTITION
1407MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x16_avg)
1408MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x32_avg)
1409MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x32_avg)
1410MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x64_avg)
1411MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x32_avg)
1412MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x64_avg)
1413MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x16_avg)
1414MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x8_avg)
1415MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x16_avg)
1416MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x8_avg)
1417MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x4_avg)
1418MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x8_avg)
1419MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x4_avg)
1420#if CONFIG_EXT_PARTITION_TYPES
1421MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x16_avg)
1422MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x4_avg)
1423MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x32_avg)
1424MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x8_avg)
1425MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x64_avg)
1426MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x16_avg)
1427#if CONFIG_EXT_PARTITION
1428MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x128_avg)
1429MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x32_avg)
1430#endif // CONFIG_EXT_PARTITION
1431#endif // CONFIG_EXT_PARTITION_TYPES
1432#endif // CONFIG_JNT_COMP
1433
David Barker0f3c94e2017-05-16 15:21:50 +01001434#define HIGHBD_MBFP(BT, MCSDF, MCSVF) \
David Barkerf19f35f2017-05-22 16:33:22 +01001435 cpi->fn_ptr[BT].msdf = MCSDF; \
1436 cpi->fn_ptr[BT].msvf = MCSVF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001437
David Barkerc155e012017-05-11 13:54:54 +01001438#define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \
1439 static unsigned int fnname##_bits8( \
1440 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1441 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1442 int m_stride, int invert_mask) { \
1443 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1444 second_pred_ptr, m, m_stride, invert_mask); \
1445 } \
1446 static unsigned int fnname##_bits10( \
1447 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1448 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1449 int m_stride, int invert_mask) { \
1450 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1451 second_pred_ptr, m, m_stride, invert_mask) >> \
1452 2; \
1453 } \
1454 static unsigned int fnname##_bits12( \
1455 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1456 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1457 int m_stride, int invert_mask) { \
1458 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1459 second_pred_ptr, m, m_stride, invert_mask) >> \
1460 4; \
1461 }
1462
Yaowu Xuc27fc142016-08-22 16:08:15 -07001463#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001464MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128)
1465MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64)
1466MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001467#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001468MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64)
1469MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32)
1470MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64)
1471MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32)
1472MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16)
1473MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32)
1474MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16)
1475MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8)
1476MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16)
1477MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8)
1478MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4)
1479MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8)
1480MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001481
1482#if CONFIG_EXT_PARTITION_TYPES
1483MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16)
1484MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4)
1485MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32)
1486MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001487MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64)
1488MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001489#if CONFIG_EXT_PARTITION
1490MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x128)
1491MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x32)
1492#endif // CONFIG_EXT_PARTITION
1493#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001494
Yaowu Xuc27fc142016-08-22 16:08:15 -07001495#define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \
1496 cpi->fn_ptr[BT].osdf = OSDF; \
1497 cpi->fn_ptr[BT].ovf = OVF; \
1498 cpi->fn_ptr[BT].osvf = OSVF;
1499
1500#define MAKE_OBFP_SAD_WRAPPER(fnname) \
1501 static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \
1502 const int32_t *wsrc, \
1503 const int32_t *msk) { \
1504 return fnname(ref, ref_stride, wsrc, msk); \
1505 } \
1506 static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \
1507 const int32_t *wsrc, \
1508 const int32_t *msk) { \
1509 return fnname(ref, ref_stride, wsrc, msk) >> 2; \
1510 } \
1511 static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \
1512 const int32_t *wsrc, \
1513 const int32_t *msk) { \
1514 return fnname(ref, ref_stride, wsrc, msk) >> 4; \
1515 }
1516
1517#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001518MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128)
1519MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64)
1520MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001521#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001522MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64)
1523MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32)
1524MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64)
1525MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32)
1526MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16)
1527MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32)
1528MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16)
1529MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8)
1530MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16)
1531MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8)
1532MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4)
1533MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8)
1534MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001535
1536#if CONFIG_EXT_PARTITION_TYPES
1537MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16)
1538MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4)
1539MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32)
1540MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001541MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64)
1542MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001543#if CONFIG_EXT_PARTITION
1544MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x128)
1545MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x32)
1546#endif // CONFIG_EXT_PARTITION
1547#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001548
Yaowu Xuf883b422016-08-30 14:01:10 -07001549static void highbd_set_var_fns(AV1_COMP *const cpi) {
1550 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001551 if (cm->use_highbitdepth) {
1552 switch (cm->bit_depth) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001553 case AOM_BITS_8:
Cheng Chenbf3d4962017-11-01 14:48:52 -07001554#if CONFIG_JNT_COMP
1555#if CONFIG_EXT_PARTITION_TYPES
1556#if CONFIG_EXT_PARTITION
1557 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8,
1558 aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32,
1559 aom_highbd_8_sub_pixel_variance128x32,
1560 aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL,
1561 aom_highbd_sad128x32x4d_bits8,
1562 aom_highbd_jnt_sad128x32_avg_bits8,
1563 aom_highbd_8_jnt_sub_pixel_avg_variance128x32)
1564
1565 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8,
1566 aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128,
1567 aom_highbd_8_sub_pixel_variance32x128,
1568 aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL,
1569 aom_highbd_sad32x128x4d_bits8,
1570 aom_highbd_jnt_sad32x128_avg_bits8,
1571 aom_highbd_8_jnt_sub_pixel_avg_variance32x128)
1572#endif // CONFIG_EXT_PARTITION
1573
1574 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8,
1575 aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16,
1576 aom_highbd_8_sub_pixel_variance64x16,
1577 aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL,
1578 aom_highbd_sad64x16x4d_bits8,
1579 aom_highbd_jnt_sad64x16_avg_bits8,
1580 aom_highbd_8_jnt_sub_pixel_avg_variance64x16)
1581
1582 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8,
1583 aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64,
1584 aom_highbd_8_sub_pixel_variance16x64,
1585 aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL,
1586 aom_highbd_sad16x64x4d_bits8,
1587 aom_highbd_jnt_sad16x64_avg_bits8,
1588 aom_highbd_8_jnt_sub_pixel_avg_variance16x64)
1589
1590 HIGHBD_BFP(
1591 BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8,
1592 aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8,
1593 aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL,
1594 aom_highbd_sad32x8x4d_bits8, aom_highbd_jnt_sad32x8_avg_bits8,
1595 aom_highbd_8_jnt_sub_pixel_avg_variance32x8)
1596
1597 HIGHBD_BFP(
1598 BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8,
1599 aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32,
1600 aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL,
1601 aom_highbd_sad8x32x4d_bits8, aom_highbd_jnt_sad8x32_avg_bits8,
1602 aom_highbd_8_jnt_sub_pixel_avg_variance8x32)
1603
1604 HIGHBD_BFP(
1605 BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8,
1606 aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4,
1607 aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL,
1608 aom_highbd_sad16x4x4d_bits8, aom_highbd_jnt_sad16x4_avg_bits8,
1609 aom_highbd_8_jnt_sub_pixel_avg_variance16x4)
1610
1611 HIGHBD_BFP(
1612 BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8,
1613 aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16,
1614 aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL,
1615 aom_highbd_sad4x16x4d_bits8, aom_highbd_jnt_sad4x16_avg_bits8,
1616 aom_highbd_8_jnt_sub_pixel_avg_variance4x16)
1617#endif
1618
1619 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8,
1620 aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16,
1621 aom_highbd_8_sub_pixel_variance32x16,
1622 aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL,
1623 aom_highbd_sad32x16x4d_bits8,
1624 aom_highbd_jnt_sad32x16_avg_bits8,
1625 aom_highbd_8_jnt_sub_pixel_avg_variance32x16)
1626
1627 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8,
1628 aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32,
1629 aom_highbd_8_sub_pixel_variance16x32,
1630 aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL,
1631 aom_highbd_sad16x32x4d_bits8,
1632 aom_highbd_jnt_sad16x32_avg_bits8,
1633 aom_highbd_8_jnt_sub_pixel_avg_variance16x32)
1634
1635 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8,
1636 aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32,
1637 aom_highbd_8_sub_pixel_variance64x32,
1638 aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL,
1639 aom_highbd_sad64x32x4d_bits8,
1640 aom_highbd_jnt_sad64x32_avg_bits8,
1641 aom_highbd_8_jnt_sub_pixel_avg_variance64x32)
1642
1643 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8,
1644 aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64,
1645 aom_highbd_8_sub_pixel_variance32x64,
1646 aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL,
1647 aom_highbd_sad32x64x4d_bits8,
1648 aom_highbd_jnt_sad32x64_avg_bits8,
1649 aom_highbd_8_jnt_sub_pixel_avg_variance32x64)
1650
1651 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8,
1652 aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32,
1653 aom_highbd_8_sub_pixel_variance32x32,
1654 aom_highbd_8_sub_pixel_avg_variance32x32,
1655 aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8,
1656 aom_highbd_sad32x32x4d_bits8,
1657 aom_highbd_jnt_sad32x32_avg_bits8,
1658 aom_highbd_8_jnt_sub_pixel_avg_variance32x32)
1659
1660 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8,
1661 aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64,
1662 aom_highbd_8_sub_pixel_variance64x64,
1663 aom_highbd_8_sub_pixel_avg_variance64x64,
1664 aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8,
1665 aom_highbd_sad64x64x4d_bits8,
1666 aom_highbd_jnt_sad64x64_avg_bits8,
1667 aom_highbd_8_jnt_sub_pixel_avg_variance64x64)
1668
1669 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8,
1670 aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16,
1671 aom_highbd_8_sub_pixel_variance16x16,
1672 aom_highbd_8_sub_pixel_avg_variance16x16,
1673 aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8,
1674 aom_highbd_sad16x16x4d_bits8,
1675 aom_highbd_jnt_sad16x16_avg_bits8,
1676 aom_highbd_8_jnt_sub_pixel_avg_variance16x16)
1677
1678 HIGHBD_BFP(
1679 BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8,
1680 aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8,
1681 aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8,
1682 aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8,
1683 aom_highbd_jnt_sad16x8_avg_bits8,
1684 aom_highbd_8_jnt_sub_pixel_avg_variance16x8)
1685
1686 HIGHBD_BFP(
1687 BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8,
1688 aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16,
1689 aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8,
1690 aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8,
1691 aom_highbd_jnt_sad8x16_avg_bits8,
1692 aom_highbd_8_jnt_sub_pixel_avg_variance8x16)
1693
1694 HIGHBD_BFP(BLOCK_8X8, aom_highbd_sad8x8_bits8,
1695 aom_highbd_sad8x8_avg_bits8, aom_highbd_8_variance8x8,
1696 aom_highbd_8_sub_pixel_variance8x8,
1697 aom_highbd_8_sub_pixel_avg_variance8x8,
1698 aom_highbd_sad8x8x3_bits8, aom_highbd_sad8x8x8_bits8,
1699 aom_highbd_sad8x8x4d_bits8, aom_highbd_jnt_sad8x8_avg_bits8,
1700 aom_highbd_8_jnt_sub_pixel_avg_variance8x8)
1701
1702 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8,
1703 aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4,
1704 aom_highbd_8_sub_pixel_variance8x4,
1705 aom_highbd_8_sub_pixel_avg_variance8x4, NULL,
1706 aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8,
1707 aom_highbd_jnt_sad8x4_avg_bits8,
1708 aom_highbd_8_jnt_sub_pixel_avg_variance8x4)
1709
1710 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8,
1711 aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8,
1712 aom_highbd_8_sub_pixel_variance4x8,
1713 aom_highbd_8_sub_pixel_avg_variance4x8, NULL,
1714 aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8,
1715 aom_highbd_jnt_sad4x8_avg_bits8,
1716 aom_highbd_8_jnt_sub_pixel_avg_variance4x8)
1717
1718 HIGHBD_BFP(BLOCK_4X4, aom_highbd_sad4x4_bits8,
1719 aom_highbd_sad4x4_avg_bits8, aom_highbd_8_variance4x4,
1720 aom_highbd_8_sub_pixel_variance4x4,
1721 aom_highbd_8_sub_pixel_avg_variance4x4,
1722 aom_highbd_sad4x4x3_bits8, aom_highbd_sad4x4x8_bits8,
1723 aom_highbd_sad4x4x4d_bits8, aom_highbd_jnt_sad4x4_avg_bits8,
1724 aom_highbd_8_jnt_sub_pixel_avg_variance4x4)
1725
Cheng Chenbf3d4962017-11-01 14:48:52 -07001726#if CONFIG_EXT_PARTITION
1727 HIGHBD_BFP(
1728 BLOCK_128X128, aom_highbd_sad128x128_bits8,
1729 aom_highbd_sad128x128_avg_bits8, aom_highbd_8_variance128x128,
1730 aom_highbd_8_sub_pixel_variance128x128,
1731 aom_highbd_8_sub_pixel_avg_variance128x128,
1732 aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8,
1733 aom_highbd_sad128x128x4d_bits8, aom_highbd_jnt_sad128x128_avg_bits8,
1734 aom_highbd_8_jnt_sub_pixel_avg_variance128x128)
1735
1736 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8,
1737 aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64,
1738 aom_highbd_8_sub_pixel_variance128x64,
1739 aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL,
1740 aom_highbd_sad128x64x4d_bits8,
1741 aom_highbd_jnt_sad128x64_avg_bits8,
1742 aom_highbd_8_jnt_sub_pixel_avg_variance128x64)
1743
1744 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8,
1745 aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128,
1746 aom_highbd_8_sub_pixel_variance64x128,
1747 aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL,
1748 aom_highbd_sad64x128x4d_bits8,
1749 aom_highbd_jnt_sad64x128_avg_bits8,
1750 aom_highbd_8_jnt_sub_pixel_avg_variance64x128)
1751#endif // CONFIG_EXT_PARTITION
1752#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001753#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001754#if CONFIG_EXT_PARTITION
1755 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8,
1756 aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32,
1757 aom_highbd_8_sub_pixel_variance128x32,
1758 aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL,
1759 aom_highbd_sad128x32x4d_bits8)
1760
1761 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8,
1762 aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128,
1763 aom_highbd_8_sub_pixel_variance32x128,
1764 aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL,
1765 aom_highbd_sad32x128x4d_bits8)
1766#endif // CONFIG_EXT_PARTITION
1767
Rupert Swarbrick72678572017-08-02 12:05:26 +01001768 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8,
1769 aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16,
1770 aom_highbd_8_sub_pixel_variance64x16,
1771 aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL,
1772 aom_highbd_sad64x16x4d_bits8)
1773
1774 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8,
1775 aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64,
1776 aom_highbd_8_sub_pixel_variance16x64,
1777 aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL,
1778 aom_highbd_sad16x64x4d_bits8)
1779
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001780 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8,
1781 aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8,
1782 aom_highbd_8_sub_pixel_variance32x8,
1783 aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL,
1784 aom_highbd_sad32x8x4d_bits8)
1785
1786 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8,
1787 aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32,
1788 aom_highbd_8_sub_pixel_variance8x32,
1789 aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL,
1790 aom_highbd_sad8x32x4d_bits8)
1791
1792 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8,
1793 aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4,
1794 aom_highbd_8_sub_pixel_variance16x4,
1795 aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL,
1796 aom_highbd_sad16x4x4d_bits8)
1797
1798 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8,
1799 aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16,
1800 aom_highbd_8_sub_pixel_variance4x16,
1801 aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL,
1802 aom_highbd_sad4x16x4d_bits8)
1803#endif
1804
Yaowu Xuf883b422016-08-30 14:01:10 -07001805 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8,
1806 aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16,
1807 aom_highbd_8_sub_pixel_variance32x16,
1808 aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL,
1809 aom_highbd_sad32x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001810
Yaowu Xuf883b422016-08-30 14:01:10 -07001811 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8,
1812 aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32,
1813 aom_highbd_8_sub_pixel_variance16x32,
1814 aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL,
1815 aom_highbd_sad16x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001816
Yaowu Xuf883b422016-08-30 14:01:10 -07001817 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8,
1818 aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32,
1819 aom_highbd_8_sub_pixel_variance64x32,
1820 aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL,
1821 aom_highbd_sad64x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001822
Yaowu Xuf883b422016-08-30 14:01:10 -07001823 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8,
1824 aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64,
1825 aom_highbd_8_sub_pixel_variance32x64,
1826 aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL,
1827 aom_highbd_sad32x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001828
Yaowu Xuf883b422016-08-30 14:01:10 -07001829 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8,
1830 aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32,
1831 aom_highbd_8_sub_pixel_variance32x32,
1832 aom_highbd_8_sub_pixel_avg_variance32x32,
1833 aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8,
1834 aom_highbd_sad32x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001835
Yaowu Xuf883b422016-08-30 14:01:10 -07001836 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8,
1837 aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64,
1838 aom_highbd_8_sub_pixel_variance64x64,
1839 aom_highbd_8_sub_pixel_avg_variance64x64,
1840 aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8,
1841 aom_highbd_sad64x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001842
Yaowu Xuf883b422016-08-30 14:01:10 -07001843 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8,
1844 aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16,
1845 aom_highbd_8_sub_pixel_variance16x16,
1846 aom_highbd_8_sub_pixel_avg_variance16x16,
1847 aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8,
1848 aom_highbd_sad16x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001849
1850 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001851 BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8,
1852 aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8,
1853 aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8,
1854 aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001855
1856 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001857 BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8,
1858 aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16,
1859 aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8,
1860 aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001861
1862 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001863 BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8,
1864 aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8,
1865 aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8,
1866 aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001867
Yaowu Xuf883b422016-08-30 14:01:10 -07001868 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8,
1869 aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4,
1870 aom_highbd_8_sub_pixel_variance8x4,
1871 aom_highbd_8_sub_pixel_avg_variance8x4, NULL,
1872 aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001873
Yaowu Xuf883b422016-08-30 14:01:10 -07001874 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8,
1875 aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8,
1876 aom_highbd_8_sub_pixel_variance4x8,
1877 aom_highbd_8_sub_pixel_avg_variance4x8, NULL,
1878 aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001879
1880 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001881 BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8,
1882 aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4,
1883 aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8,
1884 aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001885
1886#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001887 HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8,
1888 aom_highbd_sad128x128_avg_bits8,
1889 aom_highbd_8_variance128x128,
1890 aom_highbd_8_sub_pixel_variance128x128,
1891 aom_highbd_8_sub_pixel_avg_variance128x128,
1892 aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8,
1893 aom_highbd_sad128x128x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001894
Yaowu Xuf883b422016-08-30 14:01:10 -07001895 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8,
1896 aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64,
1897 aom_highbd_8_sub_pixel_variance128x64,
1898 aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL,
1899 aom_highbd_sad128x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001900
Yaowu Xuf883b422016-08-30 14:01:10 -07001901 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8,
1902 aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128,
1903 aom_highbd_8_sub_pixel_variance64x128,
1904 aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL,
1905 aom_highbd_sad64x128x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001906#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07001907#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001908
Yaowu Xuc27fc142016-08-22 16:08:15 -07001909#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001910 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8,
1911 aom_highbd_8_masked_sub_pixel_variance128x128)
1912 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8,
1913 aom_highbd_8_masked_sub_pixel_variance128x64)
1914 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8,
1915 aom_highbd_8_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001916#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001917 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8,
1918 aom_highbd_8_masked_sub_pixel_variance64x64)
1919 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8,
1920 aom_highbd_8_masked_sub_pixel_variance64x32)
1921 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8,
1922 aom_highbd_8_masked_sub_pixel_variance32x64)
1923 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8,
1924 aom_highbd_8_masked_sub_pixel_variance32x32)
1925 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8,
1926 aom_highbd_8_masked_sub_pixel_variance32x16)
1927 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8,
1928 aom_highbd_8_masked_sub_pixel_variance16x32)
1929 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8,
1930 aom_highbd_8_masked_sub_pixel_variance16x16)
1931 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8,
1932 aom_highbd_8_masked_sub_pixel_variance8x16)
1933 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8,
1934 aom_highbd_8_masked_sub_pixel_variance16x8)
1935 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8,
1936 aom_highbd_8_masked_sub_pixel_variance8x8)
1937 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8,
1938 aom_highbd_8_masked_sub_pixel_variance4x8)
1939 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8,
1940 aom_highbd_8_masked_sub_pixel_variance8x4)
1941 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8,
1942 aom_highbd_8_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001943#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001944#if CONFIG_EXT_PARTITION
1945 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits8,
1946 aom_highbd_8_masked_sub_pixel_variance128x32)
1947
1948 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits8,
1949 aom_highbd_8_masked_sub_pixel_variance32x128)
1950#endif // CONFIG_EXT_PARTITION
1951
Rupert Swarbrick72678572017-08-02 12:05:26 +01001952 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8,
1953 aom_highbd_8_masked_sub_pixel_variance64x16)
1954
1955 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8,
1956 aom_highbd_8_masked_sub_pixel_variance16x64)
1957
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001958 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8,
1959 aom_highbd_8_masked_sub_pixel_variance32x8)
1960
1961 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8,
1962 aom_highbd_8_masked_sub_pixel_variance8x32)
1963
1964 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8,
1965 aom_highbd_8_masked_sub_pixel_variance16x4)
1966
1967 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8,
1968 aom_highbd_8_masked_sub_pixel_variance4x16)
1969#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001970#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001971 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8,
1972 aom_highbd_obmc_variance128x128,
1973 aom_highbd_obmc_sub_pixel_variance128x128)
1974 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8,
1975 aom_highbd_obmc_variance128x64,
1976 aom_highbd_obmc_sub_pixel_variance128x64)
1977 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8,
1978 aom_highbd_obmc_variance64x128,
1979 aom_highbd_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001980#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001981 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8,
1982 aom_highbd_obmc_variance64x64,
1983 aom_highbd_obmc_sub_pixel_variance64x64)
1984 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8,
1985 aom_highbd_obmc_variance64x32,
1986 aom_highbd_obmc_sub_pixel_variance64x32)
1987 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8,
1988 aom_highbd_obmc_variance32x64,
1989 aom_highbd_obmc_sub_pixel_variance32x64)
1990 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8,
1991 aom_highbd_obmc_variance32x32,
1992 aom_highbd_obmc_sub_pixel_variance32x32)
1993 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8,
1994 aom_highbd_obmc_variance32x16,
1995 aom_highbd_obmc_sub_pixel_variance32x16)
1996 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8,
1997 aom_highbd_obmc_variance16x32,
1998 aom_highbd_obmc_sub_pixel_variance16x32)
1999 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8,
2000 aom_highbd_obmc_variance16x16,
2001 aom_highbd_obmc_sub_pixel_variance16x16)
2002 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8,
2003 aom_highbd_obmc_variance8x16,
2004 aom_highbd_obmc_sub_pixel_variance8x16)
2005 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8,
2006 aom_highbd_obmc_variance16x8,
2007 aom_highbd_obmc_sub_pixel_variance16x8)
2008 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8,
2009 aom_highbd_obmc_variance8x8,
2010 aom_highbd_obmc_sub_pixel_variance8x8)
2011 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8,
2012 aom_highbd_obmc_variance4x8,
2013 aom_highbd_obmc_sub_pixel_variance4x8)
2014 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8,
2015 aom_highbd_obmc_variance8x4,
2016 aom_highbd_obmc_sub_pixel_variance8x4)
2017 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8,
2018 aom_highbd_obmc_variance4x4,
2019 aom_highbd_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002020#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002021#if CONFIG_EXT_PARTITION
2022 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits8,
2023 aom_highbd_obmc_variance128x32,
2024 aom_highbd_obmc_sub_pixel_variance128x32)
2025
2026 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits8,
2027 aom_highbd_obmc_variance32x128,
2028 aom_highbd_obmc_sub_pixel_variance32x128)
2029#endif // CONFIG_EXT_PARTITION
2030
Rupert Swarbrick72678572017-08-02 12:05:26 +01002031 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8,
2032 aom_highbd_obmc_variance64x16,
2033 aom_highbd_obmc_sub_pixel_variance64x16)
2034
2035 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8,
2036 aom_highbd_obmc_variance16x64,
2037 aom_highbd_obmc_sub_pixel_variance16x64)
2038
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002039 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8,
2040 aom_highbd_obmc_variance32x8,
2041 aom_highbd_obmc_sub_pixel_variance32x8)
2042
2043 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8,
2044 aom_highbd_obmc_variance8x32,
2045 aom_highbd_obmc_sub_pixel_variance8x32)
2046
2047 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8,
2048 aom_highbd_obmc_variance16x4,
2049 aom_highbd_obmc_sub_pixel_variance16x4)
2050
2051 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8,
2052 aom_highbd_obmc_variance4x16,
2053 aom_highbd_obmc_sub_pixel_variance4x16)
2054#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002055 break;
2056
Yaowu Xuf883b422016-08-30 14:01:10 -07002057 case AOM_BITS_10:
Cheng Chenbf3d4962017-11-01 14:48:52 -07002058#if CONFIG_JNT_COMP
2059#if CONFIG_EXT_PARTITION_TYPES
2060#if CONFIG_EXT_PARTITION
2061 HIGHBD_BFP(
2062 BLOCK_128X32, aom_highbd_sad128x32_bits10,
2063 aom_highbd_sad128x32_avg_bits10, aom_highbd_10_variance128x32,
2064 aom_highbd_10_sub_pixel_variance128x32,
2065 aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL,
2066 aom_highbd_sad128x32x4d_bits10, aom_highbd_jnt_sad128x32_avg_bits10,
2067 aom_highbd_10_jnt_sub_pixel_avg_variance128x32);
2068
2069 HIGHBD_BFP(
2070 BLOCK_32X128, aom_highbd_sad32x128_bits10,
2071 aom_highbd_sad32x128_avg_bits10, aom_highbd_10_variance32x128,
2072 aom_highbd_10_sub_pixel_variance32x128,
2073 aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL,
2074 aom_highbd_sad32x128x4d_bits10, aom_highbd_jnt_sad32x128_avg_bits10,
2075 aom_highbd_10_jnt_sub_pixel_avg_variance32x128);
2076#endif // CONFIG_EXT_PARTITION
2077
2078 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10,
2079 aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16,
2080 aom_highbd_10_sub_pixel_variance64x16,
2081 aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL,
2082 aom_highbd_sad64x16x4d_bits10,
2083 aom_highbd_jnt_sad64x16_avg_bits10,
2084 aom_highbd_10_jnt_sub_pixel_avg_variance64x16);
2085
2086 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10,
2087 aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64,
2088 aom_highbd_10_sub_pixel_variance16x64,
2089 aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL,
2090 aom_highbd_sad16x64x4d_bits10,
2091 aom_highbd_jnt_sad16x64_avg_bits10,
2092 aom_highbd_10_jnt_sub_pixel_avg_variance16x64);
2093
2094 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10,
2095 aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8,
2096 aom_highbd_10_sub_pixel_variance32x8,
2097 aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL,
2098 aom_highbd_sad32x8x4d_bits10,
2099 aom_highbd_jnt_sad32x8_avg_bits10,
2100 aom_highbd_10_jnt_sub_pixel_avg_variance32x8);
2101
2102 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10,
2103 aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32,
2104 aom_highbd_10_sub_pixel_variance8x32,
2105 aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL,
2106 aom_highbd_sad8x32x4d_bits10,
2107 aom_highbd_jnt_sad8x32_avg_bits10,
2108 aom_highbd_10_jnt_sub_pixel_avg_variance8x32);
2109
2110 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10,
2111 aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4,
2112 aom_highbd_10_sub_pixel_variance16x4,
2113 aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL,
2114 aom_highbd_sad16x4x4d_bits10,
2115 aom_highbd_jnt_sad16x4_avg_bits10,
2116 aom_highbd_10_jnt_sub_pixel_avg_variance16x4);
2117
2118 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10,
2119 aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16,
2120 aom_highbd_10_sub_pixel_variance4x16,
2121 aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL,
2122 aom_highbd_sad4x16x4d_bits10,
2123 aom_highbd_jnt_sad4x16_avg_bits10,
2124 aom_highbd_10_jnt_sub_pixel_avg_variance4x16);
2125#endif
2126
2127 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10,
2128 aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16,
2129 aom_highbd_10_sub_pixel_variance32x16,
2130 aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL,
2131 aom_highbd_sad32x16x4d_bits10,
2132 aom_highbd_jnt_sad32x16_avg_bits10,
2133 aom_highbd_10_jnt_sub_pixel_avg_variance32x16);
2134
2135 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10,
2136 aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32,
2137 aom_highbd_10_sub_pixel_variance16x32,
2138 aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL,
2139 aom_highbd_sad16x32x4d_bits10,
2140 aom_highbd_jnt_sad16x32_avg_bits10,
2141 aom_highbd_10_jnt_sub_pixel_avg_variance16x32);
2142
2143 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10,
2144 aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32,
2145 aom_highbd_10_sub_pixel_variance64x32,
2146 aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL,
2147 aom_highbd_sad64x32x4d_bits10,
2148 aom_highbd_jnt_sad64x32_avg_bits10,
2149 aom_highbd_10_jnt_sub_pixel_avg_variance64x32);
2150
2151 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10,
2152 aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64,
2153 aom_highbd_10_sub_pixel_variance32x64,
2154 aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL,
2155 aom_highbd_sad32x64x4d_bits10,
2156 aom_highbd_jnt_sad32x64_avg_bits10,
2157 aom_highbd_10_jnt_sub_pixel_avg_variance32x64);
2158
2159 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10,
2160 aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32,
2161 aom_highbd_10_sub_pixel_variance32x32,
2162 aom_highbd_10_sub_pixel_avg_variance32x32,
2163 aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10,
2164 aom_highbd_sad32x32x4d_bits10,
2165 aom_highbd_jnt_sad32x32_avg_bits10,
2166 aom_highbd_10_jnt_sub_pixel_avg_variance32x32);
2167
2168 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10,
2169 aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64,
2170 aom_highbd_10_sub_pixel_variance64x64,
2171 aom_highbd_10_sub_pixel_avg_variance64x64,
2172 aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10,
2173 aom_highbd_sad64x64x4d_bits10,
2174 aom_highbd_jnt_sad64x64_avg_bits10,
2175 aom_highbd_10_jnt_sub_pixel_avg_variance64x64);
2176
2177 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10,
2178 aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16,
2179 aom_highbd_10_sub_pixel_variance16x16,
2180 aom_highbd_10_sub_pixel_avg_variance16x16,
2181 aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10,
2182 aom_highbd_sad16x16x4d_bits10,
2183 aom_highbd_jnt_sad16x16_avg_bits10,
2184 aom_highbd_10_jnt_sub_pixel_avg_variance16x16);
2185
2186 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10,
2187 aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8,
2188 aom_highbd_10_sub_pixel_variance16x8,
2189 aom_highbd_10_sub_pixel_avg_variance16x8,
2190 aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10,
2191 aom_highbd_sad16x8x4d_bits10,
2192 aom_highbd_jnt_sad16x8_avg_bits10,
2193 aom_highbd_10_jnt_sub_pixel_avg_variance16x8);
2194
2195 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10,
2196 aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16,
2197 aom_highbd_10_sub_pixel_variance8x16,
2198 aom_highbd_10_sub_pixel_avg_variance8x16,
2199 aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10,
2200 aom_highbd_sad8x16x4d_bits10,
2201 aom_highbd_jnt_sad8x16_avg_bits10,
2202 aom_highbd_10_jnt_sub_pixel_avg_variance8x16);
2203
2204 HIGHBD_BFP(
2205 BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10,
2206 aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8,
2207 aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10,
2208 aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10,
2209 aom_highbd_jnt_sad8x8_avg_bits10,
2210 aom_highbd_10_jnt_sub_pixel_avg_variance8x8);
2211
2212 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10,
2213 aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4,
2214 aom_highbd_10_sub_pixel_variance8x4,
2215 aom_highbd_10_sub_pixel_avg_variance8x4, NULL,
2216 aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10,
2217 aom_highbd_jnt_sad8x4_avg_bits10,
2218 aom_highbd_10_jnt_sub_pixel_avg_variance8x4);
2219
2220 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10,
2221 aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8,
2222 aom_highbd_10_sub_pixel_variance4x8,
2223 aom_highbd_10_sub_pixel_avg_variance4x8, NULL,
2224 aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10,
2225 aom_highbd_jnt_sad4x8_avg_bits10,
2226 aom_highbd_10_jnt_sub_pixel_avg_variance4x8);
2227
2228 HIGHBD_BFP(
2229 BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10,
2230 aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4,
2231 aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10,
2232 aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10,
2233 aom_highbd_jnt_sad4x4_avg_bits10,
2234 aom_highbd_10_jnt_sub_pixel_avg_variance4x4);
2235
Cheng Chenbf3d4962017-11-01 14:48:52 -07002236#if CONFIG_EXT_PARTITION
2237 HIGHBD_BFP(
2238 BLOCK_128X128, aom_highbd_sad128x128_bits10,
2239 aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128,
2240 aom_highbd_10_sub_pixel_variance128x128,
2241 aom_highbd_10_sub_pixel_avg_variance128x128,
2242 aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10,
2243 aom_highbd_sad128x128x4d_bits10,
2244 aom_highbd_jnt_sad128x128_avg_bits10,
2245 aom_highbd_10_jnt_sub_pixel_avg_variance128x128);
2246
2247 HIGHBD_BFP(
2248 BLOCK_128X64, aom_highbd_sad128x64_bits10,
2249 aom_highbd_sad128x64_avg_bits10, aom_highbd_10_variance128x64,
2250 aom_highbd_10_sub_pixel_variance128x64,
2251 aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL,
2252 aom_highbd_sad128x64x4d_bits10, aom_highbd_jnt_sad128x64_avg_bits10,
2253 aom_highbd_10_jnt_sub_pixel_avg_variance128x64);
2254
2255 HIGHBD_BFP(
2256 BLOCK_64X128, aom_highbd_sad64x128_bits10,
2257 aom_highbd_sad64x128_avg_bits10, aom_highbd_10_variance64x128,
2258 aom_highbd_10_sub_pixel_variance64x128,
2259 aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL,
2260 aom_highbd_sad64x128x4d_bits10, aom_highbd_jnt_sad64x128_avg_bits10,
2261 aom_highbd_10_jnt_sub_pixel_avg_variance64x128);
2262#endif // CONFIG_EXT_PARTITION
2263#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002264#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002265#if CONFIG_EXT_PARTITION
2266 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits10,
2267 aom_highbd_sad128x32_avg_bits10,
2268 aom_highbd_10_variance128x32,
2269 aom_highbd_10_sub_pixel_variance128x32,
2270 aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL,
2271 aom_highbd_sad128x32x4d_bits10)
2272
2273 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits10,
2274 aom_highbd_sad32x128_avg_bits10,
2275 aom_highbd_10_variance32x128,
2276 aom_highbd_10_sub_pixel_variance32x128,
2277 aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL,
2278 aom_highbd_sad32x128x4d_bits10)
2279#endif // CONFIG_EXT_PARTITION
2280
Rupert Swarbrick72678572017-08-02 12:05:26 +01002281 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10,
2282 aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16,
2283 aom_highbd_10_sub_pixel_variance64x16,
2284 aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL,
2285 aom_highbd_sad64x16x4d_bits10)
2286
2287 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10,
2288 aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64,
2289 aom_highbd_10_sub_pixel_variance16x64,
2290 aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL,
2291 aom_highbd_sad16x64x4d_bits10)
2292
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002293 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10,
2294 aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8,
2295 aom_highbd_10_sub_pixel_variance32x8,
2296 aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL,
2297 aom_highbd_sad32x8x4d_bits10)
2298
2299 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10,
2300 aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32,
2301 aom_highbd_10_sub_pixel_variance8x32,
2302 aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL,
2303 aom_highbd_sad8x32x4d_bits10)
2304
2305 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10,
2306 aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4,
2307 aom_highbd_10_sub_pixel_variance16x4,
2308 aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL,
2309 aom_highbd_sad16x4x4d_bits10)
2310
2311 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10,
2312 aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16,
2313 aom_highbd_10_sub_pixel_variance4x16,
2314 aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL,
2315 aom_highbd_sad4x16x4d_bits10)
2316#endif
2317
Yaowu Xuf883b422016-08-30 14:01:10 -07002318 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10,
2319 aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16,
2320 aom_highbd_10_sub_pixel_variance32x16,
2321 aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL,
2322 aom_highbd_sad32x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002323
Yaowu Xuf883b422016-08-30 14:01:10 -07002324 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10,
2325 aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32,
2326 aom_highbd_10_sub_pixel_variance16x32,
2327 aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL,
2328 aom_highbd_sad16x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002329
Yaowu Xuf883b422016-08-30 14:01:10 -07002330 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10,
2331 aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32,
2332 aom_highbd_10_sub_pixel_variance64x32,
2333 aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL,
2334 aom_highbd_sad64x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002335
Yaowu Xuf883b422016-08-30 14:01:10 -07002336 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10,
2337 aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64,
2338 aom_highbd_10_sub_pixel_variance32x64,
2339 aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL,
2340 aom_highbd_sad32x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002341
Yaowu Xuf883b422016-08-30 14:01:10 -07002342 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10,
2343 aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32,
2344 aom_highbd_10_sub_pixel_variance32x32,
2345 aom_highbd_10_sub_pixel_avg_variance32x32,
2346 aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10,
2347 aom_highbd_sad32x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002348
Yaowu Xuf883b422016-08-30 14:01:10 -07002349 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10,
2350 aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64,
2351 aom_highbd_10_sub_pixel_variance64x64,
2352 aom_highbd_10_sub_pixel_avg_variance64x64,
2353 aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10,
2354 aom_highbd_sad64x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002355
Yaowu Xuf883b422016-08-30 14:01:10 -07002356 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10,
2357 aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16,
2358 aom_highbd_10_sub_pixel_variance16x16,
2359 aom_highbd_10_sub_pixel_avg_variance16x16,
2360 aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10,
2361 aom_highbd_sad16x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002362
Yaowu Xuf883b422016-08-30 14:01:10 -07002363 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10,
2364 aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8,
2365 aom_highbd_10_sub_pixel_variance16x8,
2366 aom_highbd_10_sub_pixel_avg_variance16x8,
2367 aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10,
2368 aom_highbd_sad16x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002369
Yaowu Xuf883b422016-08-30 14:01:10 -07002370 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10,
2371 aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16,
2372 aom_highbd_10_sub_pixel_variance8x16,
2373 aom_highbd_10_sub_pixel_avg_variance8x16,
2374 aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10,
2375 aom_highbd_sad8x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002376
2377 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002378 BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10,
2379 aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8,
2380 aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10,
2381 aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002382
Yaowu Xuf883b422016-08-30 14:01:10 -07002383 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10,
2384 aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4,
2385 aom_highbd_10_sub_pixel_variance8x4,
2386 aom_highbd_10_sub_pixel_avg_variance8x4, NULL,
2387 aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002388
Yaowu Xuf883b422016-08-30 14:01:10 -07002389 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10,
2390 aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8,
2391 aom_highbd_10_sub_pixel_variance4x8,
2392 aom_highbd_10_sub_pixel_avg_variance4x8, NULL,
2393 aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002394
2395 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002396 BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10,
2397 aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4,
2398 aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10,
2399 aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002400
2401#if CONFIG_EXT_PARTITION
2402 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002403 BLOCK_128X128, aom_highbd_sad128x128_bits10,
2404 aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128,
2405 aom_highbd_10_sub_pixel_variance128x128,
2406 aom_highbd_10_sub_pixel_avg_variance128x128,
2407 aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10,
2408 aom_highbd_sad128x128x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002409
Yaowu Xuf883b422016-08-30 14:01:10 -07002410 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10,
2411 aom_highbd_sad128x64_avg_bits10,
2412 aom_highbd_10_variance128x64,
2413 aom_highbd_10_sub_pixel_variance128x64,
2414 aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL,
2415 aom_highbd_sad128x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002416
Yaowu Xuf883b422016-08-30 14:01:10 -07002417 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10,
2418 aom_highbd_sad64x128_avg_bits10,
2419 aom_highbd_10_variance64x128,
2420 aom_highbd_10_sub_pixel_variance64x128,
2421 aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL,
2422 aom_highbd_sad64x128x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002423#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07002424#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002425
Yaowu Xuc27fc142016-08-22 16:08:15 -07002426#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002427 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10,
2428 aom_highbd_10_masked_sub_pixel_variance128x128)
2429 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10,
2430 aom_highbd_10_masked_sub_pixel_variance128x64)
2431 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10,
2432 aom_highbd_10_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002433#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002434 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10,
2435 aom_highbd_10_masked_sub_pixel_variance64x64)
2436 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10,
2437 aom_highbd_10_masked_sub_pixel_variance64x32)
2438 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10,
2439 aom_highbd_10_masked_sub_pixel_variance32x64)
2440 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10,
2441 aom_highbd_10_masked_sub_pixel_variance32x32)
2442 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10,
2443 aom_highbd_10_masked_sub_pixel_variance32x16)
2444 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10,
2445 aom_highbd_10_masked_sub_pixel_variance16x32)
2446 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10,
2447 aom_highbd_10_masked_sub_pixel_variance16x16)
2448 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10,
2449 aom_highbd_10_masked_sub_pixel_variance8x16)
2450 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10,
2451 aom_highbd_10_masked_sub_pixel_variance16x8)
2452 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10,
2453 aom_highbd_10_masked_sub_pixel_variance8x8)
2454 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10,
2455 aom_highbd_10_masked_sub_pixel_variance4x8)
2456 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10,
2457 aom_highbd_10_masked_sub_pixel_variance8x4)
2458 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10,
2459 aom_highbd_10_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002460#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002461#if CONFIG_EXT_PARTITION
2462 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits10,
2463 aom_highbd_10_masked_sub_pixel_variance128x32)
2464
2465 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits10,
2466 aom_highbd_10_masked_sub_pixel_variance32x128)
2467#endif // CONFIG_EXT_PARTITION
2468
Rupert Swarbrick72678572017-08-02 12:05:26 +01002469 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10,
2470 aom_highbd_10_masked_sub_pixel_variance64x16)
2471
2472 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10,
2473 aom_highbd_10_masked_sub_pixel_variance16x64)
2474
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002475 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10,
2476 aom_highbd_10_masked_sub_pixel_variance32x8)
2477
2478 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10,
2479 aom_highbd_10_masked_sub_pixel_variance8x32)
2480
2481 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10,
2482 aom_highbd_10_masked_sub_pixel_variance16x4)
2483
2484 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10,
2485 aom_highbd_10_masked_sub_pixel_variance4x16)
2486#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002487#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07002488 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10,
2489 aom_highbd_10_obmc_variance128x128,
2490 aom_highbd_10_obmc_sub_pixel_variance128x128)
2491 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10,
2492 aom_highbd_10_obmc_variance128x64,
2493 aom_highbd_10_obmc_sub_pixel_variance128x64)
2494 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10,
2495 aom_highbd_10_obmc_variance64x128,
2496 aom_highbd_10_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002497#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07002498 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10,
2499 aom_highbd_10_obmc_variance64x64,
2500 aom_highbd_10_obmc_sub_pixel_variance64x64)
2501 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10,
2502 aom_highbd_10_obmc_variance64x32,
2503 aom_highbd_10_obmc_sub_pixel_variance64x32)
2504 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10,
2505 aom_highbd_10_obmc_variance32x64,
2506 aom_highbd_10_obmc_sub_pixel_variance32x64)
2507 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10,
2508 aom_highbd_10_obmc_variance32x32,
2509 aom_highbd_10_obmc_sub_pixel_variance32x32)
2510 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10,
2511 aom_highbd_10_obmc_variance32x16,
2512 aom_highbd_10_obmc_sub_pixel_variance32x16)
2513 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10,
2514 aom_highbd_10_obmc_variance16x32,
2515 aom_highbd_10_obmc_sub_pixel_variance16x32)
2516 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10,
2517 aom_highbd_10_obmc_variance16x16,
2518 aom_highbd_10_obmc_sub_pixel_variance16x16)
2519 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10,
2520 aom_highbd_10_obmc_variance8x16,
2521 aom_highbd_10_obmc_sub_pixel_variance8x16)
2522 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10,
2523 aom_highbd_10_obmc_variance16x8,
2524 aom_highbd_10_obmc_sub_pixel_variance16x8)
2525 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10,
2526 aom_highbd_10_obmc_variance8x8,
2527 aom_highbd_10_obmc_sub_pixel_variance8x8)
2528 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10,
2529 aom_highbd_10_obmc_variance4x8,
2530 aom_highbd_10_obmc_sub_pixel_variance4x8)
2531 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10,
2532 aom_highbd_10_obmc_variance8x4,
2533 aom_highbd_10_obmc_sub_pixel_variance8x4)
2534 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10,
2535 aom_highbd_10_obmc_variance4x4,
2536 aom_highbd_10_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002537#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002538#if CONFIG_EXT_PARTITION
2539 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits10,
2540 aom_highbd_10_obmc_variance128x32,
2541 aom_highbd_10_obmc_sub_pixel_variance128x32)
2542
2543 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits10,
2544 aom_highbd_10_obmc_variance32x128,
2545 aom_highbd_10_obmc_sub_pixel_variance32x128)
2546#endif // CONFIG_EXT_PARTITION
2547
Rupert Swarbrick72678572017-08-02 12:05:26 +01002548 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10,
2549 aom_highbd_10_obmc_variance64x16,
2550 aom_highbd_10_obmc_sub_pixel_variance64x16)
2551
2552 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10,
2553 aom_highbd_10_obmc_variance16x64,
2554 aom_highbd_10_obmc_sub_pixel_variance16x64)
2555
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002556 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10,
2557 aom_highbd_10_obmc_variance32x8,
2558 aom_highbd_10_obmc_sub_pixel_variance32x8)
2559
2560 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10,
2561 aom_highbd_10_obmc_variance8x32,
2562 aom_highbd_10_obmc_sub_pixel_variance8x32)
2563
2564 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10,
2565 aom_highbd_10_obmc_variance16x4,
2566 aom_highbd_10_obmc_sub_pixel_variance16x4)
2567
2568 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10,
2569 aom_highbd_10_obmc_variance4x16,
2570 aom_highbd_10_obmc_sub_pixel_variance4x16)
2571#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002572 break;
2573
Yaowu Xuf883b422016-08-30 14:01:10 -07002574 case AOM_BITS_12:
Cheng Chenbf3d4962017-11-01 14:48:52 -07002575#if CONFIG_JNT_COMP
2576#if CONFIG_EXT_PARTITION_TYPES
2577#if CONFIG_EXT_PARTITION
2578 HIGHBD_BFP(
2579 BLOCK_128X32, aom_highbd_sad128x32_bits12,
2580 aom_highbd_sad128x32_avg_bits12, aom_highbd_12_variance128x32,
2581 aom_highbd_12_sub_pixel_variance128x32,
2582 aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL,
2583 aom_highbd_sad128x32x4d_bits12, aom_highbd_jnt_sad128x32_avg_bits12,
2584 aom_highbd_12_jnt_sub_pixel_avg_variance128x32);
2585
2586 HIGHBD_BFP(
2587 BLOCK_32X128, aom_highbd_sad32x128_bits12,
2588 aom_highbd_sad32x128_avg_bits12, aom_highbd_12_variance32x128,
2589 aom_highbd_12_sub_pixel_variance32x128,
2590 aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL,
2591 aom_highbd_sad32x128x4d_bits12, aom_highbd_jnt_sad32x128_avg_bits12,
2592 aom_highbd_12_jnt_sub_pixel_avg_variance32x128);
2593#endif // CONFIG_EXT_PARTITION
2594
2595 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12,
2596 aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16,
2597 aom_highbd_12_sub_pixel_variance64x16,
2598 aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL,
2599 aom_highbd_sad64x16x4d_bits12,
2600 aom_highbd_jnt_sad64x16_avg_bits12,
2601 aom_highbd_12_jnt_sub_pixel_avg_variance64x16);
2602
2603 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12,
2604 aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64,
2605 aom_highbd_12_sub_pixel_variance16x64,
2606 aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL,
2607 aom_highbd_sad16x64x4d_bits12,
2608 aom_highbd_jnt_sad16x64_avg_bits12,
2609 aom_highbd_12_jnt_sub_pixel_avg_variance16x64);
2610
2611 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12,
2612 aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8,
2613 aom_highbd_12_sub_pixel_variance32x8,
2614 aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL,
2615 aom_highbd_sad32x8x4d_bits12,
2616 aom_highbd_jnt_sad32x8_avg_bits12,
2617 aom_highbd_12_jnt_sub_pixel_avg_variance32x8);
2618
2619 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12,
2620 aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32,
2621 aom_highbd_12_sub_pixel_variance8x32,
2622 aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL,
2623 aom_highbd_sad8x32x4d_bits12,
2624 aom_highbd_jnt_sad8x32_avg_bits12,
2625 aom_highbd_12_jnt_sub_pixel_avg_variance8x32);
2626
2627 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12,
2628 aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4,
2629 aom_highbd_12_sub_pixel_variance16x4,
2630 aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL,
2631 aom_highbd_sad16x4x4d_bits12,
2632 aom_highbd_jnt_sad16x4_avg_bits12,
2633 aom_highbd_12_jnt_sub_pixel_avg_variance16x4);
2634
2635 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12,
2636 aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16,
2637 aom_highbd_12_sub_pixel_variance4x16,
2638 aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL,
2639 aom_highbd_sad4x16x4d_bits12,
2640 aom_highbd_jnt_sad4x16_avg_bits12,
2641 aom_highbd_12_jnt_sub_pixel_avg_variance4x16);
2642#endif
2643
2644 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12,
2645 aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16,
2646 aom_highbd_12_sub_pixel_variance32x16,
2647 aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL,
2648 aom_highbd_sad32x16x4d_bits12,
2649 aom_highbd_jnt_sad32x16_avg_bits12,
2650 aom_highbd_12_jnt_sub_pixel_avg_variance32x16);
2651
2652 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12,
2653 aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32,
2654 aom_highbd_12_sub_pixel_variance16x32,
2655 aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL,
2656 aom_highbd_sad16x32x4d_bits12,
2657 aom_highbd_jnt_sad16x32_avg_bits12,
2658 aom_highbd_12_jnt_sub_pixel_avg_variance16x32);
2659
2660 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12,
2661 aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32,
2662 aom_highbd_12_sub_pixel_variance64x32,
2663 aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL,
2664 aom_highbd_sad64x32x4d_bits12,
2665 aom_highbd_jnt_sad64x32_avg_bits12,
2666 aom_highbd_12_jnt_sub_pixel_avg_variance64x32);
2667
2668 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12,
2669 aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64,
2670 aom_highbd_12_sub_pixel_variance32x64,
2671 aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL,
2672 aom_highbd_sad32x64x4d_bits12,
2673 aom_highbd_jnt_sad32x64_avg_bits12,
2674 aom_highbd_12_jnt_sub_pixel_avg_variance32x64);
2675
2676 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12,
2677 aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32,
2678 aom_highbd_12_sub_pixel_variance32x32,
2679 aom_highbd_12_sub_pixel_avg_variance32x32,
2680 aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12,
2681 aom_highbd_sad32x32x4d_bits12,
2682 aom_highbd_jnt_sad32x32_avg_bits12,
2683 aom_highbd_12_jnt_sub_pixel_avg_variance32x32);
2684
2685 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12,
2686 aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64,
2687 aom_highbd_12_sub_pixel_variance64x64,
2688 aom_highbd_12_sub_pixel_avg_variance64x64,
2689 aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12,
2690 aom_highbd_sad64x64x4d_bits12,
2691 aom_highbd_jnt_sad64x64_avg_bits12,
2692 aom_highbd_12_jnt_sub_pixel_avg_variance64x64);
2693
2694 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12,
2695 aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16,
2696 aom_highbd_12_sub_pixel_variance16x16,
2697 aom_highbd_12_sub_pixel_avg_variance16x16,
2698 aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12,
2699 aom_highbd_sad16x16x4d_bits12,
2700 aom_highbd_jnt_sad16x16_avg_bits12,
2701 aom_highbd_12_jnt_sub_pixel_avg_variance16x16);
2702
2703 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12,
2704 aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8,
2705 aom_highbd_12_sub_pixel_variance16x8,
2706 aom_highbd_12_sub_pixel_avg_variance16x8,
2707 aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12,
2708 aom_highbd_sad16x8x4d_bits12,
2709 aom_highbd_jnt_sad16x8_avg_bits12,
2710 aom_highbd_12_jnt_sub_pixel_avg_variance16x8);
2711
2712 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12,
2713 aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16,
2714 aom_highbd_12_sub_pixel_variance8x16,
2715 aom_highbd_12_sub_pixel_avg_variance8x16,
2716 aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12,
2717 aom_highbd_sad8x16x4d_bits12,
2718 aom_highbd_jnt_sad8x16_avg_bits12,
2719 aom_highbd_12_jnt_sub_pixel_avg_variance8x16);
2720
2721 HIGHBD_BFP(
2722 BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12,
2723 aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8,
2724 aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12,
2725 aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12,
2726 aom_highbd_jnt_sad8x8_avg_bits12,
2727 aom_highbd_12_jnt_sub_pixel_avg_variance8x8);
2728
2729 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12,
2730 aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4,
2731 aom_highbd_12_sub_pixel_variance8x4,
2732 aom_highbd_12_sub_pixel_avg_variance8x4, NULL,
2733 aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12,
2734 aom_highbd_jnt_sad8x4_avg_bits12,
2735 aom_highbd_12_jnt_sub_pixel_avg_variance8x4);
2736
2737 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12,
2738 aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8,
2739 aom_highbd_12_sub_pixel_variance4x8,
2740 aom_highbd_12_sub_pixel_avg_variance4x8, NULL,
2741 aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12,
2742 aom_highbd_jnt_sad4x8_avg_bits12,
2743 aom_highbd_12_jnt_sub_pixel_avg_variance4x8);
2744
2745 HIGHBD_BFP(
2746 BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12,
2747 aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4,
2748 aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12,
2749 aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12,
2750 aom_highbd_jnt_sad4x4_avg_bits12,
2751 aom_highbd_12_jnt_sub_pixel_avg_variance4x4);
2752
Cheng Chenbf3d4962017-11-01 14:48:52 -07002753#if CONFIG_EXT_PARTITION
2754 HIGHBD_BFP(
2755 BLOCK_128X128, aom_highbd_sad128x128_bits12,
2756 aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128,
2757 aom_highbd_12_sub_pixel_variance128x128,
2758 aom_highbd_12_sub_pixel_avg_variance128x128,
2759 aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12,
2760 aom_highbd_sad128x128x4d_bits12,
2761 aom_highbd_jnt_sad128x128_avg_bits12,
2762 aom_highbd_12_jnt_sub_pixel_avg_variance128x128);
2763
2764 HIGHBD_BFP(
2765 BLOCK_128X64, aom_highbd_sad128x64_bits12,
2766 aom_highbd_sad128x64_avg_bits12, aom_highbd_12_variance128x64,
2767 aom_highbd_12_sub_pixel_variance128x64,
2768 aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL,
2769 aom_highbd_sad128x64x4d_bits12, aom_highbd_jnt_sad128x64_avg_bits12,
2770 aom_highbd_12_jnt_sub_pixel_avg_variance128x64);
2771
2772 HIGHBD_BFP(
2773 BLOCK_64X128, aom_highbd_sad64x128_bits12,
2774 aom_highbd_sad64x128_avg_bits12, aom_highbd_12_variance64x128,
2775 aom_highbd_12_sub_pixel_variance64x128,
2776 aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL,
2777 aom_highbd_sad64x128x4d_bits12, aom_highbd_jnt_sad64x128_avg_bits12,
2778 aom_highbd_12_jnt_sub_pixel_avg_variance64x128);
2779#endif // CONFIG_EXT_PARTITION
2780#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002781#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002782#if CONFIG_EXT_PARTITION
2783 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits12,
2784 aom_highbd_sad128x32_avg_bits12,
2785 aom_highbd_12_variance128x32,
2786 aom_highbd_12_sub_pixel_variance128x32,
2787 aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL,
2788 aom_highbd_sad128x32x4d_bits12)
2789
2790 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits12,
2791 aom_highbd_sad32x128_avg_bits12,
2792 aom_highbd_12_variance32x128,
2793 aom_highbd_12_sub_pixel_variance32x128,
2794 aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL,
2795 aom_highbd_sad32x128x4d_bits12)
2796#endif // CONFIG_EXT_PARTITION
2797
Rupert Swarbrick72678572017-08-02 12:05:26 +01002798 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12,
2799 aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16,
2800 aom_highbd_12_sub_pixel_variance64x16,
2801 aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL,
2802 aom_highbd_sad64x16x4d_bits12)
2803
2804 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12,
2805 aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64,
2806 aom_highbd_12_sub_pixel_variance16x64,
2807 aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL,
2808 aom_highbd_sad16x64x4d_bits12)
2809
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002810 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12,
2811 aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8,
2812 aom_highbd_12_sub_pixel_variance32x8,
2813 aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL,
2814 aom_highbd_sad32x8x4d_bits12)
2815
2816 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12,
2817 aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32,
2818 aom_highbd_12_sub_pixel_variance8x32,
2819 aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL,
2820 aom_highbd_sad8x32x4d_bits12)
2821
2822 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12,
2823 aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4,
2824 aom_highbd_12_sub_pixel_variance16x4,
2825 aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL,
2826 aom_highbd_sad16x4x4d_bits12)
2827
2828 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12,
2829 aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16,
2830 aom_highbd_12_sub_pixel_variance4x16,
2831 aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL,
2832 aom_highbd_sad4x16x4d_bits12)
2833#endif
2834
Yaowu Xuf883b422016-08-30 14:01:10 -07002835 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12,
2836 aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16,
2837 aom_highbd_12_sub_pixel_variance32x16,
2838 aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL,
2839 aom_highbd_sad32x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002840
Yaowu Xuf883b422016-08-30 14:01:10 -07002841 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12,
2842 aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32,
2843 aom_highbd_12_sub_pixel_variance16x32,
2844 aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL,
2845 aom_highbd_sad16x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002846
Yaowu Xuf883b422016-08-30 14:01:10 -07002847 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12,
2848 aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32,
2849 aom_highbd_12_sub_pixel_variance64x32,
2850 aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL,
2851 aom_highbd_sad64x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002852
Yaowu Xuf883b422016-08-30 14:01:10 -07002853 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12,
2854 aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64,
2855 aom_highbd_12_sub_pixel_variance32x64,
2856 aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL,
2857 aom_highbd_sad32x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002858
Yaowu Xuf883b422016-08-30 14:01:10 -07002859 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12,
2860 aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32,
2861 aom_highbd_12_sub_pixel_variance32x32,
2862 aom_highbd_12_sub_pixel_avg_variance32x32,
2863 aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12,
2864 aom_highbd_sad32x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002865
Yaowu Xuf883b422016-08-30 14:01:10 -07002866 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12,
2867 aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64,
2868 aom_highbd_12_sub_pixel_variance64x64,
2869 aom_highbd_12_sub_pixel_avg_variance64x64,
2870 aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12,
2871 aom_highbd_sad64x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002872
Yaowu Xuf883b422016-08-30 14:01:10 -07002873 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12,
2874 aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16,
2875 aom_highbd_12_sub_pixel_variance16x16,
2876 aom_highbd_12_sub_pixel_avg_variance16x16,
2877 aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12,
2878 aom_highbd_sad16x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002879
Yaowu Xuf883b422016-08-30 14:01:10 -07002880 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12,
2881 aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8,
2882 aom_highbd_12_sub_pixel_variance16x8,
2883 aom_highbd_12_sub_pixel_avg_variance16x8,
2884 aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12,
2885 aom_highbd_sad16x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002886
Yaowu Xuf883b422016-08-30 14:01:10 -07002887 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12,
2888 aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16,
2889 aom_highbd_12_sub_pixel_variance8x16,
2890 aom_highbd_12_sub_pixel_avg_variance8x16,
2891 aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12,
2892 aom_highbd_sad8x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002893
2894 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002895 BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12,
2896 aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8,
2897 aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12,
2898 aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002899
Yaowu Xuf883b422016-08-30 14:01:10 -07002900 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12,
2901 aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4,
2902 aom_highbd_12_sub_pixel_variance8x4,
2903 aom_highbd_12_sub_pixel_avg_variance8x4, NULL,
2904 aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002905
Yaowu Xuf883b422016-08-30 14:01:10 -07002906 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12,
2907 aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8,
2908 aom_highbd_12_sub_pixel_variance4x8,
2909 aom_highbd_12_sub_pixel_avg_variance4x8, NULL,
2910 aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002911
2912 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002913 BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12,
2914 aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4,
2915 aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12,
2916 aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002917
2918#if CONFIG_EXT_PARTITION
2919 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002920 BLOCK_128X128, aom_highbd_sad128x128_bits12,
2921 aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128,
2922 aom_highbd_12_sub_pixel_variance128x128,
2923 aom_highbd_12_sub_pixel_avg_variance128x128,
2924 aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12,
2925 aom_highbd_sad128x128x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002926
Yaowu Xuf883b422016-08-30 14:01:10 -07002927 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12,
2928 aom_highbd_sad128x64_avg_bits12,
2929 aom_highbd_12_variance128x64,
2930 aom_highbd_12_sub_pixel_variance128x64,
2931 aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL,
2932 aom_highbd_sad128x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002933
Yaowu Xuf883b422016-08-30 14:01:10 -07002934 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12,
2935 aom_highbd_sad64x128_avg_bits12,
2936 aom_highbd_12_variance64x128,
2937 aom_highbd_12_sub_pixel_variance64x128,
2938 aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL,
2939 aom_highbd_sad64x128x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002940#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07002941#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002942
Yaowu Xuc27fc142016-08-22 16:08:15 -07002943#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002944 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12,
2945 aom_highbd_12_masked_sub_pixel_variance128x128)
2946 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12,
2947 aom_highbd_12_masked_sub_pixel_variance128x64)
2948 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12,
2949 aom_highbd_12_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002950#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002951 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12,
2952 aom_highbd_12_masked_sub_pixel_variance64x64)
2953 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12,
2954 aom_highbd_12_masked_sub_pixel_variance64x32)
2955 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12,
2956 aom_highbd_12_masked_sub_pixel_variance32x64)
2957 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12,
2958 aom_highbd_12_masked_sub_pixel_variance32x32)
2959 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12,
2960 aom_highbd_12_masked_sub_pixel_variance32x16)
2961 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12,
2962 aom_highbd_12_masked_sub_pixel_variance16x32)
2963 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12,
2964 aom_highbd_12_masked_sub_pixel_variance16x16)
2965 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12,
2966 aom_highbd_12_masked_sub_pixel_variance8x16)
2967 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12,
2968 aom_highbd_12_masked_sub_pixel_variance16x8)
2969 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12,
2970 aom_highbd_12_masked_sub_pixel_variance8x8)
2971 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12,
2972 aom_highbd_12_masked_sub_pixel_variance4x8)
2973 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12,
2974 aom_highbd_12_masked_sub_pixel_variance8x4)
2975 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12,
2976 aom_highbd_12_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002977#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002978#if CONFIG_EXT_PARTITION
2979 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits12,
2980 aom_highbd_12_masked_sub_pixel_variance128x32)
2981
2982 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits12,
2983 aom_highbd_12_masked_sub_pixel_variance32x128)
2984#endif // CONFIG_EXT_PARTITION
2985
Rupert Swarbrick72678572017-08-02 12:05:26 +01002986 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12,
2987 aom_highbd_12_masked_sub_pixel_variance64x16)
2988
2989 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12,
2990 aom_highbd_12_masked_sub_pixel_variance16x64)
2991
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002992 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12,
2993 aom_highbd_12_masked_sub_pixel_variance32x8)
2994
2995 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12,
2996 aom_highbd_12_masked_sub_pixel_variance8x32)
2997
2998 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12,
2999 aom_highbd_12_masked_sub_pixel_variance16x4)
3000
3001 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12,
3002 aom_highbd_12_masked_sub_pixel_variance4x16)
3003#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003004
Yaowu Xuc27fc142016-08-22 16:08:15 -07003005#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003006 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12,
3007 aom_highbd_12_obmc_variance128x128,
3008 aom_highbd_12_obmc_sub_pixel_variance128x128)
3009 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12,
3010 aom_highbd_12_obmc_variance128x64,
3011 aom_highbd_12_obmc_sub_pixel_variance128x64)
3012 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12,
3013 aom_highbd_12_obmc_variance64x128,
3014 aom_highbd_12_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003015#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003016 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12,
3017 aom_highbd_12_obmc_variance64x64,
3018 aom_highbd_12_obmc_sub_pixel_variance64x64)
3019 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12,
3020 aom_highbd_12_obmc_variance64x32,
3021 aom_highbd_12_obmc_sub_pixel_variance64x32)
3022 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12,
3023 aom_highbd_12_obmc_variance32x64,
3024 aom_highbd_12_obmc_sub_pixel_variance32x64)
3025 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12,
3026 aom_highbd_12_obmc_variance32x32,
3027 aom_highbd_12_obmc_sub_pixel_variance32x32)
3028 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12,
3029 aom_highbd_12_obmc_variance32x16,
3030 aom_highbd_12_obmc_sub_pixel_variance32x16)
3031 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12,
3032 aom_highbd_12_obmc_variance16x32,
3033 aom_highbd_12_obmc_sub_pixel_variance16x32)
3034 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12,
3035 aom_highbd_12_obmc_variance16x16,
3036 aom_highbd_12_obmc_sub_pixel_variance16x16)
3037 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12,
3038 aom_highbd_12_obmc_variance8x16,
3039 aom_highbd_12_obmc_sub_pixel_variance8x16)
3040 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12,
3041 aom_highbd_12_obmc_variance16x8,
3042 aom_highbd_12_obmc_sub_pixel_variance16x8)
3043 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12,
3044 aom_highbd_12_obmc_variance8x8,
3045 aom_highbd_12_obmc_sub_pixel_variance8x8)
3046 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12,
3047 aom_highbd_12_obmc_variance4x8,
3048 aom_highbd_12_obmc_sub_pixel_variance4x8)
3049 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12,
3050 aom_highbd_12_obmc_variance8x4,
3051 aom_highbd_12_obmc_sub_pixel_variance8x4)
3052 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12,
3053 aom_highbd_12_obmc_variance4x4,
3054 aom_highbd_12_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003055#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003056#if CONFIG_EXT_PARTITION
3057 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits12,
3058 aom_highbd_12_obmc_variance128x32,
3059 aom_highbd_12_obmc_sub_pixel_variance128x32)
3060
3061 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits12,
3062 aom_highbd_12_obmc_variance32x128,
3063 aom_highbd_12_obmc_sub_pixel_variance32x128)
3064#endif // CONFIG_EXT_PARTITION
3065
Rupert Swarbrick72678572017-08-02 12:05:26 +01003066 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12,
3067 aom_highbd_12_obmc_variance64x16,
3068 aom_highbd_12_obmc_sub_pixel_variance64x16)
3069
3070 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12,
3071 aom_highbd_12_obmc_variance16x64,
3072 aom_highbd_12_obmc_sub_pixel_variance16x64)
3073
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003074 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12,
3075 aom_highbd_12_obmc_variance32x8,
3076 aom_highbd_12_obmc_sub_pixel_variance32x8)
3077
3078 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12,
3079 aom_highbd_12_obmc_variance8x32,
3080 aom_highbd_12_obmc_sub_pixel_variance8x32)
3081
3082 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12,
3083 aom_highbd_12_obmc_variance16x4,
3084 aom_highbd_12_obmc_sub_pixel_variance16x4)
3085
3086 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12,
3087 aom_highbd_12_obmc_variance4x16,
3088 aom_highbd_12_obmc_sub_pixel_variance4x16)
3089#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003090 break;
3091
3092 default:
3093 assert(0 &&
Yaowu Xuf883b422016-08-30 14:01:10 -07003094 "cm->bit_depth should be AOM_BITS_8, "
3095 "AOM_BITS_10 or AOM_BITS_12");
Yaowu Xuc27fc142016-08-22 16:08:15 -07003096 }
3097 }
3098}
Yaowu Xuc27fc142016-08-22 16:08:15 -07003099
Yaowu Xuf883b422016-08-30 14:01:10 -07003100static void realloc_segmentation_maps(AV1_COMP *cpi) {
3101 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003102
3103 // Create the encoder segmentation map and set all entries to 0
Yaowu Xuf883b422016-08-30 14:01:10 -07003104 aom_free(cpi->segmentation_map);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003105 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
Yaowu Xuf883b422016-08-30 14:01:10 -07003106 aom_calloc(cm->mi_rows * cm->mi_cols, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003107
3108 // Create a map used for cyclic background refresh.
Yaowu Xuf883b422016-08-30 14:01:10 -07003109 if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003110 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
Yaowu Xuf883b422016-08-30 14:01:10 -07003111 av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003112
3113 // Create a map used to mark inactive areas.
Yaowu Xuf883b422016-08-30 14:01:10 -07003114 aom_free(cpi->active_map.map);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003115 CHECK_MEM_ERROR(cm, cpi->active_map.map,
Yaowu Xuf883b422016-08-30 14:01:10 -07003116 aom_calloc(cm->mi_rows * cm->mi_cols, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003117}
3118
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003119void set_compound_tools(AV1_COMMON *cm) {
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003120 cm->allow_interintra_compound = 1;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003121 cm->allow_masked_compound = 1;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003122}
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003123
Yaowu Xuf883b422016-08-30 14:01:10 -07003124void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) {
3125 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003126 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003127 RATE_CONTROL *const rc = &cpi->rc;
hui sud9a812b2017-07-06 14:34:37 -07003128 MACROBLOCK *const x = &cpi->td.mb;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003129
3130 if (cm->profile != oxcf->profile) cm->profile = oxcf->profile;
3131 cm->bit_depth = oxcf->bit_depth;
Andrey Norkin9e694632017-12-21 18:50:57 -08003132#if CONFIG_CICP
3133 cm->color_primaries = oxcf->color_primaries;
3134 cm->transfer_characteristics = oxcf->transfer_characteristics;
3135 cm->matrix_coefficients = oxcf->matrix_coefficients;
3136#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07003137 cm->color_space = oxcf->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08003138#endif
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08003139#if CONFIG_MONO_VIDEO
3140 cm->seq_params.monochrome = oxcf->monochrome;
3141#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07003142#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08003143#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07003144 cm->transfer_function = oxcf->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08003145#endif
anorkin76fb1262017-03-22 15:12:12 -07003146 cm->chroma_sample_position = oxcf->chroma_sample_position;
3147#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003148 cm->color_range = oxcf->color_range;
3149
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08003150 assert(IMPLIES(cm->profile <= PROFILE_1, cm->bit_depth <= AOM_BITS_10));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003151
Andrey Norkin28e9ce22018-01-08 10:11:21 -08003152#if CONFIG_TIMING_INFO_IN_SEQ_HEADERS
3153 cm->timing_info_present = oxcf->timing_info_present;
3154 cm->num_units_in_tick = oxcf->num_units_in_tick;
3155 cm->time_scale = oxcf->time_scale;
3156 cm->equal_picture_interval = oxcf->equal_picture_interval;
3157 cm->num_ticks_per_picture = oxcf->num_ticks_per_picture;
3158#endif
3159
Andrey Norkin6f1c2f72018-01-15 20:08:52 -08003160#if CONFIG_FILM_GRAIN
3161 update_film_grain_parameters(cpi, oxcf);
3162#endif
3163
Yaowu Xuc27fc142016-08-22 16:08:15 -07003164 cpi->oxcf = *oxcf;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +01003165 cpi->common.options = oxcf->cfg;
hui sud9a812b2017-07-06 14:34:37 -07003166 x->e_mbd.bd = (int)cm->bit_depth;
hui sud9a812b2017-07-06 14:34:37 -07003167 x->e_mbd.global_motion = cm->global_motion;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003168
Yaowu Xuf883b422016-08-30 14:01:10 -07003169 if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07003170 rc->baseline_gf_interval = FIXED_GF_INTERVAL;
3171 } else {
3172 rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2;
3173 }
3174
3175 cpi->refresh_last_frame = 1;
3176 cpi->refresh_golden_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003177 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07003178 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003179
3180 cm->refresh_frame_context =
3181 (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode)
James Zernf34dfc82018-02-23 16:53:33 -08003182 ? REFRESH_FRAME_CONTEXT_DISABLED
Yaowu Xuc27fc142016-08-22 16:08:15 -07003183 : REFRESH_FRAME_CONTEXT_BACKWARD;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01003184#if CONFIG_EXT_TILE
3185 if (oxcf->large_scale_tile)
James Zernf34dfc82018-02-23 16:53:33 -08003186 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01003187#endif // CONFIG_EXT_TILE
3188
Thomas Daedea6a854b2017-06-22 17:49:11 -07003189#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07003190 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
Thomas Daedea6a854b2017-06-22 17:49:11 -07003191#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003192
Alex Converse74ad0912017-07-18 10:22:58 -07003193 if (x->palette_buffer == NULL) {
hui sud9a812b2017-07-06 14:34:37 -07003194 CHECK_MEM_ERROR(cm, x->palette_buffer,
3195 aom_memalign(16, sizeof(*x->palette_buffer)));
3196 }
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003197 set_compound_tools(cm);
Yaowu Xuf883b422016-08-30 14:01:10 -07003198 av1_reset_segment_features(cm);
RogerZhou3b635242017-09-19 10:06:46 -07003199#if CONFIG_AMVR
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07003200 set_high_precision_mv(cpi, 1, 0);
RogerZhou3b635242017-09-19 10:06:46 -07003201#else
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07003202 set_high_precision_mv(cpi, 1);
RogerZhou3b635242017-09-19 10:06:46 -07003203#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003204
Yaowu Xuc27fc142016-08-22 16:08:15 -07003205 set_rc_buffer_sizes(rc, &cpi->oxcf);
3206
3207 // Under a configuration change, where maximum_buffer_size may change,
3208 // keep buffer level clipped to the maximum allowed buffer size.
Yaowu Xuf883b422016-08-30 14:01:10 -07003209 rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size);
3210 rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003211
3212 // Set up frame rate and related parameters rate control values.
Yaowu Xuf883b422016-08-30 14:01:10 -07003213 av1_new_framerate(cpi, cpi->framerate);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003214
3215 // Set absolute upper and lower quality limits
3216 rc->worst_quality = cpi->oxcf.worst_allowed_q;
3217 rc->best_quality = cpi->oxcf.best_allowed_q;
3218
Yunqing Wangb6e23bc2017-11-15 13:18:55 -08003219#if CONFIG_EXT_TILE
3220 if (!oxcf->large_scale_tile)
3221#endif // CONFIG_EXT_TILE
3222 cm->interp_filter = cpi->sf.default_interp_filter;
3223#if CONFIG_EXT_TILE
3224 else
3225 cm->interp_filter = EIGHTTAP_REGULAR;
3226#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07003227
Yue Chen5380cb52018-02-23 15:33:21 -08003228 cm->switchable_motion_mode = 1;
3229
Yaowu Xuc27fc142016-08-22 16:08:15 -07003230 if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) {
3231 cm->render_width = cpi->oxcf.render_width;
3232 cm->render_height = cpi->oxcf.render_height;
3233 } else {
3234 cm->render_width = cpi->oxcf.width;
3235 cm->render_height = cpi->oxcf.height;
3236 }
3237 cm->width = cpi->oxcf.width;
3238 cm->height = cpi->oxcf.height;
3239
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003240 int sb_size = cm->seq_params.sb_size;
3241 set_sb_size(&cm->seq_params, select_sb_size(cpi));
Dominic Symes917d6c02017-10-11 18:00:52 +02003242
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003243 if (cpi->initial_width || sb_size != cm->seq_params.sb_size) {
Dominic Symes917d6c02017-10-11 18:00:52 +02003244 if (cm->width > cpi->initial_width || cm->height > cpi->initial_height ||
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003245 cm->seq_params.sb_size != sb_size) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003246 av1_free_context_buffers(cm);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003247 av1_free_pc_tree(&cpi->td, num_planes);
Cheng Chen46f30c72017-09-07 11:13:33 -07003248 alloc_compressor_data(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003249 realloc_segmentation_maps(cpi);
3250 cpi->initial_width = cpi->initial_height = 0;
3251 }
3252 }
3253 update_frame_size(cpi);
3254
3255 cpi->alt_ref_source = NULL;
3256 rc->is_src_frame_alt_ref = 0;
3257
Yaowu Xuc27fc142016-08-22 16:08:15 -07003258 rc->is_bwd_ref_frame = 0;
3259 rc->is_last_bipred_frame = 0;
3260 rc->is_bipred_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003261
Yaowu Xuc27fc142016-08-22 16:08:15 -07003262 set_tile_info(cpi);
3263
3264 cpi->ext_refresh_frame_flags_pending = 0;
3265 cpi->ext_refresh_frame_context_pending = 0;
3266
Yaowu Xuc27fc142016-08-22 16:08:15 -07003267 highbd_set_var_fns(cpi);
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00003268
3269 cm->seq_params.force_screen_content_tools = 2;
RogerZhou3b635242017-09-19 10:06:46 -07003270#if CONFIG_AMVR
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00003271 cm->seq_params.force_integer_mv = 2;
RogerZhou3b635242017-09-19 10:06:46 -07003272#endif
Joe Youngdb5eb4c2018-02-16 17:30:40 -08003273#if CONFIG_INTRA_EDGE2
3274 cm->disable_intra_edge_filter = 0;
3275#endif // CONFIG_INTRA_EDGE2
Yaowu Xuc27fc142016-08-22 16:08:15 -07003276}
3277
Yaowu Xuf883b422016-08-30 14:01:10 -07003278AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
3279 BufferPool *const pool) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07003280 unsigned int i;
Yaowu Xuf883b422016-08-30 14:01:10 -07003281 AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP));
3282 AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003283
3284 if (!cm) return NULL;
3285
Yaowu Xuf883b422016-08-30 14:01:10 -07003286 av1_zero(*cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003287
3288 if (setjmp(cm->error.jmp)) {
3289 cm->error.setjmp = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -07003290 av1_remove_compressor(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003291 return 0;
3292 }
3293
3294 cm->error.setjmp = 1;
Cheng Chen46f30c72017-09-07 11:13:33 -07003295 cm->alloc_mi = enc_alloc_mi;
3296 cm->free_mi = enc_free_mi;
3297 cm->setup_mi = enc_setup_mi;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003298
Angie Chianga5d96c42016-10-21 16:16:56 -07003299 CHECK_MEM_ERROR(cm, cm->fc,
3300 (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
3301 CHECK_MEM_ERROR(cm, cm->frame_contexts,
3302 (FRAME_CONTEXT *)aom_memalign(
3303 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)));
3304 memset(cm->fc, 0, sizeof(*cm->fc));
3305 memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003306
3307 cpi->resize_state = 0;
3308 cpi->resize_avg_qp = 0;
3309 cpi->resize_buffer_underflow = 0;
Fergus Simpsonddc846e2017-04-24 18:09:13 -07003310
Yaowu Xuc27fc142016-08-22 16:08:15 -07003311 cpi->common.buffer_pool = pool;
3312
3313 init_config(cpi, oxcf);
Yaowu Xuf883b422016-08-30 14:01:10 -07003314 av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003315
3316 cm->current_video_frame = 0;
3317 cpi->partition_search_skippable_frame = 0;
3318 cpi->tile_data = NULL;
3319 cpi->last_show_frame_buf_idx = INVALID_IDX;
3320
3321 realloc_segmentation_maps(cpi);
3322
James Zern01a9d702017-08-25 19:09:33 +00003323 for (i = 0; i < NMV_CONTEXTS; ++i) {
3324 memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs));
3325 memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp));
3326 }
3327
Yaowu Xuc27fc142016-08-22 16:08:15 -07003328 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]));
3329 i++) {
3330 CHECK_MEM_ERROR(
3331 cm, cpi->mbgraph_stats[i].mb_stats,
Yaowu Xuf883b422016-08-30 14:01:10 -07003332 aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003333 }
3334
3335#if CONFIG_FP_MB_STATS
3336 cpi->use_fp_mb_stats = 0;
3337 if (cpi->use_fp_mb_stats) {
3338 // a place holder used to store the first pass mb stats in the first pass
3339 CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf,
Yaowu Xuf883b422016-08-30 14:01:10 -07003340 aom_calloc(cm->MBs * sizeof(uint8_t), 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003341 } else {
3342 cpi->twopass.frame_mb_stats_buf = NULL;
3343 }
3344#endif
3345
3346 cpi->refresh_alt_ref_frame = 0;
3347 cpi->multi_arf_last_grp_enabled = 0;
3348
3349 cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
3350#if CONFIG_INTERNAL_STATS
3351 cpi->b_calculate_blockiness = 1;
3352 cpi->b_calculate_consistency = 1;
3353 cpi->total_inconsistency = 0;
3354 cpi->psnr.worst = 100.0;
3355 cpi->worst_ssim = 100.0;
3356
3357 cpi->count = 0;
3358 cpi->bytes = 0;
3359
3360 if (cpi->b_calculate_psnr) {
3361 cpi->total_sq_error = 0;
3362 cpi->total_samples = 0;
3363 cpi->tot_recode_hits = 0;
3364 cpi->summed_quality = 0;
3365 cpi->summed_weights = 0;
3366 }
3367
3368 cpi->fastssim.worst = 100.0;
3369 cpi->psnrhvs.worst = 100.0;
3370
3371 if (cpi->b_calculate_blockiness) {
3372 cpi->total_blockiness = 0;
3373 cpi->worst_blockiness = 0.0;
3374 }
3375
3376 if (cpi->b_calculate_consistency) {
3377 CHECK_MEM_ERROR(cm, cpi->ssim_vars,
Yaowu Xuf883b422016-08-30 14:01:10 -07003378 aom_malloc(sizeof(*cpi->ssim_vars) * 4 *
Yaowu Xuc27fc142016-08-22 16:08:15 -07003379 cpi->common.mi_rows * cpi->common.mi_cols));
3380 cpi->worst_consistency = 100.0;
3381 }
3382#endif
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003383#if CONFIG_ENTROPY_STATS
3384 av1_zero(aggregate_fc);
Zoe Liua56f9162017-06-21 22:49:57 -07003385 av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003386#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003387
3388 cpi->first_time_stamp_ever = INT64_MAX;
3389
James Zern01a9d702017-08-25 19:09:33 +00003390 for (i = 0; i < NMV_CONTEXTS; ++i) {
3391 cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX];
3392 cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX];
3393 cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX];
3394 cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX];
3395 }
3396
Yaowu Xuc27fc142016-08-22 16:08:15 -07003397#ifdef OUTPUT_YUV_SKINMAP
3398 yuv_skinmap_file = fopen("skinmap.yuv", "ab");
3399#endif
3400#ifdef OUTPUT_YUV_REC
3401 yuv_rec_file = fopen("rec.yuv", "wb");
3402#endif
3403
3404#if 0
3405 framepsnr = fopen("framepsnr.stt", "a");
3406 kf_list = fopen("kf_list.stt", "w");
3407#endif
3408
Yaowu Xuc27fc142016-08-22 16:08:15 -07003409 if (oxcf->pass == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003410 av1_init_first_pass(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003411 } else if (oxcf->pass == 2) {
3412 const size_t packet_sz = sizeof(FIRSTPASS_STATS);
3413 const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
3414
3415#if CONFIG_FP_MB_STATS
3416 if (cpi->use_fp_mb_stats) {
3417 const size_t psz = cpi->common.MBs * sizeof(uint8_t);
3418 const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz);
3419
3420 cpi->twopass.firstpass_mb_stats.mb_stats_start =
3421 oxcf->firstpass_mb_stats_in.buf;
3422 cpi->twopass.firstpass_mb_stats.mb_stats_end =
3423 cpi->twopass.firstpass_mb_stats.mb_stats_start +
3424 (ps - 1) * cpi->common.MBs * sizeof(uint8_t);
3425 }
3426#endif
3427
3428 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
3429 cpi->twopass.stats_in = cpi->twopass.stats_in_start;
3430 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1];
3431
Yaowu Xuf883b422016-08-30 14:01:10 -07003432 av1_init_second_pass(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003433 }
3434
Yue Chen19d76012018-02-16 15:13:40 -08003435 int buf_scaler = 1;
3436
3437#if CONFIG_OBMC_HIGH_PREC_BLENDING
3438 CHECK_MEM_ERROR(cm, cpi->td.mb.above_pred_hp_buf,
3439 (CONV_BUF_TYPE *)aom_memalign(
Yue Chenb02c7c32018-02-23 17:03:28 -08003440 16, buf_scaler * MAX_MB_PLANE * (MAX_SB_SQUARE >> 1) *
Yue Chen19d76012018-02-16 15:13:40 -08003441 sizeof(*cpi->td.mb.above_pred_hp_buf)));
3442 CHECK_MEM_ERROR(cm, cpi->td.mb.left_pred_hp_buf,
3443 (CONV_BUF_TYPE *)aom_memalign(
Yue Chenb02c7c32018-02-23 17:03:28 -08003444 16, buf_scaler * MAX_MB_PLANE * (MAX_SB_SQUARE >> 1) *
Yue Chen19d76012018-02-16 15:13:40 -08003445 sizeof(*cpi->td.mb.left_pred_hp_buf)));
3446#else
Jingning Hand064cf02017-06-01 10:00:39 -07003447 CHECK_MEM_ERROR(
3448 cm, cpi->td.mb.above_pred_buf,
Johannb0ef6ff2018-02-08 14:32:21 -08003449 (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE *
3450 sizeof(*cpi->td.mb.above_pred_buf)));
Jingning Hand064cf02017-06-01 10:00:39 -07003451 CHECK_MEM_ERROR(
3452 cm, cpi->td.mb.left_pred_buf,
Johannb0ef6ff2018-02-08 14:32:21 -08003453 (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE *
3454 sizeof(*cpi->td.mb.left_pred_buf)));
Yue Chen19d76012018-02-16 15:13:40 -08003455#endif
Jingning Hand064cf02017-06-01 10:00:39 -07003456
3457 CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf,
3458 (int32_t *)aom_memalign(
3459 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf)));
3460
3461 CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf,
3462 (int32_t *)aom_memalign(
3463 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf)));
3464
Yaowu Xuf883b422016-08-30 14:01:10 -07003465 av1_set_speed_features_framesize_independent(cpi);
3466 av1_set_speed_features_framesize_dependent(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003467
Cheng Chenf78632e2017-10-20 15:30:51 -07003468#if CONFIG_JNT_COMP
3469#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, JSVAF) \
3470 cpi->fn_ptr[BT].sdf = SDF; \
3471 cpi->fn_ptr[BT].sdaf = SDAF; \
3472 cpi->fn_ptr[BT].vf = VF; \
3473 cpi->fn_ptr[BT].svf = SVF; \
3474 cpi->fn_ptr[BT].svaf = SVAF; \
3475 cpi->fn_ptr[BT].sdx3f = SDX3F; \
3476 cpi->fn_ptr[BT].sdx8f = SDX8F; \
3477 cpi->fn_ptr[BT].sdx4df = SDX4DF; \
3478 cpi->fn_ptr[BT].jsdaf = JSDAF; \
3479 cpi->fn_ptr[BT].jsvaf = JSVAF;
3480#else // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07003481#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
3482 cpi->fn_ptr[BT].sdf = SDF; \
3483 cpi->fn_ptr[BT].sdaf = SDAF; \
3484 cpi->fn_ptr[BT].vf = VF; \
3485 cpi->fn_ptr[BT].svf = SVF; \
3486 cpi->fn_ptr[BT].svaf = SVAF; \
3487 cpi->fn_ptr[BT].sdx3f = SDX3F; \
3488 cpi->fn_ptr[BT].sdx8f = SDX8F; \
3489 cpi->fn_ptr[BT].sdx4df = SDX4DF;
Cheng Chenf78632e2017-10-20 15:30:51 -07003490#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07003491
Cheng Chenf78632e2017-10-20 15:30:51 -07003492#if CONFIG_JNT_COMP
3493#if CONFIG_EXT_PARTITION_TYPES
3494 BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16,
3495 aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003496 aom_sad4x16x4d, aom_jnt_sad4x16_avg, aom_jnt_sub_pixel_avg_variance4x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003497
3498 BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4,
3499 aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003500 aom_sad16x4x4d, aom_jnt_sad16x4_avg, aom_jnt_sub_pixel_avg_variance16x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003501
3502 BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32,
3503 aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003504 aom_sad8x32x4d, aom_jnt_sad8x32_avg, aom_jnt_sub_pixel_avg_variance8x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003505
3506 BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8,
3507 aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003508 aom_sad32x8x4d, aom_jnt_sad32x8_avg, aom_jnt_sub_pixel_avg_variance32x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003509
3510 BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64,
3511 aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003512 aom_sad16x64x4d, aom_jnt_sad16x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003513 aom_jnt_sub_pixel_avg_variance16x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003514
3515 BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16,
3516 aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003517 aom_sad64x16x4d, aom_jnt_sad64x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003518 aom_jnt_sub_pixel_avg_variance64x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003519
3520#if CONFIG_EXT_PARTITION
3521 BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128,
3522 aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003523 NULL, aom_sad32x128x4d, aom_jnt_sad32x128_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003524 aom_jnt_sub_pixel_avg_variance32x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003525
3526 BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32,
3527 aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003528 NULL, aom_sad128x32x4d, aom_jnt_sad128x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003529 aom_jnt_sub_pixel_avg_variance128x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003530#endif // CONFIG_EXT_PARTITION
3531#endif // CONFIG_EXT_PARTITION_TYPES
3532
3533#if CONFIG_EXT_PARTITION
3534 BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128,
3535 aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128,
3536 aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d,
Cheng Chend0179a62017-11-16 17:02:53 -08003537 aom_jnt_sad128x128_avg, aom_jnt_sub_pixel_avg_variance128x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003538
3539 BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64,
3540 aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003541 NULL, aom_sad128x64x4d, aom_jnt_sad128x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003542 aom_jnt_sub_pixel_avg_variance128x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003543
3544 BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128,
3545 aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003546 NULL, aom_sad64x128x4d, aom_jnt_sad64x128_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003547 aom_jnt_sub_pixel_avg_variance64x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003548#endif // CONFIG_EXT_PARTITION
3549
3550 BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16,
3551 aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003552 aom_sad32x16x4d, aom_jnt_sad32x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003553 aom_jnt_sub_pixel_avg_variance32x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003554
3555 BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32,
3556 aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003557 aom_sad16x32x4d, aom_jnt_sad16x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003558 aom_jnt_sub_pixel_avg_variance16x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003559
3560 BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32,
3561 aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003562 aom_sad64x32x4d, aom_jnt_sad64x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003563 aom_jnt_sub_pixel_avg_variance64x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003564
3565 BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64,
3566 aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003567 aom_sad32x64x4d, aom_jnt_sad32x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003568 aom_jnt_sub_pixel_avg_variance32x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003569
3570 BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32,
3571 aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32,
Cheng Chend0179a62017-11-16 17:02:53 -08003572 aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d, aom_jnt_sad32x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003573 aom_jnt_sub_pixel_avg_variance32x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003574
3575 BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64,
3576 aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64,
Cheng Chend0179a62017-11-16 17:02:53 -08003577 aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d, aom_jnt_sad64x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003578 aom_jnt_sub_pixel_avg_variance64x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003579
3580 BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16,
3581 aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16,
Cheng Chend0179a62017-11-16 17:02:53 -08003582 aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d, aom_jnt_sad16x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003583 aom_jnt_sub_pixel_avg_variance16x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003584
3585 BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8,
3586 aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003587 aom_sad16x8x8, aom_sad16x8x4d, aom_jnt_sad16x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003588 aom_jnt_sub_pixel_avg_variance16x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003589
3590 BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16,
3591 aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003592 aom_sad8x16x8, aom_sad8x16x4d, aom_jnt_sad8x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003593 aom_jnt_sub_pixel_avg_variance8x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003594
3595 BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8,
3596 aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003597 aom_sad8x8x8, aom_sad8x8x4d, aom_jnt_sad8x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003598 aom_jnt_sub_pixel_avg_variance8x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003599
3600 BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4,
3601 aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003602 aom_sad8x4x8, aom_sad8x4x4d, aom_jnt_sad8x4_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003603 aom_jnt_sub_pixel_avg_variance8x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003604
3605 BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8,
3606 aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003607 aom_sad4x8x8, aom_sad4x8x4d, aom_jnt_sad4x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003608 aom_jnt_sub_pixel_avg_variance4x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003609
3610 BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4,
3611 aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003612 aom_sad4x4x8, aom_sad4x4x4d, aom_jnt_sad4x4_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003613 aom_jnt_sub_pixel_avg_variance4x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003614
Cheng Chenf78632e2017-10-20 15:30:51 -07003615#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003616#if CONFIG_EXT_PARTITION_TYPES
3617 BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16,
3618 aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL,
3619 aom_sad4x16x4d)
3620
3621 BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4,
3622 aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL,
3623 aom_sad16x4x4d)
3624
3625 BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32,
3626 aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL,
3627 aom_sad8x32x4d)
3628
3629 BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8,
3630 aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL,
3631 aom_sad32x8x4d)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003632
3633 BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64,
3634 aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL,
3635 aom_sad16x64x4d)
3636
3637 BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16,
3638 aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL,
3639 aom_sad64x16x4d)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003640
3641#if CONFIG_EXT_PARTITION
3642 BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128,
3643 aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL,
3644 NULL, aom_sad32x128x4d)
3645
3646 BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32,
3647 aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL,
3648 NULL, aom_sad128x32x4d)
3649#endif // CONFIG_EXT_PARTITION
3650#endif // CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003651
Yaowu Xuc27fc142016-08-22 16:08:15 -07003652#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003653 BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128,
3654 aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128,
3655 aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003656
Yaowu Xuf883b422016-08-30 14:01:10 -07003657 BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64,
3658 aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL,
3659 NULL, aom_sad128x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003660
Yaowu Xuf883b422016-08-30 14:01:10 -07003661 BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128,
3662 aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL,
3663 NULL, aom_sad64x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003664#endif // CONFIG_EXT_PARTITION
3665
Yaowu Xuf883b422016-08-30 14:01:10 -07003666 BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16,
3667 aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
3668 aom_sad32x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003669
Yaowu Xuf883b422016-08-30 14:01:10 -07003670 BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32,
3671 aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL,
3672 aom_sad16x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003673
Yaowu Xuf883b422016-08-30 14:01:10 -07003674 BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32,
3675 aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL,
3676 aom_sad64x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003677
Yaowu Xuf883b422016-08-30 14:01:10 -07003678 BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64,
3679 aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL,
3680 aom_sad32x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003681
Yaowu Xuf883b422016-08-30 14:01:10 -07003682 BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32,
3683 aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32,
3684 aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003685
Yaowu Xuf883b422016-08-30 14:01:10 -07003686 BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64,
3687 aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64,
3688 aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003689
Yaowu Xuf883b422016-08-30 14:01:10 -07003690 BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16,
3691 aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16,
3692 aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003693
Yaowu Xuf883b422016-08-30 14:01:10 -07003694 BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8,
3695 aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3,
3696 aom_sad16x8x8, aom_sad16x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003697
Yaowu Xuf883b422016-08-30 14:01:10 -07003698 BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16,
3699 aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3,
3700 aom_sad8x16x8, aom_sad8x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003701
Yaowu Xuf883b422016-08-30 14:01:10 -07003702 BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8,
3703 aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3,
3704 aom_sad8x8x8, aom_sad8x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003705
Yaowu Xuf883b422016-08-30 14:01:10 -07003706 BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4,
3707 aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL,
3708 aom_sad8x4x8, aom_sad8x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003709
Yaowu Xuf883b422016-08-30 14:01:10 -07003710 BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8,
3711 aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL,
3712 aom_sad4x8x8, aom_sad4x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003713
Yaowu Xuf883b422016-08-30 14:01:10 -07003714 BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4,
3715 aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
3716 aom_sad4x4x8, aom_sad4x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003717
Cheng Chenf78632e2017-10-20 15:30:51 -07003718#endif // CONFIG_JNT_COMP
Jingning Han9e7c49f2016-12-06 11:20:10 -08003719
Yaowu Xuc27fc142016-08-22 16:08:15 -07003720#define OBFP(BT, OSDF, OVF, OSVF) \
3721 cpi->fn_ptr[BT].osdf = OSDF; \
3722 cpi->fn_ptr[BT].ovf = OVF; \
3723 cpi->fn_ptr[BT].osvf = OSVF;
3724
3725#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003726 OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128,
3727 aom_obmc_sub_pixel_variance128x128)
3728 OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64,
3729 aom_obmc_sub_pixel_variance128x64)
3730 OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128,
3731 aom_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003732#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003733 OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64,
3734 aom_obmc_sub_pixel_variance64x64)
3735 OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32,
3736 aom_obmc_sub_pixel_variance64x32)
3737 OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64,
3738 aom_obmc_sub_pixel_variance32x64)
3739 OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32,
3740 aom_obmc_sub_pixel_variance32x32)
3741 OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16,
3742 aom_obmc_sub_pixel_variance32x16)
3743 OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32,
3744 aom_obmc_sub_pixel_variance16x32)
3745 OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16,
3746 aom_obmc_sub_pixel_variance16x16)
3747 OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8,
3748 aom_obmc_sub_pixel_variance16x8)
3749 OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16,
3750 aom_obmc_sub_pixel_variance8x16)
3751 OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8,
3752 aom_obmc_sub_pixel_variance8x8)
3753 OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8,
3754 aom_obmc_sub_pixel_variance4x8)
3755 OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4,
3756 aom_obmc_sub_pixel_variance8x4)
3757 OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4,
3758 aom_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003759
3760#if CONFIG_EXT_PARTITION_TYPES
3761 OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16,
3762 aom_obmc_sub_pixel_variance4x16)
3763
3764 OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4,
3765 aom_obmc_sub_pixel_variance16x4)
3766
3767 OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32,
3768 aom_obmc_sub_pixel_variance8x32)
3769
3770 OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8,
3771 aom_obmc_sub_pixel_variance32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003772
3773 OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64,
3774 aom_obmc_sub_pixel_variance16x64)
3775
3776 OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16,
3777 aom_obmc_sub_pixel_variance64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003778
3779#if CONFIG_EXT_PARTITION
3780 OBFP(BLOCK_32X128, aom_obmc_sad32x128, aom_obmc_variance32x128,
3781 aom_obmc_sub_pixel_variance32x128)
3782
3783 OBFP(BLOCK_128X32, aom_obmc_sad128x32, aom_obmc_variance128x32,
3784 aom_obmc_sub_pixel_variance128x32)
3785#endif // CONFIG_EXT_PARTITION
3786#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003787
David Barkerf19f35f2017-05-22 16:33:22 +01003788#define MBFP(BT, MCSDF, MCSVF) \
3789 cpi->fn_ptr[BT].msdf = MCSDF; \
3790 cpi->fn_ptr[BT].msvf = MCSVF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003791
3792#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01003793 MBFP(BLOCK_128X128, aom_masked_sad128x128,
3794 aom_masked_sub_pixel_variance128x128)
3795 MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64)
3796 MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003797#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01003798 MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64)
3799 MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32)
3800 MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64)
3801 MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32)
3802 MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16)
3803 MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32)
3804 MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16)
3805 MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8)
3806 MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16)
3807 MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8)
3808 MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8)
3809 MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4)
3810 MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003811
3812#if CONFIG_EXT_PARTITION_TYPES
3813 MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16)
3814
3815 MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4)
3816
3817 MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32)
3818
3819 MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003820
3821 MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64)
3822
3823 MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003824
3825#if CONFIG_EXT_PARTITION
3826 MBFP(BLOCK_32X128, aom_masked_sad32x128, aom_masked_sub_pixel_variance32x128)
3827
3828 MBFP(BLOCK_128X32, aom_masked_sad128x32, aom_masked_sub_pixel_variance128x32)
3829#endif // CONFIG_EXT_PARTITION
3830#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003831
Yaowu Xuc27fc142016-08-22 16:08:15 -07003832 highbd_set_var_fns(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003833
Yaowu Xuf883b422016-08-30 14:01:10 -07003834 /* av1_init_quantizer() is first called here. Add check in
3835 * av1_frame_init_quantizer() so that av1_init_quantizer is only
Yaowu Xuc27fc142016-08-22 16:08:15 -07003836 * called later when needed. This will avoid unnecessary calls of
Yaowu Xuf883b422016-08-30 14:01:10 -07003837 * av1_init_quantizer() for every frame.
Yaowu Xuc27fc142016-08-22 16:08:15 -07003838 */
Yaowu Xuf883b422016-08-30 14:01:10 -07003839 av1_init_quantizer(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003840#if CONFIG_AOM_QM
Zoe Liud902b742018-02-19 17:02:41 -08003841 av1_qm_init(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003842#endif
3843
Yaowu Xuf883b422016-08-30 14:01:10 -07003844 av1_loop_filter_init(cm);
Urvang Joshi94ad3702017-12-06 11:38:08 -08003845#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07003846 cm->superres_scale_denominator = SCALE_NUMERATOR;
Debargha Mukherjee29e40a62017-06-14 09:37:12 -07003847 cm->superres_upscaled_width = oxcf->width;
3848 cm->superres_upscaled_height = oxcf->height;
Urvang Joshi94ad3702017-12-06 11:38:08 -08003849#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003850#if CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -07003851 av1_loop_restoration_precal();
Yaowu Xuc27fc142016-08-22 16:08:15 -07003852#endif // CONFIG_LOOP_RESTORATION
3853
3854 cm->error.setjmp = 0;
3855
3856 return cpi;
3857}
3858
3859#define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T))
3860
3861#define SNPRINT2(H, T, V) \
3862 snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V))
3863
Yaowu Xuf883b422016-08-30 14:01:10 -07003864void av1_remove_compressor(AV1_COMP *cpi) {
3865 AV1_COMMON *cm;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003866 unsigned int i;
3867 int t;
3868
3869 if (!cpi) return;
3870
3871 cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003872 const int num_planes = av1_num_planes(cm);
3873
Yaowu Xuc27fc142016-08-22 16:08:15 -07003874 if (cm->current_video_frame > 0) {
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003875#if CONFIG_ENTROPY_STATS
3876 if (cpi->oxcf.pass != 1) {
3877 fprintf(stderr, "Writing counts.stt\n");
3878 FILE *f = fopen("counts.stt", "wb");
3879 fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f);
Zoe Liua56f9162017-06-21 22:49:57 -07003880 fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]),
3881 FRAME_CONTEXTS, f);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003882 fclose(f);
3883 }
3884#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003885#if CONFIG_INTERNAL_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -07003886 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07003887
3888 if (cpi->oxcf.pass != 1) {
3889 char headings[512] = { 0 };
3890 char results[512] = { 0 };
3891 FILE *f = fopen("opsnr.stt", "a");
3892 double time_encoded =
3893 (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) /
3894 10000000.000;
3895 double total_encode_time =
3896 (cpi->time_receive_data + cpi->time_compress_data) / 1000.000;
3897 const double dr =
3898 (double)cpi->bytes * (double)8 / (double)1000 / time_encoded;
3899 const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1);
3900 const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000;
3901 const double rate_err = ((100.0 * (dr - target_rate)) / target_rate);
3902
3903 if (cpi->b_calculate_psnr) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003904 const double total_psnr = aom_sse_to_psnr(
Yaowu Xuc27fc142016-08-22 16:08:15 -07003905 (double)cpi->total_samples, peak, (double)cpi->total_sq_error);
3906 const double total_ssim =
3907 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0);
3908 snprintf(headings, sizeof(headings),
Jingning Han87651b22017-11-28 20:02:26 -08003909 "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t"
Yaowu Xuf883b422016-08-30 14:01:10 -07003910 "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t"
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003911 "WstPsnr\tWstSsim\tWstFast\tWstHVS\t"
Jingning Han87651b22017-11-28 20:02:26 -08003912 "AVPsrnY\tAPsnrCb\tAPsnrCr");
Yaowu Xuc27fc142016-08-22 16:08:15 -07003913 snprintf(results, sizeof(results),
3914 "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
3915 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003916 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
Jingning Han87651b22017-11-28 20:02:26 -08003917 "%7.3f\t%7.3f\t%7.3f",
Yaowu Xuc27fc142016-08-22 16:08:15 -07003918 dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr,
Jingning Han87651b22017-11-28 20:02:26 -08003919 cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003920 total_ssim, cpi->fastssim.stat[ALL] / cpi->count,
3921 cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst,
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003922 cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst,
Jingning Han87651b22017-11-28 20:02:26 -08003923 cpi->psnr.stat[Y] / cpi->count, cpi->psnr.stat[U] / cpi->count,
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003924 cpi->psnr.stat[V] / cpi->count);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003925
3926 if (cpi->b_calculate_blockiness) {
3927 SNPRINT(headings, "\t Block\tWstBlck");
3928 SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count);
3929 SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness);
3930 }
3931
3932 if (cpi->b_calculate_consistency) {
3933 double consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07003934 aom_sse_to_psnr((double)cpi->total_samples, peak,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003935 (double)cpi->total_inconsistency);
3936
3937 SNPRINT(headings, "\tConsist\tWstCons");
3938 SNPRINT2(results, "\t%7.3f", consistency);
3939 SNPRINT2(results, "\t%7.3f", cpi->worst_consistency);
3940 }
Sarah Parkerf97b7862016-08-25 17:42:57 -07003941 fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings);
3942 fprintf(f, "%s\t%8.0f\t%7.2f\t%7.2f\n", results, total_encode_time,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003943 rate_err, fabs(rate_err));
3944 }
3945
3946 fclose(f);
3947 }
3948
3949#endif
3950
3951#if 0
3952 {
3953 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
3954 printf("\n_frames recive_data encod_mb_row compress_frame Total\n");
3955 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame,
3956 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000,
3957 cpi->time_compress_data / 1000,
3958 (cpi->time_receive_data + cpi->time_compress_data) / 1000);
3959 }
3960#endif
3961 }
3962
3963 for (t = 0; t < cpi->num_workers; ++t) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003964 AVxWorker *const worker = &cpi->workers[t];
Yaowu Xuc27fc142016-08-22 16:08:15 -07003965 EncWorkerData *const thread_data = &cpi->tile_thr_data[t];
3966
3967 // Deallocate allocated threads.
Yaowu Xuf883b422016-08-30 14:01:10 -07003968 aom_get_worker_interface()->end(worker);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003969
3970 // Deallocate allocated thread data.
3971 if (t < cpi->num_workers - 1) {
hui sud9a812b2017-07-06 14:34:37 -07003972 aom_free(thread_data->td->palette_buffer);
Yue Chen19d76012018-02-16 15:13:40 -08003973#if CONFIG_OBMC_HIGH_PREC_BLENDING
3974 aom_free(thread_data->td->above_pred_hp_buf);
3975 aom_free(thread_data->td->left_pred_hp_buf);
3976#else
Jingning Hand064cf02017-06-01 10:00:39 -07003977 aom_free(thread_data->td->above_pred_buf);
3978 aom_free(thread_data->td->left_pred_buf);
Yue Chen19d76012018-02-16 15:13:40 -08003979#endif
Jingning Hand064cf02017-06-01 10:00:39 -07003980 aom_free(thread_data->td->wsrc_buf);
3981 aom_free(thread_data->td->mask_buf);
Yaowu Xuf883b422016-08-30 14:01:10 -07003982 aom_free(thread_data->td->counts);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003983 av1_free_pc_tree(thread_data->td, num_planes);
Yaowu Xuf883b422016-08-30 14:01:10 -07003984 aom_free(thread_data->td);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003985 }
3986 }
Yaowu Xuf883b422016-08-30 14:01:10 -07003987 aom_free(cpi->tile_thr_data);
3988 aom_free(cpi->workers);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003989
Yaowu Xuf883b422016-08-30 14:01:10 -07003990 if (cpi->num_workers > 1) av1_loop_filter_dealloc(&cpi->lf_row_sync);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003991
3992 dealloc_compressor_data(cpi);
3993
3994 for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]);
3995 ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003996 aom_free(cpi->mbgraph_stats[i].mb_stats);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003997 }
3998
3999#if CONFIG_FP_MB_STATS
4000 if (cpi->use_fp_mb_stats) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004001 aom_free(cpi->twopass.frame_mb_stats_buf);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004002 cpi->twopass.frame_mb_stats_buf = NULL;
4003 }
4004#endif
Debargha Mukherjee5d157212017-01-10 14:44:47 -08004005#if CONFIG_INTERNAL_STATS
4006 aom_free(cpi->ssim_vars);
4007 cpi->ssim_vars = NULL;
4008#endif // CONFIG_INTERNAL_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07004009
Yaowu Xuf883b422016-08-30 14:01:10 -07004010 av1_remove_common(cm);
RogerZhou80d52342017-11-20 10:56:26 -08004011#if CONFIG_HASH_ME
4012 for (i = 0; i < FRAME_BUFFERS; ++i) {
4013 av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table);
4014 }
Michelle Findlay-Olynykdea531d2017-12-13 14:10:56 -08004015 if (cpi->sf.use_hash_based_trellis) hbt_destroy();
RogerZhou80d52342017-11-20 10:56:26 -08004016#endif // CONFIG_HASH_ME
Yaowu Xuf883b422016-08-30 14:01:10 -07004017 av1_free_ref_frame_buffers(cm->buffer_pool);
4018 aom_free(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004019
4020#ifdef OUTPUT_YUV_SKINMAP
4021 fclose(yuv_skinmap_file);
4022#endif
4023#ifdef OUTPUT_YUV_REC
4024 fclose(yuv_rec_file);
4025#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07004026#if 0
4027
4028 if (keyfile)
4029 fclose(keyfile);
4030
4031 if (framepsnr)
4032 fclose(framepsnr);
4033
4034 if (kf_list)
4035 fclose(kf_list);
4036
4037#endif
4038}
4039
Yaowu Xuf883b422016-08-30 14:01:10 -07004040static void generate_psnr_packet(AV1_COMP *cpi) {
4041 struct aom_codec_cx_pkt pkt;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004042 int i;
4043 PSNR_STATS psnr;
Alex Conversef77fd0b2017-04-20 11:00:24 -07004044 aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004045 cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004046
4047 for (i = 0; i < 4; ++i) {
4048 pkt.data.psnr.samples[i] = psnr.samples[i];
4049 pkt.data.psnr.sse[i] = psnr.sse[i];
4050 pkt.data.psnr.psnr[i] = psnr.psnr[i];
4051 }
Yaowu Xuf883b422016-08-30 14:01:10 -07004052 pkt.kind = AOM_CODEC_PSNR_PKT;
4053 aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004054}
4055
Yaowu Xuf883b422016-08-30 14:01:10 -07004056int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004057 if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1;
4058
Yunqing Wangf2e7a392017-11-08 00:27:21 -08004059 cpi->ext_ref_frame_flags = ref_frame_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004060 return 0;
4061}
4062
Yunqing Wang9a50fec2017-11-02 17:02:00 -07004063void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) {
4064 cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0;
4065 cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0;
4066 cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0;
4067 cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0;
4068 cpi->ext_refresh_alt2_ref_frame = (ref_frame_upd_flags & AOM_ALT2_FLAG) != 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004069 cpi->ext_refresh_frame_flags_pending = 1;
4070}
4071
Thomas Daede497d1952017-08-08 17:33:06 -07004072int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) {
4073 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004074 const int num_planes = av1_num_planes(cm);
Thomas Daede497d1952017-08-08 17:33:06 -07004075 YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004076 if (cfg) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004077 aom_yv12_copy_frame(cfg, sd, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004078 return 0;
4079 } else {
4080 return -1;
4081 }
4082}
4083
Thomas Daede497d1952017-08-08 17:33:06 -07004084int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) {
4085 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004086 const int num_planes = av1_num_planes(cm);
Thomas Daede497d1952017-08-08 17:33:06 -07004087 YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx);
Yaowu Xuf883b422016-08-30 14:01:10 -07004088 if (cfg) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004089 aom_yv12_copy_frame(sd, cfg, num_planes);
Yaowu Xuf883b422016-08-30 14:01:10 -07004090 return 0;
4091 } else {
4092 return -1;
4093 }
4094}
4095
4096int av1_update_entropy(AV1_COMP *cpi, int update) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004097 cpi->ext_refresh_frame_context = update;
4098 cpi->ext_refresh_frame_context_pending = 1;
4099 return 0;
4100}
4101
4102#if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP)
4103// The denoiser buffer is allocated as a YUV 440 buffer. This function writes it
4104// as YUV 420. We simply use the top-left pixels of the UV buffers, since we do
4105// not denoise the UV channels at this time. If ever we implement UV channel
4106// denoising we will have to modify this.
Yaowu Xuf883b422016-08-30 14:01:10 -07004107void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004108 uint8_t *src = s->y_buffer;
4109 int h = s->y_height;
4110
4111 do {
4112 fwrite(src, s->y_width, 1, f);
4113 src += s->y_stride;
4114 } while (--h);
4115
4116 src = s->u_buffer;
4117 h = s->uv_height;
4118
4119 do {
4120 fwrite(src, s->uv_width, 1, f);
4121 src += s->uv_stride;
4122 } while (--h);
4123
4124 src = s->v_buffer;
4125 h = s->uv_height;
4126
4127 do {
4128 fwrite(src, s->uv_width, 1, f);
4129 src += s->uv_stride;
4130 } while (--h);
4131}
4132#endif
4133
Zoe Liu8dd1c982017-09-11 10:14:35 -07004134#if USE_GF16_MULTI_LAYER
4135static void check_show_existing_frame_gf16(AV1_COMP *cpi) {
4136 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
4137 AV1_COMMON *const cm = &cpi->common;
4138 const FRAME_UPDATE_TYPE next_frame_update_type =
4139 gf_group->update_type[gf_group->index];
4140
4141 if (cm->show_existing_frame == 1) {
4142 cm->show_existing_frame = 0;
4143 } else if (cpi->rc.is_last_bipred_frame) {
4144 cpi->rc.is_last_bipred_frame = 0;
4145 cm->show_existing_frame = 1;
4146 cpi->existing_fb_idx_to_show = cpi->bwd_fb_idx;
4147 } else if (next_frame_update_type == OVERLAY_UPDATE ||
4148 next_frame_update_type == INTNL_OVERLAY_UPDATE) {
4149 // Check the temporal filtering status for the next OVERLAY frame
4150 const int num_arfs_in_gf = cpi->num_extra_arfs + 1;
4151 int which_arf = 0, arf_idx;
4152 // Identify the index to the next overlay frame.
4153 for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) {
4154 if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) {
4155 which_arf = arf_idx;
4156 break;
4157 }
4158 }
4159 assert(arf_idx < num_arfs_in_gf);
4160 if (cpi->is_arf_filter_off[which_arf]) {
4161 cm->show_existing_frame = 1;
4162 cpi->rc.is_src_frame_alt_ref = 1;
4163 cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE)
4164 ? cpi->alt_fb_idx
4165 : cpi->bwd_fb_idx;
4166 cpi->is_arf_filter_off[which_arf] = 0;
4167 }
4168 }
4169 cpi->rc.is_src_frame_ext_arf = 0;
4170}
4171#endif // USE_GF16_MULTI_LAYER
4172
Yaowu Xuf883b422016-08-30 14:01:10 -07004173static void check_show_existing_frame(AV1_COMP *cpi) {
Zoe Liu8dd1c982017-09-11 10:14:35 -07004174#if USE_GF16_MULTI_LAYER
4175 if (cpi->rc.baseline_gf_interval == 16) {
4176 check_show_existing_frame_gf16(cpi);
4177 return;
4178 }
4179#endif // USE_GF16_MULTI_LAYER
4180
Yaowu Xuc27fc142016-08-22 16:08:15 -07004181 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
Yaowu Xuf883b422016-08-30 14:01:10 -07004182 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004183 const FRAME_UPDATE_TYPE next_frame_update_type =
4184 gf_group->update_type[gf_group->index];
4185 const int which_arf = gf_group->arf_update_idx[gf_group->index];
Zoe Liu5fca7242016-10-10 17:18:57 -07004186
4187 if (cm->show_existing_frame == 1) {
4188 cm->show_existing_frame = 0;
4189 } else if (cpi->rc.is_last_bipred_frame) {
Zoe Liu8dd1c982017-09-11 10:14:35 -07004190 // NOTE: If the current frame is a last bi-predictive frame, it is
4191 // needed next to show the BWDREF_FRAME, which is pointed by
4192 // the last_fb_idxes[0] after reference frame buffer update
Yaowu Xuc27fc142016-08-22 16:08:15 -07004193 cpi->rc.is_last_bipred_frame = 0;
4194 cm->show_existing_frame = 1;
4195 cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0];
4196 } else if (cpi->is_arf_filter_off[which_arf] &&
4197 (next_frame_update_type == OVERLAY_UPDATE ||
4198 next_frame_update_type == INTNL_OVERLAY_UPDATE)) {
4199 // Other parameters related to OVERLAY_UPDATE will be taken care of
Yaowu Xuf883b422016-08-30 14:01:10 -07004200 // in av1_rc_get_second_pass_params(cpi)
Yaowu Xuc27fc142016-08-22 16:08:15 -07004201 cm->show_existing_frame = 1;
4202 cpi->rc.is_src_frame_alt_ref = 1;
Zoe Liue9b15e22017-07-19 15:53:01 -07004203 cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE)
4204 ? cpi->alt_fb_idx
4205 : cpi->alt2_fb_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004206 cpi->is_arf_filter_off[which_arf] = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004207 }
4208 cpi->rc.is_src_frame_ext_arf = 0;
4209}
Yaowu Xuc27fc142016-08-22 16:08:15 -07004210
4211#ifdef OUTPUT_YUV_REC
Yaowu Xuf883b422016-08-30 14:01:10 -07004212void aom_write_one_yuv_frame(AV1_COMMON *cm, YV12_BUFFER_CONFIG *s) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004213 uint8_t *src = s->y_buffer;
4214 int h = cm->height;
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -07004215 if (yuv_rec_file == NULL) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004216 if (s->flags & YV12_FLAG_HIGHBITDEPTH) {
4217 uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer);
4218
4219 do {
4220 fwrite(src16, s->y_width, 2, yuv_rec_file);
4221 src16 += s->y_stride;
4222 } while (--h);
4223
4224 src16 = CONVERT_TO_SHORTPTR(s->u_buffer);
4225 h = s->uv_height;
4226
4227 do {
4228 fwrite(src16, s->uv_width, 2, yuv_rec_file);
4229 src16 += s->uv_stride;
4230 } while (--h);
4231
4232 src16 = CONVERT_TO_SHORTPTR(s->v_buffer);
4233 h = s->uv_height;
4234
4235 do {
4236 fwrite(src16, s->uv_width, 2, yuv_rec_file);
4237 src16 += s->uv_stride;
4238 } while (--h);
4239
4240 fflush(yuv_rec_file);
4241 return;
4242 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004243
4244 do {
4245 fwrite(src, s->y_width, 1, yuv_rec_file);
4246 src += s->y_stride;
4247 } while (--h);
4248
4249 src = s->u_buffer;
4250 h = s->uv_height;
4251
4252 do {
4253 fwrite(src, s->uv_width, 1, yuv_rec_file);
4254 src += s->uv_stride;
4255 } while (--h);
4256
4257 src = s->v_buffer;
4258 h = s->uv_height;
4259
4260 do {
4261 fwrite(src, s->uv_width, 1, yuv_rec_file);
4262 src += s->uv_stride;
4263 } while (--h);
4264
4265 fflush(yuv_rec_file);
4266}
4267#endif // OUTPUT_YUV_REC
4268
Debargha Mukherjee11f0e402017-03-29 07:42:40 -07004269#define GM_RECODE_LOOP_NUM4X4_FACTOR 192
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004270static int recode_loop_test_global_motion(AV1_COMP *cpi) {
4271 int i;
4272 int recode = 0;
Debargha Mukherjeea575d232017-04-28 17:46:47 -07004273 RD_COUNTS *const rdc = &cpi->td.rd_counts;
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004274 AV1_COMMON *const cm = &cpi->common;
4275 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
4276 if (cm->global_motion[i].wmtype != IDENTITY &&
Debargha Mukherjeea575d232017-04-28 17:46:47 -07004277 rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR <
Debargha Mukherjee265db6d2017-03-28 11:15:27 -07004278 cpi->gmparams_cost[i]) {
David Barkerd7c8bd52017-09-25 14:47:29 +01004279 cm->global_motion[i] = default_warp_params;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004280 assert(cm->global_motion[i].wmtype == IDENTITY);
Debargha Mukherjee265db6d2017-03-28 11:15:27 -07004281 cpi->gmparams_cost[i] = 0;
David Barker43479c62016-11-30 10:34:20 +00004282 recode = 1;
Urvang Joshi02aade82017-12-18 17:18:16 -08004283 // TODO(sarahparker): The earlier condition for recoding here was:
4284 // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something
4285 // similar to that back to speed up global motion?
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004286 }
4287 }
4288 return recode;
4289}
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004290
Yaowu Xuc27fc142016-08-22 16:08:15 -07004291// Function to test for conditions that indicate we should loop
4292// back and recode a frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07004293static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q,
4294 int maxq, int minq) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004295 const RATE_CONTROL *const rc = &cpi->rc;
Yaowu Xuf883b422016-08-30 14:01:10 -07004296 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004297 const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi);
4298 int force_recode = 0;
4299
4300 if ((rc->projected_frame_size >= rc->max_frame_bandwidth) ||
4301 (cpi->sf.recode_loop == ALLOW_RECODE) ||
4302 (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004303 // TODO(agrange) high_limit could be greater than the scale-down threshold.
4304 if ((rc->projected_frame_size > high_limit && q < maxq) ||
4305 (rc->projected_frame_size < low_limit && q > minq)) {
4306 force_recode = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -07004307 } else if (cpi->oxcf.rc_mode == AOM_CQ) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004308 // Deal with frame undershoot and whether or not we are
4309 // below the automatically set cq level.
4310 if (q > oxcf->cq_level &&
4311 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) {
4312 force_recode = 1;
4313 }
4314 }
4315 }
4316 return force_recode;
4317}
4318
Yaowu Xuc27fc142016-08-22 16:08:15 -07004319#define DUMP_REF_FRAME_IMAGES 0
4320
4321#if DUMP_REF_FRAME_IMAGES == 1
Yaowu Xuf883b422016-08-30 14:01:10 -07004322static int dump_one_image(AV1_COMMON *cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004323 const YV12_BUFFER_CONFIG *const ref_buf,
4324 char *file_name) {
4325 int h;
4326 FILE *f_ref = NULL;
4327
4328 if (ref_buf == NULL) {
4329 printf("Frame data buffer is NULL.\n");
Yaowu Xuf883b422016-08-30 14:01:10 -07004330 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004331 }
4332
4333 if ((f_ref = fopen(file_name, "wb")) == NULL) {
4334 printf("Unable to open file %s to write.\n", file_name);
Yaowu Xuf883b422016-08-30 14:01:10 -07004335 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004336 }
4337
4338 // --- Y ---
4339 for (h = 0; h < cm->height; ++h) {
4340 fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref);
4341 }
4342 // --- U ---
4343 for (h = 0; h < (cm->height >> 1); ++h) {
4344 fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1),
4345 f_ref);
4346 }
4347 // --- V ---
4348 for (h = 0; h < (cm->height >> 1); ++h) {
4349 fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1),
4350 f_ref);
4351 }
4352
4353 fclose(f_ref);
4354
Yaowu Xuf883b422016-08-30 14:01:10 -07004355 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004356}
4357
Yaowu Xuf883b422016-08-30 14:01:10 -07004358static void dump_ref_frame_images(AV1_COMP *cpi) {
4359 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004360 MV_REFERENCE_FRAME ref_frame;
4361
4362 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
4363 char file_name[256] = "";
4364 snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv",
4365 cm->current_video_frame, ref_frame);
4366 dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name);
4367 }
4368}
4369#endif // DUMP_REF_FRAME_IMAGES == 1
4370
Yaowu Xuc27fc142016-08-22 16:08:15 -07004371// This function is used to shift the virtual indices of last reference frames
4372// as follows:
4373// LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME
4374// when the LAST_FRAME is updated.
Yaowu Xuf883b422016-08-30 14:01:10 -07004375static INLINE void shift_last_ref_frames(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004376 int ref_frame;
4377 for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) {
4378 cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1];
4379
4380 // [0] is allocated to the current coded frame. The statistics for the
Zoe Liuf0e46692016-10-12 12:31:43 -07004381 // reference frames start at [LAST_FRAME], i.e. [1].
Yaowu Xuc27fc142016-08-22 16:08:15 -07004382 if (!cpi->rc.is_src_frame_alt_ref) {
Zoe Liuf0e46692016-10-12 12:31:43 -07004383 memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME],
4384 cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME],
4385 sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004386 }
4387 }
4388}
Yaowu Xuc27fc142016-08-22 16:08:15 -07004389
Zoe Liu8dd1c982017-09-11 10:14:35 -07004390#if USE_GF16_MULTI_LAYER
4391static void update_reference_frames_gf16(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004392 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004393 BufferPool *const pool = cm->buffer_pool;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004394
Zoe Liu8dd1c982017-09-11 10:14:35 -07004395 if (cm->frame_type == KEY_FRAME) {
4396 for (int ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) {
4397 ref_cnt_fb(pool->frame_bufs,
4398 &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]],
4399 cm->new_fb_idx);
4400 }
4401 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4402 cm->new_fb_idx);
4403 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4404 cm->new_fb_idx);
4405 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4406 cm->new_fb_idx);
4407 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4408 cm->new_fb_idx);
4409 } else {
4410 if (cpi->refresh_last_frame || cpi->refresh_golden_frame ||
4411 cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame ||
4412 cpi->refresh_alt_ref_frame) {
4413 assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES);
4414 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx],
4415 cm->new_fb_idx);
4416 }
4417
4418 // TODO(zoeliu): To handle cpi->interp_filter_selected[].
4419
4420 // For GF of 16, an additional ref frame index mapping needs to be handled
4421 // if this is the last frame to encode in the current GF group.
4422 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
4423 if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE)
4424 av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1);
4425 }
4426
4427#if DUMP_REF_FRAME_IMAGES == 1
4428 // Dump out all reference frame images.
4429 dump_ref_frame_images(cpi);
4430#endif // DUMP_REF_FRAME_IMAGES
4431}
4432#endif // USE_GF16_MULTI_LAYER
Zoe Liu8dd1c982017-09-11 10:14:35 -07004433
4434static void update_reference_frames(AV1_COMP *cpi) {
4435 AV1_COMMON *const cm = &cpi->common;
4436
Yaowu Xuc27fc142016-08-22 16:08:15 -07004437 // NOTE: Save the new show frame buffer index for --test-code=warn, i.e.,
4438 // for the purpose to verify no mismatch between encoder and decoder.
4439 if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx;
4440
Zoe Liu8dd1c982017-09-11 10:14:35 -07004441#if USE_GF16_MULTI_LAYER
4442 if (cpi->rc.baseline_gf_interval == 16) {
4443 update_reference_frames_gf16(cpi);
4444 return;
4445 }
4446#endif // USE_GF16_MULTI_LAYER
Zoe Liu8dd1c982017-09-11 10:14:35 -07004447
4448 BufferPool *const pool = cm->buffer_pool;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004449 // At this point the new frame has been encoded.
4450 // If any buffer copy / swapping is signaled it should be done here.
4451 if (cm->frame_type == KEY_FRAME) {
4452 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4453 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004454 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4455 cm->new_fb_idx);
Zoe Liue9b15e22017-07-19 15:53:01 -07004456 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4457 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004458 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4459 cm->new_fb_idx);
Yaowu Xuf883b422016-08-30 14:01:10 -07004460 } else if (av1_preserve_existing_gf(cpi)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004461 // We have decided to preserve the previously existing golden frame as our
4462 // new ARF frame. However, in the short term in function
Yaowu Xuf883b422016-08-30 14:01:10 -07004463 // av1_bitstream.c::get_refresh_mask() we left it in the GF slot and, if
Yaowu Xuc27fc142016-08-22 16:08:15 -07004464 // we're updating the GF with the current decoded frame, we save it to the
4465 // ARF slot instead.
4466 // We now have to update the ARF with the current frame and swap gld_fb_idx
4467 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF
4468 // slot and, if we're updating the GF, the current frame becomes the new GF.
4469 int tmp;
4470
4471 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4472 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004473 tmp = cpi->alt_fb_idx;
4474 cpi->alt_fb_idx = cpi->gld_fb_idx;
4475 cpi->gld_fb_idx = tmp;
4476
Yaowu Xuc27fc142016-08-22 16:08:15 -07004477 // We need to modify the mapping accordingly
4478 cpi->arf_map[0] = cpi->alt_fb_idx;
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004479 // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to
4480 // cpi->interp_filter_selected[GOLDEN_FRAME]?
Yaowu Xuc27fc142016-08-22 16:08:15 -07004481 } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) {
4482 // Deal with the special case for showing existing internal ALTREF_FRAME
4483 // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME
4484 // by updating the virtual indices.
4485 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
Zoe Liue9b15e22017-07-19 15:53:01 -07004486 const int which_arf = gf_group->arf_ref_idx[gf_group->index];
4487 assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004488
Zoe Liue9b15e22017-07-19 15:53:01 -07004489 const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -07004490 shift_last_ref_frames(cpi);
Zoe Liue9b15e22017-07-19 15:53:01 -07004491
Zoe Liue9b15e22017-07-19 15:53:01 -07004492 cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx;
4493 cpi->alt2_fb_idx = tmp;
4494 // We need to modify the mapping accordingly
4495 cpi->arf_map[which_arf] = cpi->alt2_fb_idx;
4496
4497 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4498 cpi->interp_filter_selected[ALTREF2_FRAME],
4499 sizeof(cpi->interp_filter_selected[ALTREF2_FRAME]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004500 } else { /* For non key/golden frames */
Zoe Liue9b15e22017-07-19 15:53:01 -07004501 // === ALTREF_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004502 if (cpi->refresh_alt_ref_frame) {
4503 int arf_idx = cpi->alt_fb_idx;
4504 int which_arf = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004505 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[arf_idx], cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004506
4507 memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf],
4508 cpi->interp_filter_selected[0],
4509 sizeof(cpi->interp_filter_selected[0]));
4510 }
4511
Zoe Liue9b15e22017-07-19 15:53:01 -07004512 // === GOLDEN_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004513 if (cpi->refresh_golden_frame) {
4514 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4515 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004516
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004517 memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
4518 cpi->interp_filter_selected[0],
4519 sizeof(cpi->interp_filter_selected[0]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004520 }
4521
Zoe Liue9b15e22017-07-19 15:53:01 -07004522 // === BWDREF_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004523 if (cpi->refresh_bwd_ref_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004524 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4525 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004526
4527 memcpy(cpi->interp_filter_selected[BWDREF_FRAME],
4528 cpi->interp_filter_selected[0],
4529 sizeof(cpi->interp_filter_selected[0]));
4530 }
Zoe Liue9b15e22017-07-19 15:53:01 -07004531
Zoe Liue9b15e22017-07-19 15:53:01 -07004532 // === ALTREF2_FRAME ===
4533 if (cpi->refresh_alt2_ref_frame) {
4534 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4535 cm->new_fb_idx);
4536
4537 memcpy(cpi->interp_filter_selected[ALTREF2_FRAME],
4538 cpi->interp_filter_selected[0],
4539 sizeof(cpi->interp_filter_selected[0]));
4540 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004541 }
4542
4543 if (cpi->refresh_last_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004544 // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame
4545 // reference to the reference frame buffer virtual index; and then (2) from
4546 // the virtual index to the reference frame buffer physical index:
4547 //
4548 // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME
4549 // | | |
4550 // v v v
4551 // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx
4552 // | | |
4553 // v v v
4554 // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[]
4555 //
4556 // When refresh_last_frame is set, it is intended to retire LAST3_FRAME,
4557 // have the other 2 LAST reference frames shifted as follows:
4558 // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME
4559 // , and then have LAST_FRAME refreshed by the newly coded frame.
4560 //
4561 // To fulfill it, the decoder will be notified to execute following 2 steps:
4562 //
4563 // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME
4564 // to point to the newly coded frame, i.e.
4565 // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx;
4566 //
4567 // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the
4568 // original virtual index of LAST3_FRAME and have the other mappings
4569 // shifted as follows:
4570 // LAST_FRAME, LAST2_FRAME, LAST3_FRAME
4571 // | | |
4572 // v v v
4573 // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1]
4574 int ref_frame;
Zoe Liu5fca7242016-10-10 17:18:57 -07004575
Yaowu Xuc27fc142016-08-22 16:08:15 -07004576 if (cm->frame_type == KEY_FRAME) {
4577 for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) {
4578 ref_cnt_fb(pool->frame_bufs,
4579 &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]],
4580 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004581 }
4582 } else {
4583 int tmp;
4584
4585 ref_cnt_fb(pool->frame_bufs,
4586 &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]],
4587 cm->new_fb_idx);
4588
Yaowu Xuc27fc142016-08-22 16:08:15 -07004589 tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
4590
4591 shift_last_ref_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004592 cpi->lst_fb_idxes[0] = tmp;
4593
Zoe Liuf0e46692016-10-12 12:31:43 -07004594 assert(cm->show_existing_frame == 0);
Zoe Liuf0e46692016-10-12 12:31:43 -07004595 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4596 cpi->interp_filter_selected[0],
4597 sizeof(cpi->interp_filter_selected[0]));
Zoe Liuaff92d52017-07-11 21:35:08 -07004598
4599 if (cpi->rc.is_last_bipred_frame) {
4600 // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the
4601 // LAST3_FRAME by updating the virtual indices.
4602 //
4603 // NOTE: The source frame for BWDREF does not have a holding position as
4604 // the OVERLAY frame for ALTREF's. Hence, to resolve the reference
4605 // virtual index reshuffling for BWDREF, the encoder always
4606 // specifies a LAST_BIPRED right before BWDREF and completes the
4607 // reshuffling job accordingly.
4608 tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
4609
4610 shift_last_ref_frames(cpi);
4611 cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx;
4612 cpi->bwd_fb_idx = tmp;
4613
4614 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4615 cpi->interp_filter_selected[BWDREF_FRAME],
4616 sizeof(cpi->interp_filter_selected[BWDREF_FRAME]));
4617 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004618 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004619 }
4620
4621#if DUMP_REF_FRAME_IMAGES == 1
4622 // Dump out all reference frame images.
4623 dump_ref_frame_images(cpi);
4624#endif // DUMP_REF_FRAME_IMAGES
4625}
4626
Yaowu Xuf883b422016-08-30 14:01:10 -07004627static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) {
Debargha Mukherjee887069f2017-06-16 18:54:36 -07004628 assert(buffer_idx != INVALID_IDX);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004629 RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
Rupert Swarbrick1f990a62017-07-11 11:09:33 +01004630 ensure_mv_buffer(new_fb_ptr, cm);
4631 new_fb_ptr->width = cm->width;
4632 new_fb_ptr->height = cm->height;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004633}
4634
Cheng Chen46f30c72017-09-07 11:13:33 -07004635static void scale_references(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004636 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004637 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004638 MV_REFERENCE_FRAME ref_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -07004639 const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = {
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004640 AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG,
4641 AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG
Yaowu Xuc27fc142016-08-22 16:08:15 -07004642 };
4643
4644 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004645 // Need to convert from AOM_REFFRAME to index into ref_mask (subtract 1).
Yaowu Xuc27fc142016-08-22 16:08:15 -07004646 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) {
4647 BufferPool *const pool = cm->buffer_pool;
4648 const YV12_BUFFER_CONFIG *const ref =
4649 get_ref_frame_buffer(cpi, ref_frame);
4650
4651 if (ref == NULL) {
4652 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
4653 continue;
4654 }
4655
Yaowu Xuc27fc142016-08-22 16:08:15 -07004656 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
4657 RefCntBuffer *new_fb_ptr = NULL;
4658 int force_scaling = 0;
4659 int new_fb = cpi->scaled_ref_idx[ref_frame - 1];
4660 if (new_fb == INVALID_IDX) {
4661 new_fb = get_free_fb(cm);
4662 force_scaling = 1;
4663 }
4664 if (new_fb == INVALID_IDX) return;
4665 new_fb_ptr = &pool->frame_bufs[new_fb];
4666 if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width ||
4667 new_fb_ptr->buf.y_crop_height != cm->height) {
Yaowu Xu671f2bd2016-09-30 15:07:57 -07004668 if (aom_realloc_frame_buffer(
4669 &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x,
4670 cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
4671 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -07004672 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004673 "Failed to allocate frame buffer");
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004674 av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth,
4675 num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004676 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
4677 alloc_frame_mvs(cm, new_fb);
4678 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004679 } else {
4680 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
4681 RefCntBuffer *const buf = &pool->frame_bufs[buf_idx];
4682 buf->buf.y_crop_width = ref->y_crop_width;
4683 buf->buf.y_crop_height = ref->y_crop_height;
4684 cpi->scaled_ref_idx[ref_frame - 1] = buf_idx;
4685 ++buf->ref_count;
4686 }
4687 } else {
4688 if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
4689 }
4690 }
4691}
4692
Yaowu Xuf883b422016-08-30 14:01:10 -07004693static void release_scaled_references(AV1_COMP *cpi) {
4694 AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004695 int i;
4696 if (cpi->oxcf.pass == 0) {
4697 // Only release scaled references under certain conditions:
4698 // if reference will be updated, or if scaled reference has same resolution.
4699 int refresh[INTER_REFS_PER_FRAME];
4700 refresh[0] = (cpi->refresh_last_frame) ? 1 : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004701 refresh[1] = refresh[2] = 0;
4702 refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0;
4703 refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07004704 refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0;
4705 refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004706 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
4707 const int idx = cpi->scaled_ref_idx[i - 1];
4708 RefCntBuffer *const buf =
4709 idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL;
4710 const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i);
4711 if (buf != NULL &&
4712 (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width &&
4713 buf->buf.y_crop_height == ref->y_crop_height))) {
4714 --buf->ref_count;
4715 cpi->scaled_ref_idx[i - 1] = INVALID_IDX;
4716 }
4717 }
4718 } else {
4719 for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) {
4720 const int idx = cpi->scaled_ref_idx[i];
4721 RefCntBuffer *const buf =
4722 idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL;
4723 if (buf != NULL) {
4724 --buf->ref_count;
4725 cpi->scaled_ref_idx[i] = INVALID_IDX;
4726 }
4727 }
4728 }
4729}
4730
Yaowu Xuf883b422016-08-30 14:01:10 -07004731static void set_mv_search_params(AV1_COMP *cpi) {
4732 const AV1_COMMON *const cm = &cpi->common;
4733 const unsigned int max_mv_def = AOMMIN(cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004734
4735 // Default based on max resolution.
Yaowu Xuf883b422016-08-30 14:01:10 -07004736 cpi->mv_step_param = av1_init_search_range(max_mv_def);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004737
4738 if (cpi->sf.mv.auto_mv_step_size) {
4739 if (frame_is_intra_only(cm)) {
4740 // Initialize max_mv_magnitude for use in the first INTER frame
4741 // after a key/intra-only frame.
4742 cpi->max_mv_magnitude = max_mv_def;
4743 } else {
4744 if (cm->show_frame) {
4745 // Allow mv_steps to correspond to twice the max mv magnitude found
4746 // in the previous frame, capped by the default max_mv_magnitude based
4747 // on resolution.
Yaowu Xuf883b422016-08-30 14:01:10 -07004748 cpi->mv_step_param = av1_init_search_range(
4749 AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004750 }
4751 cpi->max_mv_magnitude = 0;
4752 }
4753 }
4754}
4755
Yaowu Xuf883b422016-08-30 14:01:10 -07004756static void set_size_independent_vars(AV1_COMP *cpi) {
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004757 int i;
4758 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
David Barkerd7c8bd52017-09-25 14:47:29 +01004759 cpi->common.global_motion[i] = default_warp_params;
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004760 }
4761 cpi->global_motion_search_done = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -07004762 av1_set_speed_features_framesize_independent(cpi);
4763 av1_set_rd_speed_thresholds(cpi);
4764 av1_set_rd_speed_thresholds_sub8x8(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004765 cpi->common.interp_filter = cpi->sf.default_interp_filter;
Yue Chen5380cb52018-02-23 15:33:21 -08004766 cpi->common.switchable_motion_mode = 1;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07004767 if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004768}
4769
Yaowu Xuf883b422016-08-30 14:01:10 -07004770static void set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004771 int *top_index) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004772 AV1_COMMON *const cm = &cpi->common;
4773 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004774
4775 // Setup variables that depend on the dimensions of the frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07004776 av1_set_speed_features_framesize_dependent(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004777
Sebastien Alaiwan41cae6a2018-01-12 12:22:29 +01004778 // Decide q and q bounds.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004779 *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index,
4780 top_index);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004781
James Zern01a9d702017-08-25 19:09:33 +00004782 if (!frame_is_intra_only(cm)) {
RogerZhou3b635242017-09-19 10:06:46 -07004783#if CONFIG_AMVR
4784 set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH,
RogerZhou10a03802017-10-26 11:49:48 -07004785 cpi->common.cur_frame_force_integer_mv);
RogerZhou3b635242017-09-19 10:06:46 -07004786#else
Cheng Chen46f30c72017-09-07 11:13:33 -07004787 set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH);
RogerZhou3b635242017-09-19 10:06:46 -07004788#endif
James Zern01a9d702017-08-25 19:09:33 +00004789 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004790
4791 // Configure experimental use of segmentation for enhanced coding of
4792 // static regions if indicated.
4793 // Only allowed in the second pass of a two pass encode, as it requires
4794 // lagged coding, and if the relevant speed feature flag is set.
4795 if (oxcf->pass == 2 && cpi->sf.static_segmentation)
4796 configure_static_seg_features(cpi);
4797}
4798
Yaowu Xuf883b422016-08-30 14:01:10 -07004799static void init_motion_estimation(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004800 int y_stride = cpi->scaled_source.y_stride;
4801
4802 if (cpi->sf.mv.search_method == NSTEP) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004803 av1_init3smotion_compensation(&cpi->ss_cfg, y_stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004804 } else if (cpi->sf.mv.search_method == DIAMOND) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004805 av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004806 }
4807}
4808
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004809#if CONFIG_LOOP_RESTORATION
Debargha Mukherjee84f567c2017-06-21 10:53:59 -07004810#define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004811static void set_restoration_unit_size(int width, int height, int sx, int sy,
4812 RestorationInfo *rst) {
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004813 (void)width;
4814 (void)height;
Debargha Mukherjee84f567c2017-06-21 10:53:59 -07004815 (void)sx;
4816 (void)sy;
4817#if COUPLED_CHROMA_FROM_LUMA_RESTORATION
4818 int s = AOMMIN(sx, sy);
4819#else
4820 int s = 0;
4821#endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION
4822
Debargha Mukherjee5f7f3672017-08-12 10:22:49 -07004823 if (width * height > 352 * 288)
4824 rst[0].restoration_unit_size = RESTORATION_TILESIZE_MAX;
4825 else
4826 rst[0].restoration_unit_size = (RESTORATION_TILESIZE_MAX >> 1);
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004827 rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s;
4828 rst[2].restoration_unit_size = rst[1].restoration_unit_size;
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004829}
4830#endif // CONFIG_LOOP_RESTORATION
4831
Cheng Chen46f30c72017-09-07 11:13:33 -07004832static void init_ref_frame_bufs(AV1_COMMON *cm) {
4833 int i;
4834 BufferPool *const pool = cm->buffer_pool;
4835 cm->new_fb_idx = INVALID_IDX;
4836 for (i = 0; i < REF_FRAMES; ++i) {
4837 cm->ref_frame_map[i] = INVALID_IDX;
4838 pool->frame_bufs[i].ref_count = 0;
4839 }
4840#if CONFIG_HASH_ME
Hui Su2d5fd742018-02-21 18:10:37 -08004841 if (av1_use_hash_me(cm)) {
4842 for (i = 0; i < FRAME_BUFFERS; ++i) {
4843 av1_hash_table_init(&pool->frame_bufs[i].hash_table);
4844 }
Cheng Chen46f30c72017-09-07 11:13:33 -07004845 }
4846#endif
4847}
4848
Yaowu Xud3e7c682017-12-21 14:08:25 -08004849static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth,
Cheng Chen46f30c72017-09-07 11:13:33 -07004850 int subsampling_x, int subsampling_y) {
4851 AV1_COMMON *const cm = &cpi->common;
4852
Yaowu Xud3e7c682017-12-21 14:08:25 -08004853 if (!cpi->initial_width || cm->use_highbitdepth != use_highbitdepth ||
Cheng Chen46f30c72017-09-07 11:13:33 -07004854 cm->subsampling_x != subsampling_x ||
4855 cm->subsampling_y != subsampling_y) {
4856 cm->subsampling_x = subsampling_x;
4857 cm->subsampling_y = subsampling_y;
Cheng Chen46f30c72017-09-07 11:13:33 -07004858 cm->use_highbitdepth = use_highbitdepth;
Cheng Chen46f30c72017-09-07 11:13:33 -07004859
4860 alloc_raw_frame_buffers(cpi);
4861 init_ref_frame_bufs(cm);
4862 alloc_util_frame_buffers(cpi);
4863
4864 init_motion_estimation(cpi); // TODO(agrange) This can be removed.
4865
4866 cpi->initial_width = cm->width;
4867 cpi->initial_height = cm->height;
4868 cpi->initial_mbs = cm->MBs;
4869 }
4870}
4871
4872// Returns 1 if the assigned width or height was <= 0.
4873static int set_size_literal(AV1_COMP *cpi, int width, int height) {
4874 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004875 const int num_planes = av1_num_planes(cm);
Cheng Chen46f30c72017-09-07 11:13:33 -07004876 check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x,
4877 cm->subsampling_y);
Cheng Chen46f30c72017-09-07 11:13:33 -07004878
4879 if (width <= 0 || height <= 0) return 1;
4880
4881 cm->width = width;
Cheng Chen46f30c72017-09-07 11:13:33 -07004882 cm->height = height;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004883
4884 if (cpi->initial_width && cpi->initial_height &&
4885 (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) {
4886 av1_free_context_buffers(cm);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004887 av1_free_pc_tree(&cpi->td, num_planes);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004888 alloc_compressor_data(cpi);
4889 realloc_segmentation_maps(cpi);
4890 cpi->initial_width = cpi->initial_height = 0;
Cheng Chen46f30c72017-09-07 11:13:33 -07004891 }
Cheng Chen46f30c72017-09-07 11:13:33 -07004892 update_frame_size(cpi);
4893
4894 return 0;
4895}
4896
Fergus Simpsonbc189932017-05-16 17:02:39 -07004897static void set_frame_size(AV1_COMP *cpi, int width, int height) {
Fergus Simpsonbc189932017-05-16 17:02:39 -07004898 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004899 const int num_planes = av1_num_planes(cm);
Fergus Simpsonbc189932017-05-16 17:02:39 -07004900 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004901 int ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004902
Fergus Simpsonbc189932017-05-16 17:02:39 -07004903 if (width != cm->width || height != cm->height) {
Fergus Simpson3502d082017-04-10 12:25:07 -07004904 // There has been a change in the encoded frame size
Cheng Chen46f30c72017-09-07 11:13:33 -07004905 set_size_literal(cpi, width, height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004906 set_mv_search_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004907 }
4908
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004909 if (cpi->oxcf.pass == 2) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004910 av1_set_target_rate(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004911 }
4912
4913 alloc_frame_mvs(cm, cm->new_fb_idx);
4914
4915 // Reset the frame pointers to the current frame size.
Yaowu Xuf883b422016-08-30 14:01:10 -07004916 if (aom_realloc_frame_buffer(get_frame_new_buffer(cm), cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004917 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -08004918 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
4919 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -07004920 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004921 "Failed to allocate frame buffer");
4922
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004923#if CONFIG_LOOP_RESTORATION
Urvang Joshi94ad3702017-12-06 11:38:08 -08004924#if CONFIG_HORZONLY_FRAME_SUPERRES
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004925 const int frame_width = cm->superres_upscaled_width;
4926 const int frame_height = cm->superres_upscaled_height;
Fergus Simpson9cd57cf2017-06-12 17:02:03 -07004927#else
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004928 const int frame_width = cm->width;
4929 const int frame_height = cm->height;
Urvang Joshi94ad3702017-12-06 11:38:08 -08004930#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004931 set_restoration_unit_size(frame_width, frame_height, cm->subsampling_x,
4932 cm->subsampling_y, cm->rst_info);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004933 for (int i = 0; i < num_planes; ++i)
Rupert Swarbrick1a96c3f2017-10-24 11:55:00 +01004934 cm->rst_info[i].frame_restoration_type = RESTORE_NONE;
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004935
4936 av1_alloc_restoration_buffers(cm);
Fergus Simpson9cd57cf2017-06-12 17:02:03 -07004937#endif // CONFIG_LOOP_RESTORATION
4938 alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways.
Yaowu Xuc27fc142016-08-22 16:08:15 -07004939 init_motion_estimation(cpi);
4940
4941 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
4942 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME];
4943 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
4944
4945 ref_buf->idx = buf_idx;
4946
4947 if (buf_idx != INVALID_IDX) {
4948 YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf;
4949 ref_buf->buf = buf;
Yaowu Xuf883b422016-08-30 14:01:10 -07004950 av1_setup_scale_factors_for_frame(
Yaowu Xuc27fc142016-08-22 16:08:15 -07004951 &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width,
4952 cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004953 if (av1_is_scaled(&ref_buf->sf))
4954 aom_extend_frame_borders(buf, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004955 } else {
4956 ref_buf->buf = NULL;
4957 }
4958 }
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07004959
Hui Su5ebd8702018-01-08 18:09:20 -08004960 av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height,
Sebastien Alaiwan1dcb7072017-05-12 11:13:05 +02004961 cm->width, cm->height,
4962 cm->use_highbitdepth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004963
4964 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
4965}
4966
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004967static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) {
4968 // Choose an arbitrary random number
4969 static unsigned int seed = 56789;
4970 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Urvang Joshide71d142017-10-05 12:12:15 -07004971 if (oxcf->pass == 1) return SCALE_NUMERATOR;
4972 uint8_t new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004973
4974 switch (oxcf->resize_mode) {
Urvang Joshide71d142017-10-05 12:12:15 -07004975 case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004976 case RESIZE_FIXED:
4977 if (cpi->common.frame_type == KEY_FRAME)
Urvang Joshide71d142017-10-05 12:12:15 -07004978 new_denom = oxcf->resize_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004979 else
Urvang Joshide71d142017-10-05 12:12:15 -07004980 new_denom = oxcf->resize_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004981 break;
Urvang Joshide71d142017-10-05 12:12:15 -07004982 case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004983 default: assert(0);
4984 }
Urvang Joshide71d142017-10-05 12:12:15 -07004985 return new_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004986}
4987
Urvang Joshi94ad3702017-12-06 11:38:08 -08004988#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshie58b5642017-10-05 17:59:43 -07004989
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004990static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) {
4991 // Choose an arbitrary random number
4992 static unsigned int seed = 34567;
4993 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Urvang Joshide71d142017-10-05 12:12:15 -07004994 if (oxcf->pass == 1) return SCALE_NUMERATOR;
4995 uint8_t new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004996 int bottom_index, top_index, q, qthresh;
4997
4998 switch (oxcf->superres_mode) {
Urvang Joshide71d142017-10-05 12:12:15 -07004999 case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005000 case SUPERRES_FIXED:
5001 if (cpi->common.frame_type == KEY_FRAME)
Urvang Joshide71d142017-10-05 12:12:15 -07005002 new_denom = oxcf->superres_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005003 else
Urvang Joshide71d142017-10-05 12:12:15 -07005004 new_denom = oxcf->superres_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005005 break;
Urvang Joshide71d142017-10-05 12:12:15 -07005006 case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005007 case SUPERRES_QTHRESH:
5008 qthresh = (cpi->common.frame_type == KEY_FRAME ? oxcf->superres_kf_qthresh
5009 : oxcf->superres_qthresh);
5010 av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height);
5011 q = av1_rc_pick_q_and_bounds(cpi, cpi->oxcf.width, cpi->oxcf.height,
5012 &bottom_index, &top_index);
5013 if (q < qthresh) {
Urvang Joshide71d142017-10-05 12:12:15 -07005014 new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005015 } else {
Urvang Joshi28983f72017-10-25 14:41:06 -07005016 const uint8_t min_denom = SCALE_NUMERATOR + 1;
5017 const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3;
5018 const uint8_t additional_denom = (q - qthresh) / denom_step;
5019 new_denom = AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005020 }
5021 break;
5022 default: assert(0);
5023 }
Urvang Joshide71d142017-10-05 12:12:15 -07005024 return new_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005025}
5026
Urvang Joshide71d142017-10-05 12:12:15 -07005027static int dimension_is_ok(int orig_dim, int resized_dim, int denom) {
5028 return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2);
5029}
5030
5031static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) {
Urvang Joshi94ad3702017-12-06 11:38:08 -08005032 // Only need to check the width, as scaling is horizontal only.
5033 (void)oheight;
5034 return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom);
Urvang Joshide71d142017-10-05 12:12:15 -07005035}
5036
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005037static int validate_size_scales(RESIZE_MODE resize_mode,
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005038 SUPERRES_MODE superres_mode, int owidth,
5039 int oheight, size_params_type *rsz) {
Urvang Joshide71d142017-10-05 12:12:15 -07005040 if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005041 return 1;
Urvang Joshide71d142017-10-05 12:12:15 -07005042 }
5043
Urvang Joshi69fde2e2017-10-09 15:34:18 -07005044 // Calculate current resize scale.
Urvang Joshide71d142017-10-05 12:12:15 -07005045 int resize_denom =
5046 AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width),
5047 DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height));
5048
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005049 if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005050 // Alter superres scale as needed to enforce conformity.
5051 rsz->superres_denom =
5052 (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom;
5053 if (!dimensions_are_ok(owidth, oheight, rsz)) {
5054 if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005055 }
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005056 } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005057 // Alter resize scale as needed to enforce conformity.
5058 resize_denom =
5059 (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005060 rsz->resize_width = owidth;
5061 rsz->resize_height = oheight;
5062 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005063 resize_denom);
5064 if (!dimensions_are_ok(owidth, oheight, rsz)) {
5065 if (resize_denom > SCALE_NUMERATOR) {
5066 --resize_denom;
5067 rsz->resize_width = owidth;
5068 rsz->resize_height = oheight;
5069 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
5070 resize_denom);
5071 }
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005072 }
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005073 } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005074 // Alter both resize and superres scales as needed to enforce conformity.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005075 do {
Urvang Joshide71d142017-10-05 12:12:15 -07005076 if (resize_denom > rsz->superres_denom)
5077 --resize_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005078 else
Urvang Joshide71d142017-10-05 12:12:15 -07005079 --rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005080 rsz->resize_width = owidth;
5081 rsz->resize_height = oheight;
5082 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005083 resize_denom);
5084 } while (!dimensions_are_ok(owidth, oheight, rsz) &&
5085 (resize_denom > SCALE_NUMERATOR ||
5086 rsz->superres_denom > SCALE_NUMERATOR));
5087 } else { // We are allowed to alter neither resize scale nor superres scale.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005088 return 0;
5089 }
Urvang Joshide71d142017-10-05 12:12:15 -07005090 return dimensions_are_ok(owidth, oheight, rsz);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005091}
Urvang Joshi94ad3702017-12-06 11:38:08 -08005092#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005093
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005094// Calculates resize and superres params for next frame
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005095size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) {
5096 const AV1EncoderConfig *oxcf = &cpi->oxcf;
5097 size_params_type rsz = {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005098 oxcf->width,
5099 oxcf->height,
Urvang Joshi94ad3702017-12-06 11:38:08 -08005100#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07005101 SCALE_NUMERATOR
Urvang Joshi94ad3702017-12-06 11:38:08 -08005102#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005103 };
Urvang Joshide71d142017-10-05 12:12:15 -07005104 int resize_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005105 if (oxcf->pass == 1) return rsz;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005106 if (cpi->resize_pending_width && cpi->resize_pending_height) {
5107 rsz.resize_width = cpi->resize_pending_width;
5108 rsz.resize_height = cpi->resize_pending_height;
5109 cpi->resize_pending_width = cpi->resize_pending_height = 0;
5110 } else {
Urvang Joshide71d142017-10-05 12:12:15 -07005111 resize_denom = calculate_next_resize_scale(cpi);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005112 rsz.resize_width = cpi->oxcf.width;
5113 rsz.resize_height = cpi->oxcf.height;
5114 av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005115 resize_denom);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005116 }
Urvang Joshi94ad3702017-12-06 11:38:08 -08005117#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07005118 rsz.superres_denom = calculate_next_superres_scale(cpi);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005119 if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width,
5120 oxcf->height, &rsz))
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005121 assert(0 && "Invalid scale parameters");
Urvang Joshi94ad3702017-12-06 11:38:08 -08005122#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005123 return rsz;
5124}
5125
5126static void setup_frame_size_from_params(AV1_COMP *cpi, size_params_type *rsz) {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005127 int encode_width = rsz->resize_width;
5128 int encode_height = rsz->resize_height;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005129
Urvang Joshi94ad3702017-12-06 11:38:08 -08005130#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005131 AV1_COMMON *cm = &cpi->common;
5132 cm->superres_upscaled_width = encode_width;
5133 cm->superres_upscaled_height = encode_height;
Urvang Joshide71d142017-10-05 12:12:15 -07005134 cm->superres_scale_denominator = rsz->superres_denom;
Urvang Joshi69fde2e2017-10-09 15:34:18 -07005135 av1_calculate_scaled_superres_size(&encode_width, &encode_height,
5136 rsz->superres_denom);
Urvang Joshi94ad3702017-12-06 11:38:08 -08005137#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005138 set_frame_size(cpi, encode_width, encode_height);
5139}
5140
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005141static void setup_frame_size(AV1_COMP *cpi) {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005142 size_params_type rsz = av1_calculate_next_size_params(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005143 setup_frame_size_from_params(cpi, &rsz);
5144}
5145
Urvang Joshi94ad3702017-12-06 11:38:08 -08005146#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005147static void superres_post_encode(AV1_COMP *cpi) {
5148 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005149 const int num_planes = av1_num_planes(cm);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005150
5151 if (av1_superres_unscaled(cm)) return;
5152
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005153 av1_superres_upscale(cm, NULL);
5154
5155 // If regular resizing is occurring the source will need to be downscaled to
5156 // match the upscaled superres resolution. Otherwise the original source is
5157 // used.
5158 if (av1_resize_unscaled(cm)) {
5159 cpi->source = cpi->unscaled_source;
5160 if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source;
5161 } else {
Fergus Simpsonabd43432017-06-12 15:54:43 -07005162 assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width);
5163 assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005164 // Do downscale. cm->(width|height) has been updated by av1_superres_upscale
5165 if (aom_realloc_frame_buffer(
5166 &cpi->scaled_source, cm->superres_upscaled_width,
5167 cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -08005168 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, cm->byte_alignment,
5169 NULL, NULL, NULL))
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005170 aom_internal_error(
5171 &cm->error, AOM_CODEC_MEM_ERROR,
5172 "Failed to reallocate scaled source buffer for superres");
5173 assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width);
5174 assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005175 av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source,
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005176 (int)cm->bit_depth, num_planes);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005177 cpi->source = &cpi->scaled_source;
5178 }
5179}
Urvang Joshi94ad3702017-12-06 11:38:08 -08005180#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005181
5182static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005183 const int num_planes = av1_num_planes(cm);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005184 MACROBLOCKD *xd = &cpi->td.mb.e_mbd;
5185 struct loopfilter *lf = &cm->lf;
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005186 int no_loopfilter = 0;
Yaowu Xu35ee2342017-11-08 11:50:46 -08005187#if CONFIG_LOOP_RESTORATION
Sebastien Alaiwan1ed20242018-02-20 14:47:18 +01005188 int no_restoration = !cpi->oxcf.using_restoration;
Hui Su27a4fb62017-11-10 16:03:50 -08005189#endif // CONFIG_LOOP_RESTORATION
5190
Yaowu Xu35ee2342017-11-08 11:50:46 -08005191 if (is_lossless_requested(&cpi->oxcf)
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005192#if CONFIG_EXT_TILE
Jingning Handa11e692017-12-19 08:45:08 -08005193 || cm->large_scale_tile
Hui Su27df8342017-11-07 15:16:05 -08005194#endif // CONFIG_EXT_TILE
Johannb0ef6ff2018-02-08 14:32:21 -08005195 ) {
Yaowu Xu35ee2342017-11-08 11:50:46 -08005196 no_loopfilter = 1;
Hui Su27a4fb62017-11-10 16:03:50 -08005197#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005198 no_restoration = 1;
Hui Su27a4fb62017-11-10 16:03:50 -08005199#endif // CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005200 }
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005201
Hui Su27a4fb62017-11-10 16:03:50 -08005202 int no_cdef = 0;
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005203 if (is_lossless_requested(&cpi->oxcf) || !cpi->oxcf.using_cdef
5204#if CONFIG_EXT_TILE
Jingning Handa11e692017-12-19 08:45:08 -08005205 || cm->large_scale_tile
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005206#endif
Johannb0ef6ff2018-02-08 14:32:21 -08005207 ) {
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005208 no_cdef = 1;
5209 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005210
5211 if (no_loopfilter) {
Cheng Chen13fc8192017-08-19 11:49:28 -07005212#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005213 lf->filter_level[0] = 0;
5214 lf->filter_level[1] = 0;
5215#else
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005216 lf->filter_level = 0;
Cheng Chen179479f2017-08-04 10:56:39 -07005217#endif
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005218 } else {
5219 struct aom_usec_timer timer;
5220
5221 aom_clear_system_state();
5222
5223 aom_usec_timer_start(&timer);
5224
5225 av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick);
5226
5227 aom_usec_timer_mark(&timer);
5228 cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer);
5229 }
5230
Cheng Chen13fc8192017-08-19 11:49:28 -07005231#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005232 if (lf->filter_level[0] || lf->filter_level[1])
5233#else
5234 if (lf->filter_level > 0)
5235#endif
5236 {
Cheng Chen13fc8192017-08-19 11:49:28 -07005237#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005238 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0],
5239 lf->filter_level[1], 0, 0);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005240 if (num_planes > 1) {
5241 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u,
5242 lf->filter_level_u, 1, 0);
5243 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v,
5244 lf->filter_level_v, 2, 0);
5245 }
Cheng Chen179479f2017-08-04 10:56:39 -07005246
Cheng Chene94df5c2017-07-19 17:25:33 -07005247#else
5248 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
Cheng Chen13fc8192017-08-19 11:49:28 -07005249#endif // CONFIG_LOOPFILTER_LEVEL
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005250 }
Debargha Mukherjeee168a782017-08-31 12:30:10 -07005251
Debargha Mukherjeea78c8f52018-01-31 11:14:38 -08005252#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005253 if (!no_restoration)
5254 av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0);
Debargha Mukherjeea78c8f52018-01-31 11:14:38 -08005255#endif // CONFIG_LOOP_RESTORATION
Ola Hugosson1e7f2d02017-09-22 21:36:26 +02005256
Yaowu Xu35ee2342017-11-08 11:50:46 -08005257 if (no_cdef) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005258 cm->cdef_bits = 0;
5259 cm->cdef_strengths[0] = 0;
5260 cm->nb_cdef_strengths = 1;
Yunqing Wangdad63d42017-12-08 12:45:07 -08005261 cm->cdef_uv_strengths[0] = 0;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005262 } else {
Steinar Midtskogen59782122017-07-20 08:49:43 +02005263 // Find CDEF parameters
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005264 av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd,
Debargha Mukherjeed7338aa2017-11-04 07:34:50 -07005265 cpi->sf.fast_cdef_search);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005266
5267 // Apply the filter
5268 av1_cdef_frame(cm->frame_to_show, cm, xd);
5269 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005270
Urvang Joshi94ad3702017-12-06 11:38:08 -08005271#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005272 superres_post_encode(cpi);
Urvang Joshi94ad3702017-12-06 11:38:08 -08005273#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005274
5275#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005276 if (no_restoration) {
5277 cm->rst_info[0].frame_restoration_type = RESTORE_NONE;
5278 cm->rst_info[1].frame_restoration_type = RESTORE_NONE;
5279 cm->rst_info[2].frame_restoration_type = RESTORE_NONE;
5280 } else {
5281 av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1);
5282 av1_pick_filter_restoration(cpi->source, cpi);
5283 if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
5284 cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
5285 cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
Rupert Swarbrick70c399e2017-12-12 09:47:49 +00005286 av1_loop_restoration_filter_frame(cm->frame_to_show, cm);
Yaowu Xu35ee2342017-11-08 11:50:46 -08005287 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005288 }
5289#endif // CONFIG_LOOP_RESTORATION
Fergus Simpsonbc189932017-05-16 17:02:39 -07005290}
5291
Yaowu Xuf883b422016-08-30 14:01:10 -07005292static void encode_without_recode_loop(AV1_COMP *cpi) {
5293 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005294 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables.
Yaowu Xuc27fc142016-08-22 16:08:15 -07005295
Yaowu Xuf883b422016-08-30 14:01:10 -07005296 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005297
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005298 set_size_independent_vars(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005299
Fergus Simpsonbc189932017-05-16 17:02:39 -07005300 setup_frame_size(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005301
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005302 assert(cm->width == cpi->scaled_source.y_crop_width);
5303 assert(cm->height == cpi->scaled_source.y_crop_height);
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -07005304
Yaowu Xuc27fc142016-08-22 16:08:15 -07005305 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
5306
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005307 cpi->source =
5308 av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
5309 if (cpi->unscaled_last_source != NULL)
5310 cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
5311 &cpi->scaled_last_source);
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005312 cpi->source->buf_8bit_valid = 0;
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005313 if (frame_is_intra_only(cm) == 0) {
Cheng Chen46f30c72017-09-07 11:13:33 -07005314 scale_references(cpi);
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005315 }
5316
Yaowu Xuf883b422016-08-30 14:01:10 -07005317 av1_set_quantizer(cm, q);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005318 setup_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005319 suppress_active_map(cpi);
hui sued5a30f2017-04-27 16:02:49 -07005320
Yaowu Xuc27fc142016-08-22 16:08:15 -07005321 // Variance adaptive and in frame q adjustment experiments are mutually
5322 // exclusive.
5323 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005324 av1_vaq_frame_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005325 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005326 av1_setup_in_frame_q_adj(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005327 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005328 av1_cyclic_refresh_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005329 }
5330 apply_active_map(cpi);
5331
5332 // transform / motion compensation build reconstruction frame
Yaowu Xuf883b422016-08-30 14:01:10 -07005333 av1_encode_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005334
5335 // Update some stats from cyclic refresh, and check if we should not update
5336 // golden reference, for 1 pass CBR.
5337 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->frame_type != KEY_FRAME &&
Yaowu Xuf883b422016-08-30 14:01:10 -07005338 (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR))
5339 av1_cyclic_refresh_check_golden_update(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005340
5341 // Update the skip mb flag probabilities based on the distribution
5342 // seen in the last encoder iteration.
5343 // update_base_skip_probs(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005344 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005345}
5346
Tom Finegane4099e32018-01-23 12:01:51 -08005347static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005348 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005349 RATE_CONTROL *const rc = &cpi->rc;
5350 int bottom_index, top_index;
5351 int loop_count = 0;
5352 int loop_at_this_size = 0;
5353 int loop = 0;
5354 int overshoot_seen = 0;
5355 int undershoot_seen = 0;
5356 int frame_over_shoot_limit;
5357 int frame_under_shoot_limit;
5358 int q = 0, q_low = 0, q_high = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005359
5360 set_size_independent_vars(cpi);
5361
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005362 cpi->source->buf_8bit_valid = 0;
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005363
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005364 aom_clear_system_state();
5365 setup_frame_size(cpi);
5366 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
5367
Yaowu Xuc27fc142016-08-22 16:08:15 -07005368 do {
Yaowu Xuf883b422016-08-30 14:01:10 -07005369 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005370
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005371 if (loop_count == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005372 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
5373 set_mv_search_params(cpi);
5374
5375 // Reset the loop state for new frame size.
5376 overshoot_seen = 0;
5377 undershoot_seen = 0;
5378
Yaowu Xuc27fc142016-08-22 16:08:15 -07005379 q_low = bottom_index;
5380 q_high = top_index;
5381
5382 loop_at_this_size = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005383
Urvang Joshi2a74cf22017-12-18 17:21:41 -08005384 // Decide frame size bounds first time through.
Yaowu Xuf883b422016-08-30 14:01:10 -07005385 av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target,
5386 &frame_under_shoot_limit,
5387 &frame_over_shoot_limit);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005388 }
5389
Debargha Mukherjee17e7b082017-08-13 09:33:03 -07005390 // if frame was scaled calculate global_motion_search again if already done
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005391 if (loop_count > 0 && cpi->source && cpi->global_motion_search_done)
5392 if (cpi->source->y_crop_width != cm->width ||
5393 cpi->source->y_crop_height != cm->height)
5394 cpi->global_motion_search_done = 0;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005395 cpi->source =
5396 av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
Debargha Mukherjee17e7b082017-08-13 09:33:03 -07005397 if (cpi->unscaled_last_source != NULL)
5398 cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
5399 &cpi->scaled_last_source);
5400
Yaowu Xuc27fc142016-08-22 16:08:15 -07005401 if (frame_is_intra_only(cm) == 0) {
5402 if (loop_count > 0) {
5403 release_scaled_references(cpi);
5404 }
Cheng Chen46f30c72017-09-07 11:13:33 -07005405 scale_references(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005406 }
Yaowu Xuf883b422016-08-30 14:01:10 -07005407 av1_set_quantizer(cm, q);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005408
5409 if (loop_count == 0) setup_frame(cpi);
5410
Yaowu Xuc27fc142016-08-22 16:08:15 -07005411 // Base q-index may have changed, so we need to assign proper default coef
5412 // probs before every iteration.
5413 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005414 av1_default_coef_probs(cm);
Hui Su3694c832017-11-10 14:15:58 -08005415 av1_setup_frame_contexts(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005416 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005417
Yaowu Xuc27fc142016-08-22 16:08:15 -07005418 // Variance adaptive and in frame q adjustment experiments are mutually
5419 // exclusive.
5420 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005421 av1_vaq_frame_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005422 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005423 av1_setup_in_frame_q_adj(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005424 }
5425
5426 // transform / motion compensation build reconstruction frame
Jingning Han8f661602017-08-19 08:16:50 -07005427 save_coding_context(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005428 av1_encode_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005429
5430 // Update the skip mb flag probabilities based on the distribution
5431 // seen in the last encoder iteration.
5432 // update_base_skip_probs(cpi);
5433
Yaowu Xuf883b422016-08-30 14:01:10 -07005434 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005435
5436 // Dummy pack of the bitstream using up to date stats to get an
5437 // accurate estimate of output frame size to determine if we need
5438 // to recode.
5439 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) {
Jingning Han8f661602017-08-19 08:16:50 -07005440 restore_coding_context(cpi);
Tom Finegane4099e32018-01-23 12:01:51 -08005441
5442 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
5443 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005444
5445 rc->projected_frame_size = (int)(*size) << 3;
5446 restore_coding_context(cpi);
5447
5448 if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1;
5449 }
5450
Yaowu Xuf883b422016-08-30 14:01:10 -07005451 if (cpi->oxcf.rc_mode == AOM_Q) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005452 loop = 0;
5453 } else {
5454 if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced &&
5455 (rc->projected_frame_size < rc->max_frame_bandwidth)) {
5456 int last_q = q;
5457 int64_t kf_err;
5458
5459 int64_t high_err_target = cpi->ambient_err;
5460 int64_t low_err_target = cpi->ambient_err >> 1;
5461
Yaowu Xuc27fc142016-08-22 16:08:15 -07005462 if (cm->use_highbitdepth) {
Alex Conversef77fd0b2017-04-20 11:00:24 -07005463 kf_err = aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005464 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07005465 kf_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005466 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005467 // Prevent possible divide by zero error below for perfect KF
5468 kf_err += !kf_err;
5469
5470 // The key frame is not good enough or we can afford
5471 // to make it better without undue risk of popping.
5472 if ((kf_err > high_err_target &&
5473 rc->projected_frame_size <= frame_over_shoot_limit) ||
5474 (kf_err > low_err_target &&
5475 rc->projected_frame_size <= frame_under_shoot_limit)) {
5476 // Lower q_high
5477 q_high = q > q_low ? q - 1 : q_low;
5478
5479 // Adjust Q
5480 q = (int)((q * high_err_target) / kf_err);
Yaowu Xuf883b422016-08-30 14:01:10 -07005481 q = AOMMIN(q, (q_high + q_low) >> 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005482 } else if (kf_err < low_err_target &&
5483 rc->projected_frame_size >= frame_under_shoot_limit) {
5484 // The key frame is much better than the previous frame
5485 // Raise q_low
5486 q_low = q < q_high ? q + 1 : q_high;
5487
5488 // Adjust Q
5489 q = (int)((q * low_err_target) / kf_err);
Yaowu Xuf883b422016-08-30 14:01:10 -07005490 q = AOMMIN(q, (q_high + q_low + 1) >> 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005491 }
5492
5493 // Clamp Q to upper and lower limits:
5494 q = clamp(q, q_low, q_high);
5495
5496 loop = q != last_q;
5497 } else if (recode_loop_test(cpi, frame_over_shoot_limit,
5498 frame_under_shoot_limit, q,
Yaowu Xuf883b422016-08-30 14:01:10 -07005499 AOMMAX(q_high, top_index), bottom_index)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005500 // Is the projected frame size out of range and are we allowed
5501 // to attempt to recode.
5502 int last_q = q;
5503 int retries = 0;
5504
Yaowu Xuc27fc142016-08-22 16:08:15 -07005505 // Frame size out of permitted range:
5506 // Update correction factor & compute new Q to try...
Yaowu Xuc27fc142016-08-22 16:08:15 -07005507 // Frame is too large
5508 if (rc->projected_frame_size > rc->this_frame_target) {
5509 // Special case if the projected size is > the max allowed.
5510 if (rc->projected_frame_size >= rc->max_frame_bandwidth)
5511 q_high = rc->worst_quality;
5512
5513 // Raise Qlow as to at least the current value
5514 q_low = q < q_high ? q + 1 : q_high;
5515
5516 if (undershoot_seen || loop_at_this_size > 1) {
5517 // Update rate_correction_factor unless
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005518 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005519
5520 q = (q_high + q_low + 1) / 2;
5521 } else {
5522 // Update rate_correction_factor unless
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005523 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005524
Yaowu Xuf883b422016-08-30 14:01:10 -07005525 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005526 AOMMAX(q_high, top_index), cm->width,
5527 cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005528
5529 while (q < q_low && retries < 10) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005530 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005531 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005532 AOMMAX(q_high, top_index), cm->width,
5533 cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005534 retries++;
5535 }
5536 }
5537
5538 overshoot_seen = 1;
5539 } else {
5540 // Frame is too small
5541 q_high = q > q_low ? q - 1 : q_low;
5542
5543 if (overshoot_seen || loop_at_this_size > 1) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005544 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005545 q = (q_high + q_low) / 2;
5546 } else {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005547 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005548 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005549 top_index, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005550 // Special case reset for qlow for constrained quality.
5551 // This should only trigger where there is very substantial
5552 // undershoot on a frame and the auto cq level is above
5553 // the user passsed in value.
Yaowu Xuf883b422016-08-30 14:01:10 -07005554 if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005555 q_low = q;
5556 }
5557
5558 while (q > q_high && retries < 10) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005559 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005560 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005561 top_index, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005562 retries++;
5563 }
5564 }
5565
5566 undershoot_seen = 1;
5567 }
5568
5569 // Clamp Q to upper and lower limits:
5570 q = clamp(q, q_low, q_high);
5571
5572 loop = (q != last_q);
5573 } else {
5574 loop = 0;
5575 }
5576 }
5577
5578 // Special case for overlay frame.
5579 if (rc->is_src_frame_alt_ref &&
5580 rc->projected_frame_size < rc->max_frame_bandwidth)
5581 loop = 0;
5582
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08005583 if (recode_loop_test_global_motion(cpi)) {
5584 loop = 1;
5585 }
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08005586
Yaowu Xuc27fc142016-08-22 16:08:15 -07005587 if (loop) {
5588 ++loop_count;
5589 ++loop_at_this_size;
5590
5591#if CONFIG_INTERNAL_STATS
5592 ++cpi->tot_recode_hits;
5593#endif
5594 }
5595 } while (loop);
Tom Finegane4099e32018-01-23 12:01:51 -08005596
5597 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005598}
5599
Yaowu Xuf883b422016-08-30 14:01:10 -07005600static int get_ref_frame_flags(const AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005601 const int *const map = cpi->common.ref_frame_map;
5602
Zoe Liu368bf162017-11-03 20:10:19 -07005603 // No.1 Priority: LAST_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -07005604 const int last2_is_last =
5605 map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]];
5606 const int last3_is_last =
5607 map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]];
5608 const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]];
5609 const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]];
Zoe Liu368bf162017-11-03 20:10:19 -07005610 const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005611 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]];
5612
Zoe Liu368bf162017-11-03 20:10:19 -07005613 // No.2 Priority: ALTREF_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -07005614 const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx];
5615 const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx];
5616 const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
5617 const int bwd_is_alt = map[cpi->bwd_fb_idx] == map[cpi->alt_fb_idx];
Zoe Liue9b15e22017-07-19 15:53:01 -07005618 const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005619
Zoe Liu368bf162017-11-03 20:10:19 -07005620 // No.3 Priority: LAST2_FRAME
5621 const int last3_is_last2 =
5622 map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]];
5623 const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]];
5624 const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]];
5625 const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005626
Zoe Liu368bf162017-11-03 20:10:19 -07005627 // No.4 Priority: LAST3_FRAME
5628 const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]];
5629 const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]];
5630 const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]];
5631
5632 // No.5 Priority: GOLDEN_FRAME
5633 const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx];
5634 const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx];
5635
5636 // No.6 Priority: BWDREF_FRAME
5637 const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx];
5638
5639 // No.7 Priority: ALTREF2_FRAME
5640
Yunqing Wang9a50fec2017-11-02 17:02:00 -07005641 // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be
5642 // adjusted according to external encoder flags.
Yunqing Wangf2e7a392017-11-08 00:27:21 -08005643 int flags = cpi->ext_ref_frame_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005644
Yaowu Xuf883b422016-08-30 14:01:10 -07005645 if (cpi->rc.frames_till_gf_update_due == INT_MAX) flags &= ~AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005646
Yaowu Xuf883b422016-08-30 14:01:10 -07005647 if (alt_is_last) flags &= ~AOM_ALT_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005648
Yaowu Xuf883b422016-08-30 14:01:10 -07005649 if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005650
Zoe Liu368bf162017-11-03 20:10:19 -07005651 if (last3_is_last || last3_is_alt || last3_is_last2) flags &= ~AOM_LAST3_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005652
Zoe Liu368bf162017-11-03 20:10:19 -07005653 if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3)
5654 flags &= ~AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005655
Zoe Liu368bf162017-11-03 20:10:19 -07005656 if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 ||
5657 bwd_is_gld) &&
Yaowu Xuf883b422016-08-30 14:01:10 -07005658 (flags & AOM_BWD_FLAG))
5659 flags &= ~AOM_BWD_FLAG;
Zoe Liue9b15e22017-07-19 15:53:01 -07005660
Zoe Liu368bf162017-11-03 20:10:19 -07005661 if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 ||
5662 alt2_is_gld || alt2_is_bwd) &&
Zoe Liue9b15e22017-07-19 15:53:01 -07005663 (flags & AOM_ALT2_FLAG))
5664 flags &= ~AOM_ALT2_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005665
5666 return flags;
5667}
5668
Yaowu Xuf883b422016-08-30 14:01:10 -07005669static void set_ext_overrides(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005670 // Overrides the defaults with the externally supplied values with
Yaowu Xuf883b422016-08-30 14:01:10 -07005671 // av1_update_reference() and av1_update_entropy() calls
Yaowu Xuc27fc142016-08-22 16:08:15 -07005672 // Note: The overrides are valid only for the next frame passed
5673 // to encode_frame_to_data_rate() function
5674 if (cpi->ext_refresh_frame_context_pending) {
5675 cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context;
5676 cpi->ext_refresh_frame_context_pending = 0;
5677 }
5678 if (cpi->ext_refresh_frame_flags_pending) {
5679 cpi->refresh_last_frame = cpi->ext_refresh_last_frame;
5680 cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame;
5681 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
Yunqing Wang9a50fec2017-11-02 17:02:00 -07005682 cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame;
5683 cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005684 cpi->ext_refresh_frame_flags_pending = 0;
5685 }
5686}
5687
Yaowu Xuf883b422016-08-30 14:01:10 -07005688static int setup_interp_filter_search_mask(AV1_COMP *cpi) {
James Zern7b9407a2016-05-18 23:48:05 -07005689 InterpFilter ifilter;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005690 int ref_total[TOTAL_REFS_PER_FRAME] = { 0 };
5691 MV_REFERENCE_FRAME ref;
5692 int mask = 0;
5693 int arf_idx = ALTREF_FRAME;
5694
Zoe Liue9b15e22017-07-19 15:53:01 -07005695 if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame ||
5696 cpi->refresh_alt2_ref_frame)
Yaowu Xuc27fc142016-08-22 16:08:15 -07005697 return mask;
5698
Yaowu Xuc27fc142016-08-22 16:08:15 -07005699 for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref)
5700 for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter)
5701 ref_total[ref] += cpi->interp_filter_selected[ref][ifilter];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005702
5703 for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) {
5704 if ((ref_total[LAST_FRAME] &&
5705 cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005706 (ref_total[LAST2_FRAME] == 0 ||
5707 cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 <
5708 ref_total[LAST2_FRAME]) &&
5709 (ref_total[LAST3_FRAME] == 0 ||
5710 cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 <
5711 ref_total[LAST3_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005712 (ref_total[GOLDEN_FRAME] == 0 ||
5713 cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 <
5714 ref_total[GOLDEN_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005715 (ref_total[BWDREF_FRAME] == 0 ||
5716 cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 <
5717 ref_total[BWDREF_FRAME]) &&
Zoe Liue9b15e22017-07-19 15:53:01 -07005718 (ref_total[ALTREF2_FRAME] == 0 ||
5719 cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 <
5720 ref_total[ALTREF2_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005721 (ref_total[ALTREF_FRAME] == 0 ||
5722 cpi->interp_filter_selected[arf_idx][ifilter] * 50 <
5723 ref_total[ALTREF_FRAME]))
5724 mask |= 1 << ifilter;
5725 }
5726 return mask;
5727}
5728
5729#define DUMP_RECON_FRAMES 0
5730
5731#if DUMP_RECON_FRAMES == 1
5732// NOTE(zoeliu): For debug - Output the filtered reconstructed video.
Yaowu Xuf883b422016-08-30 14:01:10 -07005733static void dump_filtered_recon_frames(AV1_COMP *cpi) {
5734 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005735 const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005736
Zoe Liub4f31032017-11-03 23:48:35 -07005737 if (recon_buf == NULL) {
5738 printf("Frame %d is not ready.\n", cm->current_video_frame);
5739 return;
5740 }
5741
Zoe Liub4f31032017-11-03 23:48:35 -07005742 static const int flag_list[TOTAL_REFS_PER_FRAME] = { 0,
5743 AOM_LAST_FLAG,
5744 AOM_LAST2_FLAG,
5745 AOM_LAST3_FLAG,
5746 AOM_GOLD_FLAG,
5747 AOM_BWD_FLAG,
5748 AOM_ALT2_FLAG,
5749 AOM_ALT_FLAG };
5750 printf(
5751 "\n***Frame=%d (frame_offset=%d, show_frame=%d, "
5752 "show_existing_frame=%d) "
5753 "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[",
5754 cm->current_video_frame, cm->frame_offset, cm->show_frame,
5755 cm->show_existing_frame);
5756 for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
5757 const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx;
5758 const int ref_offset =
5759 (buf_idx >= 0)
5760 ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset
5761 : -1;
Zoe Liuf452fdf2017-11-02 23:08:12 -07005762 printf(
5763 " %d(%c-%d-%4.2f)", ref_offset,
5764 (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N',
5765 (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1,
5766 (buf_idx >= 0) ? rate_factor_deltas[cpi->frame_rf_level[buf_idx]] : -1);
Zoe Liub4f31032017-11-03 23:48:35 -07005767 }
5768 printf(" ]\n");
Zoe Liub4f31032017-11-03 23:48:35 -07005769
5770 if (!cm->show_frame) {
5771 printf("Frame %d is a no show frame, so no image dump.\n",
Yaowu Xuc27fc142016-08-22 16:08:15 -07005772 cm->current_video_frame);
5773 return;
5774 }
5775
Zoe Liub4f31032017-11-03 23:48:35 -07005776 int h;
5777 char file_name[256] = "/tmp/enc_filtered_recon.yuv";
5778 FILE *f_recon = NULL;
5779
Yaowu Xuc27fc142016-08-22 16:08:15 -07005780 if (cm->current_video_frame == 0) {
5781 if ((f_recon = fopen(file_name, "wb")) == NULL) {
5782 printf("Unable to open file %s to write.\n", file_name);
5783 return;
5784 }
5785 } else {
5786 if ((f_recon = fopen(file_name, "ab")) == NULL) {
5787 printf("Unable to open file %s to append.\n", file_name);
5788 return;
5789 }
5790 }
5791 printf(
Zoe Liuf40a9572017-10-13 12:37:19 -07005792 "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, "
5793 "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, "
5794 "refresh_alt_ref_frame=%d, rf_level=%d, "
5795 "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n",
Yaowu Xuc27fc142016-08-22 16:08:15 -07005796 cm->current_video_frame, cpi->twopass.gf_group.index,
5797 cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index],
Zoe Liuf40a9572017-10-13 12:37:19 -07005798 cm->frame_offset, cm->show_frame, cm->show_existing_frame,
5799 cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame,
5800 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index],
5801 recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height);
Zoe Liue9b15e22017-07-19 15:53:01 -07005802#if 0
5803 int ref_frame;
5804 printf("get_ref_frame_map_idx: [");
5805 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame)
5806 printf(" %d", get_ref_frame_map_idx(cpi, ref_frame));
5807 printf(" ]\n");
5808 printf("cm->new_fb_idx = %d\n", cm->new_fb_idx);
5809 printf("cm->ref_frame_map = [");
5810 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
5811 printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]);
5812 }
5813 printf(" ]\n");
5814#endif // 0
Yaowu Xuc27fc142016-08-22 16:08:15 -07005815
5816 // --- Y ---
5817 for (h = 0; h < cm->height; ++h) {
5818 fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width,
5819 f_recon);
5820 }
5821 // --- U ---
5822 for (h = 0; h < (cm->height >> 1); ++h) {
5823 fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1),
5824 f_recon);
5825 }
5826 // --- V ---
5827 for (h = 0; h < (cm->height >> 1); ++h) {
5828 fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1),
5829 f_recon);
5830 }
5831
5832 fclose(f_recon);
5833}
5834#endif // DUMP_RECON_FRAMES
5835
Thomas Davies4822e142017-10-10 11:30:36 +01005836static void make_update_tile_list_enc(AV1_COMP *cpi, const int start_tile,
5837 const int num_tiles,
Thomas Davies028b57f2017-02-22 16:42:11 +00005838 FRAME_CONTEXT *ec_ctxs[]) {
5839 int i;
Thomas Davies4822e142017-10-10 11:30:36 +01005840 for (i = start_tile; i < start_tile + num_tiles; ++i)
5841 ec_ctxs[i - start_tile] = &cpi->tile_data[i].tctx;
Thomas Davies028b57f2017-02-22 16:42:11 +00005842}
5843
Tom Finegane4099e32018-01-23 12:01:51 -08005844static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest,
5845 int skip_adapt,
5846 unsigned int *frame_flags) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005847 AV1_COMMON *const cm = &cpi->common;
5848 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005849 struct segmentation *const seg = &cm->seg;
Thomas Davies4822e142017-10-10 11:30:36 +01005850 const int num_bwd_ctxs = 1;
Thomas Davies4822e142017-10-10 11:30:36 +01005851
5852 FRAME_CONTEXT **tile_ctxs =
5853 aom_malloc(num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx));
5854 aom_cdf_prob **cdf_ptrs = aom_malloc(
5855 num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005856 set_ext_overrides(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005857 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005858
Fangwen Fu8d164de2016-12-14 13:40:54 -08005859 // frame type has been decided outside of this function call
5860 cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only;
Zoe Liu2723a9d2018-02-22 20:17:00 -08005861 cm->cur_frame->frame_type = cm->frame_type;
Jingning Han2830fd92018-01-10 10:06:26 -08005862 cm->use_ref_frame_mvs = !cpi->oxcf.disable_tempmv &&
5863 !cm->cur_frame->intra_only &&
5864 frame_might_use_prev_frame_mvs(cm);
Jingning Hane17ebe92017-11-03 15:25:42 -07005865 cm->use_prev_frame_mvs = cm->use_ref_frame_mvs;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005866
Jingning Hand8a15a62017-10-30 10:53:42 -07005867 // Reset the frame packet stamp index.
5868 if (cm->frame_type == KEY_FRAME) cm->current_video_frame = 0;
5869
Yaowu Xuc27fc142016-08-22 16:08:15 -07005870 // NOTE:
5871 // (1) Move the setup of the ref_frame_flags upfront as it would be
5872 // determined by the current frame properties;
5873 // (2) The setup of the ref_frame_flags applies to both show_existing_frame's
5874 // and the other cases.
5875 if (cm->current_video_frame > 0)
5876 cpi->ref_frame_flags = get_ref_frame_flags(cpi);
5877
5878 if (cm->show_existing_frame) {
5879 // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current
5880 // BWDREF_FRAME in the reference frame buffer.
5881 cm->frame_type = INTER_FRAME;
5882 cm->show_frame = 1;
5883 cpi->frame_flags = *frame_flags;
5884
5885 // In the case of show_existing frame, we will not send fresh flag
5886 // to decoder. Any change in the reference frame buffer can be done by
5887 // switching the virtual indices.
5888
5889 cpi->refresh_last_frame = 0;
5890 cpi->refresh_golden_frame = 0;
5891 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07005892 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005893 cpi->refresh_alt_ref_frame = 0;
5894
5895 cpi->rc.is_bwd_ref_frame = 0;
5896 cpi->rc.is_last_bipred_frame = 0;
5897 cpi->rc.is_bipred_frame = 0;
5898
Jingning Han8f661602017-08-19 08:16:50 -07005899 restore_coding_context(cpi);
Zoe Liub4f31032017-11-03 23:48:35 -07005900
Yaowu Xuc27fc142016-08-22 16:08:15 -07005901 // Build the bitstream
Tom Finegane4099e32018-01-23 12:01:51 -08005902 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
5903 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005904
5905 // Set up frame to show to get ready for stats collection.
5906 cm->frame_to_show = get_frame_new_buffer(cm);
5907
Zoe Liub4f31032017-11-03 23:48:35 -07005908 // Update current frame offset.
5909 cm->frame_offset =
5910 cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset;
Zoe Liub4f31032017-11-03 23:48:35 -07005911
Yaowu Xuc27fc142016-08-22 16:08:15 -07005912#if DUMP_RECON_FRAMES == 1
5913 // NOTE(zoeliu): For debug - Output the filtered reconstructed video.
5914 dump_filtered_recon_frames(cpi);
5915#endif // DUMP_RECON_FRAMES
5916
5917 // Update the LAST_FRAME in the reference frame buffer.
Zoe Liue9b15e22017-07-19 15:53:01 -07005918 // NOTE:
5919 // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame
5920 // update has been done previously when handling the LAST_BIPRED_FRAME
5921 // right before BWDREF_FRAME (in the display order);
5922 // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame
5923 // update will be done when the following is called, which will exchange
5924 // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that
5925 // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and
5926 // ALTREF2_FRAME will serve as the new LAST_FRAME.
Cheng Chen46f30c72017-09-07 11:13:33 -07005927 update_reference_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005928
5929 // Update frame flags
5930 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
5931 cpi->frame_flags &= ~FRAMEFLAGS_BWDREF;
5932 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
5933
5934 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
5935
5936 // Update the frame type
5937 cm->last_frame_type = cm->frame_type;
5938
Yaowu Xuc27fc142016-08-22 16:08:15 -07005939 // Since we allocate a spot for the OVERLAY frame in the gf group, we need
5940 // to do post-encoding update accordingly.
5941 if (cpi->rc.is_src_frame_alt_ref) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005942 av1_set_target_rate(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005943 av1_rc_postencode_update(cpi, *size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005944 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005945
Yaowu Xuc27fc142016-08-22 16:08:15 -07005946 ++cm->current_video_frame;
5947
Jingning Hanf6214b92017-04-12 11:43:37 -07005948 aom_free(tile_ctxs);
5949 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08005950 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005951 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005952
5953 // Set default state for segment based loop filter update flags.
5954 cm->lf.mode_ref_delta_update = 0;
5955
5956 if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search)
5957 cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi);
5958
5959 // Set various flags etc to special state if it is a key frame.
5960 if (frame_is_intra_only(cm)) {
5961 // Reset the loop filter deltas and segmentation map.
Yaowu Xuf883b422016-08-30 14:01:10 -07005962 av1_reset_segment_features(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005963
5964 // If segmentation is enabled force a map update for key frames.
5965 if (seg->enabled) {
5966 seg->update_map = 1;
5967 seg->update_data = 1;
5968 }
5969
5970 // The alternate reference frame cannot be active for a key frame.
5971 cpi->rc.source_alt_ref_active = 0;
5972
5973 cm->error_resilient_mode = oxcf->error_resilient_mode;
5974
Thomas Daedea6a854b2017-06-22 17:49:11 -07005975#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07005976 // By default, encoder assumes decoder can use prev_mi.
5977 if (cm->error_resilient_mode) {
5978 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
James Zernf34dfc82018-02-23 16:53:33 -08005979 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005980 } else if (cm->intra_only) {
5981 // Only reset the current context.
5982 cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT;
5983 }
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01005984#if CONFIG_EXT_TILE
5985 if (cpi->oxcf.large_scale_tile)
James Zernf34dfc82018-02-23 16:53:33 -08005986 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01005987#endif // CONFIG_EXT_TILE
5988#endif // !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07005989 }
Thomas Daviesaf6df172016-11-09 14:04:18 +00005990 if (cpi->oxcf.mtu == 0) {
5991 cm->num_tg = cpi->oxcf.num_tile_groups;
5992 } else {
Yaowu Xu859a5272016-11-10 15:32:21 -08005993 // Use a default value for the purposes of weighting costs in probability
5994 // updates
Thomas Daviesaf6df172016-11-09 14:04:18 +00005995 cm->num_tg = DEFAULT_MAX_NUM_TG;
5996 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005997
Yunqing Wangd8cd55f2017-02-27 12:16:00 -08005998#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005999 cm->large_scale_tile = cpi->oxcf.large_scale_tile;
6000 cm->single_tile_decoding = cpi->oxcf.single_tile_decoding;
Yunqing Wangb6e23bc2017-11-15 13:18:55 -08006001#if CONFIG_REFERENCE_BUFFER
6002 if (cm->large_scale_tile) cm->seq_params.frame_id_numbers_present_flag = 0;
6003#endif // CONFIG_REFERENCE_BUFFER
Yunqing Wangd8cd55f2017-02-27 12:16:00 -08006004#endif // CONFIG_EXT_TILE
6005
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08006006#if CONFIG_MONO_VIDEO
6007 cm->seq_params.monochrome = oxcf->monochrome;
6008#endif // CONFIG_MONO_VIDEO
6009
Yaowu Xuc27fc142016-08-22 16:08:15 -07006010 // For 1 pass CBR, check if we are dropping this frame.
6011 // Never drop on key frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07006012 if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07006013 cm->frame_type != KEY_FRAME) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006014 if (av1_rc_drop_frame(cpi)) {
6015 av1_rc_postencode_update_drop_frame(cpi);
Jingning Hanf6214b92017-04-12 11:43:37 -07006016 aom_free(tile_ctxs);
6017 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006018 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006019 }
6020 }
6021
Yaowu Xuf883b422016-08-30 14:01:10 -07006022 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006023
6024#if CONFIG_INTERNAL_STATS
6025 memset(cpi->mode_chosen_counts, 0,
6026 MAX_MODES * sizeof(*cpi->mode_chosen_counts));
6027#endif
6028
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006029#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01006030 if (cm->seq_params.frame_id_numbers_present_flag) {
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006031 /* Non-normative definition of current_frame_id ("frame counter" with
Johann123e8a62017-12-28 14:40:49 -08006032 * wraparound) */
Sebastien Alaiwand418f682017-10-19 15:06:52 +02006033 const int frame_id_length = FRAME_ID_LENGTH;
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006034 if (cm->current_frame_id == -1) {
David Barker49a76562016-12-07 14:50:21 +00006035 int lsb, msb;
Yaowu Xud3e7c682017-12-21 14:08:25 -08006036 /* quasi-random initialization of current_frame_id for a key frame */
Alex Conversef77fd0b2017-04-20 11:00:24 -07006037 if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) {
6038 lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff;
6039 msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff;
David Barker49a76562016-12-07 14:50:21 +00006040 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006041 lsb = cpi->source->y_buffer[0] & 0xff;
6042 msb = cpi->source->y_buffer[1] & 0xff;
David Barker49a76562016-12-07 14:50:21 +00006043 }
Arild Fuldseth (arilfuld)788dc232016-12-20 17:55:52 +01006044 cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length);
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006045 } else {
6046 cm->current_frame_id =
Arild Fuldseth (arilfuld)788dc232016-12-20 17:55:52 +01006047 (cm->current_frame_id + 1 + (1 << frame_id_length)) %
6048 (1 << frame_id_length);
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006049 }
6050 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006051#endif // CONFIG_REFERENCE_BUFFER
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006052
Yaowu Xuc27fc142016-08-22 16:08:15 -07006053 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
6054 encode_without_recode_loop(cpi);
6055 } else {
Tom Finegane4099e32018-01-23 12:01:51 -08006056 if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK)
6057 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006058 }
6059
Yi Luo10e23002017-07-31 11:54:43 -07006060 cm->last_tile_cols = cm->tile_cols;
6061 cm->last_tile_rows = cm->tile_rows;
6062
Yaowu Xuc27fc142016-08-22 16:08:15 -07006063#ifdef OUTPUT_YUV_SKINMAP
6064 if (cpi->common.current_video_frame > 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006065 av1_compute_skin_map(cpi, yuv_skinmap_file);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006066 }
6067#endif // OUTPUT_YUV_SKINMAP
6068
6069 // Special case code to reduce pulsing when key frames are forced at a
6070 // fixed interval. Note the reconstruction error if it is the frame before
6071 // the force key frame
6072 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006073 if (cm->use_highbitdepth) {
6074 cpi->ambient_err =
Alex Conversef77fd0b2017-04-20 11:00:24 -07006075 aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006076 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006077 cpi->ambient_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006078 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006079 }
6080
6081 // If the encoder forced a KEY_FRAME decision
6082 if (cm->frame_type == KEY_FRAME) {
6083 cpi->refresh_last_frame = 1;
6084 }
6085
6086 cm->frame_to_show = get_frame_new_buffer(cm);
Andrey Norkin9e694632017-12-21 18:50:57 -08006087#if CONFIG_CICP
6088 cm->frame_to_show->color_primaries = cm->color_primaries;
6089 cm->frame_to_show->transfer_characteristics = cm->transfer_characteristics;
6090 cm->frame_to_show->matrix_coefficients = cm->matrix_coefficients;
6091#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07006092 cm->frame_to_show->color_space = cm->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08006093#endif
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08006094#if CONFIG_MONO_VIDEO
6095 cm->frame_to_show->monochrome = cm->seq_params.monochrome;
6096#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07006097#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08006098#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07006099 cm->frame_to_show->transfer_function = cm->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08006100#endif
anorkin76fb1262017-03-22 15:12:12 -07006101 cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position;
6102#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006103 cm->frame_to_show->color_range = cm->color_range;
6104 cm->frame_to_show->render_width = cm->render_width;
6105 cm->frame_to_show->render_height = cm->render_height;
6106
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006107 // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned
6108 // off.
Yaowu Xuc27fc142016-08-22 16:08:15 -07006109
6110 // Pick the loop filter level for the frame.
David Barker218556e2018-02-14 14:23:12 +00006111#if CONFIG_INTRABC
6112 if (!(cm->allow_intrabc && NO_FILTER_FOR_IBC))
6113#endif
6114 loopfilter_frame(cpi, cm);
6115
6116 // TODO(debargha): Fix mv search range on encoder side
6117 // aom_extend_frame_inner_borders(cm->frame_to_show, av1_num_planes(cm));
6118 aom_extend_frame_borders(cm->frame_to_show, av1_num_planes(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006119
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -07006120#ifdef OUTPUT_YUV_REC
6121 aom_write_one_yuv_frame(cm, cm->frame_to_show);
6122#endif
6123
Yaowu Xuc27fc142016-08-22 16:08:15 -07006124 // Build the bitstream
Tom Finegane4099e32018-01-23 12:01:51 -08006125 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
6126 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006127
Jingning Hanf6214b92017-04-12 11:43:37 -07006128 if (skip_adapt) {
Jingning Hanf6214b92017-04-12 11:43:37 -07006129 aom_free(tile_ctxs);
6130 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006131 return AOM_CODEC_OK;
Jingning Hanf6214b92017-04-12 11:43:37 -07006132 }
Rostislav Pehlivanov74021a52017-03-09 09:05:29 +00006133
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006134#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01006135 if (cm->seq_params.frame_id_numbers_present_flag) {
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006136 int i;
6137 /* Update reference frame id values based on the value of refresh_mask */
6138 for (i = 0; i < REF_FRAMES; i++) {
6139 if ((cm->refresh_mask >> i) & 1) {
6140 cm->ref_frame_id[i] = cm->current_frame_id;
6141 }
6142 }
6143 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006144#endif // CONFIG_REFERENCE_BUFFER
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006145
Yaowu Xuc27fc142016-08-22 16:08:15 -07006146#if DUMP_RECON_FRAMES == 1
6147 // NOTE(zoeliu): For debug - Output the filtered reconstructed video.
Zoe Liub4f31032017-11-03 23:48:35 -07006148 dump_filtered_recon_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006149#endif // DUMP_RECON_FRAMES
6150
Soo-Chul Han934af352017-10-15 15:21:51 -04006151#if CONFIG_SEGMENT_PRED_LAST
6152 if (cm->seg.enabled) {
6153 if (cm->seg.update_map) {
6154 update_reference_segmentation_map(cpi);
6155 } else {
6156 memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map,
6157 cm->mi_cols * cm->mi_rows * sizeof(uint8_t));
6158 }
6159 }
6160#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07006161 if (cm->seg.update_map) update_reference_segmentation_map(cpi);
Soo-Chul Han934af352017-10-15 15:21:51 -04006162#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006163
6164 if (frame_is_intra_only(cm) == 0) {
6165 release_scaled_references(cpi);
6166 }
6167
Cheng Chen46f30c72017-09-07 11:13:33 -07006168 update_reference_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006169
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08006170#if CONFIG_ENTROPY_STATS
6171 av1_accumulate_frame_counts(&aggregate_fc, &cm->counts);
Zoe Liua56f9162017-06-21 22:49:57 -07006172 assert(cm->frame_context_idx < FRAME_CONTEXTS);
6173 av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx],
6174 &cm->counts);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08006175#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07006176 if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
Thomas Davies4822e142017-10-10 11:30:36 +01006177 make_update_tile_list_enc(cpi, cm->largest_tile_id, 1, tile_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006178 av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006179 num_bwd_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006180 av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006181 num_bwd_ctxs);
Debargha Mukherjee43061b32017-10-13 16:50:17 -07006182 av1_average_tile_loopfilter_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
6183 num_bwd_ctxs);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006184 }
6185
6186 if (!frame_is_intra_only(cm)) {
6187 if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
Thomas Davies028b57f2017-02-22 16:42:11 +00006188 av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs,
Thomas Davies4822e142017-10-10 11:30:36 +01006189 cdf_ptrs, num_bwd_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006190 av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006191 num_bwd_ctxs);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006192 }
6193 }
6194
6195 if (cpi->refresh_golden_frame == 1)
6196 cpi->frame_flags |= FRAMEFLAGS_GOLDEN;
6197 else
6198 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
6199
6200 if (cpi->refresh_alt_ref_frame == 1)
6201 cpi->frame_flags |= FRAMEFLAGS_ALTREF;
6202 else
6203 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
6204
Yaowu Xuc27fc142016-08-22 16:08:15 -07006205 if (cpi->refresh_bwd_ref_frame == 1)
6206 cpi->frame_flags |= FRAMEFLAGS_BWDREF;
6207 else
6208 cpi->frame_flags &= ~FRAMEFLAGS_BWDREF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006209
Yaowu Xuc27fc142016-08-22 16:08:15 -07006210 cm->last_frame_type = cm->frame_type;
6211
Yaowu Xuf883b422016-08-30 14:01:10 -07006212 av1_rc_postencode_update(cpi, *size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006213
6214#if 0
6215 output_frame_level_debug_stats(cpi);
6216#endif
6217
6218 if (cm->frame_type == KEY_FRAME) {
6219 // Tell the caller that the frame was coded as a key frame
6220 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
6221 } else {
6222 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
6223 }
6224
6225 // Clear the one shot update flags for segmentation map and mode/ref loop
6226 // filter deltas.
6227 cm->seg.update_map = 0;
6228 cm->seg.update_data = 0;
6229 cm->lf.mode_ref_delta_update = 0;
6230
Yaowu Xuc27fc142016-08-22 16:08:15 -07006231 if (cm->show_frame) {
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006232 // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are
6233 // being used as reference.
Cheng Chen46f30c72017-09-07 11:13:33 -07006234 swap_mi_and_prev_mi(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006235 // Don't increment frame counters if this was an altref buffer
6236 // update not a real frame
6237 ++cm->current_video_frame;
6238 }
6239
Yaowu Xuc27fc142016-08-22 16:08:15 -07006240 // NOTE: Shall not refer to any frame not used as reference.
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006241 if (cm->is_reference_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006242 cm->prev_frame = cm->cur_frame;
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006243 // keep track of the last coded dimensions
6244 cm->last_width = cm->width;
6245 cm->last_height = cm->height;
6246
6247 // reset to normal state now that we are done.
6248 cm->last_show_frame = cm->show_frame;
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006249 }
Yi Luo10e23002017-07-31 11:54:43 -07006250
Thomas Davies493623e2017-03-31 16:12:25 +01006251 aom_free(tile_ctxs);
6252 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006253 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006254}
6255
Tom Finegane4099e32018-01-23 12:01:51 -08006256static int Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest,
6257 int skip_adapt, unsigned int *frame_flags) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006258 if (cpi->oxcf.rc_mode == AOM_CBR) {
6259 av1_rc_get_one_pass_cbr_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006260 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07006261 av1_rc_get_one_pass_vbr_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006262 }
Tom Finegane4099e32018-01-23 12:01:51 -08006263 return encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006264}
6265
Tom Finegane4099e32018-01-23 12:01:51 -08006266static int Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest,
6267 unsigned int *frame_flags) {
Angie Chiang5b5f4df2017-12-06 10:41:12 -08006268#if CONFIG_MISMATCH_DEBUG
6269 mismatch_move_frame_idx_w();
6270#endif
Angie Chiang4d55d762017-12-13 16:18:37 -08006271#if TXCOEFF_COST_TIMER
6272 AV1_COMMON *cm = &cpi->common;
6273 cm->txcoeff_cost_timer = 0;
6274 cm->txcoeff_cost_count = 0;
6275#endif
Tom Finegane4099e32018-01-23 12:01:51 -08006276
6277 if (encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags) !=
6278 AOM_CODEC_OK) {
6279 return AOM_CODEC_ERROR;
6280 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006281
Angie Chiang4d55d762017-12-13 16:18:37 -08006282#if TXCOEFF_COST_TIMER
6283 cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer;
6284 fprintf(stderr,
6285 "\ntxb coeff cost block number: %ld, frame time: %ld, cum time %ld "
6286 "in us\n",
6287 cm->txcoeff_cost_count, cm->txcoeff_cost_timer,
6288 cm->cum_txcoeff_cost_timer);
6289#endif
6290
Yaowu Xuc27fc142016-08-22 16:08:15 -07006291 // Do not do post-encoding update for those frames that do not have a spot in
6292 // a gf group, but note that an OVERLAY frame always has a spot in a gf group,
6293 // even when show_existing_frame is used.
6294 if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006295 av1_twopass_postencode_update(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006296 }
6297 check_show_existing_frame(cpi);
Tom Finegane4099e32018-01-23 12:01:51 -08006298 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006299}
6300
James Zern3e2613b2017-03-30 23:14:40 -07006301int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
Yaowu Xuf883b422016-08-30 14:01:10 -07006302 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
6303 int64_t end_time) {
6304 AV1_COMMON *const cm = &cpi->common;
6305 struct aom_usec_timer timer;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006306 int res = 0;
6307 const int subsampling_x = sd->subsampling_x;
6308 const int subsampling_y = sd->subsampling_y;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006309 const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006310
Yaowu Xuc27fc142016-08-22 16:08:15 -07006311 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006312
Yaowu Xuf883b422016-08-30 14:01:10 -07006313 aom_usec_timer_start(&timer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006314
Yaowu Xuf883b422016-08-30 14:01:10 -07006315 if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
Yaowu Xud3e7c682017-12-21 14:08:25 -08006316 use_highbitdepth, frame_flags))
Yaowu Xuc27fc142016-08-22 16:08:15 -07006317 res = -1;
Yaowu Xuf883b422016-08-30 14:01:10 -07006318 aom_usec_timer_mark(&timer);
6319 cpi->time_receive_data += aom_usec_timer_elapsed(&timer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006320
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006321 if ((cm->profile == PROFILE_0) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07006322 (subsampling_x != 1 || subsampling_y != 1)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006323 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006324 "Non-4:2:0 color format requires profile 1 or 2");
Yaowu Xuc27fc142016-08-22 16:08:15 -07006325 res = -1;
6326 }
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006327 if ((cm->profile == PROFILE_1) &&
6328 !(subsampling_x == 0 && subsampling_y == 0)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006329 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006330 "Profile 1 requires 4:4:4 color format");
6331 res = -1;
6332 }
6333 if ((cm->profile == PROFILE_2) && (cm->bit_depth <= AOM_BITS_10) &&
6334 !(subsampling_x == 1 && subsampling_y == 0)) {
6335 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
6336 "Profile 2 bit-depth < 10 requires 4:2:2 color format");
Yaowu Xuc27fc142016-08-22 16:08:15 -07006337 res = -1;
6338 }
6339
6340 return res;
6341}
6342
Yaowu Xuf883b422016-08-30 14:01:10 -07006343static int frame_is_reference(const AV1_COMP *cpi) {
6344 const AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006345
6346 return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame ||
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006347 cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame ||
6348 cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame ||
6349 !cm->error_resilient_mode || cm->lf.mode_ref_delta_update ||
6350 cm->seg.update_map || cm->seg.update_data;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006351}
6352
Yaowu Xuf883b422016-08-30 14:01:10 -07006353static void adjust_frame_rate(AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006354 const struct lookahead_entry *source) {
6355 int64_t this_duration;
6356 int step = 0;
6357
6358 if (source->ts_start == cpi->first_time_stamp_ever) {
6359 this_duration = source->ts_end - source->ts_start;
6360 step = 1;
6361 } else {
6362 int64_t last_duration =
6363 cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen;
6364
6365 this_duration = source->ts_end - cpi->last_end_time_stamp_seen;
6366
6367 // do a step update if the duration changes by 10%
6368 if (last_duration)
6369 step = (int)((this_duration - last_duration) * 10 / last_duration);
6370 }
6371
6372 if (this_duration) {
6373 if (step) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006374 av1_new_framerate(cpi, 10000000.0 / this_duration);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006375 } else {
6376 // Average this frame's rate into the last second's average
6377 // frame rate. If we haven't seen 1 second yet, then average
6378 // over the whole interval seen.
Yaowu Xuf883b422016-08-30 14:01:10 -07006379 const double interval = AOMMIN(
Yaowu Xuc27fc142016-08-22 16:08:15 -07006380 (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0);
6381 double avg_duration = 10000000.0 / cpi->framerate;
6382 avg_duration *= (interval - avg_duration + this_duration);
6383 avg_duration /= interval;
6384
Yaowu Xuf883b422016-08-30 14:01:10 -07006385 av1_new_framerate(cpi, 10000000.0 / avg_duration);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006386 }
6387 }
6388 cpi->last_time_stamp_seen = source->ts_start;
6389 cpi->last_end_time_stamp_seen = source->ts_end;
6390}
6391
6392// Returns 0 if this is not an alt ref else the offset of the source frame
6393// used as the arf midpoint.
Yaowu Xuf883b422016-08-30 14:01:10 -07006394static int get_arf_src_index(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006395 RATE_CONTROL *const rc = &cpi->rc;
6396 int arf_src_index = 0;
6397 if (is_altref_enabled(cpi)) {
6398 if (cpi->oxcf.pass == 2) {
6399 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6400 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
6401 arf_src_index = gf_group->arf_src_offset[gf_group->index];
6402 }
6403 } else if (rc->source_alt_ref_pending) {
6404 arf_src_index = rc->frames_till_gf_update_due;
6405 }
6406 }
6407 return arf_src_index;
6408}
6409
Yaowu Xuf883b422016-08-30 14:01:10 -07006410static int get_brf_src_index(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006411 int brf_src_index = 0;
6412 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6413
6414 // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup
6415 // flag.
6416 if (gf_group->bidir_pred_enabled[gf_group->index]) {
6417 if (cpi->oxcf.pass == 2) {
6418 if (gf_group->update_type[gf_group->index] == BRF_UPDATE)
6419 brf_src_index = gf_group->brf_src_offset[gf_group->index];
6420 } else {
6421 // TODO(zoeliu): To re-visit the setup for this scenario
6422 brf_src_index = cpi->rc.bipred_group_interval - 1;
6423 }
6424 }
6425
6426 return brf_src_index;
6427}
Zoe Liue9b15e22017-07-19 15:53:01 -07006428
Zoe Liue9b15e22017-07-19 15:53:01 -07006429// Returns 0 if this is not an alt ref else the offset of the source frame
6430// used as the arf midpoint.
6431static int get_arf2_src_index(AV1_COMP *cpi) {
6432 int arf2_src_index = 0;
6433 if (is_altref_enabled(cpi) && cpi->num_extra_arfs) {
6434 if (cpi->oxcf.pass == 2) {
6435 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6436 if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) {
6437 arf2_src_index = gf_group->arf_src_offset[gf_group->index];
6438 }
6439 }
6440 }
6441 return arf2_src_index;
6442}
Yaowu Xuc27fc142016-08-22 16:08:15 -07006443
Yaowu Xuf883b422016-08-30 14:01:10 -07006444static void check_src_altref(AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006445 const struct lookahead_entry *source) {
6446 RATE_CONTROL *const rc = &cpi->rc;
6447
6448 // If pass == 2, the parameters set here will be reset in
Yaowu Xuf883b422016-08-30 14:01:10 -07006449 // av1_rc_get_second_pass_params()
Yaowu Xuc27fc142016-08-22 16:08:15 -07006450
6451 if (cpi->oxcf.pass == 2) {
6452 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6453 rc->is_src_frame_alt_ref =
Yaowu Xuc27fc142016-08-22 16:08:15 -07006454 (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07006455 (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE);
Zoe Liue9b15e22017-07-19 15:53:01 -07006456 rc->is_src_frame_ext_arf =
6457 gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006458 } else {
6459 rc->is_src_frame_alt_ref =
6460 cpi->alt_ref_source && (source == cpi->alt_ref_source);
6461 }
6462
6463 if (rc->is_src_frame_alt_ref) {
6464 // Current frame is an ARF overlay frame.
6465 cpi->alt_ref_source = NULL;
6466
Zoe Liue9b15e22017-07-19 15:53:01 -07006467 if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) {
6468 // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to
6469 // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3,
6470 // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST.
6471 cpi->refresh_last_frame = 1;
6472 } else {
Zoe Liue9b15e22017-07-19 15:53:01 -07006473 // Don't refresh the last buffer for an ARF overlay frame. It will
6474 // become the GF so preserve last as an alternative prediction option.
6475 cpi->refresh_last_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006476 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006477 }
6478}
6479
6480#if CONFIG_INTERNAL_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -07006481extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch,
6482 const unsigned char *img2, int img2_pitch,
6483 int width, int height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006484
6485static void adjust_image_stat(double y, double u, double v, double all,
6486 ImageStat *s) {
6487 s->stat[Y] += y;
6488 s->stat[U] += u;
6489 s->stat[V] += v;
6490 s->stat[ALL] += all;
Yaowu Xuf883b422016-08-30 14:01:10 -07006491 s->worst = AOMMIN(s->worst, all);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006492}
6493
Angie Chiang08a22a62017-07-17 17:29:17 -07006494static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006495 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006496 double samples = 0.0;
6497 uint32_t in_bit_depth = 8;
6498 uint32_t bit_depth = 8;
6499
Angie Chiang08a22a62017-07-17 17:29:17 -07006500#if CONFIG_INTER_STATS_ONLY
Yaowu Xu1b4ffc42017-07-26 09:54:07 -07006501 if (cm->frame_type == KEY_FRAME) return; // skip key frame
Angie Chiang08a22a62017-07-17 17:29:17 -07006502#endif
6503 cpi->bytes += frame_bytes;
6504
Yaowu Xuc27fc142016-08-22 16:08:15 -07006505 if (cm->use_highbitdepth) {
6506 in_bit_depth = cpi->oxcf.input_bit_depth;
6507 bit_depth = cm->bit_depth;
6508 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006509 if (cm->show_frame) {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006510 const YV12_BUFFER_CONFIG *orig = cpi->source;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006511 const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
6512 double y, u, v, frame_all;
6513
6514 cpi->count++;
6515 if (cpi->b_calculate_psnr) {
6516 PSNR_STATS psnr;
6517 double frame_ssim2 = 0.0, weight = 0.0;
Yaowu Xuf883b422016-08-30 14:01:10 -07006518 aom_clear_system_state();
Yaowu Xud3e7c682017-12-21 14:08:25 -08006519 // TODO(yaowu): unify these two versions into one.
Yaowu Xuf883b422016-08-30 14:01:10 -07006520 aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006521
6522 adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0],
6523 &cpi->psnr);
6524 cpi->total_sq_error += psnr.sse[0];
6525 cpi->total_samples += psnr.samples[0];
6526 samples = psnr.samples[0];
Yaowu Xud3e7c682017-12-21 14:08:25 -08006527 // TODO(yaowu): unify these two versions into one.
Yaowu Xuc27fc142016-08-22 16:08:15 -07006528 if (cm->use_highbitdepth)
6529 frame_ssim2 =
Yaowu Xuf883b422016-08-30 14:01:10 -07006530 aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006531 else
Yaowu Xuf883b422016-08-30 14:01:10 -07006532 frame_ssim2 = aom_calc_ssim(orig, recon, &weight);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006533
Yaowu Xuf883b422016-08-30 14:01:10 -07006534 cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006535 cpi->summed_quality += frame_ssim2 * weight;
6536 cpi->summed_weights += weight;
6537
6538#if 0
6539 {
6540 FILE *f = fopen("q_used.stt", "a");
Zoe Liuee202be2017-11-17 12:14:33 -08006541 double y2 = psnr.psnr[1];
6542 double u2 = psnr.psnr[2];
6543 double v2 = psnr.psnr[3];
6544 double frame_psnr2 = psnr.psnr[0];
Yaowu Xuc27fc142016-08-22 16:08:15 -07006545 fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n",
Zoe Liuee202be2017-11-17 12:14:33 -08006546 cm->current_video_frame, y2, u2, v2,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006547 frame_psnr2, frame_ssim2);
6548 fclose(f);
6549 }
6550#endif
6551 }
6552 if (cpi->b_calculate_blockiness) {
Yaowu Xud3e7c682017-12-21 14:08:25 -08006553 if (!cm->use_highbitdepth) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006554 const double frame_blockiness =
Yaowu Xuf883b422016-08-30 14:01:10 -07006555 av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer,
6556 recon->y_stride, orig->y_width, orig->y_height);
6557 cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006558 cpi->total_blockiness += frame_blockiness;
6559 }
6560
6561 if (cpi->b_calculate_consistency) {
Yaowu Xud3e7c682017-12-21 14:08:25 -08006562 if (!cm->use_highbitdepth) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006563 const double this_inconsistency = aom_get_ssim_metrics(
Yaowu Xuc27fc142016-08-22 16:08:15 -07006564 orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride,
6565 orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1);
6566
6567 const double peak = (double)((1 << in_bit_depth) - 1);
6568 const double consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07006569 aom_sse_to_psnr(samples, peak, cpi->total_inconsistency);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006570 if (consistency > 0.0)
6571 cpi->worst_consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07006572 AOMMIN(cpi->worst_consistency, consistency);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006573 cpi->total_inconsistency += this_inconsistency;
6574 }
6575 }
6576 }
6577
6578 frame_all =
Yaowu Xuf883b422016-08-30 14:01:10 -07006579 aom_calc_fastssim(orig, recon, &y, &u, &v, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006580 adjust_image_stat(y, u, v, frame_all, &cpi->fastssim);
Yaowu Xuf883b422016-08-30 14:01:10 -07006581 frame_all = aom_psnrhvs(orig, recon, &y, &u, &v, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006582 adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs);
6583 }
6584}
6585#endif // CONFIG_INTERNAL_STATS
6586
RogerZhou3b635242017-09-19 10:06:46 -07006587#if CONFIG_AMVR
6588static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture,
6589 const YV12_BUFFER_CONFIG *last_picture,
6590 hash_table *last_hash_table) {
6591 aom_clear_system_state();
6592 // check use hash ME
6593 int k;
6594 uint32_t hash_value_1;
6595 uint32_t hash_value_2;
6596
6597 const int block_size = 8;
6598 const double threshold_current = 0.8;
6599 const double threshold_average = 0.95;
6600 const int max_history_size = 32;
6601 int T = 0; // total block
6602 int C = 0; // match with collocated block
6603 int S = 0; // smooth region but not match with collocated block
6604 int M = 0; // match with other block
6605
6606 const int pic_width = cur_picture->y_width;
6607 const int pic_height = cur_picture->y_height;
6608 for (int i = 0; i + block_size <= pic_height; i += block_size) {
6609 for (int j = 0; j + block_size <= pic_width; j += block_size) {
6610 const int x_pos = j;
6611 const int y_pos = i;
6612 int match = 1;
6613 T++;
6614
6615 // check whether collocated block match with current
6616 uint8_t *p_cur = cur_picture->y_buffer;
6617 uint8_t *p_ref = last_picture->y_buffer;
6618 int stride_cur = cur_picture->y_stride;
6619 int stride_ref = last_picture->y_stride;
6620 p_cur += (y_pos * stride_cur + x_pos);
6621 p_ref += (y_pos * stride_ref + x_pos);
6622
6623 for (int tmpY = 0; tmpY < block_size && match; tmpY++) {
6624 for (int tmpX = 0; tmpX < block_size && match; tmpX++) {
6625 if (p_cur[tmpX] != p_ref[tmpX]) {
6626 match = 0;
6627 }
6628 }
6629 p_cur += stride_cur;
6630 p_ref += stride_ref;
6631 }
6632
6633 if (match) {
6634 C++;
6635 continue;
6636 }
6637
6638 if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos,
6639 y_pos) ||
6640 av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) {
6641 S++;
6642 continue;
6643 }
6644
6645 av1_get_block_hash_value(
6646 cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur,
6647 block_size, &hash_value_1, &hash_value_2);
6648
6649 if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) {
6650 M++;
6651 }
6652 }
6653 }
6654
6655 assert(T > 0);
6656 double csm_rate = ((double)(C + S + M)) / ((double)(T));
6657 double m_rate = ((double)(M)) / ((double)(T));
6658
6659 cpi->csm_rate_array[cpi->rate_index] = csm_rate;
6660 cpi->m_rate_array[cpi->rate_index] = m_rate;
6661
6662 cpi->rate_index = (cpi->rate_index + 1) % max_history_size;
6663 cpi->rate_size++;
6664 cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size);
6665
6666 if (csm_rate < threshold_current) {
6667 return 0;
6668 }
6669
6670 if (C == T) {
6671 return 1;
6672 }
6673
6674 double csm_average = 0.0;
6675 double m_average = 0.0;
6676
6677 for (k = 0; k < cpi->rate_size; k++) {
6678 csm_average += cpi->csm_rate_array[k];
6679 m_average += cpi->m_rate_array[k];
6680 }
6681 csm_average /= cpi->rate_size;
6682 m_average /= cpi->rate_size;
6683
6684 if (csm_average < threshold_average) {
6685 return 0;
6686 }
6687
6688 if (M > (T - C - S) / 3) {
6689 return 1;
6690 }
6691
6692 if (csm_rate > 0.99 && m_rate > 0.01) {
6693 return 1;
6694 }
6695
6696 if (csm_average + m_average > 1.01) {
6697 return 1;
6698 }
6699
6700 return 0;
6701}
6702#endif
6703
Yaowu Xuf883b422016-08-30 14:01:10 -07006704int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
6705 size_t *size, uint8_t *dest, int64_t *time_stamp,
6706 int64_t *time_end, int flush) {
6707 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
6708 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006709 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006710 BufferPool *const pool = cm->buffer_pool;
6711 RATE_CONTROL *const rc = &cpi->rc;
Yaowu Xuf883b422016-08-30 14:01:10 -07006712 struct aom_usec_timer cmptimer;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006713 YV12_BUFFER_CONFIG *force_src_buffer = NULL;
6714 struct lookahead_entry *last_source = NULL;
6715 struct lookahead_entry *source = NULL;
6716 int arf_src_index;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006717 int brf_src_index;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006718 int i;
6719
6720#if CONFIG_BITSTREAM_DEBUG
6721 assert(cpi->oxcf.max_threads == 0 &&
6722 "bitstream debug tool does not support multithreading");
6723 bitstream_queue_record_write();
Angie Chiangcb9a9eb2016-09-01 16:10:50 -07006724 bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006725#endif
6726
Yaowu Xuf883b422016-08-30 14:01:10 -07006727 aom_usec_timer_start(&cmptimer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006728
RogerZhou3b635242017-09-19 10:06:46 -07006729#if CONFIG_AMVR
6730 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0);
6731#else
Cheng Chen46f30c72017-09-07 11:13:33 -07006732 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
RogerZhou3b635242017-09-19 10:06:46 -07006733#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006734
6735 // Is multi-arf enabled.
6736 // Note that at the moment multi_arf is only configured for 2 pass VBR
6737 if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1))
6738 cpi->multi_arf_allowed = 1;
6739 else
6740 cpi->multi_arf_allowed = 0;
6741
Thomas Daedea6a854b2017-06-22 17:49:11 -07006742// Normal defaults
6743#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07006744 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
Thomas Daedea6a854b2017-06-22 17:49:11 -07006745#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006746 cm->refresh_frame_context =
6747 (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode)
James Zernf34dfc82018-02-23 16:53:33 -08006748 ? REFRESH_FRAME_CONTEXT_DISABLED
Yaowu Xuc27fc142016-08-22 16:08:15 -07006749 : REFRESH_FRAME_CONTEXT_BACKWARD;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01006750#if CONFIG_EXT_TILE
6751 if (oxcf->large_scale_tile)
James Zernf34dfc82018-02-23 16:53:33 -08006752 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01006753#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07006754
6755 cpi->refresh_last_frame = 1;
6756 cpi->refresh_golden_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006757 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006758 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006759 cpi->refresh_alt_ref_frame = 0;
6760
Zoe Liub4991202017-12-21 15:31:06 -08006761#if CONFIG_FWD_KF
6762 // TODO(zoeliu@gmail.com): To support forward-KEY_FRAME and set up the
6763 // following flag accordingly.
6764 cm->reset_decoder_state = 0;
6765#endif // CONFIG_FWD_KF
6766
Yaowu Xuc27fc142016-08-22 16:08:15 -07006767 if (oxcf->pass == 2 && cm->show_existing_frame) {
6768 // Manage the source buffer and flush out the source frame that has been
6769 // coded already; Also get prepared for PSNR calculation if needed.
Yaowu Xuf883b422016-08-30 14:01:10 -07006770 if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006771 *size = 0;
6772 return -1;
6773 }
Alex Conversef77fd0b2017-04-20 11:00:24 -07006774 cpi->source = &source->img;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006775 // TODO(zoeliu): To track down to determine whether it's needed to adjust
6776 // the frame rate.
6777 *time_stamp = source->ts_start;
6778 *time_end = source->ts_end;
6779
6780 // We need to adjust frame rate for an overlay frame
Zoe Liue04abf72017-04-19 15:37:11 -07006781 if (cpi->rc.is_src_frame_alt_ref) adjust_frame_rate(cpi, source);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006782
6783 // Find a free buffer for the new frame, releasing the reference previously
6784 // held.
6785 if (cm->new_fb_idx != INVALID_IDX) {
6786 --pool->frame_bufs[cm->new_fb_idx].ref_count;
6787 }
6788 cm->new_fb_idx = get_free_fb(cm);
6789
6790 if (cm->new_fb_idx == INVALID_IDX) return -1;
6791
6792 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006793 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006794
6795 // Start with a 0 size frame.
6796 *size = 0;
6797
6798 // We need to update the gf_group for show_existing overlay frame
Zoe Liue04abf72017-04-19 15:37:11 -07006799 if (cpi->rc.is_src_frame_alt_ref) av1_rc_get_second_pass_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006800
Tom Finegane4099e32018-01-23 12:01:51 -08006801 if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK)
6802 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006803
6804 if (cpi->b_calculate_psnr) generate_psnr_packet(cpi);
6805
6806#if CONFIG_INTERNAL_STATS
Angie Chiang08a22a62017-07-17 17:29:17 -07006807 compute_internal_stats(cpi, (int)(*size));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006808#endif // CONFIG_INTERNAL_STATS
6809
6810 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006811 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006812
6813 cm->show_existing_frame = 0;
6814 return 0;
6815 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006816
6817 // Should we encode an arf frame.
6818 arf_src_index = get_arf_src_index(cpi);
6819 if (arf_src_index) {
6820 for (i = 0; i <= arf_src_index; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006821 struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006822 // Avoid creating an alt-ref if there's a forced keyframe pending.
6823 if (e == NULL) {
6824 break;
Yaowu Xuf883b422016-08-30 14:01:10 -07006825 } else if (e->flags == AOM_EFLAG_FORCE_KF) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006826 arf_src_index = 0;
6827 flush = 1;
6828 break;
6829 }
6830 }
6831 }
6832
6833 if (arf_src_index) {
6834 assert(arf_src_index <= rc->frames_to_key);
6835
Yaowu Xuf883b422016-08-30 14:01:10 -07006836 if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006837 cpi->alt_ref_source = source;
6838
6839 if (oxcf->arnr_max_frames > 0) {
Sebastien Alaiwan6697acf2018-02-21 16:59:17 +01006840 // Produce the filtered ARF frame.
6841 av1_temporal_filter(cpi, arf_src_index);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006842 aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006843 force_src_buffer = &cpi->alt_ref_buffer;
6844 }
6845
6846 cm->show_frame = 0;
6847 cm->intra_only = 0;
6848 cpi->refresh_alt_ref_frame = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006849 cpi->refresh_last_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006850 cpi->refresh_golden_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006851 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006852 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006853 rc->is_src_frame_alt_ref = 0;
6854 }
6855 rc->source_alt_ref_pending = 0;
6856 }
6857
Zoe Liue9b15e22017-07-19 15:53:01 -07006858 // Should we encode an arf2 frame.
6859 arf_src_index = get_arf2_src_index(cpi);
6860 if (arf_src_index) {
6861 for (i = 0; i <= arf_src_index; ++i) {
6862 struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i);
6863 // Avoid creating an alt-ref if there's a forced keyframe pending.
6864 if (e == NULL) {
6865 break;
6866 } else if (e->flags == AOM_EFLAG_FORCE_KF) {
6867 arf_src_index = 0;
6868 flush = 1;
6869 break;
6870 }
6871 }
6872 }
6873
6874 if (arf_src_index) {
6875 assert(arf_src_index <= rc->frames_to_key);
6876
6877 if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
6878 cpi->alt_ref_source = source;
6879
6880 if (oxcf->arnr_max_frames > 0) {
6881 // Produce the filtered ARF frame.
Sebastien Alaiwan6697acf2018-02-21 16:59:17 +01006882 av1_temporal_filter(cpi, arf_src_index);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006883 aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes);
Zoe Liue9b15e22017-07-19 15:53:01 -07006884 force_src_buffer = &cpi->alt_ref_buffer;
6885 }
6886
6887 cm->show_frame = 0;
6888 cm->intra_only = 0;
6889 cpi->refresh_alt2_ref_frame = 1;
6890 cpi->refresh_last_frame = 0;
6891 cpi->refresh_golden_frame = 0;
6892 cpi->refresh_bwd_ref_frame = 0;
6893 cpi->refresh_alt_ref_frame = 0;
6894 rc->is_src_frame_alt_ref = 0;
6895 rc->is_src_frame_ext_arf = 0;
6896 }
6897 rc->source_alt_ref_pending = 0;
6898 }
Zoe Liue9b15e22017-07-19 15:53:01 -07006899
Yaowu Xuc27fc142016-08-22 16:08:15 -07006900 rc->is_bwd_ref_frame = 0;
6901 brf_src_index = get_brf_src_index(cpi);
6902 if (brf_src_index) {
6903 assert(brf_src_index <= rc->frames_to_key);
Yaowu Xuf883b422016-08-30 14:01:10 -07006904 if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006905 cm->show_frame = 0;
6906 cm->intra_only = 0;
6907
6908 cpi->refresh_bwd_ref_frame = 1;
6909 cpi->refresh_last_frame = 0;
6910 cpi->refresh_golden_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006911 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006912 cpi->refresh_alt_ref_frame = 0;
6913
6914 rc->is_bwd_ref_frame = 1;
6915 }
6916 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006917
6918 if (!source) {
6919 // Get last frame source.
6920 if (cm->current_video_frame > 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006921 if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL)
Yaowu Xuc27fc142016-08-22 16:08:15 -07006922 return -1;
6923 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07006924 if (cm->current_video_frame > 0) assert(last_source != NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006925 // Read in the source frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07006926 source = av1_lookahead_pop(cpi->lookahead, flush);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006927
6928 if (source != NULL) {
6929 cm->show_frame = 1;
6930 cm->intra_only = 0;
6931
6932 // Check to see if the frame should be encoded as an arf overlay.
6933 check_src_altref(cpi, source);
6934 }
6935 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006936 if (source) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07006937 cpi->unscaled_source = cpi->source =
Yaowu Xuc27fc142016-08-22 16:08:15 -07006938 force_src_buffer ? force_src_buffer : &source->img;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006939 cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL;
6940
6941 *time_stamp = source->ts_start;
6942 *time_end = source->ts_end;
Yaowu Xuf883b422016-08-30 14:01:10 -07006943 *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006944
6945 } else {
6946 *size = 0;
6947 if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006948 av1_end_first_pass(cpi); /* get last stats packet */
Yaowu Xuc27fc142016-08-22 16:08:15 -07006949 cpi->twopass.first_pass_done = 1;
6950 }
6951 return -1;
6952 }
6953
6954 if (source->ts_start < cpi->first_time_stamp_ever) {
6955 cpi->first_time_stamp_ever = source->ts_start;
6956 cpi->last_end_time_stamp_seen = source->ts_start;
6957 }
6958
6959 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006960 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006961
6962 // adjust frame rates based on timestamps given
6963 if (cm->show_frame) adjust_frame_rate(cpi, source);
6964
6965 // Find a free buffer for the new frame, releasing the reference previously
6966 // held.
6967 if (cm->new_fb_idx != INVALID_IDX) {
6968 --pool->frame_bufs[cm->new_fb_idx].ref_count;
6969 }
6970 cm->new_fb_idx = get_free_fb(cm);
6971
6972 if (cm->new_fb_idx == INVALID_IDX) return -1;
6973
Zoe Liuf452fdf2017-11-02 23:08:12 -07006974 // Retain the RF_LEVEL for the current newly coded frame.
6975 cpi->frame_rf_level[cm->new_fb_idx] =
6976 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
Zoe Liuf452fdf2017-11-02 23:08:12 -07006977
Yaowu Xuc27fc142016-08-22 16:08:15 -07006978 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
Yaowu Xu9b0f7032017-07-31 11:01:19 -07006979 cm->cur_frame->buf.buf_8bit_valid = 0;
Zoe Liu6cfaff92016-10-18 17:12:11 -07006980
Yaowu Xuc27fc142016-08-22 16:08:15 -07006981 // Start with a 0 size frame.
6982 *size = 0;
6983
6984 cpi->frame_flags = *frame_flags;
6985
6986 if (oxcf->pass == 2) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006987 av1_rc_get_second_pass_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006988 } else if (oxcf->pass == 1) {
Fergus Simpsonbc189932017-05-16 17:02:39 -07006989 setup_frame_size(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006990 }
6991
6992 if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) {
6993 for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i)
6994 cpi->scaled_ref_idx[i] = INVALID_IDX;
6995 }
6996
6997#if CONFIG_AOM_QM
6998 cm->using_qmatrix = cpi->oxcf.using_qm;
6999 cm->min_qmlevel = cpi->oxcf.qm_minlevel;
7000 cm->max_qmlevel = cpi->oxcf.qm_maxlevel;
7001#endif
7002
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01007003#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01007004 if (cm->seq_params.frame_id_numbers_present_flag) {
Debargha Mukherjee778023d2017-09-26 17:50:27 -07007005 if (*time_stamp == 0) {
7006 cpi->common.current_frame_id = -1;
7007 }
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01007008 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07007009#endif // CONFIG_REFERENCE_BUFFER
RogerZhou3b635242017-09-19 10:06:46 -07007010#if CONFIG_AMVR
7011 cpi->cur_poc++;
7012 if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) {
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00007013 if (cpi->common.seq_params.force_integer_mv == 2) {
RogerZhou3b635242017-09-19 10:06:46 -07007014 struct lookahead_entry *previous_entry =
7015 cpi->lookahead->buf + cpi->previsous_index;
RogerZhou10a03802017-10-26 11:49:48 -07007016 cpi->common.cur_frame_force_integer_mv = is_integer_mv(
RogerZhou3b635242017-09-19 10:06:46 -07007017 cpi, cpi->source, &previous_entry->img, cpi->previsou_hash_table);
7018 } else {
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00007019 cpi->common.cur_frame_force_integer_mv =
7020 cpi->common.seq_params.force_integer_mv;
RogerZhou3b635242017-09-19 10:06:46 -07007021 }
7022 } else {
RogerZhou10a03802017-10-26 11:49:48 -07007023 cpi->common.cur_frame_force_integer_mv = 0;
RogerZhou3b635242017-09-19 10:06:46 -07007024 }
7025#endif
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01007026
Yaowu Xuc27fc142016-08-22 16:08:15 -07007027 if (oxcf->pass == 1) {
7028 cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf);
Yaowu Xuf883b422016-08-30 14:01:10 -07007029 av1_first_pass(cpi, source);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007030 } else if (oxcf->pass == 2) {
Tom Finegane4099e32018-01-23 12:01:51 -08007031 if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK)
7032 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007033 } else {
7034 // One pass encode
Tom Finegane4099e32018-01-23 12:01:51 -08007035 if (Pass0Encode(cpi, size, dest, 0, frame_flags) != AOM_CODEC_OK)
7036 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007037 }
RogerZhoucc5d35d2017-08-07 22:20:15 -07007038#if CONFIG_HASH_ME
7039 if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) {
RogerZhou3b635242017-09-19 10:06:46 -07007040#if CONFIG_AMVR
7041 cpi->previsou_hash_table = &cm->cur_frame->hash_table;
7042 {
7043 int l;
7044 for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) {
7045 if ((cpi->lookahead->buf + l) == source) {
7046 cpi->previsous_index = l;
7047 break;
7048 }
7049 }
7050
7051 if (l == cpi->lookahead->max_sz) {
7052 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
7053 "Failed to find last frame original buffer");
7054 }
7055 }
7056#endif
RogerZhoucc5d35d2017-08-07 22:20:15 -07007057 }
7058
7059#endif
7060
Yunqing Wang267e3272017-11-09 14:23:22 -08007061#if CONFIG_EXT_TILE
7062 if (!cm->large_scale_tile) {
7063#endif // CONFIG_EXT_TILE
Thomas Daededa4d8b92017-06-05 15:44:14 -07007064#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yunqing Wang267e3272017-11-09 14:23:22 -08007065 cm->frame_contexts[cm->new_fb_idx] = *cm->fc;
Thomas Daededa4d8b92017-06-05 15:44:14 -07007066#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07007067 if (!cm->error_resilient_mode)
7068 cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
Thomas Daededa4d8b92017-06-05 15:44:14 -07007069#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yunqing Wang267e3272017-11-09 14:23:22 -08007070#if CONFIG_EXT_TILE
7071 }
7072#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07007073
Yunqing Wangb041d8a2017-11-15 12:31:18 -08007074#if CONFIG_EXT_TILE
7075#define EXT_TILE_DEBUG 0
7076#if EXT_TILE_DEBUG
7077 if (cm->large_scale_tile && oxcf->pass == 2) {
7078 char fn[20] = "./fc";
7079 fn[4] = cm->current_video_frame / 100 + '0';
7080 fn[5] = (cm->current_video_frame % 100) / 10 + '0';
7081 fn[6] = (cm->current_video_frame % 10) + '0';
7082 fn[7] = '\0';
7083 av1_print_frame_contexts(cm->fc, fn);
7084 }
7085#endif // EXT_TILE_DEBUG
7086#undef EXT_TILE_DEBUG
7087#endif // CONFIG_EXT_TILE
7088
Yaowu Xuc27fc142016-08-22 16:08:15 -07007089 // No frame encoded, or frame was dropped, release scaled references.
7090 if ((*size == 0) && (frame_is_intra_only(cm) == 0)) {
7091 release_scaled_references(cpi);
7092 }
7093
7094 if (*size > 0) {
7095 cpi->droppable = !frame_is_reference(cpi);
7096 }
7097
Yaowu Xuf883b422016-08-30 14:01:10 -07007098 aom_usec_timer_mark(&cmptimer);
7099 cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007100
7101 if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame)
7102 generate_psnr_packet(cpi);
7103
7104#if CONFIG_INTERNAL_STATS
7105 if (oxcf->pass != 1) {
Angie Chiang08a22a62017-07-17 17:29:17 -07007106 compute_internal_stats(cpi, (int)(*size));
Yaowu Xuc27fc142016-08-22 16:08:15 -07007107 }
7108#endif // CONFIG_INTERNAL_STATS
7109
Yaowu Xuf883b422016-08-30 14:01:10 -07007110 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07007111
7112 return 0;
7113}
7114
Yaowu Xuf883b422016-08-30 14:01:10 -07007115int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) {
7116 AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007117 if (!cm->show_frame) {
7118 return -1;
7119 } else {
7120 int ret;
7121 if (cm->frame_to_show) {
7122 *dest = *cm->frame_to_show;
7123 dest->y_width = cm->width;
7124 dest->y_height = cm->height;
7125 dest->uv_width = cm->width >> cm->subsampling_x;
7126 dest->uv_height = cm->height >> cm->subsampling_y;
7127 ret = 0;
7128 } else {
7129 ret = -1;
7130 }
Yaowu Xuf883b422016-08-30 14:01:10 -07007131 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07007132 return ret;
7133 }
7134}
7135
Yaowu Xuf883b422016-08-30 14:01:10 -07007136int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07007137 if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1;
7138
7139 *frame =
7140 cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf;
7141 return 0;
7142}
7143
Yaowu Xuf883b422016-08-30 14:01:10 -07007144int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
7145 AOM_SCALING vert_mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07007146 int hr = 0, hs = 0, vr = 0, vs = 0;
7147
7148 if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1;
7149
7150 Scale2Ratio(horiz_mode, &hr, &hs);
7151 Scale2Ratio(vert_mode, &vr, &vs);
7152
7153 // always go to the next whole number
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07007154 cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs;
7155 cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007156
7157 return 0;
7158}
7159
Yaowu Xuf883b422016-08-30 14:01:10 -07007160int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007161
Yaowu Xuf883b422016-08-30 14:01:10 -07007162void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) {
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007163 // TODO(yunqingwang): For what references to use, external encoding flags
7164 // should be consistent with internal reference frame selection. Need to
7165 // ensure that there is not conflict between the two. In AV1 encoder, the
7166 // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3,
7167 // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be
7168 // LAST.
Yunqing Wangf2e7a392017-11-08 00:27:21 -08007169 cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007170 if (flags &
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007171 (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
7172 AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD |
7173 AOM_EFLAG_NO_REF_ARF2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07007174 if (flags & AOM_EFLAG_NO_REF_LAST) {
Yunqing Wangf2e7a392017-11-08 00:27:21 -08007175 cpi->ext_ref_frame_flags = 0;
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007176 } else {
7177 int ref = AOM_REFFRAME_ALL;
7178
7179 if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG;
7180 if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG;
7181
7182 if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG;
7183
7184 if (flags & AOM_EFLAG_NO_REF_ARF) {
7185 ref ^= AOM_ALT_FLAG;
7186 ref ^= AOM_BWD_FLAG;
7187 ref ^= AOM_ALT2_FLAG;
7188 } else {
7189 if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG;
7190 if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG;
7191 }
7192
7193 av1_use_as_reference(cpi, ref);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007194 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007195 }
7196
7197 if (flags &
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007198 (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07007199 int upd = AOM_REFFRAME_ALL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007200
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007201 // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag.
7202 if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007203
Yaowu Xuf883b422016-08-30 14:01:10 -07007204 if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007205
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007206 if (flags & AOM_EFLAG_NO_UPD_ARF) {
7207 upd ^= AOM_ALT_FLAG;
7208 upd ^= AOM_BWD_FLAG;
7209 upd ^= AOM_ALT2_FLAG;
7210 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007211
Yaowu Xuf883b422016-08-30 14:01:10 -07007212 av1_update_reference(cpi, upd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007213 }
7214
Yaowu Xuf883b422016-08-30 14:01:10 -07007215 if (flags & AOM_EFLAG_NO_UPD_ENTROPY) {
7216 av1_update_entropy(cpi, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007217 }
7218}