blob: 6e55bbb172317ad701da2886efcb74eb1381af2a [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"
Todd Nguyen302d0972017-06-16 16:16:29 -070031#if CONFIG_BGSPRITE
32#include "av1/encoder/bgsprite.h"
33#endif // CONFIG_BGSPRITE
Yaowu Xuc27fc142016-08-22 16:08:15 -070034#include "av1/encoder/context_tree.h"
35#include "av1/encoder/encodeframe.h"
36#include "av1/encoder/encodemv.h"
37#include "av1/encoder/encoder.h"
Angie Chiangf0fbf9d2017-03-15 15:01:22 -070038#if CONFIG_LV_MAP
39#include "av1/encoder/encodetxb.h"
40#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070041#include "av1/encoder/ethread.h"
42#include "av1/encoder/firstpass.h"
RogerZhoucc5d35d2017-08-07 22:20:15 -070043#if CONFIG_HASH_ME
44#include "av1/encoder/hash_motion.h"
45#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070046#include "av1/encoder/mbgraph.h"
47#include "av1/encoder/picklpf.h"
48#if CONFIG_LOOP_RESTORATION
49#include "av1/encoder/pickrst.h"
50#endif // CONFIG_LOOP_RESTORATION
Debargha Mukherjee7166f222017-09-05 21:32:42 -070051#include "av1/encoder/random.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070052#include "av1/encoder/ratectrl.h"
53#include "av1/encoder/rd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070054#include "av1/encoder/segmentation.h"
55#include "av1/encoder/speed_features.h"
56#include "av1/encoder/temporal_filter.h"
57
Yaowu Xuf883b422016-08-30 14:01:10 -070058#include "./av1_rtcd.h"
59#include "./aom_dsp_rtcd.h"
60#include "./aom_scale_rtcd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070061#include "aom_dsp/psnr.h"
62#if CONFIG_INTERNAL_STATS
63#include "aom_dsp/ssim.h"
64#endif
Andrey Norkin6f1c2f72018-01-15 20:08:52 -080065#if CONFIG_FILM_GRAIN
66#include "av1/encoder/grain_test_vectors.h"
67#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070068#include "aom_dsp/aom_dsp_common.h"
69#include "aom_dsp/aom_filter.h"
Jingning Han1aab8182016-06-03 11:09:06 -070070#include "aom_ports/aom_timer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070071#include "aom_ports/mem.h"
72#include "aom_ports/system_state.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070073#include "aom_scale/aom_scale.h"
Angie Chiang5b5f4df2017-12-06 10:41:12 -080074#if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -070075#include "aom_util/debug_util.h"
Angie Chiang5b5f4df2017-12-06 10:41:12 -080076#endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -070077
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -080078#if CONFIG_ENTROPY_STATS
79FRAME_COUNTS aggregate_fc;
Zoe Liua56f9162017-06-21 22:49:57 -070080// Aggregate frame counts per frame context type
81FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS];
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -080082#endif // CONFIG_ENTROPY_STATS
83
Yaowu Xuc27fc142016-08-22 16:08:15 -070084#define AM_SEGMENT_ID_INACTIVE 7
85#define AM_SEGMENT_ID_ACTIVE 0
86
Johannb0ef6ff2018-02-08 14:32:21 -080087// Whether to use high precision mv for altref computation.
88#define ALTREF_HIGH_PRECISION_MV 1
89
90// Q threshold for high precision mv. Choose a very high value for now so that
91// HIGH_PRECISION is always chosen.
92#define HIGH_PRECISION_MV_QTHRESH 200
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -070093
Yaowu Xuc27fc142016-08-22 16:08:15 -070094// #define OUTPUT_YUV_REC
Yaowu Xuc27fc142016-08-22 16:08:15 -070095#ifdef OUTPUT_YUV_SKINMAP
96FILE *yuv_skinmap_file = NULL;
97#endif
98#ifdef OUTPUT_YUV_REC
99FILE *yuv_rec_file;
100#define FILE_NAME_LEN 100
101#endif
102
103#if 0
104FILE *framepsnr;
105FILE *kf_list;
106FILE *keyfile;
107#endif
108
Urvang Joshib5ed3502016-10-17 16:38:05 -0700109#if CONFIG_INTERNAL_STATS
110typedef enum { Y, U, V, ALL } STAT_TYPE;
111#endif // CONFIG_INTERNAL_STATS
112
Yaowu Xuf883b422016-08-30 14:01:10 -0700113static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114 switch (mode) {
115 case NORMAL:
116 *hr = 1;
117 *hs = 1;
118 break;
119 case FOURFIVE:
120 *hr = 4;
121 *hs = 5;
122 break;
123 case THREEFIVE:
124 *hr = 3;
125 *hs = 5;
126 break;
127 case ONETWO:
128 *hr = 1;
129 *hs = 2;
130 break;
131 default:
132 *hr = 1;
133 *hs = 1;
134 assert(0);
135 break;
136 }
137}
138
139// Mark all inactive blocks as active. Other segmentation features may be set
140// so memset cannot be used, instead only inactive blocks should be reset.
Yaowu Xuf883b422016-08-30 14:01:10 -0700141static void suppress_active_map(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700142 unsigned char *const seg_map = cpi->segmentation_map;
143 int i;
144 if (cpi->active_map.enabled || cpi->active_map.update)
145 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
146 if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
147 seg_map[i] = AM_SEGMENT_ID_ACTIVE;
148}
149
Yaowu Xuf883b422016-08-30 14:01:10 -0700150static void apply_active_map(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700151 struct segmentation *const seg = &cpi->common.seg;
152 unsigned char *const seg_map = cpi->segmentation_map;
153 const unsigned char *const active_map = cpi->active_map.map;
154 int i;
155
156 assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE);
157
158 if (frame_is_intra_only(&cpi->common)) {
159 cpi->active_map.enabled = 0;
160 cpi->active_map.update = 1;
161 }
162
163 if (cpi->active_map.update) {
164 if (cpi->active_map.enabled) {
165 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
166 if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i];
Yaowu Xuf883b422016-08-30 14:01:10 -0700167 av1_enable_segmentation(seg);
168 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
Cheng Chend8184da2017-09-26 18:15:22 -0700169#if CONFIG_LOOPFILTER_LEVEL
170 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H);
171 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V);
172 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U);
173 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V);
174
175 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H,
176 -MAX_LOOP_FILTER);
177 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V,
178 -MAX_LOOP_FILTER);
179 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U,
180 -MAX_LOOP_FILTER);
181 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V,
182 -MAX_LOOP_FILTER);
183#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700184 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700185 // Setting the data to -MAX_LOOP_FILTER will result in the computed loop
Yushin Chod728c212017-11-03 12:30:24 -0700186 // filter level being zero.
Yaowu Xuf883b422016-08-30 14:01:10 -0700187 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF,
188 -MAX_LOOP_FILTER);
Cheng Chend8184da2017-09-26 18:15:22 -0700189#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700190 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700191 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
Cheng Chend8184da2017-09-26 18:15:22 -0700192#if CONFIG_LOOPFILTER_LEVEL
193 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H);
194 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V);
195 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U);
196 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V);
197#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700198 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
Cheng Chend8184da2017-09-26 18:15:22 -0700199#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700200 if (seg->enabled) {
201 seg->update_data = 1;
202 seg->update_map = 1;
203 }
204 }
205 cpi->active_map.update = 0;
206 }
207}
208
Yaowu Xuf883b422016-08-30 14:01:10 -0700209int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows,
210 int cols) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700211 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
212 unsigned char *const active_map_8x8 = cpi->active_map.map;
213 const int mi_rows = cpi->common.mi_rows;
214 const int mi_cols = cpi->common.mi_cols;
Jingning Han9d533022017-04-07 10:14:42 -0700215 const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2;
216 const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700217 cpi->active_map.update = 1;
218 if (new_map_16x16) {
219 int r, c;
220 for (r = 0; r < mi_rows; ++r) {
221 for (c = 0; c < mi_cols; ++c) {
222 active_map_8x8[r * mi_cols + c] =
Jingning Han9d533022017-04-07 10:14:42 -0700223 new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)]
Yaowu Xuc27fc142016-08-22 16:08:15 -0700224 ? AM_SEGMENT_ID_ACTIVE
225 : AM_SEGMENT_ID_INACTIVE;
226 }
227 }
228 cpi->active_map.enabled = 1;
229 } else {
230 cpi->active_map.enabled = 0;
231 }
232 return 0;
233 } else {
234 return -1;
235 }
236}
237
Yaowu Xuf883b422016-08-30 14:01:10 -0700238int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows,
239 int cols) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700240 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols &&
241 new_map_16x16) {
242 unsigned char *const seg_map_8x8 = cpi->segmentation_map;
243 const int mi_rows = cpi->common.mi_rows;
244 const int mi_cols = cpi->common.mi_cols;
Jingning Han9d533022017-04-07 10:14:42 -0700245 const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2;
246 const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2;
247
Yaowu Xuc27fc142016-08-22 16:08:15 -0700248 memset(new_map_16x16, !cpi->active_map.enabled, rows * cols);
249 if (cpi->active_map.enabled) {
250 int r, c;
251 for (r = 0; r < mi_rows; ++r) {
252 for (c = 0; c < mi_cols; ++c) {
253 // Cyclic refresh segments are considered active despite not having
254 // AM_SEGMENT_ID_ACTIVE
Jingning Han9d533022017-04-07 10:14:42 -0700255 new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |=
Yaowu Xuc27fc142016-08-22 16:08:15 -0700256 seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE;
257 }
258 }
259 }
260 return 0;
261 } else {
262 return -1;
263 }
264}
265
RogerZhou3b635242017-09-19 10:06:46 -0700266static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv
267#if CONFIG_AMVR
268 ,
RogerZhou10a03802017-10-26 11:49:48 -0700269 int cur_frame_force_integer_mv
RogerZhou3b635242017-09-19 10:06:46 -0700270#endif
Johannb0ef6ff2018-02-08 14:32:21 -0800271) {
James Zern01a9d702017-08-25 19:09:33 +0000272 MACROBLOCK *const mb = &cpi->td.mb;
273 cpi->common.allow_high_precision_mv = allow_high_precision_mv;
274
RogerZhou3b635242017-09-19 10:06:46 -0700275#if CONFIG_AMVR
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000276 const int copy_hp =
277 cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0;
RogerZhou3b635242017-09-19 10:06:46 -0700278#else
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000279 const int copy_hp = cpi->common.allow_high_precision_mv;
RogerZhou3b635242017-09-19 10:06:46 -0700280#endif
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000281 int *(*src)[2] = copy_hp ? mb->nmvcost_hp : mb->nmvcost;
282 for (int i = 0; i < NMV_CONTEXTS; ++i) {
283 mb->mv_cost_stack[i] = src[i];
James Zern01a9d702017-08-25 19:09:33 +0000284 }
285}
286
Yaowu Xuf883b422016-08-30 14:01:10 -0700287static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700288#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700289 if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700290 return BLOCK_64X64;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100291#if CONFIG_FILEOPTIONS
292 if (cpi->common.options && cpi->common.options->ext_partition)
293#endif
294 if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128)
295 return BLOCK_128X128;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700296
Yaowu Xuf883b422016-08-30 14:01:10 -0700297 assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700298
Dominic Symes917d6c02017-10-11 18:00:52 +0200299#if !CONFIG_MAX_TILE
300 // for the max_tile experiment there is no common tile_width, tile_height
301 // max_tile assumes tile dimensions are in superblocks (not 64x64 units)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700302 assert(IMPLIES(cpi->common.tile_cols > 1,
303 cpi->common.tile_width % MAX_MIB_SIZE == 0));
304 assert(IMPLIES(cpi->common.tile_rows > 1,
305 cpi->common.tile_height % MAX_MIB_SIZE == 0));
Dominic Symes917d6c02017-10-11 18:00:52 +0200306#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700307
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100308// TODO(any): Possibly could improve this with a heuristic.
309#if CONFIG_FILEOPTIONS
310 if (cpi->common.options && !cpi->common.options->ext_partition)
311 return BLOCK_64X64;
312#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700313 return BLOCK_128X128;
314#else
315 (void)cpi;
316 return BLOCK_64X64;
317#endif // CONFIG_EXT_PARTITION
318}
319
Yaowu Xuf883b422016-08-30 14:01:10 -0700320static void setup_frame(AV1_COMP *cpi) {
321 AV1_COMMON *const cm = &cpi->common;
Johannb0ef6ff2018-02-08 14:32:21 -0800322 // Set up entropy context depending on frame type. The decoder mandates
323 // the use of the default context, index 0, for keyframes and inter
324 // frames where the error_resilient_mode or intra_only flag is set. For
325 // other inter-frames the encoder currently uses only two contexts;
326 // context 1 for ALTREF frames and context 0 for the others.
Soo-Chul Han85e8c792018-01-21 01:58:15 -0500327
328#if CONFIG_SEGMENT_PRED_LAST
329 if (cm->prev_frame) cm->last_frame_seg_map = cm->prev_frame->seg_map;
330 cm->current_frame_seg_map = cm->cur_frame->seg_map;
331#endif
332
Yaowu Xuc27fc142016-08-22 16:08:15 -0700333 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700334 av1_setup_past_independence(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700335 } else {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700336#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
337// Just use frame context from first signaled reference frame.
338// This will always be LAST_FRAME for now.
339#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340 const GF_GROUP *gf_group = &cpi->twopass.gf_group;
Zoe Liue9b15e22017-07-19 15:53:01 -0700341 if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700342 cm->frame_context_idx = EXT_ARF_FRAME;
343 else if (cpi->refresh_alt_ref_frame)
344 cm->frame_context_idx = ARF_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700345 else if (cpi->rc.is_src_frame_alt_ref)
346 cm->frame_context_idx = OVERLAY_FRAME;
347 else if (cpi->refresh_golden_frame)
348 cm->frame_context_idx = GLD_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700349 else if (cpi->refresh_bwd_ref_frame)
350 cm->frame_context_idx = BRF_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700351 else
352 cm->frame_context_idx = REGULAR_FRAME;
Thomas Daededa4d8b92017-06-05 15:44:14 -0700353#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700354 }
355
356 if (cm->frame_type == KEY_FRAME) {
357 cpi->refresh_golden_frame = 1;
358 cpi->refresh_alt_ref_frame = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700359 av1_zero(cpi->interp_filter_selected);
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000360 set_sb_size(&cm->seq_params, select_sb_size(cpi));
Debargha Mukherjee778023d2017-09-26 17:50:27 -0700361#if CONFIG_REFERENCE_BUFFER
362 set_use_reference_buffer(cm, 0);
363#endif // CONFIG_REFERENCE_BUFFER
David Barker11eac7b2017-12-07 12:22:36 +0000364#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
365 cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
366#else
367 cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx];
368#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700369 } else {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700370#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
David Barker11eac7b2017-12-07 12:22:36 +0000371 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700372 *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
David Barker11eac7b2017-12-07 12:22:36 +0000373 cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700374 } else {
David Barker11eac7b2017-12-07 12:22:36 +0000375 assert(cm->frame_refs[0].idx >= 0);
Thomas Daededa4d8b92017-06-05 15:44:14 -0700376 *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx];
David Barker11eac7b2017-12-07 12:22:36 +0000377 cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700378 }
379#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700380 *cm->fc = cm->frame_contexts[cm->frame_context_idx];
David Barker11eac7b2017-12-07 12:22:36 +0000381 cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700382#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuf883b422016-08-30 14:01:10 -0700383 av1_zero(cpi->interp_filter_selected[0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700384 }
Zoe Liuc01dddb2017-11-07 08:44:06 -0800385#if !CONFIG_EXT_COMP_REFS // No change to bitstream
Arild Fuldseth (arilfuld)3f429082017-04-28 15:54:28 +0200386 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
387 cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame;
388 cpi->rc.is_bipred_frame = 1;
389 }
Zoe Liuc01dddb2017-11-07 08:44:06 -0800390#endif // !CONFIG_EXT_COMP_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700391
392 cpi->vaq_refresh = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700393}
394
Cheng Chen46f30c72017-09-07 11:13:33 -0700395static void enc_setup_mi(AV1_COMMON *cm) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700396 int i;
397 cm->mi = cm->mip + cm->mi_stride + 1;
398 memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip));
399 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
400 // Clear top border row
401 memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride);
402 // Clear left border column
403 for (i = 1; i < cm->mi_rows + 1; ++i)
404 memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700405 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
406 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
407
408 memset(cm->mi_grid_base, 0,
409 cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base));
Frank Bossen4ef06b52018-01-18 19:51:15 -0500410
411 memset(cm->boundary_info, 0,
412 cm->boundary_info_alloc_size * sizeof(*cm->boundary_info));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700413}
414
Cheng Chen46f30c72017-09-07 11:13:33 -0700415static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700416 cm->mip = aom_calloc(mi_size, sizeof(*cm->mip));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700417 if (!cm->mip) return 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700418 cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700419 if (!cm->prev_mip) return 1;
420 cm->mi_alloc_size = mi_size;
421
Yaowu Xuf883b422016-08-30 14:01:10 -0700422 cm->mi_grid_base = (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700423 if (!cm->mi_grid_base) return 1;
424 cm->prev_mi_grid_base =
Yaowu Xuf883b422016-08-30 14:01:10 -0700425 (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700426 if (!cm->prev_mi_grid_base) return 1;
427
428 return 0;
429}
430
Cheng Chen46f30c72017-09-07 11:13:33 -0700431static void enc_free_mi(AV1_COMMON *cm) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700432 aom_free(cm->mip);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700433 cm->mip = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700434 aom_free(cm->prev_mip);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700435 cm->prev_mip = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700436 aom_free(cm->mi_grid_base);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700437 cm->mi_grid_base = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700438 aom_free(cm->prev_mi_grid_base);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700439 cm->prev_mi_grid_base = NULL;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700440 cm->mi_alloc_size = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700441}
442
Cheng Chen46f30c72017-09-07 11:13:33 -0700443static void swap_mi_and_prev_mi(AV1_COMMON *cm) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700444 // Current mip will be the prev_mip for the next frame.
445 MODE_INFO **temp_base = cm->prev_mi_grid_base;
446 MODE_INFO *temp = cm->prev_mip;
447 cm->prev_mip = cm->mip;
448 cm->mip = temp;
449
450 // Update the upper left visible macroblock ptrs.
451 cm->mi = cm->mip + cm->mi_stride + 1;
452 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
453
454 cm->prev_mi_grid_base = cm->mi_grid_base;
455 cm->mi_grid_base = temp_base;
456 cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
457 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1;
458}
459
Yaowu Xuf883b422016-08-30 14:01:10 -0700460void av1_initialize_enc(void) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700461 static volatile int init_done = 0;
462
463 if (!init_done) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700464 av1_rtcd();
465 aom_dsp_rtcd();
466 aom_scale_rtcd();
467 av1_init_intra_predictors();
468 av1_init_me_luts();
469 av1_rc_init_minq_luts();
Yaowu Xuf883b422016-08-30 14:01:10 -0700470 av1_init_wedge_masks();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700471 init_done = 1;
472 }
473}
474
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700475static void dealloc_context_buffers_ext(AV1_COMP *cpi) {
476 if (cpi->mbmi_ext_base) {
477 aom_free(cpi->mbmi_ext_base);
478 cpi->mbmi_ext_base = NULL;
479 }
480}
481
482static void alloc_context_buffers_ext(AV1_COMP *cpi) {
483 AV1_COMMON *cm = &cpi->common;
484 int mi_size = cm->mi_cols * cm->mi_rows;
485
486 dealloc_context_buffers_ext(cpi);
487 CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base,
488 aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base)));
489}
490
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800491#if CONFIG_FILM_GRAIN
492static void update_film_grain_parameters(struct AV1_COMP *cpi,
493 const AV1EncoderConfig *oxcf) {
494 AV1_COMMON *const cm = &cpi->common;
495 cpi->oxcf = *oxcf;
496
497 if (oxcf->film_grain_test_vector) {
498 cm->film_grain_params_present = 1;
499 if (cm->frame_type == KEY_FRAME) {
500 memcpy(&cm->film_grain_params,
501 film_grain_test_vectors + oxcf->film_grain_test_vector - 1,
502 sizeof(cm->film_grain_params));
503
504 cm->film_grain_params.bit_depth = cm->bit_depth;
505 if (cm->color_range == AOM_CR_FULL_RANGE) {
506 cm->film_grain_params.clip_to_restricted_range = 0;
507 }
508 }
509 } else {
510 cm->film_grain_params_present = 0;
511 memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params));
512 }
513}
514#endif
515
Yaowu Xuf883b422016-08-30 14:01:10 -0700516static void dealloc_compressor_data(AV1_COMP *cpi) {
517 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000518 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700519
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700520 dealloc_context_buffers_ext(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700521
Yaowu Xuf883b422016-08-30 14:01:10 -0700522 aom_free(cpi->tile_data);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700523 cpi->tile_data = NULL;
524
525 // Delete sementation map
Yaowu Xuf883b422016-08-30 14:01:10 -0700526 aom_free(cpi->segmentation_map);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700527 cpi->segmentation_map = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700528
Yaowu Xuf883b422016-08-30 14:01:10 -0700529 av1_cyclic_refresh_free(cpi->cyclic_refresh);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700530 cpi->cyclic_refresh = NULL;
531
Yaowu Xuf883b422016-08-30 14:01:10 -0700532 aom_free(cpi->active_map.map);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700533 cpi->active_map.map = NULL;
534
Jingning Hand064cf02017-06-01 10:00:39 -0700535 aom_free(cpi->td.mb.above_pred_buf);
536 cpi->td.mb.above_pred_buf = NULL;
537
538 aom_free(cpi->td.mb.left_pred_buf);
539 cpi->td.mb.left_pred_buf = NULL;
540
541 aom_free(cpi->td.mb.wsrc_buf);
542 cpi->td.mb.wsrc_buf = NULL;
543
544 aom_free(cpi->td.mb.mask_buf);
545 cpi->td.mb.mask_buf = NULL;
Jingning Hand064cf02017-06-01 10:00:39 -0700546
Jingning Han6cc1fd32017-10-13 09:05:36 -0700547#if CONFIG_MFMV
548 aom_free(cm->tpl_mvs);
549 cm->tpl_mvs = NULL;
550#endif
551
Yaowu Xuf883b422016-08-30 14:01:10 -0700552 av1_free_ref_frame_buffers(cm->buffer_pool);
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700553#if CONFIG_LV_MAP
554 av1_free_txb_buf(cpi);
555#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700556 av1_free_context_buffers(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700557
Yaowu Xuf883b422016-08-30 14:01:10 -0700558 aom_free_frame_buffer(&cpi->last_frame_uf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700559#if CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -0700560 av1_free_restoration_buffers(cm);
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800561 aom_free_frame_buffer(&cpi->trial_frame_rst);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700562#endif // CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -0700563 aom_free_frame_buffer(&cpi->scaled_source);
564 aom_free_frame_buffer(&cpi->scaled_last_source);
565 aom_free_frame_buffer(&cpi->alt_ref_buffer);
566 av1_lookahead_destroy(cpi->lookahead);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700567
Yaowu Xuf883b422016-08-30 14:01:10 -0700568 aom_free(cpi->tile_tok[0][0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700569 cpi->tile_tok[0][0] = 0;
570
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000571 av1_free_pc_tree(&cpi->td, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700572
hui sud9a812b2017-07-06 14:34:37 -0700573 aom_free(cpi->td.mb.palette_buffer);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700574}
575
Yaowu Xuf883b422016-08-30 14:01:10 -0700576static void save_coding_context(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700577 CODING_CONTEXT *const cc = &cpi->coding_context;
Yaowu Xuf883b422016-08-30 14:01:10 -0700578 AV1_COMMON *cm = &cpi->common;
James Zern01a9d702017-08-25 19:09:33 +0000579 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700580
Sebastien Alaiwane140c502017-04-27 09:52:34 +0200581 // Stores a snapshot of key state variables which can subsequently be
582 // restored with a call to av1_restore_coding_context. These functions are
583 // intended for use in a re-code loop in av1_compress_frame where the
584 // quantizer value is adjusted between loop iterations.
James Zern01a9d702017-08-25 19:09:33 +0000585 for (i = 0; i < NMV_CONTEXTS; ++i) {
586 av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]);
587 av1_copy(cc->nmv_costs, cpi->nmv_costs);
588 av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp);
589 }
590
Yaowu Xuf883b422016-08-30 14:01:10 -0700591 av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas);
592 av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700593
594 cc->fc = *cm->fc;
595}
596
Yaowu Xuf883b422016-08-30 14:01:10 -0700597static void restore_coding_context(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700598 CODING_CONTEXT *const cc = &cpi->coding_context;
Yaowu Xuf883b422016-08-30 14:01:10 -0700599 AV1_COMMON *cm = &cpi->common;
James Zern01a9d702017-08-25 19:09:33 +0000600 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700601
Sebastien Alaiwane140c502017-04-27 09:52:34 +0200602 // Restore key state variables to the snapshot state stored in the
603 // previous call to av1_save_coding_context.
James Zern01a9d702017-08-25 19:09:33 +0000604 for (i = 0; i < NMV_CONTEXTS; ++i) {
605 av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]);
606 av1_copy(cpi->nmv_costs, cc->nmv_costs);
607 av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp);
608 }
609
Yaowu Xuf883b422016-08-30 14:01:10 -0700610 av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas);
611 av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700612
613 *cm->fc = cc->fc;
614}
615
Yaowu Xuf883b422016-08-30 14:01:10 -0700616static void configure_static_seg_features(AV1_COMP *cpi) {
617 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700618 const RATE_CONTROL *const rc = &cpi->rc;
619 struct segmentation *const seg = &cm->seg;
620
621 int high_q = (int)(rc->avg_q > 48.0);
622 int qi_delta;
623
624 // Disable and clear down for KF
625 if (cm->frame_type == KEY_FRAME) {
626 // Clear down the global segmentation map
627 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
628 seg->update_map = 0;
629 seg->update_data = 0;
630 cpi->static_mb_pct = 0;
631
632 // Disable segmentation
Yaowu Xuf883b422016-08-30 14:01:10 -0700633 av1_disable_segmentation(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700634
635 // Clear down the segment features.
Yaowu Xuf883b422016-08-30 14:01:10 -0700636 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700637 } else if (cpi->refresh_alt_ref_frame) {
638 // If this is an alt ref frame
639 // Clear down the global segmentation map
640 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
641 seg->update_map = 0;
642 seg->update_data = 0;
643 cpi->static_mb_pct = 0;
644
645 // Disable segmentation and individual segment features by default
Yaowu Xuf883b422016-08-30 14:01:10 -0700646 av1_disable_segmentation(seg);
647 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700648
649 // Scan frames from current to arf frame.
650 // This function re-enables segmentation if appropriate.
Yaowu Xuf883b422016-08-30 14:01:10 -0700651 av1_update_mbgraph_stats(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700652
653 // If segmentation was enabled set those features needed for the
654 // arf itself.
655 if (seg->enabled) {
656 seg->update_map = 1;
657 seg->update_data = 1;
658
659 qi_delta =
Yaowu Xuf883b422016-08-30 14:01:10 -0700660 av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth);
661 av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2);
Cheng Chend8184da2017-09-26 18:15:22 -0700662#if CONFIG_LOOPFILTER_LEVEL
663 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2);
664 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2);
665 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2);
666 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2);
667
668 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H);
669 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V);
670 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U);
671 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V);
672#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700673 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
Cheng Chend8184da2017-09-26 18:15:22 -0700674 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
675#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700676
Yaowu Xuf883b422016-08-30 14:01:10 -0700677 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700678 }
679 } else if (seg->enabled) {
680 // All other frames if segmentation has been enabled
681
682 // First normal frame in a valid gf or alt ref group
683 if (rc->frames_since_golden == 0) {
684 // Set up segment features for normal frames in an arf group
685 if (rc->source_alt_ref_active) {
686 seg->update_map = 0;
687 seg->update_data = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700688
Yaowu Xuf883b422016-08-30 14:01:10 -0700689 qi_delta =
690 av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth);
691 av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2);
692 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700693
Cheng Chend8184da2017-09-26 18:15:22 -0700694#if CONFIG_LOOPFILTER_LEVEL
695 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2);
696 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2);
697 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2);
698 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2);
699
700 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H);
701 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V);
702 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U);
703 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V);
704#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700705 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
706 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
Cheng Chend8184da2017-09-26 18:15:22 -0700707#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700708
709 // Segment coding disabled for compred testing
710 if (high_q || (cpi->static_mb_pct == 100)) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700711 av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
712 av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
713 av1_enable_segfeature(seg, 1, SEG_LVL_SKIP);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700714 }
715 } else {
716 // Disable segmentation and clear down features if alt ref
717 // is not active for this group
718
Yaowu Xuf883b422016-08-30 14:01:10 -0700719 av1_disable_segmentation(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700720
721 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
722
723 seg->update_map = 0;
724 seg->update_data = 0;
725
Yaowu Xuf883b422016-08-30 14:01:10 -0700726 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700727 }
728 } else if (rc->is_src_frame_alt_ref) {
729 // Special case where we are coding over the top of a previous
730 // alt ref frame.
731 // Segment coding disabled for compred testing
732
733 // Enable ref frame features for segment 0 as well
Yaowu Xuf883b422016-08-30 14:01:10 -0700734 av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME);
735 av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700736
737 // All mbs should use ALTREF_FRAME
Yaowu Xuf883b422016-08-30 14:01:10 -0700738 av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME);
739 av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
740 av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME);
741 av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700742
743 // Skip all MBs if high Q (0,0 mv and skip coeffs)
744 if (high_q) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700745 av1_enable_segfeature(seg, 0, SEG_LVL_SKIP);
746 av1_enable_segfeature(seg, 1, SEG_LVL_SKIP);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700747 }
748 // Enable data update
749 seg->update_data = 1;
750 } else {
751 // All other frames.
752
753 // No updates.. leave things as they are.
754 seg->update_map = 0;
755 seg->update_data = 0;
756 }
757 }
758}
759
Yaowu Xuf883b422016-08-30 14:01:10 -0700760static void update_reference_segmentation_map(AV1_COMP *cpi) {
761 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700762 MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible;
Soo-Chul Han934af352017-10-15 15:21:51 -0400763#if CONFIG_SEGMENT_PRED_LAST
764 uint8_t *cache_ptr = cm->current_frame_seg_map;
765#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700766 uint8_t *cache_ptr = cm->last_frame_seg_map;
Soo-Chul Han934af352017-10-15 15:21:51 -0400767#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700768 int row, col;
769
770 for (row = 0; row < cm->mi_rows; row++) {
771 MODE_INFO **mi_8x8 = mi_8x8_ptr;
772 uint8_t *cache = cache_ptr;
773 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++)
774 cache[0] = mi_8x8[0]->mbmi.segment_id;
775 mi_8x8_ptr += cm->mi_stride;
776 cache_ptr += cm->mi_cols;
777 }
778}
779
Yaowu Xuf883b422016-08-30 14:01:10 -0700780static void alloc_raw_frame_buffers(AV1_COMP *cpi) {
781 AV1_COMMON *cm = &cpi->common;
782 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700783
784 if (!cpi->lookahead)
Yaowu Xud3e7c682017-12-21 14:08:25 -0800785 cpi->lookahead = av1_lookahead_init(
786 oxcf->width, oxcf->height, cm->subsampling_x, cm->subsampling_y,
787 cm->use_highbitdepth, oxcf->lag_in_frames);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700788 if (!cpi->lookahead)
Yaowu Xuf883b422016-08-30 14:01:10 -0700789 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700790 "Failed to allocate lag buffers");
791
792 // TODO(agrange) Check if ARF is enabled and skip allocation if not.
Yaowu Xuf883b422016-08-30 14:01:10 -0700793 if (aom_realloc_frame_buffer(&cpi->alt_ref_buffer, oxcf->width, oxcf->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700794 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800795 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
796 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700797 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700798 "Failed to allocate altref buffer");
799}
800
Yaowu Xuf883b422016-08-30 14:01:10 -0700801static void alloc_util_frame_buffers(AV1_COMP *cpi) {
802 AV1_COMMON *const cm = &cpi->common;
803 if (aom_realloc_frame_buffer(&cpi->last_frame_uf, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700804 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800805 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
806 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700807 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700808 "Failed to allocate last frame buffer");
809
810#if CONFIG_LOOP_RESTORATION
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700811 if (aom_realloc_frame_buffer(
812 &cpi->trial_frame_rst,
Urvang Joshi94ad3702017-12-06 11:38:08 -0800813#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700814 cm->superres_upscaled_width, cm->superres_upscaled_height,
815#else
816 cm->width, cm->height,
Urvang Joshi94ad3702017-12-06 11:38:08 -0800817#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Yaowu Xud3e7c682017-12-21 14:08:25 -0800818 cm->subsampling_x, cm->subsampling_y, cm->use_highbitdepth,
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700819 AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL))
Debargha Mukherjee874d36d2016-12-14 16:53:17 -0800820 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800821 "Failed to allocate trial restored frame buffer");
Yaowu Xuc27fc142016-08-22 16:08:15 -0700822#endif // CONFIG_LOOP_RESTORATION
823
Yaowu Xuf883b422016-08-30 14:01:10 -0700824 if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700825 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800826 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
827 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700828 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700829 "Failed to allocate scaled source buffer");
830
Yaowu Xuf883b422016-08-30 14:01:10 -0700831 if (aom_realloc_frame_buffer(&cpi->scaled_last_source, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700832 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800833 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
834 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700835 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700836 "Failed to allocate scaled last source buffer");
837}
838
Cheng Chen46f30c72017-09-07 11:13:33 -0700839static void alloc_compressor_data(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700840 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000841 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700842
Yaowu Xuf883b422016-08-30 14:01:10 -0700843 av1_alloc_context_buffers(cm, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700844
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700845#if CONFIG_LV_MAP
846 av1_alloc_txb_buf(cpi);
847#endif
848
Yaowu Xuc27fc142016-08-22 16:08:15 -0700849 alloc_context_buffers_ext(cpi);
850
Yaowu Xuf883b422016-08-30 14:01:10 -0700851 aom_free(cpi->tile_tok[0][0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700852
853 {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000854 unsigned int tokens =
855 get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700856 CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0],
Yaowu Xuf883b422016-08-30 14:01:10 -0700857 aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0])));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700858 }
859
Yaowu Xuf883b422016-08-30 14:01:10 -0700860 av1_setup_pc_tree(&cpi->common, &cpi->td);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700861}
862
Yaowu Xuf883b422016-08-30 14:01:10 -0700863void av1_new_framerate(AV1_COMP *cpi, double framerate) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700864 cpi->framerate = framerate < 0.1 ? 30 : framerate;
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700865 av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700866}
867
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200868#if CONFIG_MAX_TILE
869
870static void set_tile_info_max_tile(AV1_COMP *cpi) {
871 AV1_COMMON *const cm = &cpi->common;
Dominic Symesf58f1112017-09-25 12:47:40 +0200872 int i, start_sb;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200873
874 av1_get_tile_limits(cm);
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200875
876 // configure tile columns
Dominic Symes26ad0b22017-10-01 16:35:13 +0200877 if (cpi->oxcf.tile_width_count == 0 || cpi->oxcf.tile_height_count == 0) {
Dominic Symesf58f1112017-09-25 12:47:40 +0200878 cm->uniform_tile_spacing_flag = 1;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200879 cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols);
880 cm->log2_tile_cols = AOMMIN(cm->log2_tile_cols, cm->max_log2_tile_cols);
Dominic Symesf58f1112017-09-25 12:47:40 +0200881 } else {
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000882 int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2);
883 int sb_cols = mi_cols >> cm->seq_params.mib_size_log2;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200884 int size_sb, j = 0;
Dominic Symesf58f1112017-09-25 12:47:40 +0200885 cm->uniform_tile_spacing_flag = 0;
886 for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) {
887 cm->tile_col_start_sb[i] = start_sb;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200888 size_sb = cpi->oxcf.tile_widths[j++];
889 if (j >= cpi->oxcf.tile_width_count) j = 0;
890 start_sb += AOMMIN(size_sb, MAX_TILE_WIDTH_SB);
Dominic Symesf58f1112017-09-25 12:47:40 +0200891 }
892 cm->tile_cols = i;
893 cm->tile_col_start_sb[i] = sb_cols;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200894 }
895 av1_calculate_tile_cols(cm);
896
897 // configure tile rows
898 if (cm->uniform_tile_spacing_flag) {
899 cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows);
900 cm->log2_tile_rows = AOMMIN(cm->log2_tile_rows, cm->max_log2_tile_rows);
Dominic Symesf58f1112017-09-25 12:47:40 +0200901 } else {
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000902 int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2);
903 int sb_rows = mi_rows >> cm->seq_params.mib_size_log2;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200904 int size_sb, j = 0;
Dominic Symesf58f1112017-09-25 12:47:40 +0200905 for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) {
906 cm->tile_row_start_sb[i] = start_sb;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200907 size_sb = cpi->oxcf.tile_heights[j++];
908 if (j >= cpi->oxcf.tile_height_count) j = 0;
909 start_sb += AOMMIN(size_sb, cm->max_tile_height_sb);
Dominic Symesf58f1112017-09-25 12:47:40 +0200910 }
911 cm->tile_rows = i;
912 cm->tile_row_start_sb[i] = sb_rows;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200913 }
914 av1_calculate_tile_rows(cm);
915}
916
917#endif
918
Yaowu Xuf883b422016-08-30 14:01:10 -0700919static void set_tile_info(AV1_COMP *cpi) {
920 AV1_COMMON *const cm = &cpi->common;
Yue Chen4eba69b2017-11-09 22:37:35 -0800921 (void)cm;
Thomas Daviesb25ba502017-07-18 10:18:24 +0100922#if CONFIG_DEPENDENT_HORZTILES
Fangwen Fu73126c02017-02-08 22:37:47 -0800923 int tile_row, tile_col, num_tiles_in_tg;
924 int tg_row_start, tg_col_start;
925#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700926#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700927 if (cpi->oxcf.large_scale_tile) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700928#if CONFIG_EXT_PARTITION
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700929 if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) {
930 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32);
931 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32);
932 cm->tile_width <<= MAX_MIB_SIZE_LOG2;
933 cm->tile_height <<= MAX_MIB_SIZE_LOG2;
934 } else {
935 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64);
936 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64);
937 cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1;
938 cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1;
939 }
940#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700941 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64);
942 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700943 cm->tile_width <<= MAX_MIB_SIZE_LOG2;
944 cm->tile_height <<= MAX_MIB_SIZE_LOG2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700945#endif // CONFIG_EXT_PARTITION
946
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700947 cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols);
948 cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700949
Yaowu Xu8d0039c2017-10-13 07:51:46 -0700950 assert(cm->tile_width >> MAX_MIB_SIZE_LOG2 <= 32);
951 assert(cm->tile_height >> MAX_MIB_SIZE_LOG2 <= 32);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700952
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700953 // Get the number of tiles
954 cm->tile_cols = 1;
955 while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700956
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700957 cm->tile_rows = 1;
958 while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows;
Dominic Symes917d6c02017-10-11 18:00:52 +0200959#if CONFIG_MAX_TILE
960 int i;
961 for (i = 0; i <= cm->tile_cols; i++) {
962 cm->tile_col_start_sb[i] =
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000963 ((i * cm->tile_width - 1) >> cm->seq_params.mib_size_log2) + 1;
Dominic Symes917d6c02017-10-11 18:00:52 +0200964 }
965 for (i = 0; i <= cm->tile_rows; i++) {
966 cm->tile_row_start_sb[i] =
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000967 ((i * cm->tile_height - 1) >> cm->seq_params.mib_size_log2) + 1;
Dominic Symes917d6c02017-10-11 18:00:52 +0200968 }
969#endif // CONFIG_MAX_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700970 } else {
971#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700972
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200973#if CONFIG_MAX_TILE
974 set_tile_info_max_tile(cpi);
Sebastien Alaiwan619f4172017-11-13 17:13:42 +0100975 (void)cm;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200976#else
977 int min_log2_tile_cols, max_log2_tile_cols;
978 av1_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700979
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200980 cm->log2_tile_cols =
981 clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols);
982 cm->log2_tile_rows = cpi->oxcf.tile_rows;
Rupert Swarbrick940942b2017-09-01 12:05:55 +0100983
Rupert Swarbrick5a010aa2017-09-26 16:16:48 +0100984 cm->tile_width =
985 get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols);
986 cm->tile_height =
987 get_tile_size(cm->mi_rows, cm->log2_tile_rows, &cm->tile_rows);
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200988#endif // CONFIG_MAX_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700989#if CONFIG_EXT_TILE
990 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700991#endif // CONFIG_EXT_TILE
Ryan Lei7386eda2016-12-08 21:08:31 -0800992
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800993#if CONFIG_DEPENDENT_HORZTILES
994 cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles;
Fangwen Fu70bcb892017-05-06 17:05:19 -0700995#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700996 if (cm->large_scale_tile) {
997 // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted.
998 cm->dependent_horz_tiles = 0;
Fangwen Fu73126c02017-02-08 22:37:47 -0800999 } else {
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001000#endif // CONFIG_EXT_TILE
1001 if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0;
1002#if CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001003 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001004#endif // CONFIG_EXT_TILE
1005
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001006#if CONFIG_EXT_TILE
1007 if (!cm->large_scale_tile) {
1008#endif // CONFIG_EXT_TILE
1009 if (cpi->oxcf.mtu == 0) {
1010 cm->num_tg = cpi->oxcf.num_tile_groups;
1011 } else {
1012 // Use a default value for the purposes of weighting costs in probability
1013 // updates
1014 cm->num_tg = DEFAULT_MAX_NUM_TG;
Fangwen Fu73126c02017-02-08 22:37:47 -08001015 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001016 num_tiles_in_tg =
1017 (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg;
1018 tg_row_start = 0;
1019 tg_col_start = 0;
1020 for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) {
1021 for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) {
1022 if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) {
1023 tg_row_start = tile_row;
1024 tg_col_start = tile_col;
1025 }
1026 cm->tile_group_start_row[tile_row][tile_col] = tg_row_start;
1027 cm->tile_group_start_col[tile_row][tile_col] = tg_col_start;
1028 }
1029 }
1030#if CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001031 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001032#endif // CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001033#endif
Fangwen Fu7b9f2b32017-01-17 14:01:52 -08001034
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001035#if CONFIG_LOOPFILTERING_ACROSS_TILES
Lei7bb501d2017-12-13 15:10:34 -08001036#if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
1037 cm->loop_filter_across_tiles_v_enabled =
1038 cpi->oxcf.loop_filter_across_tiles_v_enabled;
1039 cm->loop_filter_across_tiles_h_enabled =
1040 cpi->oxcf.loop_filter_across_tiles_h_enabled;
1041#else
Ryan Lei7386eda2016-12-08 21:08:31 -08001042 cm->loop_filter_across_tiles_enabled =
1043 cpi->oxcf.loop_filter_across_tiles_enabled;
Lei7bb501d2017-12-13 15:10:34 -08001044#endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001045#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001046}
1047
Yaowu Xuf883b422016-08-30 14:01:10 -07001048static void update_frame_size(AV1_COMP *cpi) {
1049 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001050 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
1051
Yaowu Xuf883b422016-08-30 14:01:10 -07001052 av1_set_mb_mi(cm, cm->width, cm->height);
1053 av1_init_context_buffers(cm);
Luc Trudeau1e84af52017-11-25 15:00:28 -05001054 av1_init_macroblockd(cm, xd, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001055 memset(cpi->mbmi_ext_base, 0,
1056 cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001057 set_tile_info(cpi);
1058}
1059
Yaowu Xuf883b422016-08-30 14:01:10 -07001060static void init_buffer_indices(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001061 int fb_idx;
1062 for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx)
1063 cpi->lst_fb_idxes[fb_idx] = fb_idx;
1064 cpi->gld_fb_idx = LAST_REF_FRAMES;
1065 cpi->bwd_fb_idx = LAST_REF_FRAMES + 1;
Zoe Liue9b15e22017-07-19 15:53:01 -07001066 cpi->alt2_fb_idx = LAST_REF_FRAMES + 2;
1067 cpi->alt_fb_idx = LAST_REF_FRAMES + 3;
Zoe Liu8dd1c982017-09-11 10:14:35 -07001068 cpi->ext_fb_idx = LAST_REF_FRAMES + 4;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001069 for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx)
1070 cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx;
RogerZhou3b635242017-09-19 10:06:46 -07001071#if CONFIG_AMVR
1072 cpi->rate_index = 0;
1073 cpi->rate_size = 0;
1074 cpi->cur_poc = -1;
1075#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001076}
1077
Yaowu Xuf883b422016-08-30 14:01:10 -07001078static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) {
1079 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001080
1081 cpi->oxcf = *oxcf;
1082 cpi->framerate = oxcf->init_framerate;
1083
1084 cm->profile = oxcf->profile;
1085 cm->bit_depth = oxcf->bit_depth;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001086 cm->use_highbitdepth = oxcf->use_highbitdepth;
Andrey Norkin9e694632017-12-21 18:50:57 -08001087#if CONFIG_CICP
1088 cm->color_primaries = oxcf->color_primaries;
1089 cm->transfer_characteristics = oxcf->transfer_characteristics;
1090 cm->matrix_coefficients = oxcf->matrix_coefficients;
1091#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001092 cm->color_space = oxcf->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08001093#endif // CONFIG_CICP
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08001094#if CONFIG_MONO_VIDEO
1095 cm->seq_params.monochrome = oxcf->monochrome;
1096#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07001097#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08001098#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07001099 cm->transfer_function = oxcf->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08001100#endif
anorkin76fb1262017-03-22 15:12:12 -07001101 cm->chroma_sample_position = oxcf->chroma_sample_position;
1102#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001103 cm->color_range = oxcf->color_range;
Andrey Norkin28e9ce22018-01-08 10:11:21 -08001104#if CONFIG_TIMING_INFO_IN_SEQ_HEADERS
1105 cm->timing_info_present = oxcf->timing_info_present;
1106 cm->num_units_in_tick = oxcf->num_units_in_tick;
1107 cm->time_scale = oxcf->time_scale;
1108 cm->equal_picture_interval = oxcf->equal_picture_interval;
1109 cm->num_ticks_per_picture = oxcf->num_ticks_per_picture;
1110#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001111
1112 cm->width = oxcf->width;
1113 cm->height = oxcf->height;
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00001114 set_sb_size(&cm->seq_params,
1115 select_sb_size(cpi)); // set sb size before allocations
Cheng Chen46f30c72017-09-07 11:13:33 -07001116 alloc_compressor_data(cpi);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -08001117#if CONFIG_FILM_GRAIN
1118 update_film_grain_parameters(cpi, oxcf);
1119#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001120
1121 // Single thread case: use counts in common.
1122 cpi->td.counts = &cm->counts;
1123
1124 // change includes all joint functionality
Yaowu Xuf883b422016-08-30 14:01:10 -07001125 av1_change_config(cpi, oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001126
1127 cpi->static_mb_pct = 0;
1128 cpi->ref_frame_flags = 0;
1129
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07001130 // Reset resize pending flags
1131 cpi->resize_pending_width = 0;
1132 cpi->resize_pending_height = 0;
1133
Yaowu Xuc27fc142016-08-22 16:08:15 -07001134 init_buffer_indices(cpi);
1135}
1136
1137static void set_rc_buffer_sizes(RATE_CONTROL *rc,
Yaowu Xuf883b422016-08-30 14:01:10 -07001138 const AV1EncoderConfig *oxcf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001139 const int64_t bandwidth = oxcf->target_bandwidth;
1140 const int64_t starting = oxcf->starting_buffer_level_ms;
1141 const int64_t optimal = oxcf->optimal_buffer_level_ms;
1142 const int64_t maximum = oxcf->maximum_buffer_size_ms;
1143
1144 rc->starting_buffer_level = starting * bandwidth / 1000;
1145 rc->optimal_buffer_level =
1146 (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000;
1147 rc->maximum_buffer_size =
1148 (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000;
1149}
1150
Cheng Chenbf3d4962017-11-01 14:48:52 -07001151#if CONFIG_JNT_COMP
1152#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, \
1153 JSVAF) \
1154 cpi->fn_ptr[BT].sdf = SDF; \
1155 cpi->fn_ptr[BT].sdaf = SDAF; \
1156 cpi->fn_ptr[BT].vf = VF; \
1157 cpi->fn_ptr[BT].svf = SVF; \
1158 cpi->fn_ptr[BT].svaf = SVAF; \
1159 cpi->fn_ptr[BT].sdx3f = SDX3F; \
1160 cpi->fn_ptr[BT].sdx8f = SDX8F; \
1161 cpi->fn_ptr[BT].sdx4df = SDX4DF; \
1162 cpi->fn_ptr[BT].jsdaf = JSDAF; \
1163 cpi->fn_ptr[BT].jsvaf = JSVAF;
1164#else // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001165#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
1166 cpi->fn_ptr[BT].sdf = SDF; \
1167 cpi->fn_ptr[BT].sdaf = SDAF; \
1168 cpi->fn_ptr[BT].vf = VF; \
1169 cpi->fn_ptr[BT].svf = SVF; \
1170 cpi->fn_ptr[BT].svaf = SVAF; \
1171 cpi->fn_ptr[BT].sdx3f = SDX3F; \
1172 cpi->fn_ptr[BT].sdx8f = SDX8F; \
1173 cpi->fn_ptr[BT].sdx4df = SDX4DF;
Cheng Chenbf3d4962017-11-01 14:48:52 -07001174#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001175
1176#define MAKE_BFP_SAD_WRAPPER(fnname) \
1177 static unsigned int fnname##_bits8(const uint8_t *src_ptr, \
1178 int source_stride, \
1179 const uint8_t *ref_ptr, int ref_stride) { \
1180 return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \
1181 } \
1182 static unsigned int fnname##_bits10( \
1183 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1184 int ref_stride) { \
1185 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \
1186 } \
1187 static unsigned int fnname##_bits12( \
1188 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1189 int ref_stride) { \
1190 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \
1191 }
1192
1193#define MAKE_BFP_SADAVG_WRAPPER(fnname) \
1194 static unsigned int fnname##_bits8( \
1195 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1196 int ref_stride, const uint8_t *second_pred) { \
1197 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \
1198 } \
1199 static unsigned int fnname##_bits10( \
1200 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1201 int ref_stride, const uint8_t *second_pred) { \
1202 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
1203 2; \
1204 } \
1205 static unsigned int fnname##_bits12( \
1206 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1207 int ref_stride, const uint8_t *second_pred) { \
1208 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
1209 4; \
1210 }
1211
1212#define MAKE_BFP_SAD3_WRAPPER(fnname) \
1213 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1214 const uint8_t *ref_ptr, int ref_stride, \
1215 unsigned int *sad_array) { \
1216 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1217 } \
1218 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1219 const uint8_t *ref_ptr, int ref_stride, \
1220 unsigned int *sad_array) { \
1221 int i; \
1222 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1223 for (i = 0; i < 3; i++) sad_array[i] >>= 2; \
1224 } \
1225 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1226 const uint8_t *ref_ptr, int ref_stride, \
1227 unsigned int *sad_array) { \
1228 int i; \
1229 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1230 for (i = 0; i < 3; i++) sad_array[i] >>= 4; \
1231 }
1232
1233#define MAKE_BFP_SAD8_WRAPPER(fnname) \
1234 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1235 const uint8_t *ref_ptr, int ref_stride, \
1236 unsigned int *sad_array) { \
1237 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1238 } \
1239 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1240 const uint8_t *ref_ptr, int ref_stride, \
1241 unsigned int *sad_array) { \
1242 int i; \
1243 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1244 for (i = 0; i < 8; i++) sad_array[i] >>= 2; \
1245 } \
1246 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1247 const uint8_t *ref_ptr, int ref_stride, \
1248 unsigned int *sad_array) { \
1249 int i; \
1250 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1251 for (i = 0; i < 8; i++) sad_array[i] >>= 4; \
1252 }
1253#define MAKE_BFP_SAD4D_WRAPPER(fnname) \
1254 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1255 const uint8_t *const ref_ptr[], int ref_stride, \
1256 unsigned int *sad_array) { \
1257 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1258 } \
1259 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1260 const uint8_t *const ref_ptr[], int ref_stride, \
1261 unsigned int *sad_array) { \
1262 int i; \
1263 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1264 for (i = 0; i < 4; i++) sad_array[i] >>= 2; \
1265 } \
1266 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1267 const uint8_t *const ref_ptr[], int ref_stride, \
1268 unsigned int *sad_array) { \
1269 int i; \
1270 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1271 for (i = 0; i < 4; i++) sad_array[i] >>= 4; \
1272 }
1273
Cheng Chenbf3d4962017-11-01 14:48:52 -07001274#if CONFIG_JNT_COMP
1275#define MAKE_BFP_JSADAVG_WRAPPER(fnname) \
1276 static unsigned int fnname##_bits8( \
1277 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1278 int ref_stride, const uint8_t *second_pred, \
1279 const JNT_COMP_PARAMS *jcp_param) { \
1280 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1281 jcp_param); \
1282 } \
1283 static unsigned int fnname##_bits10( \
1284 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1285 int ref_stride, const uint8_t *second_pred, \
1286 const JNT_COMP_PARAMS *jcp_param) { \
1287 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1288 jcp_param) >> \
1289 2; \
1290 } \
1291 static unsigned int fnname##_bits12( \
1292 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1293 int ref_stride, const uint8_t *second_pred, \
1294 const JNT_COMP_PARAMS *jcp_param) { \
1295 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1296 jcp_param) >> \
1297 4; \
1298 }
1299#endif // CONFIG_JNT_COMP
1300
Yaowu Xuc27fc142016-08-22 16:08:15 -07001301#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001302MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128)
1303MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)
1304MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3)
1305MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8)
1306MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d)
1307MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64)
1308MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg)
1309MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d)
1310MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128)
1311MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg)
1312MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001313#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001314MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16)
1315MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg)
1316MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d)
1317MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32)
1318MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg)
1319MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d)
1320MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32)
1321MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg)
1322MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d)
1323MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64)
1324MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg)
1325MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d)
1326MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32)
1327MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg)
1328MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3)
1329MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8)
1330MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d)
1331MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64)
1332MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg)
1333MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3)
1334MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8)
1335MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d)
1336MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16)
1337MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg)
1338MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3)
1339MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8)
1340MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d)
1341MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8)
1342MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg)
1343MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3)
1344MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8)
1345MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d)
1346MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16)
1347MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg)
1348MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3)
1349MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8)
1350MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d)
1351MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8)
1352MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg)
1353MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3)
1354MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8)
1355MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d)
1356MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4)
1357MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg)
1358MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8)
1359MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d)
1360MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8)
1361MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg)
1362MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8)
1363MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d)
1364MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4)
1365MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg)
1366MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3)
1367MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8)
1368MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001369
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001370#if CONFIG_EXT_PARTITION_TYPES
1371MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16)
1372MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg)
1373MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d)
1374MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4)
1375MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg)
1376MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d)
1377MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32)
1378MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg)
1379MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d)
1380MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8)
1381MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg)
1382MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001383MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64)
1384MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg)
1385MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d)
1386MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16)
1387MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg)
1388MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001389#if CONFIG_EXT_PARTITION
1390MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x128)
1391MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x128_avg)
1392MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x128x4d)
1393MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x32)
1394MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x32_avg)
1395MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x32x4d)
1396#endif // CONFIG_EXT_PARTITION
1397#endif // CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001398
Cheng Chenbf3d4962017-11-01 14:48:52 -07001399#if CONFIG_JNT_COMP
1400#if CONFIG_EXT_PARTITION
1401MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x128_avg)
1402MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x64_avg)
1403MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x128_avg)
1404#endif // CONFIG_EXT_PARTITION
1405MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x16_avg)
1406MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x32_avg)
1407MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x32_avg)
1408MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x64_avg)
1409MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x32_avg)
1410MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x64_avg)
1411MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x16_avg)
1412MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x8_avg)
1413MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x16_avg)
1414MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x8_avg)
1415MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x4_avg)
1416MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x8_avg)
1417MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x4_avg)
1418#if CONFIG_EXT_PARTITION_TYPES
1419MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x16_avg)
1420MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x4_avg)
1421MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x32_avg)
1422MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x8_avg)
1423MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x64_avg)
1424MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x16_avg)
1425#if CONFIG_EXT_PARTITION
1426MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x128_avg)
1427MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x32_avg)
1428#endif // CONFIG_EXT_PARTITION
1429#endif // CONFIG_EXT_PARTITION_TYPES
1430#endif // CONFIG_JNT_COMP
1431
David Barker0f3c94e2017-05-16 15:21:50 +01001432#define HIGHBD_MBFP(BT, MCSDF, MCSVF) \
David Barkerf19f35f2017-05-22 16:33:22 +01001433 cpi->fn_ptr[BT].msdf = MCSDF; \
1434 cpi->fn_ptr[BT].msvf = MCSVF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001435
David Barkerc155e012017-05-11 13:54:54 +01001436#define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \
1437 static unsigned int fnname##_bits8( \
1438 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1439 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1440 int m_stride, int invert_mask) { \
1441 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1442 second_pred_ptr, m, m_stride, invert_mask); \
1443 } \
1444 static unsigned int fnname##_bits10( \
1445 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1446 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1447 int m_stride, int invert_mask) { \
1448 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1449 second_pred_ptr, m, m_stride, invert_mask) >> \
1450 2; \
1451 } \
1452 static unsigned int fnname##_bits12( \
1453 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1454 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1455 int m_stride, int invert_mask) { \
1456 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1457 second_pred_ptr, m, m_stride, invert_mask) >> \
1458 4; \
1459 }
1460
Yaowu Xuc27fc142016-08-22 16:08:15 -07001461#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001462MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128)
1463MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64)
1464MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001465#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001466MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64)
1467MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32)
1468MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64)
1469MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32)
1470MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16)
1471MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32)
1472MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16)
1473MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8)
1474MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16)
1475MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8)
1476MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4)
1477MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8)
1478MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001479
1480#if CONFIG_EXT_PARTITION_TYPES
1481MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16)
1482MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4)
1483MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32)
1484MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001485MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64)
1486MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001487#if CONFIG_EXT_PARTITION
1488MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x128)
1489MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x32)
1490#endif // CONFIG_EXT_PARTITION
1491#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001492
Yaowu Xuc27fc142016-08-22 16:08:15 -07001493#define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \
1494 cpi->fn_ptr[BT].osdf = OSDF; \
1495 cpi->fn_ptr[BT].ovf = OVF; \
1496 cpi->fn_ptr[BT].osvf = OSVF;
1497
1498#define MAKE_OBFP_SAD_WRAPPER(fnname) \
1499 static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \
1500 const int32_t *wsrc, \
1501 const int32_t *msk) { \
1502 return fnname(ref, ref_stride, wsrc, msk); \
1503 } \
1504 static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \
1505 const int32_t *wsrc, \
1506 const int32_t *msk) { \
1507 return fnname(ref, ref_stride, wsrc, msk) >> 2; \
1508 } \
1509 static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \
1510 const int32_t *wsrc, \
1511 const int32_t *msk) { \
1512 return fnname(ref, ref_stride, wsrc, msk) >> 4; \
1513 }
1514
1515#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001516MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128)
1517MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64)
1518MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001519#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001520MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64)
1521MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32)
1522MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64)
1523MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32)
1524MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16)
1525MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32)
1526MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16)
1527MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8)
1528MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16)
1529MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8)
1530MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4)
1531MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8)
1532MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001533
1534#if CONFIG_EXT_PARTITION_TYPES
1535MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16)
1536MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4)
1537MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32)
1538MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001539MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64)
1540MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001541#if CONFIG_EXT_PARTITION
1542MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x128)
1543MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x32)
1544#endif // CONFIG_EXT_PARTITION
1545#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001546
Yaowu Xuf883b422016-08-30 14:01:10 -07001547static void highbd_set_var_fns(AV1_COMP *const cpi) {
1548 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001549 if (cm->use_highbitdepth) {
1550 switch (cm->bit_depth) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001551 case AOM_BITS_8:
Cheng Chenbf3d4962017-11-01 14:48:52 -07001552#if CONFIG_JNT_COMP
1553#if CONFIG_EXT_PARTITION_TYPES
1554#if CONFIG_EXT_PARTITION
1555 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8,
1556 aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32,
1557 aom_highbd_8_sub_pixel_variance128x32,
1558 aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL,
1559 aom_highbd_sad128x32x4d_bits8,
1560 aom_highbd_jnt_sad128x32_avg_bits8,
1561 aom_highbd_8_jnt_sub_pixel_avg_variance128x32)
1562
1563 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8,
1564 aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128,
1565 aom_highbd_8_sub_pixel_variance32x128,
1566 aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL,
1567 aom_highbd_sad32x128x4d_bits8,
1568 aom_highbd_jnt_sad32x128_avg_bits8,
1569 aom_highbd_8_jnt_sub_pixel_avg_variance32x128)
1570#endif // CONFIG_EXT_PARTITION
1571
1572 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8,
1573 aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16,
1574 aom_highbd_8_sub_pixel_variance64x16,
1575 aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL,
1576 aom_highbd_sad64x16x4d_bits8,
1577 aom_highbd_jnt_sad64x16_avg_bits8,
1578 aom_highbd_8_jnt_sub_pixel_avg_variance64x16)
1579
1580 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8,
1581 aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64,
1582 aom_highbd_8_sub_pixel_variance16x64,
1583 aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL,
1584 aom_highbd_sad16x64x4d_bits8,
1585 aom_highbd_jnt_sad16x64_avg_bits8,
1586 aom_highbd_8_jnt_sub_pixel_avg_variance16x64)
1587
1588 HIGHBD_BFP(
1589 BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8,
1590 aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8,
1591 aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL,
1592 aom_highbd_sad32x8x4d_bits8, aom_highbd_jnt_sad32x8_avg_bits8,
1593 aom_highbd_8_jnt_sub_pixel_avg_variance32x8)
1594
1595 HIGHBD_BFP(
1596 BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8,
1597 aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32,
1598 aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL,
1599 aom_highbd_sad8x32x4d_bits8, aom_highbd_jnt_sad8x32_avg_bits8,
1600 aom_highbd_8_jnt_sub_pixel_avg_variance8x32)
1601
1602 HIGHBD_BFP(
1603 BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8,
1604 aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4,
1605 aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL,
1606 aom_highbd_sad16x4x4d_bits8, aom_highbd_jnt_sad16x4_avg_bits8,
1607 aom_highbd_8_jnt_sub_pixel_avg_variance16x4)
1608
1609 HIGHBD_BFP(
1610 BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8,
1611 aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16,
1612 aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL,
1613 aom_highbd_sad4x16x4d_bits8, aom_highbd_jnt_sad4x16_avg_bits8,
1614 aom_highbd_8_jnt_sub_pixel_avg_variance4x16)
1615#endif
1616
1617 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8,
1618 aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16,
1619 aom_highbd_8_sub_pixel_variance32x16,
1620 aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL,
1621 aom_highbd_sad32x16x4d_bits8,
1622 aom_highbd_jnt_sad32x16_avg_bits8,
1623 aom_highbd_8_jnt_sub_pixel_avg_variance32x16)
1624
1625 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8,
1626 aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32,
1627 aom_highbd_8_sub_pixel_variance16x32,
1628 aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL,
1629 aom_highbd_sad16x32x4d_bits8,
1630 aom_highbd_jnt_sad16x32_avg_bits8,
1631 aom_highbd_8_jnt_sub_pixel_avg_variance16x32)
1632
1633 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8,
1634 aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32,
1635 aom_highbd_8_sub_pixel_variance64x32,
1636 aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL,
1637 aom_highbd_sad64x32x4d_bits8,
1638 aom_highbd_jnt_sad64x32_avg_bits8,
1639 aom_highbd_8_jnt_sub_pixel_avg_variance64x32)
1640
1641 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8,
1642 aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64,
1643 aom_highbd_8_sub_pixel_variance32x64,
1644 aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL,
1645 aom_highbd_sad32x64x4d_bits8,
1646 aom_highbd_jnt_sad32x64_avg_bits8,
1647 aom_highbd_8_jnt_sub_pixel_avg_variance32x64)
1648
1649 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8,
1650 aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32,
1651 aom_highbd_8_sub_pixel_variance32x32,
1652 aom_highbd_8_sub_pixel_avg_variance32x32,
1653 aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8,
1654 aom_highbd_sad32x32x4d_bits8,
1655 aom_highbd_jnt_sad32x32_avg_bits8,
1656 aom_highbd_8_jnt_sub_pixel_avg_variance32x32)
1657
1658 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8,
1659 aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64,
1660 aom_highbd_8_sub_pixel_variance64x64,
1661 aom_highbd_8_sub_pixel_avg_variance64x64,
1662 aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8,
1663 aom_highbd_sad64x64x4d_bits8,
1664 aom_highbd_jnt_sad64x64_avg_bits8,
1665 aom_highbd_8_jnt_sub_pixel_avg_variance64x64)
1666
1667 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8,
1668 aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16,
1669 aom_highbd_8_sub_pixel_variance16x16,
1670 aom_highbd_8_sub_pixel_avg_variance16x16,
1671 aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8,
1672 aom_highbd_sad16x16x4d_bits8,
1673 aom_highbd_jnt_sad16x16_avg_bits8,
1674 aom_highbd_8_jnt_sub_pixel_avg_variance16x16)
1675
1676 HIGHBD_BFP(
1677 BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8,
1678 aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8,
1679 aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8,
1680 aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8,
1681 aom_highbd_jnt_sad16x8_avg_bits8,
1682 aom_highbd_8_jnt_sub_pixel_avg_variance16x8)
1683
1684 HIGHBD_BFP(
1685 BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8,
1686 aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16,
1687 aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8,
1688 aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8,
1689 aom_highbd_jnt_sad8x16_avg_bits8,
1690 aom_highbd_8_jnt_sub_pixel_avg_variance8x16)
1691
1692 HIGHBD_BFP(BLOCK_8X8, aom_highbd_sad8x8_bits8,
1693 aom_highbd_sad8x8_avg_bits8, aom_highbd_8_variance8x8,
1694 aom_highbd_8_sub_pixel_variance8x8,
1695 aom_highbd_8_sub_pixel_avg_variance8x8,
1696 aom_highbd_sad8x8x3_bits8, aom_highbd_sad8x8x8_bits8,
1697 aom_highbd_sad8x8x4d_bits8, aom_highbd_jnt_sad8x8_avg_bits8,
1698 aom_highbd_8_jnt_sub_pixel_avg_variance8x8)
1699
1700 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8,
1701 aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4,
1702 aom_highbd_8_sub_pixel_variance8x4,
1703 aom_highbd_8_sub_pixel_avg_variance8x4, NULL,
1704 aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8,
1705 aom_highbd_jnt_sad8x4_avg_bits8,
1706 aom_highbd_8_jnt_sub_pixel_avg_variance8x4)
1707
1708 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8,
1709 aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8,
1710 aom_highbd_8_sub_pixel_variance4x8,
1711 aom_highbd_8_sub_pixel_avg_variance4x8, NULL,
1712 aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8,
1713 aom_highbd_jnt_sad4x8_avg_bits8,
1714 aom_highbd_8_jnt_sub_pixel_avg_variance4x8)
1715
1716 HIGHBD_BFP(BLOCK_4X4, aom_highbd_sad4x4_bits8,
1717 aom_highbd_sad4x4_avg_bits8, aom_highbd_8_variance4x4,
1718 aom_highbd_8_sub_pixel_variance4x4,
1719 aom_highbd_8_sub_pixel_avg_variance4x4,
1720 aom_highbd_sad4x4x3_bits8, aom_highbd_sad4x4x8_bits8,
1721 aom_highbd_sad4x4x4d_bits8, aom_highbd_jnt_sad4x4_avg_bits8,
1722 aom_highbd_8_jnt_sub_pixel_avg_variance4x4)
1723
Cheng Chenbf3d4962017-11-01 14:48:52 -07001724#if CONFIG_EXT_PARTITION
1725 HIGHBD_BFP(
1726 BLOCK_128X128, aom_highbd_sad128x128_bits8,
1727 aom_highbd_sad128x128_avg_bits8, aom_highbd_8_variance128x128,
1728 aom_highbd_8_sub_pixel_variance128x128,
1729 aom_highbd_8_sub_pixel_avg_variance128x128,
1730 aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8,
1731 aom_highbd_sad128x128x4d_bits8, aom_highbd_jnt_sad128x128_avg_bits8,
1732 aom_highbd_8_jnt_sub_pixel_avg_variance128x128)
1733
1734 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8,
1735 aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64,
1736 aom_highbd_8_sub_pixel_variance128x64,
1737 aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL,
1738 aom_highbd_sad128x64x4d_bits8,
1739 aom_highbd_jnt_sad128x64_avg_bits8,
1740 aom_highbd_8_jnt_sub_pixel_avg_variance128x64)
1741
1742 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8,
1743 aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128,
1744 aom_highbd_8_sub_pixel_variance64x128,
1745 aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL,
1746 aom_highbd_sad64x128x4d_bits8,
1747 aom_highbd_jnt_sad64x128_avg_bits8,
1748 aom_highbd_8_jnt_sub_pixel_avg_variance64x128)
1749#endif // CONFIG_EXT_PARTITION
1750#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001751#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001752#if CONFIG_EXT_PARTITION
1753 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8,
1754 aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32,
1755 aom_highbd_8_sub_pixel_variance128x32,
1756 aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL,
1757 aom_highbd_sad128x32x4d_bits8)
1758
1759 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8,
1760 aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128,
1761 aom_highbd_8_sub_pixel_variance32x128,
1762 aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL,
1763 aom_highbd_sad32x128x4d_bits8)
1764#endif // CONFIG_EXT_PARTITION
1765
Rupert Swarbrick72678572017-08-02 12:05:26 +01001766 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8,
1767 aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16,
1768 aom_highbd_8_sub_pixel_variance64x16,
1769 aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL,
1770 aom_highbd_sad64x16x4d_bits8)
1771
1772 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8,
1773 aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64,
1774 aom_highbd_8_sub_pixel_variance16x64,
1775 aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL,
1776 aom_highbd_sad16x64x4d_bits8)
1777
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001778 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8,
1779 aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8,
1780 aom_highbd_8_sub_pixel_variance32x8,
1781 aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL,
1782 aom_highbd_sad32x8x4d_bits8)
1783
1784 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8,
1785 aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32,
1786 aom_highbd_8_sub_pixel_variance8x32,
1787 aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL,
1788 aom_highbd_sad8x32x4d_bits8)
1789
1790 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8,
1791 aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4,
1792 aom_highbd_8_sub_pixel_variance16x4,
1793 aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL,
1794 aom_highbd_sad16x4x4d_bits8)
1795
1796 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8,
1797 aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16,
1798 aom_highbd_8_sub_pixel_variance4x16,
1799 aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL,
1800 aom_highbd_sad4x16x4d_bits8)
1801#endif
1802
Yaowu Xuf883b422016-08-30 14:01:10 -07001803 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8,
1804 aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16,
1805 aom_highbd_8_sub_pixel_variance32x16,
1806 aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL,
1807 aom_highbd_sad32x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001808
Yaowu Xuf883b422016-08-30 14:01:10 -07001809 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8,
1810 aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32,
1811 aom_highbd_8_sub_pixel_variance16x32,
1812 aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL,
1813 aom_highbd_sad16x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001814
Yaowu Xuf883b422016-08-30 14:01:10 -07001815 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8,
1816 aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32,
1817 aom_highbd_8_sub_pixel_variance64x32,
1818 aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL,
1819 aom_highbd_sad64x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001820
Yaowu Xuf883b422016-08-30 14:01:10 -07001821 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8,
1822 aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64,
1823 aom_highbd_8_sub_pixel_variance32x64,
1824 aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL,
1825 aom_highbd_sad32x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001826
Yaowu Xuf883b422016-08-30 14:01:10 -07001827 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8,
1828 aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32,
1829 aom_highbd_8_sub_pixel_variance32x32,
1830 aom_highbd_8_sub_pixel_avg_variance32x32,
1831 aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8,
1832 aom_highbd_sad32x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001833
Yaowu Xuf883b422016-08-30 14:01:10 -07001834 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8,
1835 aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64,
1836 aom_highbd_8_sub_pixel_variance64x64,
1837 aom_highbd_8_sub_pixel_avg_variance64x64,
1838 aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8,
1839 aom_highbd_sad64x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001840
Yaowu Xuf883b422016-08-30 14:01:10 -07001841 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8,
1842 aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16,
1843 aom_highbd_8_sub_pixel_variance16x16,
1844 aom_highbd_8_sub_pixel_avg_variance16x16,
1845 aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8,
1846 aom_highbd_sad16x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001847
1848 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001849 BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8,
1850 aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8,
1851 aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8,
1852 aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001853
1854 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001855 BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8,
1856 aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16,
1857 aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8,
1858 aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001859
1860 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001861 BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8,
1862 aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8,
1863 aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8,
1864 aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001865
Yaowu Xuf883b422016-08-30 14:01:10 -07001866 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8,
1867 aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4,
1868 aom_highbd_8_sub_pixel_variance8x4,
1869 aom_highbd_8_sub_pixel_avg_variance8x4, NULL,
1870 aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001871
Yaowu Xuf883b422016-08-30 14:01:10 -07001872 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8,
1873 aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8,
1874 aom_highbd_8_sub_pixel_variance4x8,
1875 aom_highbd_8_sub_pixel_avg_variance4x8, NULL,
1876 aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001877
1878 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001879 BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8,
1880 aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4,
1881 aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8,
1882 aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001883
1884#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001885 HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8,
1886 aom_highbd_sad128x128_avg_bits8,
1887 aom_highbd_8_variance128x128,
1888 aom_highbd_8_sub_pixel_variance128x128,
1889 aom_highbd_8_sub_pixel_avg_variance128x128,
1890 aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8,
1891 aom_highbd_sad128x128x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001892
Yaowu Xuf883b422016-08-30 14:01:10 -07001893 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8,
1894 aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64,
1895 aom_highbd_8_sub_pixel_variance128x64,
1896 aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL,
1897 aom_highbd_sad128x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001898
Yaowu Xuf883b422016-08-30 14:01:10 -07001899 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8,
1900 aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128,
1901 aom_highbd_8_sub_pixel_variance64x128,
1902 aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL,
1903 aom_highbd_sad64x128x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001904#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07001905#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001906
Yaowu Xuc27fc142016-08-22 16:08:15 -07001907#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001908 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8,
1909 aom_highbd_8_masked_sub_pixel_variance128x128)
1910 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8,
1911 aom_highbd_8_masked_sub_pixel_variance128x64)
1912 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8,
1913 aom_highbd_8_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001914#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001915 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8,
1916 aom_highbd_8_masked_sub_pixel_variance64x64)
1917 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8,
1918 aom_highbd_8_masked_sub_pixel_variance64x32)
1919 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8,
1920 aom_highbd_8_masked_sub_pixel_variance32x64)
1921 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8,
1922 aom_highbd_8_masked_sub_pixel_variance32x32)
1923 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8,
1924 aom_highbd_8_masked_sub_pixel_variance32x16)
1925 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8,
1926 aom_highbd_8_masked_sub_pixel_variance16x32)
1927 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8,
1928 aom_highbd_8_masked_sub_pixel_variance16x16)
1929 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8,
1930 aom_highbd_8_masked_sub_pixel_variance8x16)
1931 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8,
1932 aom_highbd_8_masked_sub_pixel_variance16x8)
1933 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8,
1934 aom_highbd_8_masked_sub_pixel_variance8x8)
1935 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8,
1936 aom_highbd_8_masked_sub_pixel_variance4x8)
1937 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8,
1938 aom_highbd_8_masked_sub_pixel_variance8x4)
1939 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8,
1940 aom_highbd_8_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001941#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001942#if CONFIG_EXT_PARTITION
1943 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits8,
1944 aom_highbd_8_masked_sub_pixel_variance128x32)
1945
1946 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits8,
1947 aom_highbd_8_masked_sub_pixel_variance32x128)
1948#endif // CONFIG_EXT_PARTITION
1949
Rupert Swarbrick72678572017-08-02 12:05:26 +01001950 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8,
1951 aom_highbd_8_masked_sub_pixel_variance64x16)
1952
1953 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8,
1954 aom_highbd_8_masked_sub_pixel_variance16x64)
1955
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001956 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8,
1957 aom_highbd_8_masked_sub_pixel_variance32x8)
1958
1959 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8,
1960 aom_highbd_8_masked_sub_pixel_variance8x32)
1961
1962 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8,
1963 aom_highbd_8_masked_sub_pixel_variance16x4)
1964
1965 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8,
1966 aom_highbd_8_masked_sub_pixel_variance4x16)
1967#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001968#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001969 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8,
1970 aom_highbd_obmc_variance128x128,
1971 aom_highbd_obmc_sub_pixel_variance128x128)
1972 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8,
1973 aom_highbd_obmc_variance128x64,
1974 aom_highbd_obmc_sub_pixel_variance128x64)
1975 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8,
1976 aom_highbd_obmc_variance64x128,
1977 aom_highbd_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001978#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001979 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8,
1980 aom_highbd_obmc_variance64x64,
1981 aom_highbd_obmc_sub_pixel_variance64x64)
1982 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8,
1983 aom_highbd_obmc_variance64x32,
1984 aom_highbd_obmc_sub_pixel_variance64x32)
1985 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8,
1986 aom_highbd_obmc_variance32x64,
1987 aom_highbd_obmc_sub_pixel_variance32x64)
1988 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8,
1989 aom_highbd_obmc_variance32x32,
1990 aom_highbd_obmc_sub_pixel_variance32x32)
1991 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8,
1992 aom_highbd_obmc_variance32x16,
1993 aom_highbd_obmc_sub_pixel_variance32x16)
1994 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8,
1995 aom_highbd_obmc_variance16x32,
1996 aom_highbd_obmc_sub_pixel_variance16x32)
1997 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8,
1998 aom_highbd_obmc_variance16x16,
1999 aom_highbd_obmc_sub_pixel_variance16x16)
2000 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8,
2001 aom_highbd_obmc_variance8x16,
2002 aom_highbd_obmc_sub_pixel_variance8x16)
2003 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8,
2004 aom_highbd_obmc_variance16x8,
2005 aom_highbd_obmc_sub_pixel_variance16x8)
2006 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8,
2007 aom_highbd_obmc_variance8x8,
2008 aom_highbd_obmc_sub_pixel_variance8x8)
2009 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8,
2010 aom_highbd_obmc_variance4x8,
2011 aom_highbd_obmc_sub_pixel_variance4x8)
2012 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8,
2013 aom_highbd_obmc_variance8x4,
2014 aom_highbd_obmc_sub_pixel_variance8x4)
2015 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8,
2016 aom_highbd_obmc_variance4x4,
2017 aom_highbd_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002018#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002019#if CONFIG_EXT_PARTITION
2020 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits8,
2021 aom_highbd_obmc_variance128x32,
2022 aom_highbd_obmc_sub_pixel_variance128x32)
2023
2024 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits8,
2025 aom_highbd_obmc_variance32x128,
2026 aom_highbd_obmc_sub_pixel_variance32x128)
2027#endif // CONFIG_EXT_PARTITION
2028
Rupert Swarbrick72678572017-08-02 12:05:26 +01002029 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8,
2030 aom_highbd_obmc_variance64x16,
2031 aom_highbd_obmc_sub_pixel_variance64x16)
2032
2033 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8,
2034 aom_highbd_obmc_variance16x64,
2035 aom_highbd_obmc_sub_pixel_variance16x64)
2036
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002037 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8,
2038 aom_highbd_obmc_variance32x8,
2039 aom_highbd_obmc_sub_pixel_variance32x8)
2040
2041 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8,
2042 aom_highbd_obmc_variance8x32,
2043 aom_highbd_obmc_sub_pixel_variance8x32)
2044
2045 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8,
2046 aom_highbd_obmc_variance16x4,
2047 aom_highbd_obmc_sub_pixel_variance16x4)
2048
2049 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8,
2050 aom_highbd_obmc_variance4x16,
2051 aom_highbd_obmc_sub_pixel_variance4x16)
2052#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002053 break;
2054
Yaowu Xuf883b422016-08-30 14:01:10 -07002055 case AOM_BITS_10:
Cheng Chenbf3d4962017-11-01 14:48:52 -07002056#if CONFIG_JNT_COMP
2057#if CONFIG_EXT_PARTITION_TYPES
2058#if CONFIG_EXT_PARTITION
2059 HIGHBD_BFP(
2060 BLOCK_128X32, aom_highbd_sad128x32_bits10,
2061 aom_highbd_sad128x32_avg_bits10, aom_highbd_10_variance128x32,
2062 aom_highbd_10_sub_pixel_variance128x32,
2063 aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL,
2064 aom_highbd_sad128x32x4d_bits10, aom_highbd_jnt_sad128x32_avg_bits10,
2065 aom_highbd_10_jnt_sub_pixel_avg_variance128x32);
2066
2067 HIGHBD_BFP(
2068 BLOCK_32X128, aom_highbd_sad32x128_bits10,
2069 aom_highbd_sad32x128_avg_bits10, aom_highbd_10_variance32x128,
2070 aom_highbd_10_sub_pixel_variance32x128,
2071 aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL,
2072 aom_highbd_sad32x128x4d_bits10, aom_highbd_jnt_sad32x128_avg_bits10,
2073 aom_highbd_10_jnt_sub_pixel_avg_variance32x128);
2074#endif // CONFIG_EXT_PARTITION
2075
2076 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10,
2077 aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16,
2078 aom_highbd_10_sub_pixel_variance64x16,
2079 aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL,
2080 aom_highbd_sad64x16x4d_bits10,
2081 aom_highbd_jnt_sad64x16_avg_bits10,
2082 aom_highbd_10_jnt_sub_pixel_avg_variance64x16);
2083
2084 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10,
2085 aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64,
2086 aom_highbd_10_sub_pixel_variance16x64,
2087 aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL,
2088 aom_highbd_sad16x64x4d_bits10,
2089 aom_highbd_jnt_sad16x64_avg_bits10,
2090 aom_highbd_10_jnt_sub_pixel_avg_variance16x64);
2091
2092 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10,
2093 aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8,
2094 aom_highbd_10_sub_pixel_variance32x8,
2095 aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL,
2096 aom_highbd_sad32x8x4d_bits10,
2097 aom_highbd_jnt_sad32x8_avg_bits10,
2098 aom_highbd_10_jnt_sub_pixel_avg_variance32x8);
2099
2100 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10,
2101 aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32,
2102 aom_highbd_10_sub_pixel_variance8x32,
2103 aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL,
2104 aom_highbd_sad8x32x4d_bits10,
2105 aom_highbd_jnt_sad8x32_avg_bits10,
2106 aom_highbd_10_jnt_sub_pixel_avg_variance8x32);
2107
2108 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10,
2109 aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4,
2110 aom_highbd_10_sub_pixel_variance16x4,
2111 aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL,
2112 aom_highbd_sad16x4x4d_bits10,
2113 aom_highbd_jnt_sad16x4_avg_bits10,
2114 aom_highbd_10_jnt_sub_pixel_avg_variance16x4);
2115
2116 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10,
2117 aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16,
2118 aom_highbd_10_sub_pixel_variance4x16,
2119 aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL,
2120 aom_highbd_sad4x16x4d_bits10,
2121 aom_highbd_jnt_sad4x16_avg_bits10,
2122 aom_highbd_10_jnt_sub_pixel_avg_variance4x16);
2123#endif
2124
2125 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10,
2126 aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16,
2127 aom_highbd_10_sub_pixel_variance32x16,
2128 aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL,
2129 aom_highbd_sad32x16x4d_bits10,
2130 aom_highbd_jnt_sad32x16_avg_bits10,
2131 aom_highbd_10_jnt_sub_pixel_avg_variance32x16);
2132
2133 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10,
2134 aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32,
2135 aom_highbd_10_sub_pixel_variance16x32,
2136 aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL,
2137 aom_highbd_sad16x32x4d_bits10,
2138 aom_highbd_jnt_sad16x32_avg_bits10,
2139 aom_highbd_10_jnt_sub_pixel_avg_variance16x32);
2140
2141 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10,
2142 aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32,
2143 aom_highbd_10_sub_pixel_variance64x32,
2144 aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL,
2145 aom_highbd_sad64x32x4d_bits10,
2146 aom_highbd_jnt_sad64x32_avg_bits10,
2147 aom_highbd_10_jnt_sub_pixel_avg_variance64x32);
2148
2149 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10,
2150 aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64,
2151 aom_highbd_10_sub_pixel_variance32x64,
2152 aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL,
2153 aom_highbd_sad32x64x4d_bits10,
2154 aom_highbd_jnt_sad32x64_avg_bits10,
2155 aom_highbd_10_jnt_sub_pixel_avg_variance32x64);
2156
2157 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10,
2158 aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32,
2159 aom_highbd_10_sub_pixel_variance32x32,
2160 aom_highbd_10_sub_pixel_avg_variance32x32,
2161 aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10,
2162 aom_highbd_sad32x32x4d_bits10,
2163 aom_highbd_jnt_sad32x32_avg_bits10,
2164 aom_highbd_10_jnt_sub_pixel_avg_variance32x32);
2165
2166 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10,
2167 aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64,
2168 aom_highbd_10_sub_pixel_variance64x64,
2169 aom_highbd_10_sub_pixel_avg_variance64x64,
2170 aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10,
2171 aom_highbd_sad64x64x4d_bits10,
2172 aom_highbd_jnt_sad64x64_avg_bits10,
2173 aom_highbd_10_jnt_sub_pixel_avg_variance64x64);
2174
2175 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10,
2176 aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16,
2177 aom_highbd_10_sub_pixel_variance16x16,
2178 aom_highbd_10_sub_pixel_avg_variance16x16,
2179 aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10,
2180 aom_highbd_sad16x16x4d_bits10,
2181 aom_highbd_jnt_sad16x16_avg_bits10,
2182 aom_highbd_10_jnt_sub_pixel_avg_variance16x16);
2183
2184 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10,
2185 aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8,
2186 aom_highbd_10_sub_pixel_variance16x8,
2187 aom_highbd_10_sub_pixel_avg_variance16x8,
2188 aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10,
2189 aom_highbd_sad16x8x4d_bits10,
2190 aom_highbd_jnt_sad16x8_avg_bits10,
2191 aom_highbd_10_jnt_sub_pixel_avg_variance16x8);
2192
2193 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10,
2194 aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16,
2195 aom_highbd_10_sub_pixel_variance8x16,
2196 aom_highbd_10_sub_pixel_avg_variance8x16,
2197 aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10,
2198 aom_highbd_sad8x16x4d_bits10,
2199 aom_highbd_jnt_sad8x16_avg_bits10,
2200 aom_highbd_10_jnt_sub_pixel_avg_variance8x16);
2201
2202 HIGHBD_BFP(
2203 BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10,
2204 aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8,
2205 aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10,
2206 aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10,
2207 aom_highbd_jnt_sad8x8_avg_bits10,
2208 aom_highbd_10_jnt_sub_pixel_avg_variance8x8);
2209
2210 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10,
2211 aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4,
2212 aom_highbd_10_sub_pixel_variance8x4,
2213 aom_highbd_10_sub_pixel_avg_variance8x4, NULL,
2214 aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10,
2215 aom_highbd_jnt_sad8x4_avg_bits10,
2216 aom_highbd_10_jnt_sub_pixel_avg_variance8x4);
2217
2218 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10,
2219 aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8,
2220 aom_highbd_10_sub_pixel_variance4x8,
2221 aom_highbd_10_sub_pixel_avg_variance4x8, NULL,
2222 aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10,
2223 aom_highbd_jnt_sad4x8_avg_bits10,
2224 aom_highbd_10_jnt_sub_pixel_avg_variance4x8);
2225
2226 HIGHBD_BFP(
2227 BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10,
2228 aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4,
2229 aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10,
2230 aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10,
2231 aom_highbd_jnt_sad4x4_avg_bits10,
2232 aom_highbd_10_jnt_sub_pixel_avg_variance4x4);
2233
Cheng Chenbf3d4962017-11-01 14:48:52 -07002234#if CONFIG_EXT_PARTITION
2235 HIGHBD_BFP(
2236 BLOCK_128X128, aom_highbd_sad128x128_bits10,
2237 aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128,
2238 aom_highbd_10_sub_pixel_variance128x128,
2239 aom_highbd_10_sub_pixel_avg_variance128x128,
2240 aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10,
2241 aom_highbd_sad128x128x4d_bits10,
2242 aom_highbd_jnt_sad128x128_avg_bits10,
2243 aom_highbd_10_jnt_sub_pixel_avg_variance128x128);
2244
2245 HIGHBD_BFP(
2246 BLOCK_128X64, aom_highbd_sad128x64_bits10,
2247 aom_highbd_sad128x64_avg_bits10, aom_highbd_10_variance128x64,
2248 aom_highbd_10_sub_pixel_variance128x64,
2249 aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL,
2250 aom_highbd_sad128x64x4d_bits10, aom_highbd_jnt_sad128x64_avg_bits10,
2251 aom_highbd_10_jnt_sub_pixel_avg_variance128x64);
2252
2253 HIGHBD_BFP(
2254 BLOCK_64X128, aom_highbd_sad64x128_bits10,
2255 aom_highbd_sad64x128_avg_bits10, aom_highbd_10_variance64x128,
2256 aom_highbd_10_sub_pixel_variance64x128,
2257 aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL,
2258 aom_highbd_sad64x128x4d_bits10, aom_highbd_jnt_sad64x128_avg_bits10,
2259 aom_highbd_10_jnt_sub_pixel_avg_variance64x128);
2260#endif // CONFIG_EXT_PARTITION
2261#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002262#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002263#if CONFIG_EXT_PARTITION
2264 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits10,
2265 aom_highbd_sad128x32_avg_bits10,
2266 aom_highbd_10_variance128x32,
2267 aom_highbd_10_sub_pixel_variance128x32,
2268 aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL,
2269 aom_highbd_sad128x32x4d_bits10)
2270
2271 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits10,
2272 aom_highbd_sad32x128_avg_bits10,
2273 aom_highbd_10_variance32x128,
2274 aom_highbd_10_sub_pixel_variance32x128,
2275 aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL,
2276 aom_highbd_sad32x128x4d_bits10)
2277#endif // CONFIG_EXT_PARTITION
2278
Rupert Swarbrick72678572017-08-02 12:05:26 +01002279 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10,
2280 aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16,
2281 aom_highbd_10_sub_pixel_variance64x16,
2282 aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL,
2283 aom_highbd_sad64x16x4d_bits10)
2284
2285 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10,
2286 aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64,
2287 aom_highbd_10_sub_pixel_variance16x64,
2288 aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL,
2289 aom_highbd_sad16x64x4d_bits10)
2290
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002291 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10,
2292 aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8,
2293 aom_highbd_10_sub_pixel_variance32x8,
2294 aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL,
2295 aom_highbd_sad32x8x4d_bits10)
2296
2297 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10,
2298 aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32,
2299 aom_highbd_10_sub_pixel_variance8x32,
2300 aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL,
2301 aom_highbd_sad8x32x4d_bits10)
2302
2303 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10,
2304 aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4,
2305 aom_highbd_10_sub_pixel_variance16x4,
2306 aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL,
2307 aom_highbd_sad16x4x4d_bits10)
2308
2309 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10,
2310 aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16,
2311 aom_highbd_10_sub_pixel_variance4x16,
2312 aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL,
2313 aom_highbd_sad4x16x4d_bits10)
2314#endif
2315
Yaowu Xuf883b422016-08-30 14:01:10 -07002316 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10,
2317 aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16,
2318 aom_highbd_10_sub_pixel_variance32x16,
2319 aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL,
2320 aom_highbd_sad32x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002321
Yaowu Xuf883b422016-08-30 14:01:10 -07002322 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10,
2323 aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32,
2324 aom_highbd_10_sub_pixel_variance16x32,
2325 aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL,
2326 aom_highbd_sad16x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002327
Yaowu Xuf883b422016-08-30 14:01:10 -07002328 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10,
2329 aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32,
2330 aom_highbd_10_sub_pixel_variance64x32,
2331 aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL,
2332 aom_highbd_sad64x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002333
Yaowu Xuf883b422016-08-30 14:01:10 -07002334 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10,
2335 aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64,
2336 aom_highbd_10_sub_pixel_variance32x64,
2337 aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL,
2338 aom_highbd_sad32x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002339
Yaowu Xuf883b422016-08-30 14:01:10 -07002340 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10,
2341 aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32,
2342 aom_highbd_10_sub_pixel_variance32x32,
2343 aom_highbd_10_sub_pixel_avg_variance32x32,
2344 aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10,
2345 aom_highbd_sad32x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002346
Yaowu Xuf883b422016-08-30 14:01:10 -07002347 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10,
2348 aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64,
2349 aom_highbd_10_sub_pixel_variance64x64,
2350 aom_highbd_10_sub_pixel_avg_variance64x64,
2351 aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10,
2352 aom_highbd_sad64x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002353
Yaowu Xuf883b422016-08-30 14:01:10 -07002354 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10,
2355 aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16,
2356 aom_highbd_10_sub_pixel_variance16x16,
2357 aom_highbd_10_sub_pixel_avg_variance16x16,
2358 aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10,
2359 aom_highbd_sad16x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002360
Yaowu Xuf883b422016-08-30 14:01:10 -07002361 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10,
2362 aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8,
2363 aom_highbd_10_sub_pixel_variance16x8,
2364 aom_highbd_10_sub_pixel_avg_variance16x8,
2365 aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10,
2366 aom_highbd_sad16x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002367
Yaowu Xuf883b422016-08-30 14:01:10 -07002368 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10,
2369 aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16,
2370 aom_highbd_10_sub_pixel_variance8x16,
2371 aom_highbd_10_sub_pixel_avg_variance8x16,
2372 aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10,
2373 aom_highbd_sad8x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002374
2375 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002376 BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10,
2377 aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8,
2378 aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10,
2379 aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002380
Yaowu Xuf883b422016-08-30 14:01:10 -07002381 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10,
2382 aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4,
2383 aom_highbd_10_sub_pixel_variance8x4,
2384 aom_highbd_10_sub_pixel_avg_variance8x4, NULL,
2385 aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002386
Yaowu Xuf883b422016-08-30 14:01:10 -07002387 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10,
2388 aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8,
2389 aom_highbd_10_sub_pixel_variance4x8,
2390 aom_highbd_10_sub_pixel_avg_variance4x8, NULL,
2391 aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002392
2393 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002394 BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10,
2395 aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4,
2396 aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10,
2397 aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002398
2399#if CONFIG_EXT_PARTITION
2400 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002401 BLOCK_128X128, aom_highbd_sad128x128_bits10,
2402 aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128,
2403 aom_highbd_10_sub_pixel_variance128x128,
2404 aom_highbd_10_sub_pixel_avg_variance128x128,
2405 aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10,
2406 aom_highbd_sad128x128x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002407
Yaowu Xuf883b422016-08-30 14:01:10 -07002408 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10,
2409 aom_highbd_sad128x64_avg_bits10,
2410 aom_highbd_10_variance128x64,
2411 aom_highbd_10_sub_pixel_variance128x64,
2412 aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL,
2413 aom_highbd_sad128x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002414
Yaowu Xuf883b422016-08-30 14:01:10 -07002415 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10,
2416 aom_highbd_sad64x128_avg_bits10,
2417 aom_highbd_10_variance64x128,
2418 aom_highbd_10_sub_pixel_variance64x128,
2419 aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL,
2420 aom_highbd_sad64x128x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002421#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07002422#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002423
Yaowu Xuc27fc142016-08-22 16:08:15 -07002424#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002425 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10,
2426 aom_highbd_10_masked_sub_pixel_variance128x128)
2427 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10,
2428 aom_highbd_10_masked_sub_pixel_variance128x64)
2429 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10,
2430 aom_highbd_10_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002431#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002432 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10,
2433 aom_highbd_10_masked_sub_pixel_variance64x64)
2434 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10,
2435 aom_highbd_10_masked_sub_pixel_variance64x32)
2436 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10,
2437 aom_highbd_10_masked_sub_pixel_variance32x64)
2438 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10,
2439 aom_highbd_10_masked_sub_pixel_variance32x32)
2440 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10,
2441 aom_highbd_10_masked_sub_pixel_variance32x16)
2442 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10,
2443 aom_highbd_10_masked_sub_pixel_variance16x32)
2444 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10,
2445 aom_highbd_10_masked_sub_pixel_variance16x16)
2446 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10,
2447 aom_highbd_10_masked_sub_pixel_variance8x16)
2448 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10,
2449 aom_highbd_10_masked_sub_pixel_variance16x8)
2450 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10,
2451 aom_highbd_10_masked_sub_pixel_variance8x8)
2452 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10,
2453 aom_highbd_10_masked_sub_pixel_variance4x8)
2454 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10,
2455 aom_highbd_10_masked_sub_pixel_variance8x4)
2456 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10,
2457 aom_highbd_10_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002458#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002459#if CONFIG_EXT_PARTITION
2460 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits10,
2461 aom_highbd_10_masked_sub_pixel_variance128x32)
2462
2463 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits10,
2464 aom_highbd_10_masked_sub_pixel_variance32x128)
2465#endif // CONFIG_EXT_PARTITION
2466
Rupert Swarbrick72678572017-08-02 12:05:26 +01002467 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10,
2468 aom_highbd_10_masked_sub_pixel_variance64x16)
2469
2470 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10,
2471 aom_highbd_10_masked_sub_pixel_variance16x64)
2472
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002473 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10,
2474 aom_highbd_10_masked_sub_pixel_variance32x8)
2475
2476 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10,
2477 aom_highbd_10_masked_sub_pixel_variance8x32)
2478
2479 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10,
2480 aom_highbd_10_masked_sub_pixel_variance16x4)
2481
2482 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10,
2483 aom_highbd_10_masked_sub_pixel_variance4x16)
2484#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002485#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07002486 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10,
2487 aom_highbd_10_obmc_variance128x128,
2488 aom_highbd_10_obmc_sub_pixel_variance128x128)
2489 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10,
2490 aom_highbd_10_obmc_variance128x64,
2491 aom_highbd_10_obmc_sub_pixel_variance128x64)
2492 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10,
2493 aom_highbd_10_obmc_variance64x128,
2494 aom_highbd_10_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002495#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07002496 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10,
2497 aom_highbd_10_obmc_variance64x64,
2498 aom_highbd_10_obmc_sub_pixel_variance64x64)
2499 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10,
2500 aom_highbd_10_obmc_variance64x32,
2501 aom_highbd_10_obmc_sub_pixel_variance64x32)
2502 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10,
2503 aom_highbd_10_obmc_variance32x64,
2504 aom_highbd_10_obmc_sub_pixel_variance32x64)
2505 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10,
2506 aom_highbd_10_obmc_variance32x32,
2507 aom_highbd_10_obmc_sub_pixel_variance32x32)
2508 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10,
2509 aom_highbd_10_obmc_variance32x16,
2510 aom_highbd_10_obmc_sub_pixel_variance32x16)
2511 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10,
2512 aom_highbd_10_obmc_variance16x32,
2513 aom_highbd_10_obmc_sub_pixel_variance16x32)
2514 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10,
2515 aom_highbd_10_obmc_variance16x16,
2516 aom_highbd_10_obmc_sub_pixel_variance16x16)
2517 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10,
2518 aom_highbd_10_obmc_variance8x16,
2519 aom_highbd_10_obmc_sub_pixel_variance8x16)
2520 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10,
2521 aom_highbd_10_obmc_variance16x8,
2522 aom_highbd_10_obmc_sub_pixel_variance16x8)
2523 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10,
2524 aom_highbd_10_obmc_variance8x8,
2525 aom_highbd_10_obmc_sub_pixel_variance8x8)
2526 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10,
2527 aom_highbd_10_obmc_variance4x8,
2528 aom_highbd_10_obmc_sub_pixel_variance4x8)
2529 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10,
2530 aom_highbd_10_obmc_variance8x4,
2531 aom_highbd_10_obmc_sub_pixel_variance8x4)
2532 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10,
2533 aom_highbd_10_obmc_variance4x4,
2534 aom_highbd_10_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002535#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002536#if CONFIG_EXT_PARTITION
2537 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits10,
2538 aom_highbd_10_obmc_variance128x32,
2539 aom_highbd_10_obmc_sub_pixel_variance128x32)
2540
2541 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits10,
2542 aom_highbd_10_obmc_variance32x128,
2543 aom_highbd_10_obmc_sub_pixel_variance32x128)
2544#endif // CONFIG_EXT_PARTITION
2545
Rupert Swarbrick72678572017-08-02 12:05:26 +01002546 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10,
2547 aom_highbd_10_obmc_variance64x16,
2548 aom_highbd_10_obmc_sub_pixel_variance64x16)
2549
2550 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10,
2551 aom_highbd_10_obmc_variance16x64,
2552 aom_highbd_10_obmc_sub_pixel_variance16x64)
2553
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002554 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10,
2555 aom_highbd_10_obmc_variance32x8,
2556 aom_highbd_10_obmc_sub_pixel_variance32x8)
2557
2558 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10,
2559 aom_highbd_10_obmc_variance8x32,
2560 aom_highbd_10_obmc_sub_pixel_variance8x32)
2561
2562 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10,
2563 aom_highbd_10_obmc_variance16x4,
2564 aom_highbd_10_obmc_sub_pixel_variance16x4)
2565
2566 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10,
2567 aom_highbd_10_obmc_variance4x16,
2568 aom_highbd_10_obmc_sub_pixel_variance4x16)
2569#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002570 break;
2571
Yaowu Xuf883b422016-08-30 14:01:10 -07002572 case AOM_BITS_12:
Cheng Chenbf3d4962017-11-01 14:48:52 -07002573#if CONFIG_JNT_COMP
2574#if CONFIG_EXT_PARTITION_TYPES
2575#if CONFIG_EXT_PARTITION
2576 HIGHBD_BFP(
2577 BLOCK_128X32, aom_highbd_sad128x32_bits12,
2578 aom_highbd_sad128x32_avg_bits12, aom_highbd_12_variance128x32,
2579 aom_highbd_12_sub_pixel_variance128x32,
2580 aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL,
2581 aom_highbd_sad128x32x4d_bits12, aom_highbd_jnt_sad128x32_avg_bits12,
2582 aom_highbd_12_jnt_sub_pixel_avg_variance128x32);
2583
2584 HIGHBD_BFP(
2585 BLOCK_32X128, aom_highbd_sad32x128_bits12,
2586 aom_highbd_sad32x128_avg_bits12, aom_highbd_12_variance32x128,
2587 aom_highbd_12_sub_pixel_variance32x128,
2588 aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL,
2589 aom_highbd_sad32x128x4d_bits12, aom_highbd_jnt_sad32x128_avg_bits12,
2590 aom_highbd_12_jnt_sub_pixel_avg_variance32x128);
2591#endif // CONFIG_EXT_PARTITION
2592
2593 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12,
2594 aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16,
2595 aom_highbd_12_sub_pixel_variance64x16,
2596 aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL,
2597 aom_highbd_sad64x16x4d_bits12,
2598 aom_highbd_jnt_sad64x16_avg_bits12,
2599 aom_highbd_12_jnt_sub_pixel_avg_variance64x16);
2600
2601 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12,
2602 aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64,
2603 aom_highbd_12_sub_pixel_variance16x64,
2604 aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL,
2605 aom_highbd_sad16x64x4d_bits12,
2606 aom_highbd_jnt_sad16x64_avg_bits12,
2607 aom_highbd_12_jnt_sub_pixel_avg_variance16x64);
2608
2609 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12,
2610 aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8,
2611 aom_highbd_12_sub_pixel_variance32x8,
2612 aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL,
2613 aom_highbd_sad32x8x4d_bits12,
2614 aom_highbd_jnt_sad32x8_avg_bits12,
2615 aom_highbd_12_jnt_sub_pixel_avg_variance32x8);
2616
2617 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12,
2618 aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32,
2619 aom_highbd_12_sub_pixel_variance8x32,
2620 aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL,
2621 aom_highbd_sad8x32x4d_bits12,
2622 aom_highbd_jnt_sad8x32_avg_bits12,
2623 aom_highbd_12_jnt_sub_pixel_avg_variance8x32);
2624
2625 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12,
2626 aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4,
2627 aom_highbd_12_sub_pixel_variance16x4,
2628 aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL,
2629 aom_highbd_sad16x4x4d_bits12,
2630 aom_highbd_jnt_sad16x4_avg_bits12,
2631 aom_highbd_12_jnt_sub_pixel_avg_variance16x4);
2632
2633 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12,
2634 aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16,
2635 aom_highbd_12_sub_pixel_variance4x16,
2636 aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL,
2637 aom_highbd_sad4x16x4d_bits12,
2638 aom_highbd_jnt_sad4x16_avg_bits12,
2639 aom_highbd_12_jnt_sub_pixel_avg_variance4x16);
2640#endif
2641
2642 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12,
2643 aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16,
2644 aom_highbd_12_sub_pixel_variance32x16,
2645 aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL,
2646 aom_highbd_sad32x16x4d_bits12,
2647 aom_highbd_jnt_sad32x16_avg_bits12,
2648 aom_highbd_12_jnt_sub_pixel_avg_variance32x16);
2649
2650 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12,
2651 aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32,
2652 aom_highbd_12_sub_pixel_variance16x32,
2653 aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL,
2654 aom_highbd_sad16x32x4d_bits12,
2655 aom_highbd_jnt_sad16x32_avg_bits12,
2656 aom_highbd_12_jnt_sub_pixel_avg_variance16x32);
2657
2658 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12,
2659 aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32,
2660 aom_highbd_12_sub_pixel_variance64x32,
2661 aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL,
2662 aom_highbd_sad64x32x4d_bits12,
2663 aom_highbd_jnt_sad64x32_avg_bits12,
2664 aom_highbd_12_jnt_sub_pixel_avg_variance64x32);
2665
2666 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12,
2667 aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64,
2668 aom_highbd_12_sub_pixel_variance32x64,
2669 aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL,
2670 aom_highbd_sad32x64x4d_bits12,
2671 aom_highbd_jnt_sad32x64_avg_bits12,
2672 aom_highbd_12_jnt_sub_pixel_avg_variance32x64);
2673
2674 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12,
2675 aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32,
2676 aom_highbd_12_sub_pixel_variance32x32,
2677 aom_highbd_12_sub_pixel_avg_variance32x32,
2678 aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12,
2679 aom_highbd_sad32x32x4d_bits12,
2680 aom_highbd_jnt_sad32x32_avg_bits12,
2681 aom_highbd_12_jnt_sub_pixel_avg_variance32x32);
2682
2683 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12,
2684 aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64,
2685 aom_highbd_12_sub_pixel_variance64x64,
2686 aom_highbd_12_sub_pixel_avg_variance64x64,
2687 aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12,
2688 aom_highbd_sad64x64x4d_bits12,
2689 aom_highbd_jnt_sad64x64_avg_bits12,
2690 aom_highbd_12_jnt_sub_pixel_avg_variance64x64);
2691
2692 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12,
2693 aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16,
2694 aom_highbd_12_sub_pixel_variance16x16,
2695 aom_highbd_12_sub_pixel_avg_variance16x16,
2696 aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12,
2697 aom_highbd_sad16x16x4d_bits12,
2698 aom_highbd_jnt_sad16x16_avg_bits12,
2699 aom_highbd_12_jnt_sub_pixel_avg_variance16x16);
2700
2701 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12,
2702 aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8,
2703 aom_highbd_12_sub_pixel_variance16x8,
2704 aom_highbd_12_sub_pixel_avg_variance16x8,
2705 aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12,
2706 aom_highbd_sad16x8x4d_bits12,
2707 aom_highbd_jnt_sad16x8_avg_bits12,
2708 aom_highbd_12_jnt_sub_pixel_avg_variance16x8);
2709
2710 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12,
2711 aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16,
2712 aom_highbd_12_sub_pixel_variance8x16,
2713 aom_highbd_12_sub_pixel_avg_variance8x16,
2714 aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12,
2715 aom_highbd_sad8x16x4d_bits12,
2716 aom_highbd_jnt_sad8x16_avg_bits12,
2717 aom_highbd_12_jnt_sub_pixel_avg_variance8x16);
2718
2719 HIGHBD_BFP(
2720 BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12,
2721 aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8,
2722 aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12,
2723 aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12,
2724 aom_highbd_jnt_sad8x8_avg_bits12,
2725 aom_highbd_12_jnt_sub_pixel_avg_variance8x8);
2726
2727 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12,
2728 aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4,
2729 aom_highbd_12_sub_pixel_variance8x4,
2730 aom_highbd_12_sub_pixel_avg_variance8x4, NULL,
2731 aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12,
2732 aom_highbd_jnt_sad8x4_avg_bits12,
2733 aom_highbd_12_jnt_sub_pixel_avg_variance8x4);
2734
2735 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12,
2736 aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8,
2737 aom_highbd_12_sub_pixel_variance4x8,
2738 aom_highbd_12_sub_pixel_avg_variance4x8, NULL,
2739 aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12,
2740 aom_highbd_jnt_sad4x8_avg_bits12,
2741 aom_highbd_12_jnt_sub_pixel_avg_variance4x8);
2742
2743 HIGHBD_BFP(
2744 BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12,
2745 aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4,
2746 aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12,
2747 aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12,
2748 aom_highbd_jnt_sad4x4_avg_bits12,
2749 aom_highbd_12_jnt_sub_pixel_avg_variance4x4);
2750
Cheng Chenbf3d4962017-11-01 14:48:52 -07002751#if CONFIG_EXT_PARTITION
2752 HIGHBD_BFP(
2753 BLOCK_128X128, aom_highbd_sad128x128_bits12,
2754 aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128,
2755 aom_highbd_12_sub_pixel_variance128x128,
2756 aom_highbd_12_sub_pixel_avg_variance128x128,
2757 aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12,
2758 aom_highbd_sad128x128x4d_bits12,
2759 aom_highbd_jnt_sad128x128_avg_bits12,
2760 aom_highbd_12_jnt_sub_pixel_avg_variance128x128);
2761
2762 HIGHBD_BFP(
2763 BLOCK_128X64, aom_highbd_sad128x64_bits12,
2764 aom_highbd_sad128x64_avg_bits12, aom_highbd_12_variance128x64,
2765 aom_highbd_12_sub_pixel_variance128x64,
2766 aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL,
2767 aom_highbd_sad128x64x4d_bits12, aom_highbd_jnt_sad128x64_avg_bits12,
2768 aom_highbd_12_jnt_sub_pixel_avg_variance128x64);
2769
2770 HIGHBD_BFP(
2771 BLOCK_64X128, aom_highbd_sad64x128_bits12,
2772 aom_highbd_sad64x128_avg_bits12, aom_highbd_12_variance64x128,
2773 aom_highbd_12_sub_pixel_variance64x128,
2774 aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL,
2775 aom_highbd_sad64x128x4d_bits12, aom_highbd_jnt_sad64x128_avg_bits12,
2776 aom_highbd_12_jnt_sub_pixel_avg_variance64x128);
2777#endif // CONFIG_EXT_PARTITION
2778#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002779#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002780#if CONFIG_EXT_PARTITION
2781 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits12,
2782 aom_highbd_sad128x32_avg_bits12,
2783 aom_highbd_12_variance128x32,
2784 aom_highbd_12_sub_pixel_variance128x32,
2785 aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL,
2786 aom_highbd_sad128x32x4d_bits12)
2787
2788 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits12,
2789 aom_highbd_sad32x128_avg_bits12,
2790 aom_highbd_12_variance32x128,
2791 aom_highbd_12_sub_pixel_variance32x128,
2792 aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL,
2793 aom_highbd_sad32x128x4d_bits12)
2794#endif // CONFIG_EXT_PARTITION
2795
Rupert Swarbrick72678572017-08-02 12:05:26 +01002796 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12,
2797 aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16,
2798 aom_highbd_12_sub_pixel_variance64x16,
2799 aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL,
2800 aom_highbd_sad64x16x4d_bits12)
2801
2802 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12,
2803 aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64,
2804 aom_highbd_12_sub_pixel_variance16x64,
2805 aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL,
2806 aom_highbd_sad16x64x4d_bits12)
2807
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002808 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12,
2809 aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8,
2810 aom_highbd_12_sub_pixel_variance32x8,
2811 aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL,
2812 aom_highbd_sad32x8x4d_bits12)
2813
2814 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12,
2815 aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32,
2816 aom_highbd_12_sub_pixel_variance8x32,
2817 aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL,
2818 aom_highbd_sad8x32x4d_bits12)
2819
2820 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12,
2821 aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4,
2822 aom_highbd_12_sub_pixel_variance16x4,
2823 aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL,
2824 aom_highbd_sad16x4x4d_bits12)
2825
2826 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12,
2827 aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16,
2828 aom_highbd_12_sub_pixel_variance4x16,
2829 aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL,
2830 aom_highbd_sad4x16x4d_bits12)
2831#endif
2832
Yaowu Xuf883b422016-08-30 14:01:10 -07002833 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12,
2834 aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16,
2835 aom_highbd_12_sub_pixel_variance32x16,
2836 aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL,
2837 aom_highbd_sad32x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002838
Yaowu Xuf883b422016-08-30 14:01:10 -07002839 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12,
2840 aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32,
2841 aom_highbd_12_sub_pixel_variance16x32,
2842 aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL,
2843 aom_highbd_sad16x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002844
Yaowu Xuf883b422016-08-30 14:01:10 -07002845 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12,
2846 aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32,
2847 aom_highbd_12_sub_pixel_variance64x32,
2848 aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL,
2849 aom_highbd_sad64x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002850
Yaowu Xuf883b422016-08-30 14:01:10 -07002851 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12,
2852 aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64,
2853 aom_highbd_12_sub_pixel_variance32x64,
2854 aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL,
2855 aom_highbd_sad32x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002856
Yaowu Xuf883b422016-08-30 14:01:10 -07002857 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12,
2858 aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32,
2859 aom_highbd_12_sub_pixel_variance32x32,
2860 aom_highbd_12_sub_pixel_avg_variance32x32,
2861 aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12,
2862 aom_highbd_sad32x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002863
Yaowu Xuf883b422016-08-30 14:01:10 -07002864 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12,
2865 aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64,
2866 aom_highbd_12_sub_pixel_variance64x64,
2867 aom_highbd_12_sub_pixel_avg_variance64x64,
2868 aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12,
2869 aom_highbd_sad64x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002870
Yaowu Xuf883b422016-08-30 14:01:10 -07002871 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12,
2872 aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16,
2873 aom_highbd_12_sub_pixel_variance16x16,
2874 aom_highbd_12_sub_pixel_avg_variance16x16,
2875 aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12,
2876 aom_highbd_sad16x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002877
Yaowu Xuf883b422016-08-30 14:01:10 -07002878 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12,
2879 aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8,
2880 aom_highbd_12_sub_pixel_variance16x8,
2881 aom_highbd_12_sub_pixel_avg_variance16x8,
2882 aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12,
2883 aom_highbd_sad16x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002884
Yaowu Xuf883b422016-08-30 14:01:10 -07002885 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12,
2886 aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16,
2887 aom_highbd_12_sub_pixel_variance8x16,
2888 aom_highbd_12_sub_pixel_avg_variance8x16,
2889 aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12,
2890 aom_highbd_sad8x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002891
2892 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002893 BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12,
2894 aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8,
2895 aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12,
2896 aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002897
Yaowu Xuf883b422016-08-30 14:01:10 -07002898 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12,
2899 aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4,
2900 aom_highbd_12_sub_pixel_variance8x4,
2901 aom_highbd_12_sub_pixel_avg_variance8x4, NULL,
2902 aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002903
Yaowu Xuf883b422016-08-30 14:01:10 -07002904 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12,
2905 aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8,
2906 aom_highbd_12_sub_pixel_variance4x8,
2907 aom_highbd_12_sub_pixel_avg_variance4x8, NULL,
2908 aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002909
2910 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002911 BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12,
2912 aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4,
2913 aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12,
2914 aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002915
2916#if CONFIG_EXT_PARTITION
2917 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002918 BLOCK_128X128, aom_highbd_sad128x128_bits12,
2919 aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128,
2920 aom_highbd_12_sub_pixel_variance128x128,
2921 aom_highbd_12_sub_pixel_avg_variance128x128,
2922 aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12,
2923 aom_highbd_sad128x128x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002924
Yaowu Xuf883b422016-08-30 14:01:10 -07002925 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12,
2926 aom_highbd_sad128x64_avg_bits12,
2927 aom_highbd_12_variance128x64,
2928 aom_highbd_12_sub_pixel_variance128x64,
2929 aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL,
2930 aom_highbd_sad128x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002931
Yaowu Xuf883b422016-08-30 14:01:10 -07002932 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12,
2933 aom_highbd_sad64x128_avg_bits12,
2934 aom_highbd_12_variance64x128,
2935 aom_highbd_12_sub_pixel_variance64x128,
2936 aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL,
2937 aom_highbd_sad64x128x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002938#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07002939#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002940
Yaowu Xuc27fc142016-08-22 16:08:15 -07002941#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002942 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12,
2943 aom_highbd_12_masked_sub_pixel_variance128x128)
2944 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12,
2945 aom_highbd_12_masked_sub_pixel_variance128x64)
2946 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12,
2947 aom_highbd_12_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002948#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002949 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12,
2950 aom_highbd_12_masked_sub_pixel_variance64x64)
2951 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12,
2952 aom_highbd_12_masked_sub_pixel_variance64x32)
2953 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12,
2954 aom_highbd_12_masked_sub_pixel_variance32x64)
2955 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12,
2956 aom_highbd_12_masked_sub_pixel_variance32x32)
2957 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12,
2958 aom_highbd_12_masked_sub_pixel_variance32x16)
2959 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12,
2960 aom_highbd_12_masked_sub_pixel_variance16x32)
2961 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12,
2962 aom_highbd_12_masked_sub_pixel_variance16x16)
2963 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12,
2964 aom_highbd_12_masked_sub_pixel_variance8x16)
2965 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12,
2966 aom_highbd_12_masked_sub_pixel_variance16x8)
2967 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12,
2968 aom_highbd_12_masked_sub_pixel_variance8x8)
2969 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12,
2970 aom_highbd_12_masked_sub_pixel_variance4x8)
2971 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12,
2972 aom_highbd_12_masked_sub_pixel_variance8x4)
2973 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12,
2974 aom_highbd_12_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002975#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002976#if CONFIG_EXT_PARTITION
2977 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits12,
2978 aom_highbd_12_masked_sub_pixel_variance128x32)
2979
2980 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits12,
2981 aom_highbd_12_masked_sub_pixel_variance32x128)
2982#endif // CONFIG_EXT_PARTITION
2983
Rupert Swarbrick72678572017-08-02 12:05:26 +01002984 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12,
2985 aom_highbd_12_masked_sub_pixel_variance64x16)
2986
2987 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12,
2988 aom_highbd_12_masked_sub_pixel_variance16x64)
2989
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002990 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12,
2991 aom_highbd_12_masked_sub_pixel_variance32x8)
2992
2993 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12,
2994 aom_highbd_12_masked_sub_pixel_variance8x32)
2995
2996 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12,
2997 aom_highbd_12_masked_sub_pixel_variance16x4)
2998
2999 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12,
3000 aom_highbd_12_masked_sub_pixel_variance4x16)
3001#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003002
Yaowu Xuc27fc142016-08-22 16:08:15 -07003003#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003004 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12,
3005 aom_highbd_12_obmc_variance128x128,
3006 aom_highbd_12_obmc_sub_pixel_variance128x128)
3007 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12,
3008 aom_highbd_12_obmc_variance128x64,
3009 aom_highbd_12_obmc_sub_pixel_variance128x64)
3010 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12,
3011 aom_highbd_12_obmc_variance64x128,
3012 aom_highbd_12_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003013#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003014 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12,
3015 aom_highbd_12_obmc_variance64x64,
3016 aom_highbd_12_obmc_sub_pixel_variance64x64)
3017 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12,
3018 aom_highbd_12_obmc_variance64x32,
3019 aom_highbd_12_obmc_sub_pixel_variance64x32)
3020 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12,
3021 aom_highbd_12_obmc_variance32x64,
3022 aom_highbd_12_obmc_sub_pixel_variance32x64)
3023 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12,
3024 aom_highbd_12_obmc_variance32x32,
3025 aom_highbd_12_obmc_sub_pixel_variance32x32)
3026 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12,
3027 aom_highbd_12_obmc_variance32x16,
3028 aom_highbd_12_obmc_sub_pixel_variance32x16)
3029 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12,
3030 aom_highbd_12_obmc_variance16x32,
3031 aom_highbd_12_obmc_sub_pixel_variance16x32)
3032 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12,
3033 aom_highbd_12_obmc_variance16x16,
3034 aom_highbd_12_obmc_sub_pixel_variance16x16)
3035 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12,
3036 aom_highbd_12_obmc_variance8x16,
3037 aom_highbd_12_obmc_sub_pixel_variance8x16)
3038 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12,
3039 aom_highbd_12_obmc_variance16x8,
3040 aom_highbd_12_obmc_sub_pixel_variance16x8)
3041 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12,
3042 aom_highbd_12_obmc_variance8x8,
3043 aom_highbd_12_obmc_sub_pixel_variance8x8)
3044 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12,
3045 aom_highbd_12_obmc_variance4x8,
3046 aom_highbd_12_obmc_sub_pixel_variance4x8)
3047 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12,
3048 aom_highbd_12_obmc_variance8x4,
3049 aom_highbd_12_obmc_sub_pixel_variance8x4)
3050 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12,
3051 aom_highbd_12_obmc_variance4x4,
3052 aom_highbd_12_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003053#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003054#if CONFIG_EXT_PARTITION
3055 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits12,
3056 aom_highbd_12_obmc_variance128x32,
3057 aom_highbd_12_obmc_sub_pixel_variance128x32)
3058
3059 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits12,
3060 aom_highbd_12_obmc_variance32x128,
3061 aom_highbd_12_obmc_sub_pixel_variance32x128)
3062#endif // CONFIG_EXT_PARTITION
3063
Rupert Swarbrick72678572017-08-02 12:05:26 +01003064 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12,
3065 aom_highbd_12_obmc_variance64x16,
3066 aom_highbd_12_obmc_sub_pixel_variance64x16)
3067
3068 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12,
3069 aom_highbd_12_obmc_variance16x64,
3070 aom_highbd_12_obmc_sub_pixel_variance16x64)
3071
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003072 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12,
3073 aom_highbd_12_obmc_variance32x8,
3074 aom_highbd_12_obmc_sub_pixel_variance32x8)
3075
3076 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12,
3077 aom_highbd_12_obmc_variance8x32,
3078 aom_highbd_12_obmc_sub_pixel_variance8x32)
3079
3080 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12,
3081 aom_highbd_12_obmc_variance16x4,
3082 aom_highbd_12_obmc_sub_pixel_variance16x4)
3083
3084 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12,
3085 aom_highbd_12_obmc_variance4x16,
3086 aom_highbd_12_obmc_sub_pixel_variance4x16)
3087#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003088 break;
3089
3090 default:
3091 assert(0 &&
Yaowu Xuf883b422016-08-30 14:01:10 -07003092 "cm->bit_depth should be AOM_BITS_8, "
3093 "AOM_BITS_10 or AOM_BITS_12");
Yaowu Xuc27fc142016-08-22 16:08:15 -07003094 }
3095 }
3096}
Yaowu Xuc27fc142016-08-22 16:08:15 -07003097
Yaowu Xuf883b422016-08-30 14:01:10 -07003098static void realloc_segmentation_maps(AV1_COMP *cpi) {
3099 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003100
3101 // Create the encoder segmentation map and set all entries to 0
Yaowu Xuf883b422016-08-30 14:01:10 -07003102 aom_free(cpi->segmentation_map);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003103 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
Yaowu Xuf883b422016-08-30 14:01:10 -07003104 aom_calloc(cm->mi_rows * cm->mi_cols, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003105
3106 // Create a map used for cyclic background refresh.
Yaowu Xuf883b422016-08-30 14:01:10 -07003107 if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003108 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
Yaowu Xuf883b422016-08-30 14:01:10 -07003109 av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003110
3111 // Create a map used to mark inactive areas.
Yaowu Xuf883b422016-08-30 14:01:10 -07003112 aom_free(cpi->active_map.map);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003113 CHECK_MEM_ERROR(cm, cpi->active_map.map,
Yaowu Xuf883b422016-08-30 14:01:10 -07003114 aom_calloc(cm->mi_rows * cm->mi_cols, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003115}
3116
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003117void set_compound_tools(AV1_COMMON *cm) {
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003118 cm->allow_interintra_compound = 1;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003119 cm->allow_masked_compound = 1;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003120}
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003121
Yaowu Xuf883b422016-08-30 14:01:10 -07003122void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) {
3123 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003124 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003125 RATE_CONTROL *const rc = &cpi->rc;
hui sud9a812b2017-07-06 14:34:37 -07003126 MACROBLOCK *const x = &cpi->td.mb;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003127
3128 if (cm->profile != oxcf->profile) cm->profile = oxcf->profile;
3129 cm->bit_depth = oxcf->bit_depth;
Andrey Norkin9e694632017-12-21 18:50:57 -08003130#if CONFIG_CICP
3131 cm->color_primaries = oxcf->color_primaries;
3132 cm->transfer_characteristics = oxcf->transfer_characteristics;
3133 cm->matrix_coefficients = oxcf->matrix_coefficients;
3134#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07003135 cm->color_space = oxcf->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08003136#endif
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08003137#if CONFIG_MONO_VIDEO
3138 cm->seq_params.monochrome = oxcf->monochrome;
3139#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07003140#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08003141#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07003142 cm->transfer_function = oxcf->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08003143#endif
anorkin76fb1262017-03-22 15:12:12 -07003144 cm->chroma_sample_position = oxcf->chroma_sample_position;
3145#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003146 cm->color_range = oxcf->color_range;
3147
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08003148 assert(IMPLIES(cm->profile <= PROFILE_1, cm->bit_depth <= AOM_BITS_10));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003149
Andrey Norkin28e9ce22018-01-08 10:11:21 -08003150#if CONFIG_TIMING_INFO_IN_SEQ_HEADERS
3151 cm->timing_info_present = oxcf->timing_info_present;
3152 cm->num_units_in_tick = oxcf->num_units_in_tick;
3153 cm->time_scale = oxcf->time_scale;
3154 cm->equal_picture_interval = oxcf->equal_picture_interval;
3155 cm->num_ticks_per_picture = oxcf->num_ticks_per_picture;
3156#endif
3157
Andrey Norkin6f1c2f72018-01-15 20:08:52 -08003158#if CONFIG_FILM_GRAIN
3159 update_film_grain_parameters(cpi, oxcf);
3160#endif
3161
Yaowu Xuc27fc142016-08-22 16:08:15 -07003162 cpi->oxcf = *oxcf;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +01003163 cpi->common.options = oxcf->cfg;
hui sud9a812b2017-07-06 14:34:37 -07003164 x->e_mbd.bd = (int)cm->bit_depth;
hui sud9a812b2017-07-06 14:34:37 -07003165 x->e_mbd.global_motion = cm->global_motion;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003166
Yaowu Xuf883b422016-08-30 14:01:10 -07003167 if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07003168 rc->baseline_gf_interval = FIXED_GF_INTERVAL;
3169 } else {
3170 rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2;
3171 }
3172
3173 cpi->refresh_last_frame = 1;
3174 cpi->refresh_golden_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003175 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07003176 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003177
3178 cm->refresh_frame_context =
3179 (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode)
3180 ? REFRESH_FRAME_CONTEXT_FORWARD
3181 : REFRESH_FRAME_CONTEXT_BACKWARD;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01003182#if CONFIG_EXT_TILE
3183 if (oxcf->large_scale_tile)
3184 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
3185#endif // CONFIG_EXT_TILE
3186
Thomas Daedea6a854b2017-06-22 17:49:11 -07003187#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07003188 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
Thomas Daedea6a854b2017-06-22 17:49:11 -07003189#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003190
Alex Converse74ad0912017-07-18 10:22:58 -07003191 if (x->palette_buffer == NULL) {
hui sud9a812b2017-07-06 14:34:37 -07003192 CHECK_MEM_ERROR(cm, x->palette_buffer,
3193 aom_memalign(16, sizeof(*x->palette_buffer)));
3194 }
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003195 set_compound_tools(cm);
Yaowu Xuf883b422016-08-30 14:01:10 -07003196 av1_reset_segment_features(cm);
RogerZhou3b635242017-09-19 10:06:46 -07003197#if CONFIG_AMVR
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07003198 set_high_precision_mv(cpi, 1, 0);
RogerZhou3b635242017-09-19 10:06:46 -07003199#else
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07003200 set_high_precision_mv(cpi, 1);
RogerZhou3b635242017-09-19 10:06:46 -07003201#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003202
Yaowu Xuc27fc142016-08-22 16:08:15 -07003203 set_rc_buffer_sizes(rc, &cpi->oxcf);
3204
3205 // Under a configuration change, where maximum_buffer_size may change,
3206 // keep buffer level clipped to the maximum allowed buffer size.
Yaowu Xuf883b422016-08-30 14:01:10 -07003207 rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size);
3208 rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003209
3210 // Set up frame rate and related parameters rate control values.
Yaowu Xuf883b422016-08-30 14:01:10 -07003211 av1_new_framerate(cpi, cpi->framerate);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003212
3213 // Set absolute upper and lower quality limits
3214 rc->worst_quality = cpi->oxcf.worst_allowed_q;
3215 rc->best_quality = cpi->oxcf.best_allowed_q;
3216
Yunqing Wangb6e23bc2017-11-15 13:18:55 -08003217#if CONFIG_EXT_TILE
3218 if (!oxcf->large_scale_tile)
3219#endif // CONFIG_EXT_TILE
3220 cm->interp_filter = cpi->sf.default_interp_filter;
3221#if CONFIG_EXT_TILE
3222 else
3223 cm->interp_filter = EIGHTTAP_REGULAR;
3224#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07003225
3226 if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) {
3227 cm->render_width = cpi->oxcf.render_width;
3228 cm->render_height = cpi->oxcf.render_height;
3229 } else {
3230 cm->render_width = cpi->oxcf.width;
3231 cm->render_height = cpi->oxcf.height;
3232 }
3233 cm->width = cpi->oxcf.width;
3234 cm->height = cpi->oxcf.height;
3235
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003236 int sb_size = cm->seq_params.sb_size;
3237 set_sb_size(&cm->seq_params, select_sb_size(cpi));
Dominic Symes917d6c02017-10-11 18:00:52 +02003238
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003239 if (cpi->initial_width || sb_size != cm->seq_params.sb_size) {
Dominic Symes917d6c02017-10-11 18:00:52 +02003240 if (cm->width > cpi->initial_width || cm->height > cpi->initial_height ||
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003241 cm->seq_params.sb_size != sb_size) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003242 av1_free_context_buffers(cm);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003243 av1_free_pc_tree(&cpi->td, num_planes);
Cheng Chen46f30c72017-09-07 11:13:33 -07003244 alloc_compressor_data(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003245 realloc_segmentation_maps(cpi);
3246 cpi->initial_width = cpi->initial_height = 0;
3247 }
3248 }
3249 update_frame_size(cpi);
3250
3251 cpi->alt_ref_source = NULL;
3252 rc->is_src_frame_alt_ref = 0;
3253
Yaowu Xuc27fc142016-08-22 16:08:15 -07003254 rc->is_bwd_ref_frame = 0;
3255 rc->is_last_bipred_frame = 0;
3256 rc->is_bipred_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003257
Yaowu Xuc27fc142016-08-22 16:08:15 -07003258 set_tile_info(cpi);
3259
3260 cpi->ext_refresh_frame_flags_pending = 0;
3261 cpi->ext_refresh_frame_context_pending = 0;
3262
Yaowu Xuc27fc142016-08-22 16:08:15 -07003263 highbd_set_var_fns(cpi);
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00003264
3265 cm->seq_params.force_screen_content_tools = 2;
RogerZhou3b635242017-09-19 10:06:46 -07003266#if CONFIG_AMVR
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00003267 cm->seq_params.force_integer_mv = 2;
RogerZhou3b635242017-09-19 10:06:46 -07003268#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003269}
3270
Yaowu Xuf883b422016-08-30 14:01:10 -07003271AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
3272 BufferPool *const pool) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07003273 unsigned int i;
Yaowu Xuf883b422016-08-30 14:01:10 -07003274 AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP));
3275 AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003276
3277 if (!cm) return NULL;
3278
Yaowu Xuf883b422016-08-30 14:01:10 -07003279 av1_zero(*cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003280
3281 if (setjmp(cm->error.jmp)) {
3282 cm->error.setjmp = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -07003283 av1_remove_compressor(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003284 return 0;
3285 }
3286
3287 cm->error.setjmp = 1;
Cheng Chen46f30c72017-09-07 11:13:33 -07003288 cm->alloc_mi = enc_alloc_mi;
3289 cm->free_mi = enc_free_mi;
3290 cm->setup_mi = enc_setup_mi;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003291
Angie Chianga5d96c42016-10-21 16:16:56 -07003292 CHECK_MEM_ERROR(cm, cm->fc,
3293 (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
3294 CHECK_MEM_ERROR(cm, cm->frame_contexts,
3295 (FRAME_CONTEXT *)aom_memalign(
3296 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)));
3297 memset(cm->fc, 0, sizeof(*cm->fc));
3298 memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003299
3300 cpi->resize_state = 0;
3301 cpi->resize_avg_qp = 0;
3302 cpi->resize_buffer_underflow = 0;
Fergus Simpsonddc846e2017-04-24 18:09:13 -07003303
Yaowu Xuc27fc142016-08-22 16:08:15 -07003304 cpi->common.buffer_pool = pool;
3305
3306 init_config(cpi, oxcf);
Yaowu Xuf883b422016-08-30 14:01:10 -07003307 av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003308
3309 cm->current_video_frame = 0;
3310 cpi->partition_search_skippable_frame = 0;
3311 cpi->tile_data = NULL;
3312 cpi->last_show_frame_buf_idx = INVALID_IDX;
3313
3314 realloc_segmentation_maps(cpi);
3315
James Zern01a9d702017-08-25 19:09:33 +00003316 for (i = 0; i < NMV_CONTEXTS; ++i) {
3317 memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs));
3318 memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp));
3319 }
3320
Yaowu Xuc27fc142016-08-22 16:08:15 -07003321 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]));
3322 i++) {
3323 CHECK_MEM_ERROR(
3324 cm, cpi->mbgraph_stats[i].mb_stats,
Yaowu Xuf883b422016-08-30 14:01:10 -07003325 aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003326 }
3327
3328#if CONFIG_FP_MB_STATS
3329 cpi->use_fp_mb_stats = 0;
3330 if (cpi->use_fp_mb_stats) {
3331 // a place holder used to store the first pass mb stats in the first pass
3332 CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf,
Yaowu Xuf883b422016-08-30 14:01:10 -07003333 aom_calloc(cm->MBs * sizeof(uint8_t), 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003334 } else {
3335 cpi->twopass.frame_mb_stats_buf = NULL;
3336 }
3337#endif
3338
3339 cpi->refresh_alt_ref_frame = 0;
3340 cpi->multi_arf_last_grp_enabled = 0;
3341
3342 cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
3343#if CONFIG_INTERNAL_STATS
3344 cpi->b_calculate_blockiness = 1;
3345 cpi->b_calculate_consistency = 1;
3346 cpi->total_inconsistency = 0;
3347 cpi->psnr.worst = 100.0;
3348 cpi->worst_ssim = 100.0;
3349
3350 cpi->count = 0;
3351 cpi->bytes = 0;
3352
3353 if (cpi->b_calculate_psnr) {
3354 cpi->total_sq_error = 0;
3355 cpi->total_samples = 0;
3356 cpi->tot_recode_hits = 0;
3357 cpi->summed_quality = 0;
3358 cpi->summed_weights = 0;
3359 }
3360
3361 cpi->fastssim.worst = 100.0;
3362 cpi->psnrhvs.worst = 100.0;
3363
3364 if (cpi->b_calculate_blockiness) {
3365 cpi->total_blockiness = 0;
3366 cpi->worst_blockiness = 0.0;
3367 }
3368
3369 if (cpi->b_calculate_consistency) {
3370 CHECK_MEM_ERROR(cm, cpi->ssim_vars,
Yaowu Xuf883b422016-08-30 14:01:10 -07003371 aom_malloc(sizeof(*cpi->ssim_vars) * 4 *
Yaowu Xuc27fc142016-08-22 16:08:15 -07003372 cpi->common.mi_rows * cpi->common.mi_cols));
3373 cpi->worst_consistency = 100.0;
3374 }
3375#endif
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003376#if CONFIG_ENTROPY_STATS
3377 av1_zero(aggregate_fc);
Zoe Liua56f9162017-06-21 22:49:57 -07003378 av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003379#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003380
3381 cpi->first_time_stamp_ever = INT64_MAX;
3382
James Zern01a9d702017-08-25 19:09:33 +00003383 for (i = 0; i < NMV_CONTEXTS; ++i) {
3384 cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX];
3385 cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX];
3386 cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX];
3387 cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX];
3388 }
3389
Yaowu Xuc27fc142016-08-22 16:08:15 -07003390#ifdef OUTPUT_YUV_SKINMAP
3391 yuv_skinmap_file = fopen("skinmap.yuv", "ab");
3392#endif
3393#ifdef OUTPUT_YUV_REC
3394 yuv_rec_file = fopen("rec.yuv", "wb");
3395#endif
3396
3397#if 0
3398 framepsnr = fopen("framepsnr.stt", "a");
3399 kf_list = fopen("kf_list.stt", "w");
3400#endif
3401
Yaowu Xuc27fc142016-08-22 16:08:15 -07003402 if (oxcf->pass == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003403 av1_init_first_pass(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003404 } else if (oxcf->pass == 2) {
3405 const size_t packet_sz = sizeof(FIRSTPASS_STATS);
3406 const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
3407
3408#if CONFIG_FP_MB_STATS
3409 if (cpi->use_fp_mb_stats) {
3410 const size_t psz = cpi->common.MBs * sizeof(uint8_t);
3411 const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz);
3412
3413 cpi->twopass.firstpass_mb_stats.mb_stats_start =
3414 oxcf->firstpass_mb_stats_in.buf;
3415 cpi->twopass.firstpass_mb_stats.mb_stats_end =
3416 cpi->twopass.firstpass_mb_stats.mb_stats_start +
3417 (ps - 1) * cpi->common.MBs * sizeof(uint8_t);
3418 }
3419#endif
3420
3421 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
3422 cpi->twopass.stats_in = cpi->twopass.stats_in_start;
3423 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1];
3424
Yaowu Xuf883b422016-08-30 14:01:10 -07003425 av1_init_second_pass(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003426 }
3427
Jingning Hand064cf02017-06-01 10:00:39 -07003428 int buf_scaler = 2;
Jingning Hand064cf02017-06-01 10:00:39 -07003429 CHECK_MEM_ERROR(
3430 cm, cpi->td.mb.above_pred_buf,
Johannb0ef6ff2018-02-08 14:32:21 -08003431 (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE *
3432 sizeof(*cpi->td.mb.above_pred_buf)));
Jingning Hand064cf02017-06-01 10:00:39 -07003433 CHECK_MEM_ERROR(
3434 cm, cpi->td.mb.left_pred_buf,
Johannb0ef6ff2018-02-08 14:32:21 -08003435 (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE *
3436 sizeof(*cpi->td.mb.left_pred_buf)));
Jingning Hand064cf02017-06-01 10:00:39 -07003437
3438 CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf,
3439 (int32_t *)aom_memalign(
3440 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf)));
3441
3442 CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf,
3443 (int32_t *)aom_memalign(
3444 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf)));
3445
Yaowu Xuf883b422016-08-30 14:01:10 -07003446 av1_set_speed_features_framesize_independent(cpi);
3447 av1_set_speed_features_framesize_dependent(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003448
Cheng Chenf78632e2017-10-20 15:30:51 -07003449#if CONFIG_JNT_COMP
3450#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, JSVAF) \
3451 cpi->fn_ptr[BT].sdf = SDF; \
3452 cpi->fn_ptr[BT].sdaf = SDAF; \
3453 cpi->fn_ptr[BT].vf = VF; \
3454 cpi->fn_ptr[BT].svf = SVF; \
3455 cpi->fn_ptr[BT].svaf = SVAF; \
3456 cpi->fn_ptr[BT].sdx3f = SDX3F; \
3457 cpi->fn_ptr[BT].sdx8f = SDX8F; \
3458 cpi->fn_ptr[BT].sdx4df = SDX4DF; \
3459 cpi->fn_ptr[BT].jsdaf = JSDAF; \
3460 cpi->fn_ptr[BT].jsvaf = JSVAF;
3461#else // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07003462#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
3463 cpi->fn_ptr[BT].sdf = SDF; \
3464 cpi->fn_ptr[BT].sdaf = SDAF; \
3465 cpi->fn_ptr[BT].vf = VF; \
3466 cpi->fn_ptr[BT].svf = SVF; \
3467 cpi->fn_ptr[BT].svaf = SVAF; \
3468 cpi->fn_ptr[BT].sdx3f = SDX3F; \
3469 cpi->fn_ptr[BT].sdx8f = SDX8F; \
3470 cpi->fn_ptr[BT].sdx4df = SDX4DF;
Cheng Chenf78632e2017-10-20 15:30:51 -07003471#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07003472
Cheng Chenf78632e2017-10-20 15:30:51 -07003473#if CONFIG_JNT_COMP
3474#if CONFIG_EXT_PARTITION_TYPES
3475 BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16,
3476 aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003477 aom_sad4x16x4d, aom_jnt_sad4x16_avg, aom_jnt_sub_pixel_avg_variance4x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003478
3479 BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4,
3480 aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003481 aom_sad16x4x4d, aom_jnt_sad16x4_avg, aom_jnt_sub_pixel_avg_variance16x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003482
3483 BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32,
3484 aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003485 aom_sad8x32x4d, aom_jnt_sad8x32_avg, aom_jnt_sub_pixel_avg_variance8x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003486
3487 BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8,
3488 aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003489 aom_sad32x8x4d, aom_jnt_sad32x8_avg, aom_jnt_sub_pixel_avg_variance32x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003490
3491 BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64,
3492 aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003493 aom_sad16x64x4d, aom_jnt_sad16x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003494 aom_jnt_sub_pixel_avg_variance16x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003495
3496 BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16,
3497 aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003498 aom_sad64x16x4d, aom_jnt_sad64x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003499 aom_jnt_sub_pixel_avg_variance64x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003500
3501#if CONFIG_EXT_PARTITION
3502 BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128,
3503 aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003504 NULL, aom_sad32x128x4d, aom_jnt_sad32x128_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003505 aom_jnt_sub_pixel_avg_variance32x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003506
3507 BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32,
3508 aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003509 NULL, aom_sad128x32x4d, aom_jnt_sad128x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003510 aom_jnt_sub_pixel_avg_variance128x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003511#endif // CONFIG_EXT_PARTITION
3512#endif // CONFIG_EXT_PARTITION_TYPES
3513
3514#if CONFIG_EXT_PARTITION
3515 BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128,
3516 aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128,
3517 aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d,
Cheng Chend0179a62017-11-16 17:02:53 -08003518 aom_jnt_sad128x128_avg, aom_jnt_sub_pixel_avg_variance128x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003519
3520 BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64,
3521 aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003522 NULL, aom_sad128x64x4d, aom_jnt_sad128x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003523 aom_jnt_sub_pixel_avg_variance128x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003524
3525 BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128,
3526 aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003527 NULL, aom_sad64x128x4d, aom_jnt_sad64x128_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003528 aom_jnt_sub_pixel_avg_variance64x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003529#endif // CONFIG_EXT_PARTITION
3530
3531 BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16,
3532 aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003533 aom_sad32x16x4d, aom_jnt_sad32x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003534 aom_jnt_sub_pixel_avg_variance32x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003535
3536 BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32,
3537 aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003538 aom_sad16x32x4d, aom_jnt_sad16x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003539 aom_jnt_sub_pixel_avg_variance16x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003540
3541 BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32,
3542 aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003543 aom_sad64x32x4d, aom_jnt_sad64x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003544 aom_jnt_sub_pixel_avg_variance64x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003545
3546 BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64,
3547 aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003548 aom_sad32x64x4d, aom_jnt_sad32x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003549 aom_jnt_sub_pixel_avg_variance32x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003550
3551 BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32,
3552 aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32,
Cheng Chend0179a62017-11-16 17:02:53 -08003553 aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d, aom_jnt_sad32x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003554 aom_jnt_sub_pixel_avg_variance32x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003555
3556 BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64,
3557 aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64,
Cheng Chend0179a62017-11-16 17:02:53 -08003558 aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d, aom_jnt_sad64x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003559 aom_jnt_sub_pixel_avg_variance64x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003560
3561 BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16,
3562 aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16,
Cheng Chend0179a62017-11-16 17:02:53 -08003563 aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d, aom_jnt_sad16x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003564 aom_jnt_sub_pixel_avg_variance16x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003565
3566 BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8,
3567 aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003568 aom_sad16x8x8, aom_sad16x8x4d, aom_jnt_sad16x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003569 aom_jnt_sub_pixel_avg_variance16x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003570
3571 BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16,
3572 aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003573 aom_sad8x16x8, aom_sad8x16x4d, aom_jnt_sad8x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003574 aom_jnt_sub_pixel_avg_variance8x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003575
3576 BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8,
3577 aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003578 aom_sad8x8x8, aom_sad8x8x4d, aom_jnt_sad8x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003579 aom_jnt_sub_pixel_avg_variance8x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003580
3581 BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4,
3582 aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003583 aom_sad8x4x8, aom_sad8x4x4d, aom_jnt_sad8x4_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003584 aom_jnt_sub_pixel_avg_variance8x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003585
3586 BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8,
3587 aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003588 aom_sad4x8x8, aom_sad4x8x4d, aom_jnt_sad4x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003589 aom_jnt_sub_pixel_avg_variance4x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003590
3591 BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4,
3592 aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003593 aom_sad4x4x8, aom_sad4x4x4d, aom_jnt_sad4x4_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003594 aom_jnt_sub_pixel_avg_variance4x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003595
Cheng Chenf78632e2017-10-20 15:30:51 -07003596#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003597#if CONFIG_EXT_PARTITION_TYPES
3598 BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16,
3599 aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL,
3600 aom_sad4x16x4d)
3601
3602 BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4,
3603 aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL,
3604 aom_sad16x4x4d)
3605
3606 BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32,
3607 aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL,
3608 aom_sad8x32x4d)
3609
3610 BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8,
3611 aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL,
3612 aom_sad32x8x4d)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003613
3614 BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64,
3615 aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL,
3616 aom_sad16x64x4d)
3617
3618 BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16,
3619 aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL,
3620 aom_sad64x16x4d)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003621
3622#if CONFIG_EXT_PARTITION
3623 BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128,
3624 aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL,
3625 NULL, aom_sad32x128x4d)
3626
3627 BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32,
3628 aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL,
3629 NULL, aom_sad128x32x4d)
3630#endif // CONFIG_EXT_PARTITION
3631#endif // CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003632
Yaowu Xuc27fc142016-08-22 16:08:15 -07003633#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003634 BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128,
3635 aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128,
3636 aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003637
Yaowu Xuf883b422016-08-30 14:01:10 -07003638 BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64,
3639 aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL,
3640 NULL, aom_sad128x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003641
Yaowu Xuf883b422016-08-30 14:01:10 -07003642 BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128,
3643 aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL,
3644 NULL, aom_sad64x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003645#endif // CONFIG_EXT_PARTITION
3646
Yaowu Xuf883b422016-08-30 14:01:10 -07003647 BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16,
3648 aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
3649 aom_sad32x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003650
Yaowu Xuf883b422016-08-30 14:01:10 -07003651 BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32,
3652 aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL,
3653 aom_sad16x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003654
Yaowu Xuf883b422016-08-30 14:01:10 -07003655 BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32,
3656 aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL,
3657 aom_sad64x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003658
Yaowu Xuf883b422016-08-30 14:01:10 -07003659 BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64,
3660 aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL,
3661 aom_sad32x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003662
Yaowu Xuf883b422016-08-30 14:01:10 -07003663 BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32,
3664 aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32,
3665 aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003666
Yaowu Xuf883b422016-08-30 14:01:10 -07003667 BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64,
3668 aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64,
3669 aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003670
Yaowu Xuf883b422016-08-30 14:01:10 -07003671 BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16,
3672 aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16,
3673 aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003674
Yaowu Xuf883b422016-08-30 14:01:10 -07003675 BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8,
3676 aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3,
3677 aom_sad16x8x8, aom_sad16x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003678
Yaowu Xuf883b422016-08-30 14:01:10 -07003679 BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16,
3680 aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3,
3681 aom_sad8x16x8, aom_sad8x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003682
Yaowu Xuf883b422016-08-30 14:01:10 -07003683 BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8,
3684 aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3,
3685 aom_sad8x8x8, aom_sad8x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003686
Yaowu Xuf883b422016-08-30 14:01:10 -07003687 BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4,
3688 aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL,
3689 aom_sad8x4x8, aom_sad8x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003690
Yaowu Xuf883b422016-08-30 14:01:10 -07003691 BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8,
3692 aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL,
3693 aom_sad4x8x8, aom_sad4x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003694
Yaowu Xuf883b422016-08-30 14:01:10 -07003695 BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4,
3696 aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
3697 aom_sad4x4x8, aom_sad4x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003698
Cheng Chenf78632e2017-10-20 15:30:51 -07003699#endif // CONFIG_JNT_COMP
Jingning Han9e7c49f2016-12-06 11:20:10 -08003700
Yaowu Xuc27fc142016-08-22 16:08:15 -07003701#define OBFP(BT, OSDF, OVF, OSVF) \
3702 cpi->fn_ptr[BT].osdf = OSDF; \
3703 cpi->fn_ptr[BT].ovf = OVF; \
3704 cpi->fn_ptr[BT].osvf = OSVF;
3705
3706#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003707 OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128,
3708 aom_obmc_sub_pixel_variance128x128)
3709 OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64,
3710 aom_obmc_sub_pixel_variance128x64)
3711 OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128,
3712 aom_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003713#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003714 OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64,
3715 aom_obmc_sub_pixel_variance64x64)
3716 OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32,
3717 aom_obmc_sub_pixel_variance64x32)
3718 OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64,
3719 aom_obmc_sub_pixel_variance32x64)
3720 OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32,
3721 aom_obmc_sub_pixel_variance32x32)
3722 OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16,
3723 aom_obmc_sub_pixel_variance32x16)
3724 OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32,
3725 aom_obmc_sub_pixel_variance16x32)
3726 OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16,
3727 aom_obmc_sub_pixel_variance16x16)
3728 OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8,
3729 aom_obmc_sub_pixel_variance16x8)
3730 OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16,
3731 aom_obmc_sub_pixel_variance8x16)
3732 OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8,
3733 aom_obmc_sub_pixel_variance8x8)
3734 OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8,
3735 aom_obmc_sub_pixel_variance4x8)
3736 OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4,
3737 aom_obmc_sub_pixel_variance8x4)
3738 OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4,
3739 aom_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003740
3741#if CONFIG_EXT_PARTITION_TYPES
3742 OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16,
3743 aom_obmc_sub_pixel_variance4x16)
3744
3745 OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4,
3746 aom_obmc_sub_pixel_variance16x4)
3747
3748 OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32,
3749 aom_obmc_sub_pixel_variance8x32)
3750
3751 OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8,
3752 aom_obmc_sub_pixel_variance32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003753
3754 OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64,
3755 aom_obmc_sub_pixel_variance16x64)
3756
3757 OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16,
3758 aom_obmc_sub_pixel_variance64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003759
3760#if CONFIG_EXT_PARTITION
3761 OBFP(BLOCK_32X128, aom_obmc_sad32x128, aom_obmc_variance32x128,
3762 aom_obmc_sub_pixel_variance32x128)
3763
3764 OBFP(BLOCK_128X32, aom_obmc_sad128x32, aom_obmc_variance128x32,
3765 aom_obmc_sub_pixel_variance128x32)
3766#endif // CONFIG_EXT_PARTITION
3767#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003768
David Barkerf19f35f2017-05-22 16:33:22 +01003769#define MBFP(BT, MCSDF, MCSVF) \
3770 cpi->fn_ptr[BT].msdf = MCSDF; \
3771 cpi->fn_ptr[BT].msvf = MCSVF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003772
3773#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01003774 MBFP(BLOCK_128X128, aom_masked_sad128x128,
3775 aom_masked_sub_pixel_variance128x128)
3776 MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64)
3777 MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003778#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01003779 MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64)
3780 MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32)
3781 MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64)
3782 MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32)
3783 MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16)
3784 MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32)
3785 MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16)
3786 MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8)
3787 MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16)
3788 MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8)
3789 MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8)
3790 MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4)
3791 MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003792
3793#if CONFIG_EXT_PARTITION_TYPES
3794 MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16)
3795
3796 MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4)
3797
3798 MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32)
3799
3800 MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003801
3802 MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64)
3803
3804 MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003805
3806#if CONFIG_EXT_PARTITION
3807 MBFP(BLOCK_32X128, aom_masked_sad32x128, aom_masked_sub_pixel_variance32x128)
3808
3809 MBFP(BLOCK_128X32, aom_masked_sad128x32, aom_masked_sub_pixel_variance128x32)
3810#endif // CONFIG_EXT_PARTITION
3811#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003812
Yaowu Xuc27fc142016-08-22 16:08:15 -07003813 highbd_set_var_fns(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003814
Yaowu Xuf883b422016-08-30 14:01:10 -07003815 /* av1_init_quantizer() is first called here. Add check in
3816 * av1_frame_init_quantizer() so that av1_init_quantizer is only
Yaowu Xuc27fc142016-08-22 16:08:15 -07003817 * called later when needed. This will avoid unnecessary calls of
Yaowu Xuf883b422016-08-30 14:01:10 -07003818 * av1_init_quantizer() for every frame.
Yaowu Xuc27fc142016-08-22 16:08:15 -07003819 */
Yaowu Xuf883b422016-08-30 14:01:10 -07003820 av1_init_quantizer(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003821#if CONFIG_AOM_QM
3822 aom_qm_init(cm);
3823#endif
3824
Yaowu Xuf883b422016-08-30 14:01:10 -07003825 av1_loop_filter_init(cm);
Urvang Joshi94ad3702017-12-06 11:38:08 -08003826#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07003827 cm->superres_scale_denominator = SCALE_NUMERATOR;
Debargha Mukherjee29e40a62017-06-14 09:37:12 -07003828 cm->superres_upscaled_width = oxcf->width;
3829 cm->superres_upscaled_height = oxcf->height;
Urvang Joshi94ad3702017-12-06 11:38:08 -08003830#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003831#if CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -07003832 av1_loop_restoration_precal();
Yaowu Xuc27fc142016-08-22 16:08:15 -07003833#endif // CONFIG_LOOP_RESTORATION
3834
3835 cm->error.setjmp = 0;
3836
3837 return cpi;
3838}
3839
3840#define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T))
3841
3842#define SNPRINT2(H, T, V) \
3843 snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V))
3844
Yaowu Xuf883b422016-08-30 14:01:10 -07003845void av1_remove_compressor(AV1_COMP *cpi) {
3846 AV1_COMMON *cm;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003847 unsigned int i;
3848 int t;
3849
3850 if (!cpi) return;
3851
3852 cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003853 const int num_planes = av1_num_planes(cm);
3854
Yaowu Xuc27fc142016-08-22 16:08:15 -07003855 if (cm->current_video_frame > 0) {
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003856#if CONFIG_ENTROPY_STATS
3857 if (cpi->oxcf.pass != 1) {
3858 fprintf(stderr, "Writing counts.stt\n");
3859 FILE *f = fopen("counts.stt", "wb");
3860 fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f);
Zoe Liua56f9162017-06-21 22:49:57 -07003861 fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]),
3862 FRAME_CONTEXTS, f);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003863 fclose(f);
3864 }
3865#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003866#if CONFIG_INTERNAL_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -07003867 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07003868
3869 if (cpi->oxcf.pass != 1) {
3870 char headings[512] = { 0 };
3871 char results[512] = { 0 };
3872 FILE *f = fopen("opsnr.stt", "a");
3873 double time_encoded =
3874 (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) /
3875 10000000.000;
3876 double total_encode_time =
3877 (cpi->time_receive_data + cpi->time_compress_data) / 1000.000;
3878 const double dr =
3879 (double)cpi->bytes * (double)8 / (double)1000 / time_encoded;
3880 const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1);
3881 const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000;
3882 const double rate_err = ((100.0 * (dr - target_rate)) / target_rate);
3883
3884 if (cpi->b_calculate_psnr) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003885 const double total_psnr = aom_sse_to_psnr(
Yaowu Xuc27fc142016-08-22 16:08:15 -07003886 (double)cpi->total_samples, peak, (double)cpi->total_sq_error);
3887 const double total_ssim =
3888 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0);
3889 snprintf(headings, sizeof(headings),
Jingning Han87651b22017-11-28 20:02:26 -08003890 "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t"
Yaowu Xuf883b422016-08-30 14:01:10 -07003891 "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t"
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003892 "WstPsnr\tWstSsim\tWstFast\tWstHVS\t"
Jingning Han87651b22017-11-28 20:02:26 -08003893 "AVPsrnY\tAPsnrCb\tAPsnrCr");
Yaowu Xuc27fc142016-08-22 16:08:15 -07003894 snprintf(results, sizeof(results),
3895 "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
3896 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003897 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
Jingning Han87651b22017-11-28 20:02:26 -08003898 "%7.3f\t%7.3f\t%7.3f",
Yaowu Xuc27fc142016-08-22 16:08:15 -07003899 dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr,
Jingning Han87651b22017-11-28 20:02:26 -08003900 cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003901 total_ssim, cpi->fastssim.stat[ALL] / cpi->count,
3902 cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst,
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003903 cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst,
Jingning Han87651b22017-11-28 20:02:26 -08003904 cpi->psnr.stat[Y] / cpi->count, cpi->psnr.stat[U] / cpi->count,
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003905 cpi->psnr.stat[V] / cpi->count);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003906
3907 if (cpi->b_calculate_blockiness) {
3908 SNPRINT(headings, "\t Block\tWstBlck");
3909 SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count);
3910 SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness);
3911 }
3912
3913 if (cpi->b_calculate_consistency) {
3914 double consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07003915 aom_sse_to_psnr((double)cpi->total_samples, peak,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003916 (double)cpi->total_inconsistency);
3917
3918 SNPRINT(headings, "\tConsist\tWstCons");
3919 SNPRINT2(results, "\t%7.3f", consistency);
3920 SNPRINT2(results, "\t%7.3f", cpi->worst_consistency);
3921 }
Sarah Parkerf97b7862016-08-25 17:42:57 -07003922 fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings);
3923 fprintf(f, "%s\t%8.0f\t%7.2f\t%7.2f\n", results, total_encode_time,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003924 rate_err, fabs(rate_err));
3925 }
3926
3927 fclose(f);
3928 }
3929
3930#endif
3931
3932#if 0
3933 {
3934 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
3935 printf("\n_frames recive_data encod_mb_row compress_frame Total\n");
3936 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame,
3937 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000,
3938 cpi->time_compress_data / 1000,
3939 (cpi->time_receive_data + cpi->time_compress_data) / 1000);
3940 }
3941#endif
3942 }
3943
3944 for (t = 0; t < cpi->num_workers; ++t) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003945 AVxWorker *const worker = &cpi->workers[t];
Yaowu Xuc27fc142016-08-22 16:08:15 -07003946 EncWorkerData *const thread_data = &cpi->tile_thr_data[t];
3947
3948 // Deallocate allocated threads.
Yaowu Xuf883b422016-08-30 14:01:10 -07003949 aom_get_worker_interface()->end(worker);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003950
3951 // Deallocate allocated thread data.
3952 if (t < cpi->num_workers - 1) {
hui sud9a812b2017-07-06 14:34:37 -07003953 aom_free(thread_data->td->palette_buffer);
Jingning Hand064cf02017-06-01 10:00:39 -07003954 aom_free(thread_data->td->above_pred_buf);
3955 aom_free(thread_data->td->left_pred_buf);
3956 aom_free(thread_data->td->wsrc_buf);
3957 aom_free(thread_data->td->mask_buf);
Yaowu Xuf883b422016-08-30 14:01:10 -07003958 aom_free(thread_data->td->counts);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003959 av1_free_pc_tree(thread_data->td, num_planes);
Yaowu Xuf883b422016-08-30 14:01:10 -07003960 aom_free(thread_data->td);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003961 }
3962 }
Yaowu Xuf883b422016-08-30 14:01:10 -07003963 aom_free(cpi->tile_thr_data);
3964 aom_free(cpi->workers);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003965
Yaowu Xuf883b422016-08-30 14:01:10 -07003966 if (cpi->num_workers > 1) av1_loop_filter_dealloc(&cpi->lf_row_sync);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003967
3968 dealloc_compressor_data(cpi);
3969
3970 for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]);
3971 ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003972 aom_free(cpi->mbgraph_stats[i].mb_stats);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003973 }
3974
3975#if CONFIG_FP_MB_STATS
3976 if (cpi->use_fp_mb_stats) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003977 aom_free(cpi->twopass.frame_mb_stats_buf);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003978 cpi->twopass.frame_mb_stats_buf = NULL;
3979 }
3980#endif
Debargha Mukherjee5d157212017-01-10 14:44:47 -08003981#if CONFIG_INTERNAL_STATS
3982 aom_free(cpi->ssim_vars);
3983 cpi->ssim_vars = NULL;
3984#endif // CONFIG_INTERNAL_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003985
Yaowu Xuf883b422016-08-30 14:01:10 -07003986 av1_remove_common(cm);
RogerZhou80d52342017-11-20 10:56:26 -08003987#if CONFIG_HASH_ME
3988 for (i = 0; i < FRAME_BUFFERS; ++i) {
3989 av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table);
3990 }
Michelle Findlay-Olynykdea531d2017-12-13 14:10:56 -08003991 if (cpi->sf.use_hash_based_trellis) hbt_destroy();
RogerZhou80d52342017-11-20 10:56:26 -08003992#endif // CONFIG_HASH_ME
Yaowu Xuf883b422016-08-30 14:01:10 -07003993 av1_free_ref_frame_buffers(cm->buffer_pool);
3994 aom_free(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003995
3996#ifdef OUTPUT_YUV_SKINMAP
3997 fclose(yuv_skinmap_file);
3998#endif
3999#ifdef OUTPUT_YUV_REC
4000 fclose(yuv_rec_file);
4001#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07004002#if 0
4003
4004 if (keyfile)
4005 fclose(keyfile);
4006
4007 if (framepsnr)
4008 fclose(framepsnr);
4009
4010 if (kf_list)
4011 fclose(kf_list);
4012
4013#endif
4014}
4015
Yaowu Xuf883b422016-08-30 14:01:10 -07004016static void generate_psnr_packet(AV1_COMP *cpi) {
4017 struct aom_codec_cx_pkt pkt;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004018 int i;
4019 PSNR_STATS psnr;
Alex Conversef77fd0b2017-04-20 11:00:24 -07004020 aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004021 cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004022
4023 for (i = 0; i < 4; ++i) {
4024 pkt.data.psnr.samples[i] = psnr.samples[i];
4025 pkt.data.psnr.sse[i] = psnr.sse[i];
4026 pkt.data.psnr.psnr[i] = psnr.psnr[i];
4027 }
Yaowu Xuf883b422016-08-30 14:01:10 -07004028 pkt.kind = AOM_CODEC_PSNR_PKT;
4029 aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004030}
4031
Yaowu Xuf883b422016-08-30 14:01:10 -07004032int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004033 if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1;
4034
Yunqing Wangf2e7a392017-11-08 00:27:21 -08004035 cpi->ext_ref_frame_flags = ref_frame_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004036 return 0;
4037}
4038
Yunqing Wang9a50fec2017-11-02 17:02:00 -07004039void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) {
4040 cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0;
4041 cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0;
4042 cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0;
4043 cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0;
4044 cpi->ext_refresh_alt2_ref_frame = (ref_frame_upd_flags & AOM_ALT2_FLAG) != 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004045 cpi->ext_refresh_frame_flags_pending = 1;
4046}
4047
Thomas Daede497d1952017-08-08 17:33:06 -07004048int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) {
4049 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004050 const int num_planes = av1_num_planes(cm);
Thomas Daede497d1952017-08-08 17:33:06 -07004051 YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004052 if (cfg) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004053 aom_yv12_copy_frame(cfg, sd, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004054 return 0;
4055 } else {
4056 return -1;
4057 }
4058}
4059
Thomas Daede497d1952017-08-08 17:33:06 -07004060int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) {
4061 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004062 const int num_planes = av1_num_planes(cm);
Thomas Daede497d1952017-08-08 17:33:06 -07004063 YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx);
Yaowu Xuf883b422016-08-30 14:01:10 -07004064 if (cfg) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004065 aom_yv12_copy_frame(sd, cfg, num_planes);
Yaowu Xuf883b422016-08-30 14:01:10 -07004066 return 0;
4067 } else {
4068 return -1;
4069 }
4070}
4071
4072int av1_update_entropy(AV1_COMP *cpi, int update) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004073 cpi->ext_refresh_frame_context = update;
4074 cpi->ext_refresh_frame_context_pending = 1;
4075 return 0;
4076}
4077
4078#if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP)
4079// The denoiser buffer is allocated as a YUV 440 buffer. This function writes it
4080// as YUV 420. We simply use the top-left pixels of the UV buffers, since we do
4081// not denoise the UV channels at this time. If ever we implement UV channel
4082// denoising we will have to modify this.
Yaowu Xuf883b422016-08-30 14:01:10 -07004083void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004084 uint8_t *src = s->y_buffer;
4085 int h = s->y_height;
4086
4087 do {
4088 fwrite(src, s->y_width, 1, f);
4089 src += s->y_stride;
4090 } while (--h);
4091
4092 src = s->u_buffer;
4093 h = s->uv_height;
4094
4095 do {
4096 fwrite(src, s->uv_width, 1, f);
4097 src += s->uv_stride;
4098 } while (--h);
4099
4100 src = s->v_buffer;
4101 h = s->uv_height;
4102
4103 do {
4104 fwrite(src, s->uv_width, 1, f);
4105 src += s->uv_stride;
4106 } while (--h);
4107}
4108#endif
4109
Zoe Liu8dd1c982017-09-11 10:14:35 -07004110#if USE_GF16_MULTI_LAYER
4111static void check_show_existing_frame_gf16(AV1_COMP *cpi) {
4112 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
4113 AV1_COMMON *const cm = &cpi->common;
4114 const FRAME_UPDATE_TYPE next_frame_update_type =
4115 gf_group->update_type[gf_group->index];
4116
4117 if (cm->show_existing_frame == 1) {
4118 cm->show_existing_frame = 0;
4119 } else if (cpi->rc.is_last_bipred_frame) {
4120 cpi->rc.is_last_bipred_frame = 0;
4121 cm->show_existing_frame = 1;
4122 cpi->existing_fb_idx_to_show = cpi->bwd_fb_idx;
4123 } else if (next_frame_update_type == OVERLAY_UPDATE ||
4124 next_frame_update_type == INTNL_OVERLAY_UPDATE) {
4125 // Check the temporal filtering status for the next OVERLAY frame
4126 const int num_arfs_in_gf = cpi->num_extra_arfs + 1;
4127 int which_arf = 0, arf_idx;
4128 // Identify the index to the next overlay frame.
4129 for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) {
4130 if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) {
4131 which_arf = arf_idx;
4132 break;
4133 }
4134 }
4135 assert(arf_idx < num_arfs_in_gf);
4136 if (cpi->is_arf_filter_off[which_arf]) {
4137 cm->show_existing_frame = 1;
4138 cpi->rc.is_src_frame_alt_ref = 1;
4139 cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE)
4140 ? cpi->alt_fb_idx
4141 : cpi->bwd_fb_idx;
4142 cpi->is_arf_filter_off[which_arf] = 0;
4143 }
4144 }
4145 cpi->rc.is_src_frame_ext_arf = 0;
4146}
4147#endif // USE_GF16_MULTI_LAYER
4148
Yaowu Xuf883b422016-08-30 14:01:10 -07004149static void check_show_existing_frame(AV1_COMP *cpi) {
Zoe Liu8dd1c982017-09-11 10:14:35 -07004150#if USE_GF16_MULTI_LAYER
4151 if (cpi->rc.baseline_gf_interval == 16) {
4152 check_show_existing_frame_gf16(cpi);
4153 return;
4154 }
4155#endif // USE_GF16_MULTI_LAYER
4156
Yaowu Xuc27fc142016-08-22 16:08:15 -07004157 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
Yaowu Xuf883b422016-08-30 14:01:10 -07004158 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004159 const FRAME_UPDATE_TYPE next_frame_update_type =
4160 gf_group->update_type[gf_group->index];
4161 const int which_arf = gf_group->arf_update_idx[gf_group->index];
Zoe Liu5fca7242016-10-10 17:18:57 -07004162
4163 if (cm->show_existing_frame == 1) {
4164 cm->show_existing_frame = 0;
4165 } else if (cpi->rc.is_last_bipred_frame) {
Zoe Liu8dd1c982017-09-11 10:14:35 -07004166 // NOTE: If the current frame is a last bi-predictive frame, it is
4167 // needed next to show the BWDREF_FRAME, which is pointed by
4168 // the last_fb_idxes[0] after reference frame buffer update
Yaowu Xuc27fc142016-08-22 16:08:15 -07004169 cpi->rc.is_last_bipred_frame = 0;
4170 cm->show_existing_frame = 1;
4171 cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0];
4172 } else if (cpi->is_arf_filter_off[which_arf] &&
4173 (next_frame_update_type == OVERLAY_UPDATE ||
4174 next_frame_update_type == INTNL_OVERLAY_UPDATE)) {
4175 // Other parameters related to OVERLAY_UPDATE will be taken care of
Yaowu Xuf883b422016-08-30 14:01:10 -07004176 // in av1_rc_get_second_pass_params(cpi)
Yaowu Xuc27fc142016-08-22 16:08:15 -07004177 cm->show_existing_frame = 1;
4178 cpi->rc.is_src_frame_alt_ref = 1;
Zoe Liue9b15e22017-07-19 15:53:01 -07004179 cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE)
4180 ? cpi->alt_fb_idx
4181 : cpi->alt2_fb_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004182 cpi->is_arf_filter_off[which_arf] = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004183 }
4184 cpi->rc.is_src_frame_ext_arf = 0;
4185}
Yaowu Xuc27fc142016-08-22 16:08:15 -07004186
4187#ifdef OUTPUT_YUV_REC
Yaowu Xuf883b422016-08-30 14:01:10 -07004188void aom_write_one_yuv_frame(AV1_COMMON *cm, YV12_BUFFER_CONFIG *s) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004189 uint8_t *src = s->y_buffer;
4190 int h = cm->height;
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -07004191 if (yuv_rec_file == NULL) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004192 if (s->flags & YV12_FLAG_HIGHBITDEPTH) {
4193 uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer);
4194
4195 do {
4196 fwrite(src16, s->y_width, 2, yuv_rec_file);
4197 src16 += s->y_stride;
4198 } while (--h);
4199
4200 src16 = CONVERT_TO_SHORTPTR(s->u_buffer);
4201 h = s->uv_height;
4202
4203 do {
4204 fwrite(src16, s->uv_width, 2, yuv_rec_file);
4205 src16 += s->uv_stride;
4206 } while (--h);
4207
4208 src16 = CONVERT_TO_SHORTPTR(s->v_buffer);
4209 h = s->uv_height;
4210
4211 do {
4212 fwrite(src16, s->uv_width, 2, yuv_rec_file);
4213 src16 += s->uv_stride;
4214 } while (--h);
4215
4216 fflush(yuv_rec_file);
4217 return;
4218 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004219
4220 do {
4221 fwrite(src, s->y_width, 1, yuv_rec_file);
4222 src += s->y_stride;
4223 } while (--h);
4224
4225 src = s->u_buffer;
4226 h = s->uv_height;
4227
4228 do {
4229 fwrite(src, s->uv_width, 1, yuv_rec_file);
4230 src += s->uv_stride;
4231 } while (--h);
4232
4233 src = s->v_buffer;
4234 h = s->uv_height;
4235
4236 do {
4237 fwrite(src, s->uv_width, 1, yuv_rec_file);
4238 src += s->uv_stride;
4239 } while (--h);
4240
4241 fflush(yuv_rec_file);
4242}
4243#endif // OUTPUT_YUV_REC
4244
Debargha Mukherjee11f0e402017-03-29 07:42:40 -07004245#define GM_RECODE_LOOP_NUM4X4_FACTOR 192
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004246static int recode_loop_test_global_motion(AV1_COMP *cpi) {
4247 int i;
4248 int recode = 0;
Debargha Mukherjeea575d232017-04-28 17:46:47 -07004249 RD_COUNTS *const rdc = &cpi->td.rd_counts;
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004250 AV1_COMMON *const cm = &cpi->common;
4251 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
4252 if (cm->global_motion[i].wmtype != IDENTITY &&
Debargha Mukherjeea575d232017-04-28 17:46:47 -07004253 rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR <
Debargha Mukherjee265db6d2017-03-28 11:15:27 -07004254 cpi->gmparams_cost[i]) {
David Barkerd7c8bd52017-09-25 14:47:29 +01004255 cm->global_motion[i] = default_warp_params;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004256 assert(cm->global_motion[i].wmtype == IDENTITY);
Debargha Mukherjee265db6d2017-03-28 11:15:27 -07004257 cpi->gmparams_cost[i] = 0;
David Barker43479c62016-11-30 10:34:20 +00004258 recode = 1;
Urvang Joshi02aade82017-12-18 17:18:16 -08004259 // TODO(sarahparker): The earlier condition for recoding here was:
4260 // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something
4261 // similar to that back to speed up global motion?
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004262 }
4263 }
4264 return recode;
4265}
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004266
Yaowu Xuc27fc142016-08-22 16:08:15 -07004267// Function to test for conditions that indicate we should loop
4268// back and recode a frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07004269static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q,
4270 int maxq, int minq) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004271 const RATE_CONTROL *const rc = &cpi->rc;
Yaowu Xuf883b422016-08-30 14:01:10 -07004272 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004273 const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi);
4274 int force_recode = 0;
4275
4276 if ((rc->projected_frame_size >= rc->max_frame_bandwidth) ||
4277 (cpi->sf.recode_loop == ALLOW_RECODE) ||
4278 (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004279 // TODO(agrange) high_limit could be greater than the scale-down threshold.
4280 if ((rc->projected_frame_size > high_limit && q < maxq) ||
4281 (rc->projected_frame_size < low_limit && q > minq)) {
4282 force_recode = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -07004283 } else if (cpi->oxcf.rc_mode == AOM_CQ) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004284 // Deal with frame undershoot and whether or not we are
4285 // below the automatically set cq level.
4286 if (q > oxcf->cq_level &&
4287 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) {
4288 force_recode = 1;
4289 }
4290 }
4291 }
4292 return force_recode;
4293}
4294
Yaowu Xuc27fc142016-08-22 16:08:15 -07004295#define DUMP_REF_FRAME_IMAGES 0
4296
4297#if DUMP_REF_FRAME_IMAGES == 1
Yaowu Xuf883b422016-08-30 14:01:10 -07004298static int dump_one_image(AV1_COMMON *cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004299 const YV12_BUFFER_CONFIG *const ref_buf,
4300 char *file_name) {
4301 int h;
4302 FILE *f_ref = NULL;
4303
4304 if (ref_buf == NULL) {
4305 printf("Frame data buffer is NULL.\n");
Yaowu Xuf883b422016-08-30 14:01:10 -07004306 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004307 }
4308
4309 if ((f_ref = fopen(file_name, "wb")) == NULL) {
4310 printf("Unable to open file %s to write.\n", file_name);
Yaowu Xuf883b422016-08-30 14:01:10 -07004311 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004312 }
4313
4314 // --- Y ---
4315 for (h = 0; h < cm->height; ++h) {
4316 fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref);
4317 }
4318 // --- U ---
4319 for (h = 0; h < (cm->height >> 1); ++h) {
4320 fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1),
4321 f_ref);
4322 }
4323 // --- V ---
4324 for (h = 0; h < (cm->height >> 1); ++h) {
4325 fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1),
4326 f_ref);
4327 }
4328
4329 fclose(f_ref);
4330
Yaowu Xuf883b422016-08-30 14:01:10 -07004331 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004332}
4333
Yaowu Xuf883b422016-08-30 14:01:10 -07004334static void dump_ref_frame_images(AV1_COMP *cpi) {
4335 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004336 MV_REFERENCE_FRAME ref_frame;
4337
4338 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
4339 char file_name[256] = "";
4340 snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv",
4341 cm->current_video_frame, ref_frame);
4342 dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name);
4343 }
4344}
4345#endif // DUMP_REF_FRAME_IMAGES == 1
4346
Yaowu Xuc27fc142016-08-22 16:08:15 -07004347// This function is used to shift the virtual indices of last reference frames
4348// as follows:
4349// LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME
4350// when the LAST_FRAME is updated.
Yaowu Xuf883b422016-08-30 14:01:10 -07004351static INLINE void shift_last_ref_frames(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004352 int ref_frame;
4353 for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) {
4354 cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1];
4355
4356 // [0] is allocated to the current coded frame. The statistics for the
Zoe Liuf0e46692016-10-12 12:31:43 -07004357 // reference frames start at [LAST_FRAME], i.e. [1].
Yaowu Xuc27fc142016-08-22 16:08:15 -07004358 if (!cpi->rc.is_src_frame_alt_ref) {
Zoe Liuf0e46692016-10-12 12:31:43 -07004359 memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME],
4360 cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME],
4361 sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004362 }
4363 }
4364}
Yaowu Xuc27fc142016-08-22 16:08:15 -07004365
Zoe Liu8dd1c982017-09-11 10:14:35 -07004366#if USE_GF16_MULTI_LAYER
4367static void update_reference_frames_gf16(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004368 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004369 BufferPool *const pool = cm->buffer_pool;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004370
Zoe Liu8dd1c982017-09-11 10:14:35 -07004371 if (cm->frame_type == KEY_FRAME) {
4372 for (int ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) {
4373 ref_cnt_fb(pool->frame_bufs,
4374 &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]],
4375 cm->new_fb_idx);
4376 }
4377 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4378 cm->new_fb_idx);
4379 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4380 cm->new_fb_idx);
4381 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4382 cm->new_fb_idx);
4383 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4384 cm->new_fb_idx);
4385 } else {
4386 if (cpi->refresh_last_frame || cpi->refresh_golden_frame ||
4387 cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame ||
4388 cpi->refresh_alt_ref_frame) {
4389 assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES);
4390 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx],
4391 cm->new_fb_idx);
4392 }
4393
4394 // TODO(zoeliu): To handle cpi->interp_filter_selected[].
4395
4396 // For GF of 16, an additional ref frame index mapping needs to be handled
4397 // if this is the last frame to encode in the current GF group.
4398 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
4399 if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE)
4400 av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1);
4401 }
4402
4403#if DUMP_REF_FRAME_IMAGES == 1
4404 // Dump out all reference frame images.
4405 dump_ref_frame_images(cpi);
4406#endif // DUMP_REF_FRAME_IMAGES
4407}
4408#endif // USE_GF16_MULTI_LAYER
Zoe Liu8dd1c982017-09-11 10:14:35 -07004409
4410static void update_reference_frames(AV1_COMP *cpi) {
4411 AV1_COMMON *const cm = &cpi->common;
4412
Yaowu Xuc27fc142016-08-22 16:08:15 -07004413 // NOTE: Save the new show frame buffer index for --test-code=warn, i.e.,
4414 // for the purpose to verify no mismatch between encoder and decoder.
4415 if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx;
4416
Zoe Liu8dd1c982017-09-11 10:14:35 -07004417#if USE_GF16_MULTI_LAYER
4418 if (cpi->rc.baseline_gf_interval == 16) {
4419 update_reference_frames_gf16(cpi);
4420 return;
4421 }
4422#endif // USE_GF16_MULTI_LAYER
Zoe Liu8dd1c982017-09-11 10:14:35 -07004423
4424 BufferPool *const pool = cm->buffer_pool;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004425 // At this point the new frame has been encoded.
4426 // If any buffer copy / swapping is signaled it should be done here.
4427 if (cm->frame_type == KEY_FRAME) {
4428 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4429 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004430 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4431 cm->new_fb_idx);
Zoe Liue9b15e22017-07-19 15:53:01 -07004432 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4433 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004434 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4435 cm->new_fb_idx);
Yaowu Xuf883b422016-08-30 14:01:10 -07004436 } else if (av1_preserve_existing_gf(cpi)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004437 // We have decided to preserve the previously existing golden frame as our
4438 // new ARF frame. However, in the short term in function
Yaowu Xuf883b422016-08-30 14:01:10 -07004439 // av1_bitstream.c::get_refresh_mask() we left it in the GF slot and, if
Yaowu Xuc27fc142016-08-22 16:08:15 -07004440 // we're updating the GF with the current decoded frame, we save it to the
4441 // ARF slot instead.
4442 // We now have to update the ARF with the current frame and swap gld_fb_idx
4443 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF
4444 // slot and, if we're updating the GF, the current frame becomes the new GF.
4445 int tmp;
4446
4447 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4448 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004449 tmp = cpi->alt_fb_idx;
4450 cpi->alt_fb_idx = cpi->gld_fb_idx;
4451 cpi->gld_fb_idx = tmp;
4452
Yaowu Xuc27fc142016-08-22 16:08:15 -07004453 // We need to modify the mapping accordingly
4454 cpi->arf_map[0] = cpi->alt_fb_idx;
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004455 // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to
4456 // cpi->interp_filter_selected[GOLDEN_FRAME]?
Yaowu Xuc27fc142016-08-22 16:08:15 -07004457 } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) {
4458 // Deal with the special case for showing existing internal ALTREF_FRAME
4459 // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME
4460 // by updating the virtual indices.
4461 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
Zoe Liue9b15e22017-07-19 15:53:01 -07004462 const int which_arf = gf_group->arf_ref_idx[gf_group->index];
4463 assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004464
Zoe Liue9b15e22017-07-19 15:53:01 -07004465 const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -07004466 shift_last_ref_frames(cpi);
Zoe Liue9b15e22017-07-19 15:53:01 -07004467
Zoe Liue9b15e22017-07-19 15:53:01 -07004468 cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx;
4469 cpi->alt2_fb_idx = tmp;
4470 // We need to modify the mapping accordingly
4471 cpi->arf_map[which_arf] = cpi->alt2_fb_idx;
4472
4473 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4474 cpi->interp_filter_selected[ALTREF2_FRAME],
4475 sizeof(cpi->interp_filter_selected[ALTREF2_FRAME]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004476 } else { /* For non key/golden frames */
Zoe Liue9b15e22017-07-19 15:53:01 -07004477 // === ALTREF_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004478 if (cpi->refresh_alt_ref_frame) {
4479 int arf_idx = cpi->alt_fb_idx;
4480 int which_arf = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004481 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[arf_idx], cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004482
4483 memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf],
4484 cpi->interp_filter_selected[0],
4485 sizeof(cpi->interp_filter_selected[0]));
4486 }
4487
Zoe Liue9b15e22017-07-19 15:53:01 -07004488 // === GOLDEN_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004489 if (cpi->refresh_golden_frame) {
4490 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4491 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004492
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004493 memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
4494 cpi->interp_filter_selected[0],
4495 sizeof(cpi->interp_filter_selected[0]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004496 }
4497
Zoe Liue9b15e22017-07-19 15:53:01 -07004498 // === BWDREF_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004499 if (cpi->refresh_bwd_ref_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004500 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4501 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004502
4503 memcpy(cpi->interp_filter_selected[BWDREF_FRAME],
4504 cpi->interp_filter_selected[0],
4505 sizeof(cpi->interp_filter_selected[0]));
4506 }
Zoe Liue9b15e22017-07-19 15:53:01 -07004507
Zoe Liue9b15e22017-07-19 15:53:01 -07004508 // === ALTREF2_FRAME ===
4509 if (cpi->refresh_alt2_ref_frame) {
4510 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4511 cm->new_fb_idx);
4512
4513 memcpy(cpi->interp_filter_selected[ALTREF2_FRAME],
4514 cpi->interp_filter_selected[0],
4515 sizeof(cpi->interp_filter_selected[0]));
4516 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004517 }
4518
4519 if (cpi->refresh_last_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004520 // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame
4521 // reference to the reference frame buffer virtual index; and then (2) from
4522 // the virtual index to the reference frame buffer physical index:
4523 //
4524 // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME
4525 // | | |
4526 // v v v
4527 // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx
4528 // | | |
4529 // v v v
4530 // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[]
4531 //
4532 // When refresh_last_frame is set, it is intended to retire LAST3_FRAME,
4533 // have the other 2 LAST reference frames shifted as follows:
4534 // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME
4535 // , and then have LAST_FRAME refreshed by the newly coded frame.
4536 //
4537 // To fulfill it, the decoder will be notified to execute following 2 steps:
4538 //
4539 // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME
4540 // to point to the newly coded frame, i.e.
4541 // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx;
4542 //
4543 // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the
4544 // original virtual index of LAST3_FRAME and have the other mappings
4545 // shifted as follows:
4546 // LAST_FRAME, LAST2_FRAME, LAST3_FRAME
4547 // | | |
4548 // v v v
4549 // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1]
4550 int ref_frame;
Zoe Liu5fca7242016-10-10 17:18:57 -07004551
Yaowu Xuc27fc142016-08-22 16:08:15 -07004552 if (cm->frame_type == KEY_FRAME) {
4553 for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) {
4554 ref_cnt_fb(pool->frame_bufs,
4555 &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]],
4556 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004557 }
4558 } else {
4559 int tmp;
4560
4561 ref_cnt_fb(pool->frame_bufs,
4562 &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]],
4563 cm->new_fb_idx);
4564
Yaowu Xuc27fc142016-08-22 16:08:15 -07004565 tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
4566
4567 shift_last_ref_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004568 cpi->lst_fb_idxes[0] = tmp;
4569
Zoe Liuf0e46692016-10-12 12:31:43 -07004570 assert(cm->show_existing_frame == 0);
Zoe Liuf0e46692016-10-12 12:31:43 -07004571 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4572 cpi->interp_filter_selected[0],
4573 sizeof(cpi->interp_filter_selected[0]));
Zoe Liuaff92d52017-07-11 21:35:08 -07004574
4575 if (cpi->rc.is_last_bipred_frame) {
4576 // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the
4577 // LAST3_FRAME by updating the virtual indices.
4578 //
4579 // NOTE: The source frame for BWDREF does not have a holding position as
4580 // the OVERLAY frame for ALTREF's. Hence, to resolve the reference
4581 // virtual index reshuffling for BWDREF, the encoder always
4582 // specifies a LAST_BIPRED right before BWDREF and completes the
4583 // reshuffling job accordingly.
4584 tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
4585
4586 shift_last_ref_frames(cpi);
4587 cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx;
4588 cpi->bwd_fb_idx = tmp;
4589
4590 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4591 cpi->interp_filter_selected[BWDREF_FRAME],
4592 sizeof(cpi->interp_filter_selected[BWDREF_FRAME]));
4593 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004594 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004595 }
4596
4597#if DUMP_REF_FRAME_IMAGES == 1
4598 // Dump out all reference frame images.
4599 dump_ref_frame_images(cpi);
4600#endif // DUMP_REF_FRAME_IMAGES
4601}
4602
Yaowu Xuf883b422016-08-30 14:01:10 -07004603static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) {
Debargha Mukherjee887069f2017-06-16 18:54:36 -07004604 assert(buffer_idx != INVALID_IDX);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004605 RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
Rupert Swarbrick1f990a62017-07-11 11:09:33 +01004606 ensure_mv_buffer(new_fb_ptr, cm);
4607 new_fb_ptr->width = cm->width;
4608 new_fb_ptr->height = cm->height;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004609}
4610
Cheng Chen46f30c72017-09-07 11:13:33 -07004611static void scale_references(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004612 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004613 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004614 MV_REFERENCE_FRAME ref_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -07004615 const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = {
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004616 AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG,
4617 AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG
Yaowu Xuc27fc142016-08-22 16:08:15 -07004618 };
4619
4620 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004621 // Need to convert from AOM_REFFRAME to index into ref_mask (subtract 1).
Yaowu Xuc27fc142016-08-22 16:08:15 -07004622 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) {
4623 BufferPool *const pool = cm->buffer_pool;
4624 const YV12_BUFFER_CONFIG *const ref =
4625 get_ref_frame_buffer(cpi, ref_frame);
4626
4627 if (ref == NULL) {
4628 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
4629 continue;
4630 }
4631
Yaowu Xuc27fc142016-08-22 16:08:15 -07004632 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
4633 RefCntBuffer *new_fb_ptr = NULL;
4634 int force_scaling = 0;
4635 int new_fb = cpi->scaled_ref_idx[ref_frame - 1];
4636 if (new_fb == INVALID_IDX) {
4637 new_fb = get_free_fb(cm);
4638 force_scaling = 1;
4639 }
4640 if (new_fb == INVALID_IDX) return;
4641 new_fb_ptr = &pool->frame_bufs[new_fb];
4642 if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width ||
4643 new_fb_ptr->buf.y_crop_height != cm->height) {
Yaowu Xu671f2bd2016-09-30 15:07:57 -07004644 if (aom_realloc_frame_buffer(
4645 &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x,
4646 cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
4647 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -07004648 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004649 "Failed to allocate frame buffer");
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004650 av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth,
4651 num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004652 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
4653 alloc_frame_mvs(cm, new_fb);
4654 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004655 } else {
4656 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
4657 RefCntBuffer *const buf = &pool->frame_bufs[buf_idx];
4658 buf->buf.y_crop_width = ref->y_crop_width;
4659 buf->buf.y_crop_height = ref->y_crop_height;
4660 cpi->scaled_ref_idx[ref_frame - 1] = buf_idx;
4661 ++buf->ref_count;
4662 }
4663 } else {
4664 if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
4665 }
4666 }
4667}
4668
Yaowu Xuf883b422016-08-30 14:01:10 -07004669static void release_scaled_references(AV1_COMP *cpi) {
4670 AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004671 int i;
4672 if (cpi->oxcf.pass == 0) {
4673 // Only release scaled references under certain conditions:
4674 // if reference will be updated, or if scaled reference has same resolution.
4675 int refresh[INTER_REFS_PER_FRAME];
4676 refresh[0] = (cpi->refresh_last_frame) ? 1 : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004677 refresh[1] = refresh[2] = 0;
4678 refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0;
4679 refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07004680 refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0;
4681 refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004682 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
4683 const int idx = cpi->scaled_ref_idx[i - 1];
4684 RefCntBuffer *const buf =
4685 idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL;
4686 const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i);
4687 if (buf != NULL &&
4688 (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width &&
4689 buf->buf.y_crop_height == ref->y_crop_height))) {
4690 --buf->ref_count;
4691 cpi->scaled_ref_idx[i - 1] = INVALID_IDX;
4692 }
4693 }
4694 } else {
4695 for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) {
4696 const int idx = cpi->scaled_ref_idx[i];
4697 RefCntBuffer *const buf =
4698 idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL;
4699 if (buf != NULL) {
4700 --buf->ref_count;
4701 cpi->scaled_ref_idx[i] = INVALID_IDX;
4702 }
4703 }
4704 }
4705}
4706
Yaowu Xuf883b422016-08-30 14:01:10 -07004707static void set_mv_search_params(AV1_COMP *cpi) {
4708 const AV1_COMMON *const cm = &cpi->common;
4709 const unsigned int max_mv_def = AOMMIN(cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004710
4711 // Default based on max resolution.
Yaowu Xuf883b422016-08-30 14:01:10 -07004712 cpi->mv_step_param = av1_init_search_range(max_mv_def);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004713
4714 if (cpi->sf.mv.auto_mv_step_size) {
4715 if (frame_is_intra_only(cm)) {
4716 // Initialize max_mv_magnitude for use in the first INTER frame
4717 // after a key/intra-only frame.
4718 cpi->max_mv_magnitude = max_mv_def;
4719 } else {
4720 if (cm->show_frame) {
4721 // Allow mv_steps to correspond to twice the max mv magnitude found
4722 // in the previous frame, capped by the default max_mv_magnitude based
4723 // on resolution.
Yaowu Xuf883b422016-08-30 14:01:10 -07004724 cpi->mv_step_param = av1_init_search_range(
4725 AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004726 }
4727 cpi->max_mv_magnitude = 0;
4728 }
4729 }
4730}
4731
Yaowu Xuf883b422016-08-30 14:01:10 -07004732static void set_size_independent_vars(AV1_COMP *cpi) {
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004733 int i;
4734 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
David Barkerd7c8bd52017-09-25 14:47:29 +01004735 cpi->common.global_motion[i] = default_warp_params;
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004736 }
4737 cpi->global_motion_search_done = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -07004738 av1_set_speed_features_framesize_independent(cpi);
4739 av1_set_rd_speed_thresholds(cpi);
4740 av1_set_rd_speed_thresholds_sub8x8(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004741 cpi->common.interp_filter = cpi->sf.default_interp_filter;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07004742 if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004743}
4744
Yaowu Xuf883b422016-08-30 14:01:10 -07004745static void set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004746 int *top_index) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004747 AV1_COMMON *const cm = &cpi->common;
4748 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004749
4750 // Setup variables that depend on the dimensions of the frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07004751 av1_set_speed_features_framesize_dependent(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004752
Sebastien Alaiwan41cae6a2018-01-12 12:22:29 +01004753 // Decide q and q bounds.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004754 *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index,
4755 top_index);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004756
James Zern01a9d702017-08-25 19:09:33 +00004757 if (!frame_is_intra_only(cm)) {
RogerZhou3b635242017-09-19 10:06:46 -07004758#if CONFIG_AMVR
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07004759#if CONFIG_EIGHTH_PEL_MV_ONLY
4760 set_high_precision_mv(cpi, 1, cpi->common.cur_frame_force_integer_mv);
4761#else
RogerZhou3b635242017-09-19 10:06:46 -07004762 set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH,
RogerZhou10a03802017-10-26 11:49:48 -07004763 cpi->common.cur_frame_force_integer_mv);
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07004764#endif // CONFIG_EIGHTH_PEL_MV_ONLY
4765#else
4766#if CONFIG_EIGHTH_PEL_MV_ONLY
4767 set_high_precision_mv(cpi, 1);
RogerZhou3b635242017-09-19 10:06:46 -07004768#else
Cheng Chen46f30c72017-09-07 11:13:33 -07004769 set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH);
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07004770#endif // CONFIG_EIGHTH_PEL_MV_ONLY
RogerZhou3b635242017-09-19 10:06:46 -07004771#endif
James Zern01a9d702017-08-25 19:09:33 +00004772 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004773
4774 // Configure experimental use of segmentation for enhanced coding of
4775 // static regions if indicated.
4776 // Only allowed in the second pass of a two pass encode, as it requires
4777 // lagged coding, and if the relevant speed feature flag is set.
4778 if (oxcf->pass == 2 && cpi->sf.static_segmentation)
4779 configure_static_seg_features(cpi);
4780}
4781
Yaowu Xuf883b422016-08-30 14:01:10 -07004782static void init_motion_estimation(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004783 int y_stride = cpi->scaled_source.y_stride;
4784
4785 if (cpi->sf.mv.search_method == NSTEP) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004786 av1_init3smotion_compensation(&cpi->ss_cfg, y_stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004787 } else if (cpi->sf.mv.search_method == DIAMOND) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004788 av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004789 }
4790}
4791
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004792#if CONFIG_LOOP_RESTORATION
Debargha Mukherjee84f567c2017-06-21 10:53:59 -07004793#define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004794static void set_restoration_unit_size(int width, int height, int sx, int sy,
4795 RestorationInfo *rst) {
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004796 (void)width;
4797 (void)height;
Debargha Mukherjee84f567c2017-06-21 10:53:59 -07004798 (void)sx;
4799 (void)sy;
4800#if COUPLED_CHROMA_FROM_LUMA_RESTORATION
4801 int s = AOMMIN(sx, sy);
4802#else
4803 int s = 0;
4804#endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION
4805
Debargha Mukherjee5f7f3672017-08-12 10:22:49 -07004806 if (width * height > 352 * 288)
4807 rst[0].restoration_unit_size = RESTORATION_TILESIZE_MAX;
4808 else
4809 rst[0].restoration_unit_size = (RESTORATION_TILESIZE_MAX >> 1);
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004810 rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s;
4811 rst[2].restoration_unit_size = rst[1].restoration_unit_size;
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004812}
4813#endif // CONFIG_LOOP_RESTORATION
4814
Cheng Chen46f30c72017-09-07 11:13:33 -07004815static void init_ref_frame_bufs(AV1_COMMON *cm) {
4816 int i;
4817 BufferPool *const pool = cm->buffer_pool;
4818 cm->new_fb_idx = INVALID_IDX;
4819 for (i = 0; i < REF_FRAMES; ++i) {
4820 cm->ref_frame_map[i] = INVALID_IDX;
4821 pool->frame_bufs[i].ref_count = 0;
4822 }
4823#if CONFIG_HASH_ME
4824 for (i = 0; i < FRAME_BUFFERS; ++i) {
4825 av1_hash_table_init(&pool->frame_bufs[i].hash_table);
4826 }
4827#endif
4828}
4829
Yaowu Xud3e7c682017-12-21 14:08:25 -08004830static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth,
Cheng Chen46f30c72017-09-07 11:13:33 -07004831 int subsampling_x, int subsampling_y) {
4832 AV1_COMMON *const cm = &cpi->common;
4833
Yaowu Xud3e7c682017-12-21 14:08:25 -08004834 if (!cpi->initial_width || cm->use_highbitdepth != use_highbitdepth ||
Cheng Chen46f30c72017-09-07 11:13:33 -07004835 cm->subsampling_x != subsampling_x ||
4836 cm->subsampling_y != subsampling_y) {
4837 cm->subsampling_x = subsampling_x;
4838 cm->subsampling_y = subsampling_y;
Cheng Chen46f30c72017-09-07 11:13:33 -07004839 cm->use_highbitdepth = use_highbitdepth;
Cheng Chen46f30c72017-09-07 11:13:33 -07004840
4841 alloc_raw_frame_buffers(cpi);
4842 init_ref_frame_bufs(cm);
4843 alloc_util_frame_buffers(cpi);
4844
4845 init_motion_estimation(cpi); // TODO(agrange) This can be removed.
4846
4847 cpi->initial_width = cm->width;
4848 cpi->initial_height = cm->height;
4849 cpi->initial_mbs = cm->MBs;
4850 }
4851}
4852
4853// Returns 1 if the assigned width or height was <= 0.
4854static int set_size_literal(AV1_COMP *cpi, int width, int height) {
4855 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004856 const int num_planes = av1_num_planes(cm);
Cheng Chen46f30c72017-09-07 11:13:33 -07004857 check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x,
4858 cm->subsampling_y);
Cheng Chen46f30c72017-09-07 11:13:33 -07004859
4860 if (width <= 0 || height <= 0) return 1;
4861
4862 cm->width = width;
Cheng Chen46f30c72017-09-07 11:13:33 -07004863 cm->height = height;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004864
4865 if (cpi->initial_width && cpi->initial_height &&
4866 (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) {
4867 av1_free_context_buffers(cm);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004868 av1_free_pc_tree(&cpi->td, num_planes);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004869 alloc_compressor_data(cpi);
4870 realloc_segmentation_maps(cpi);
4871 cpi->initial_width = cpi->initial_height = 0;
Cheng Chen46f30c72017-09-07 11:13:33 -07004872 }
Cheng Chen46f30c72017-09-07 11:13:33 -07004873 update_frame_size(cpi);
4874
4875 return 0;
4876}
4877
Fergus Simpsonbc189932017-05-16 17:02:39 -07004878static void set_frame_size(AV1_COMP *cpi, int width, int height) {
Fergus Simpsonbc189932017-05-16 17:02:39 -07004879 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004880 const int num_planes = av1_num_planes(cm);
Fergus Simpsonbc189932017-05-16 17:02:39 -07004881 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004882 int ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004883
Fergus Simpsonbc189932017-05-16 17:02:39 -07004884 if (width != cm->width || height != cm->height) {
Fergus Simpson3502d082017-04-10 12:25:07 -07004885 // There has been a change in the encoded frame size
Cheng Chen46f30c72017-09-07 11:13:33 -07004886 set_size_literal(cpi, width, height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004887 set_mv_search_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004888 }
4889
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004890 if (cpi->oxcf.pass == 2) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004891 av1_set_target_rate(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004892 }
4893
4894 alloc_frame_mvs(cm, cm->new_fb_idx);
4895
4896 // Reset the frame pointers to the current frame size.
Yaowu Xuf883b422016-08-30 14:01:10 -07004897 if (aom_realloc_frame_buffer(get_frame_new_buffer(cm), cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004898 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -08004899 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
4900 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -07004901 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004902 "Failed to allocate frame buffer");
4903
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004904#if CONFIG_LOOP_RESTORATION
Urvang Joshi94ad3702017-12-06 11:38:08 -08004905#if CONFIG_HORZONLY_FRAME_SUPERRES
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004906 const int frame_width = cm->superres_upscaled_width;
4907 const int frame_height = cm->superres_upscaled_height;
Fergus Simpson9cd57cf2017-06-12 17:02:03 -07004908#else
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004909 const int frame_width = cm->width;
4910 const int frame_height = cm->height;
Urvang Joshi94ad3702017-12-06 11:38:08 -08004911#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004912 set_restoration_unit_size(frame_width, frame_height, cm->subsampling_x,
4913 cm->subsampling_y, cm->rst_info);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004914 for (int i = 0; i < num_planes; ++i)
Rupert Swarbrick1a96c3f2017-10-24 11:55:00 +01004915 cm->rst_info[i].frame_restoration_type = RESTORE_NONE;
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004916
4917 av1_alloc_restoration_buffers(cm);
Fergus Simpson9cd57cf2017-06-12 17:02:03 -07004918#endif // CONFIG_LOOP_RESTORATION
4919 alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways.
Yaowu Xuc27fc142016-08-22 16:08:15 -07004920 init_motion_estimation(cpi);
4921
4922 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
4923 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME];
4924 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
4925
4926 ref_buf->idx = buf_idx;
4927
4928 if (buf_idx != INVALID_IDX) {
4929 YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf;
4930 ref_buf->buf = buf;
Yaowu Xuf883b422016-08-30 14:01:10 -07004931 av1_setup_scale_factors_for_frame(
Yaowu Xuc27fc142016-08-22 16:08:15 -07004932 &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width,
4933 cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004934 if (av1_is_scaled(&ref_buf->sf))
4935 aom_extend_frame_borders(buf, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004936 } else {
4937 ref_buf->buf = NULL;
4938 }
4939 }
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07004940
Hui Su5ebd8702018-01-08 18:09:20 -08004941 av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height,
Sebastien Alaiwan1dcb7072017-05-12 11:13:05 +02004942 cm->width, cm->height,
4943 cm->use_highbitdepth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004944
4945 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
4946}
4947
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004948static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) {
4949 // Choose an arbitrary random number
4950 static unsigned int seed = 56789;
4951 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Urvang Joshide71d142017-10-05 12:12:15 -07004952 if (oxcf->pass == 1) return SCALE_NUMERATOR;
4953 uint8_t new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004954
4955 switch (oxcf->resize_mode) {
Urvang Joshide71d142017-10-05 12:12:15 -07004956 case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004957 case RESIZE_FIXED:
4958 if (cpi->common.frame_type == KEY_FRAME)
Urvang Joshide71d142017-10-05 12:12:15 -07004959 new_denom = oxcf->resize_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004960 else
Urvang Joshide71d142017-10-05 12:12:15 -07004961 new_denom = oxcf->resize_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004962 break;
Urvang Joshide71d142017-10-05 12:12:15 -07004963 case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004964 default: assert(0);
4965 }
Urvang Joshide71d142017-10-05 12:12:15 -07004966 return new_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004967}
4968
Urvang Joshi94ad3702017-12-06 11:38:08 -08004969#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshie58b5642017-10-05 17:59:43 -07004970
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004971static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) {
4972 // Choose an arbitrary random number
4973 static unsigned int seed = 34567;
4974 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Urvang Joshide71d142017-10-05 12:12:15 -07004975 if (oxcf->pass == 1) return SCALE_NUMERATOR;
4976 uint8_t new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004977 int bottom_index, top_index, q, qthresh;
4978
4979 switch (oxcf->superres_mode) {
Urvang Joshide71d142017-10-05 12:12:15 -07004980 case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004981 case SUPERRES_FIXED:
4982 if (cpi->common.frame_type == KEY_FRAME)
Urvang Joshide71d142017-10-05 12:12:15 -07004983 new_denom = oxcf->superres_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004984 else
Urvang Joshide71d142017-10-05 12:12:15 -07004985 new_denom = oxcf->superres_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004986 break;
Urvang Joshide71d142017-10-05 12:12:15 -07004987 case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004988 case SUPERRES_QTHRESH:
4989 qthresh = (cpi->common.frame_type == KEY_FRAME ? oxcf->superres_kf_qthresh
4990 : oxcf->superres_qthresh);
4991 av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height);
4992 q = av1_rc_pick_q_and_bounds(cpi, cpi->oxcf.width, cpi->oxcf.height,
4993 &bottom_index, &top_index);
4994 if (q < qthresh) {
Urvang Joshide71d142017-10-05 12:12:15 -07004995 new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004996 } else {
Urvang Joshi28983f72017-10-25 14:41:06 -07004997 const uint8_t min_denom = SCALE_NUMERATOR + 1;
4998 const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3;
4999 const uint8_t additional_denom = (q - qthresh) / denom_step;
5000 new_denom = AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005001 }
5002 break;
5003 default: assert(0);
5004 }
Urvang Joshide71d142017-10-05 12:12:15 -07005005 return new_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005006}
5007
Urvang Joshide71d142017-10-05 12:12:15 -07005008static int dimension_is_ok(int orig_dim, int resized_dim, int denom) {
5009 return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2);
5010}
5011
5012static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) {
Urvang Joshi94ad3702017-12-06 11:38:08 -08005013 // Only need to check the width, as scaling is horizontal only.
5014 (void)oheight;
5015 return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom);
Urvang Joshide71d142017-10-05 12:12:15 -07005016}
5017
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005018static int validate_size_scales(RESIZE_MODE resize_mode,
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005019 SUPERRES_MODE superres_mode, int owidth,
5020 int oheight, size_params_type *rsz) {
Urvang Joshide71d142017-10-05 12:12:15 -07005021 if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005022 return 1;
Urvang Joshide71d142017-10-05 12:12:15 -07005023 }
5024
Urvang Joshi69fde2e2017-10-09 15:34:18 -07005025 // Calculate current resize scale.
Urvang Joshide71d142017-10-05 12:12:15 -07005026 int resize_denom =
5027 AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width),
5028 DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height));
5029
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005030 if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005031 // Alter superres scale as needed to enforce conformity.
5032 rsz->superres_denom =
5033 (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom;
5034 if (!dimensions_are_ok(owidth, oheight, rsz)) {
5035 if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005036 }
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005037 } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005038 // Alter resize scale as needed to enforce conformity.
5039 resize_denom =
5040 (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005041 rsz->resize_width = owidth;
5042 rsz->resize_height = oheight;
5043 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005044 resize_denom);
5045 if (!dimensions_are_ok(owidth, oheight, rsz)) {
5046 if (resize_denom > SCALE_NUMERATOR) {
5047 --resize_denom;
5048 rsz->resize_width = owidth;
5049 rsz->resize_height = oheight;
5050 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
5051 resize_denom);
5052 }
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005053 }
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005054 } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005055 // Alter both resize and superres scales as needed to enforce conformity.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005056 do {
Urvang Joshide71d142017-10-05 12:12:15 -07005057 if (resize_denom > rsz->superres_denom)
5058 --resize_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005059 else
Urvang Joshide71d142017-10-05 12:12:15 -07005060 --rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005061 rsz->resize_width = owidth;
5062 rsz->resize_height = oheight;
5063 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005064 resize_denom);
5065 } while (!dimensions_are_ok(owidth, oheight, rsz) &&
5066 (resize_denom > SCALE_NUMERATOR ||
5067 rsz->superres_denom > SCALE_NUMERATOR));
5068 } else { // We are allowed to alter neither resize scale nor superres scale.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005069 return 0;
5070 }
Urvang Joshide71d142017-10-05 12:12:15 -07005071 return dimensions_are_ok(owidth, oheight, rsz);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005072}
Urvang Joshi94ad3702017-12-06 11:38:08 -08005073#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005074
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005075// Calculates resize and superres params for next frame
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005076size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) {
5077 const AV1EncoderConfig *oxcf = &cpi->oxcf;
5078 size_params_type rsz = {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005079 oxcf->width,
5080 oxcf->height,
Urvang Joshi94ad3702017-12-06 11:38:08 -08005081#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07005082 SCALE_NUMERATOR
Urvang Joshi94ad3702017-12-06 11:38:08 -08005083#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005084 };
Urvang Joshide71d142017-10-05 12:12:15 -07005085 int resize_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005086 if (oxcf->pass == 1) return rsz;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005087 if (cpi->resize_pending_width && cpi->resize_pending_height) {
5088 rsz.resize_width = cpi->resize_pending_width;
5089 rsz.resize_height = cpi->resize_pending_height;
5090 cpi->resize_pending_width = cpi->resize_pending_height = 0;
5091 } else {
Urvang Joshide71d142017-10-05 12:12:15 -07005092 resize_denom = calculate_next_resize_scale(cpi);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005093 rsz.resize_width = cpi->oxcf.width;
5094 rsz.resize_height = cpi->oxcf.height;
5095 av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005096 resize_denom);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005097 }
Urvang Joshi94ad3702017-12-06 11:38:08 -08005098#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07005099 rsz.superres_denom = calculate_next_superres_scale(cpi);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005100 if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width,
5101 oxcf->height, &rsz))
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005102 assert(0 && "Invalid scale parameters");
Urvang Joshi94ad3702017-12-06 11:38:08 -08005103#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005104 return rsz;
5105}
5106
5107static void setup_frame_size_from_params(AV1_COMP *cpi, size_params_type *rsz) {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005108 int encode_width = rsz->resize_width;
5109 int encode_height = rsz->resize_height;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005110
Urvang Joshi94ad3702017-12-06 11:38:08 -08005111#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005112 AV1_COMMON *cm = &cpi->common;
5113 cm->superres_upscaled_width = encode_width;
5114 cm->superres_upscaled_height = encode_height;
Urvang Joshide71d142017-10-05 12:12:15 -07005115 cm->superres_scale_denominator = rsz->superres_denom;
Urvang Joshi69fde2e2017-10-09 15:34:18 -07005116 av1_calculate_scaled_superres_size(&encode_width, &encode_height,
5117 rsz->superres_denom);
Urvang Joshi94ad3702017-12-06 11:38:08 -08005118#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005119 set_frame_size(cpi, encode_width, encode_height);
5120}
5121
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005122static void setup_frame_size(AV1_COMP *cpi) {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005123 size_params_type rsz = av1_calculate_next_size_params(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005124 setup_frame_size_from_params(cpi, &rsz);
5125}
5126
Urvang Joshi94ad3702017-12-06 11:38:08 -08005127#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005128static void superres_post_encode(AV1_COMP *cpi) {
5129 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005130 const int num_planes = av1_num_planes(cm);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005131
5132 if (av1_superres_unscaled(cm)) return;
5133
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005134 av1_superres_upscale(cm, NULL);
5135
5136 // If regular resizing is occurring the source will need to be downscaled to
5137 // match the upscaled superres resolution. Otherwise the original source is
5138 // used.
5139 if (av1_resize_unscaled(cm)) {
5140 cpi->source = cpi->unscaled_source;
5141 if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source;
5142 } else {
Fergus Simpsonabd43432017-06-12 15:54:43 -07005143 assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width);
5144 assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005145 // Do downscale. cm->(width|height) has been updated by av1_superres_upscale
5146 if (aom_realloc_frame_buffer(
5147 &cpi->scaled_source, cm->superres_upscaled_width,
5148 cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -08005149 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, cm->byte_alignment,
5150 NULL, NULL, NULL))
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005151 aom_internal_error(
5152 &cm->error, AOM_CODEC_MEM_ERROR,
5153 "Failed to reallocate scaled source buffer for superres");
5154 assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width);
5155 assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005156 av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source,
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005157 (int)cm->bit_depth, num_planes);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005158 cpi->source = &cpi->scaled_source;
5159 }
5160}
Urvang Joshi94ad3702017-12-06 11:38:08 -08005161#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005162
5163static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005164 const int num_planes = av1_num_planes(cm);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005165 MACROBLOCKD *xd = &cpi->td.mb.e_mbd;
5166 struct loopfilter *lf = &cm->lf;
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005167 int no_loopfilter = 0;
Yaowu Xu35ee2342017-11-08 11:50:46 -08005168#if CONFIG_LOOP_RESTORATION
5169 int no_restoration = 0;
Hui Su27a4fb62017-11-10 16:03:50 -08005170#endif // CONFIG_LOOP_RESTORATION
5171
Yaowu Xu35ee2342017-11-08 11:50:46 -08005172 if (is_lossless_requested(&cpi->oxcf)
Hui Su27df8342017-11-07 15:16:05 -08005173#if CONFIG_INTRABC
5174 || (cm->allow_intrabc && NO_FILTER_FOR_IBC)
5175#endif // CONFIG_INTRABC
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005176#if CONFIG_EXT_TILE
Jingning Handa11e692017-12-19 08:45:08 -08005177 || cm->large_scale_tile
Hui Su27df8342017-11-07 15:16:05 -08005178#endif // CONFIG_EXT_TILE
Johannb0ef6ff2018-02-08 14:32:21 -08005179 ) {
Yaowu Xu35ee2342017-11-08 11:50:46 -08005180 no_loopfilter = 1;
Hui Su27a4fb62017-11-10 16:03:50 -08005181#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005182 no_restoration = 1;
Hui Su27a4fb62017-11-10 16:03:50 -08005183#endif // CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005184 }
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005185
Hui Su27a4fb62017-11-10 16:03:50 -08005186 int no_cdef = 0;
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005187 if (is_lossless_requested(&cpi->oxcf) || !cpi->oxcf.using_cdef
Hui Su27a4fb62017-11-10 16:03:50 -08005188#if CONFIG_INTRABC
5189 || (cm->allow_intrabc && NO_FILTER_FOR_IBC)
5190#endif // CONFIG_INTRABC
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005191#if CONFIG_EXT_TILE
Jingning Handa11e692017-12-19 08:45:08 -08005192 || cm->large_scale_tile
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005193#endif
Johannb0ef6ff2018-02-08 14:32:21 -08005194 ) {
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005195 no_cdef = 1;
5196 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005197
5198 if (no_loopfilter) {
Cheng Chen13fc8192017-08-19 11:49:28 -07005199#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005200 lf->filter_level[0] = 0;
5201 lf->filter_level[1] = 0;
5202#else
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005203 lf->filter_level = 0;
Cheng Chen179479f2017-08-04 10:56:39 -07005204#endif
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005205 } else {
5206 struct aom_usec_timer timer;
5207
5208 aom_clear_system_state();
5209
5210 aom_usec_timer_start(&timer);
5211
5212 av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick);
5213
5214 aom_usec_timer_mark(&timer);
5215 cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer);
5216 }
5217
Cheng Chen13fc8192017-08-19 11:49:28 -07005218#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005219 if (lf->filter_level[0] || lf->filter_level[1])
5220#else
5221 if (lf->filter_level > 0)
5222#endif
5223 {
Cheng Chen13fc8192017-08-19 11:49:28 -07005224#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005225 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0],
5226 lf->filter_level[1], 0, 0);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005227 if (num_planes > 1) {
5228 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u,
5229 lf->filter_level_u, 1, 0);
5230 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v,
5231 lf->filter_level_v, 2, 0);
5232 }
Cheng Chen179479f2017-08-04 10:56:39 -07005233
Cheng Chene94df5c2017-07-19 17:25:33 -07005234#else
5235 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
Cheng Chen13fc8192017-08-19 11:49:28 -07005236#endif // CONFIG_LOOPFILTER_LEVEL
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005237 }
Debargha Mukherjeee168a782017-08-31 12:30:10 -07005238
Debargha Mukherjeea78c8f52018-01-31 11:14:38 -08005239#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005240 if (!no_restoration)
5241 av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0);
Debargha Mukherjeea78c8f52018-01-31 11:14:38 -08005242#endif // CONFIG_LOOP_RESTORATION
Ola Hugosson1e7f2d02017-09-22 21:36:26 +02005243
Yaowu Xu35ee2342017-11-08 11:50:46 -08005244 if (no_cdef) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005245 cm->cdef_bits = 0;
5246 cm->cdef_strengths[0] = 0;
5247 cm->nb_cdef_strengths = 1;
Yunqing Wangdad63d42017-12-08 12:45:07 -08005248 cm->cdef_uv_strengths[0] = 0;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005249 } else {
Steinar Midtskogen59782122017-07-20 08:49:43 +02005250 // Find CDEF parameters
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005251 av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd,
Debargha Mukherjeed7338aa2017-11-04 07:34:50 -07005252 cpi->sf.fast_cdef_search);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005253
5254 // Apply the filter
5255 av1_cdef_frame(cm->frame_to_show, cm, xd);
5256 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005257
Urvang Joshi94ad3702017-12-06 11:38:08 -08005258#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005259 superres_post_encode(cpi);
Urvang Joshi94ad3702017-12-06 11:38:08 -08005260#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005261
5262#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005263 if (no_restoration) {
5264 cm->rst_info[0].frame_restoration_type = RESTORE_NONE;
5265 cm->rst_info[1].frame_restoration_type = RESTORE_NONE;
5266 cm->rst_info[2].frame_restoration_type = RESTORE_NONE;
5267 } else {
5268 av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1);
5269 av1_pick_filter_restoration(cpi->source, cpi);
5270 if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
5271 cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
5272 cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
Rupert Swarbrick70c399e2017-12-12 09:47:49 +00005273 av1_loop_restoration_filter_frame(cm->frame_to_show, cm);
Yaowu Xu35ee2342017-11-08 11:50:46 -08005274 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005275 }
5276#endif // CONFIG_LOOP_RESTORATION
5277 // TODO(debargha): Fix mv search range on encoder side
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005278 // aom_extend_frame_inner_borders(cm->frame_to_show, num_planes);
5279 aom_extend_frame_borders(cm->frame_to_show, num_planes);
Fergus Simpsonbc189932017-05-16 17:02:39 -07005280}
5281
Yaowu Xuf883b422016-08-30 14:01:10 -07005282static void encode_without_recode_loop(AV1_COMP *cpi) {
5283 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005284 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables.
Yaowu Xuc27fc142016-08-22 16:08:15 -07005285
Yaowu Xuf883b422016-08-30 14:01:10 -07005286 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005287
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005288 set_size_independent_vars(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005289
Fergus Simpsonbc189932017-05-16 17:02:39 -07005290 setup_frame_size(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005291
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005292 assert(cm->width == cpi->scaled_source.y_crop_width);
5293 assert(cm->height == cpi->scaled_source.y_crop_height);
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -07005294
Yaowu Xuc27fc142016-08-22 16:08:15 -07005295 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
5296
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005297 cpi->source =
5298 av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
5299 if (cpi->unscaled_last_source != NULL)
5300 cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
5301 &cpi->scaled_last_source);
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005302 cpi->source->buf_8bit_valid = 0;
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005303 if (frame_is_intra_only(cm) == 0) {
Cheng Chen46f30c72017-09-07 11:13:33 -07005304 scale_references(cpi);
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005305 }
5306
Yaowu Xuf883b422016-08-30 14:01:10 -07005307 av1_set_quantizer(cm, q);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005308 setup_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005309 suppress_active_map(cpi);
hui sued5a30f2017-04-27 16:02:49 -07005310
Yaowu Xuc27fc142016-08-22 16:08:15 -07005311 // Variance adaptive and in frame q adjustment experiments are mutually
5312 // exclusive.
5313 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005314 av1_vaq_frame_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005315 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005316 av1_setup_in_frame_q_adj(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005317 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005318 av1_cyclic_refresh_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005319 }
5320 apply_active_map(cpi);
5321
5322 // transform / motion compensation build reconstruction frame
Yaowu Xuf883b422016-08-30 14:01:10 -07005323 av1_encode_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005324
5325 // Update some stats from cyclic refresh, and check if we should not update
5326 // golden reference, for 1 pass CBR.
5327 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->frame_type != KEY_FRAME &&
Yaowu Xuf883b422016-08-30 14:01:10 -07005328 (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR))
5329 av1_cyclic_refresh_check_golden_update(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005330
5331 // Update the skip mb flag probabilities based on the distribution
5332 // seen in the last encoder iteration.
5333 // update_base_skip_probs(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005334 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005335}
5336
Tom Finegane4099e32018-01-23 12:01:51 -08005337static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005338 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005339 RATE_CONTROL *const rc = &cpi->rc;
5340 int bottom_index, top_index;
5341 int loop_count = 0;
5342 int loop_at_this_size = 0;
5343 int loop = 0;
5344 int overshoot_seen = 0;
5345 int undershoot_seen = 0;
5346 int frame_over_shoot_limit;
5347 int frame_under_shoot_limit;
5348 int q = 0, q_low = 0, q_high = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005349
5350 set_size_independent_vars(cpi);
5351
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005352 cpi->source->buf_8bit_valid = 0;
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005353
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005354 aom_clear_system_state();
5355 setup_frame_size(cpi);
5356 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
5357
Yaowu Xuc27fc142016-08-22 16:08:15 -07005358 do {
Yaowu Xuf883b422016-08-30 14:01:10 -07005359 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005360
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005361 if (loop_count == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005362 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
5363 set_mv_search_params(cpi);
5364
5365 // Reset the loop state for new frame size.
5366 overshoot_seen = 0;
5367 undershoot_seen = 0;
5368
Yaowu Xuc27fc142016-08-22 16:08:15 -07005369 q_low = bottom_index;
5370 q_high = top_index;
5371
5372 loop_at_this_size = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005373
Urvang Joshi2a74cf22017-12-18 17:21:41 -08005374 // Decide frame size bounds first time through.
Yaowu Xuf883b422016-08-30 14:01:10 -07005375 av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target,
5376 &frame_under_shoot_limit,
5377 &frame_over_shoot_limit);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005378 }
5379
Debargha Mukherjee17e7b082017-08-13 09:33:03 -07005380 // if frame was scaled calculate global_motion_search again if already done
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005381 if (loop_count > 0 && cpi->source && cpi->global_motion_search_done)
5382 if (cpi->source->y_crop_width != cm->width ||
5383 cpi->source->y_crop_height != cm->height)
5384 cpi->global_motion_search_done = 0;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005385 cpi->source =
5386 av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
Debargha Mukherjee17e7b082017-08-13 09:33:03 -07005387 if (cpi->unscaled_last_source != NULL)
5388 cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
5389 &cpi->scaled_last_source);
5390
Yaowu Xuc27fc142016-08-22 16:08:15 -07005391 if (frame_is_intra_only(cm) == 0) {
5392 if (loop_count > 0) {
5393 release_scaled_references(cpi);
5394 }
Cheng Chen46f30c72017-09-07 11:13:33 -07005395 scale_references(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005396 }
Yaowu Xuf883b422016-08-30 14:01:10 -07005397 av1_set_quantizer(cm, q);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005398
5399 if (loop_count == 0) setup_frame(cpi);
5400
Yaowu Xuc27fc142016-08-22 16:08:15 -07005401 // Base q-index may have changed, so we need to assign proper default coef
5402 // probs before every iteration.
5403 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005404 av1_default_coef_probs(cm);
Hui Su3694c832017-11-10 14:15:58 -08005405 av1_setup_frame_contexts(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005406 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005407
Yaowu Xuc27fc142016-08-22 16:08:15 -07005408 // Variance adaptive and in frame q adjustment experiments are mutually
5409 // exclusive.
5410 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005411 av1_vaq_frame_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005412 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005413 av1_setup_in_frame_q_adj(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005414 }
5415
5416 // transform / motion compensation build reconstruction frame
Jingning Han8f661602017-08-19 08:16:50 -07005417 save_coding_context(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005418 av1_encode_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005419
5420 // Update the skip mb flag probabilities based on the distribution
5421 // seen in the last encoder iteration.
5422 // update_base_skip_probs(cpi);
5423
Yaowu Xuf883b422016-08-30 14:01:10 -07005424 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005425
5426 // Dummy pack of the bitstream using up to date stats to get an
5427 // accurate estimate of output frame size to determine if we need
5428 // to recode.
5429 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) {
Jingning Han8f661602017-08-19 08:16:50 -07005430 restore_coding_context(cpi);
Tom Finegane4099e32018-01-23 12:01:51 -08005431
5432 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
5433 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005434
5435 rc->projected_frame_size = (int)(*size) << 3;
5436 restore_coding_context(cpi);
5437
5438 if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1;
5439 }
5440
Yaowu Xuf883b422016-08-30 14:01:10 -07005441 if (cpi->oxcf.rc_mode == AOM_Q) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005442 loop = 0;
5443 } else {
5444 if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced &&
5445 (rc->projected_frame_size < rc->max_frame_bandwidth)) {
5446 int last_q = q;
5447 int64_t kf_err;
5448
5449 int64_t high_err_target = cpi->ambient_err;
5450 int64_t low_err_target = cpi->ambient_err >> 1;
5451
Yaowu Xuc27fc142016-08-22 16:08:15 -07005452 if (cm->use_highbitdepth) {
Alex Conversef77fd0b2017-04-20 11:00:24 -07005453 kf_err = aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005454 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07005455 kf_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005456 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005457 // Prevent possible divide by zero error below for perfect KF
5458 kf_err += !kf_err;
5459
5460 // The key frame is not good enough or we can afford
5461 // to make it better without undue risk of popping.
5462 if ((kf_err > high_err_target &&
5463 rc->projected_frame_size <= frame_over_shoot_limit) ||
5464 (kf_err > low_err_target &&
5465 rc->projected_frame_size <= frame_under_shoot_limit)) {
5466 // Lower q_high
5467 q_high = q > q_low ? q - 1 : q_low;
5468
5469 // Adjust Q
5470 q = (int)((q * high_err_target) / kf_err);
Yaowu Xuf883b422016-08-30 14:01:10 -07005471 q = AOMMIN(q, (q_high + q_low) >> 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005472 } else if (kf_err < low_err_target &&
5473 rc->projected_frame_size >= frame_under_shoot_limit) {
5474 // The key frame is much better than the previous frame
5475 // Raise q_low
5476 q_low = q < q_high ? q + 1 : q_high;
5477
5478 // Adjust Q
5479 q = (int)((q * low_err_target) / kf_err);
Yaowu Xuf883b422016-08-30 14:01:10 -07005480 q = AOMMIN(q, (q_high + q_low + 1) >> 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005481 }
5482
5483 // Clamp Q to upper and lower limits:
5484 q = clamp(q, q_low, q_high);
5485
5486 loop = q != last_q;
5487 } else if (recode_loop_test(cpi, frame_over_shoot_limit,
5488 frame_under_shoot_limit, q,
Yaowu Xuf883b422016-08-30 14:01:10 -07005489 AOMMAX(q_high, top_index), bottom_index)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005490 // Is the projected frame size out of range and are we allowed
5491 // to attempt to recode.
5492 int last_q = q;
5493 int retries = 0;
5494
Yaowu Xuc27fc142016-08-22 16:08:15 -07005495 // Frame size out of permitted range:
5496 // Update correction factor & compute new Q to try...
Yaowu Xuc27fc142016-08-22 16:08:15 -07005497 // Frame is too large
5498 if (rc->projected_frame_size > rc->this_frame_target) {
5499 // Special case if the projected size is > the max allowed.
5500 if (rc->projected_frame_size >= rc->max_frame_bandwidth)
5501 q_high = rc->worst_quality;
5502
5503 // Raise Qlow as to at least the current value
5504 q_low = q < q_high ? q + 1 : q_high;
5505
5506 if (undershoot_seen || loop_at_this_size > 1) {
5507 // Update rate_correction_factor unless
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005508 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005509
5510 q = (q_high + q_low + 1) / 2;
5511 } else {
5512 // Update rate_correction_factor unless
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005513 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005514
Yaowu Xuf883b422016-08-30 14:01:10 -07005515 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005516 AOMMAX(q_high, top_index), cm->width,
5517 cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005518
5519 while (q < q_low && retries < 10) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005520 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005521 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005522 AOMMAX(q_high, top_index), cm->width,
5523 cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005524 retries++;
5525 }
5526 }
5527
5528 overshoot_seen = 1;
5529 } else {
5530 // Frame is too small
5531 q_high = q > q_low ? q - 1 : q_low;
5532
5533 if (overshoot_seen || loop_at_this_size > 1) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005534 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005535 q = (q_high + q_low) / 2;
5536 } else {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005537 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005538 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005539 top_index, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005540 // Special case reset for qlow for constrained quality.
5541 // This should only trigger where there is very substantial
5542 // undershoot on a frame and the auto cq level is above
5543 // the user passsed in value.
Yaowu Xuf883b422016-08-30 14:01:10 -07005544 if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005545 q_low = q;
5546 }
5547
5548 while (q > q_high && retries < 10) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005549 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005550 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005551 top_index, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005552 retries++;
5553 }
5554 }
5555
5556 undershoot_seen = 1;
5557 }
5558
5559 // Clamp Q to upper and lower limits:
5560 q = clamp(q, q_low, q_high);
5561
5562 loop = (q != last_q);
5563 } else {
5564 loop = 0;
5565 }
5566 }
5567
5568 // Special case for overlay frame.
5569 if (rc->is_src_frame_alt_ref &&
5570 rc->projected_frame_size < rc->max_frame_bandwidth)
5571 loop = 0;
5572
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08005573 if (recode_loop_test_global_motion(cpi)) {
5574 loop = 1;
5575 }
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08005576
Yaowu Xuc27fc142016-08-22 16:08:15 -07005577 if (loop) {
5578 ++loop_count;
5579 ++loop_at_this_size;
5580
5581#if CONFIG_INTERNAL_STATS
5582 ++cpi->tot_recode_hits;
5583#endif
5584 }
5585 } while (loop);
Tom Finegane4099e32018-01-23 12:01:51 -08005586
5587 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005588}
5589
Yaowu Xuf883b422016-08-30 14:01:10 -07005590static int get_ref_frame_flags(const AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005591 const int *const map = cpi->common.ref_frame_map;
5592
Zoe Liu368bf162017-11-03 20:10:19 -07005593 // No.1 Priority: LAST_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -07005594 const int last2_is_last =
5595 map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]];
5596 const int last3_is_last =
5597 map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]];
5598 const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]];
5599 const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]];
Zoe Liu368bf162017-11-03 20:10:19 -07005600 const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005601 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]];
5602
Zoe Liu368bf162017-11-03 20:10:19 -07005603 // No.2 Priority: ALTREF_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -07005604 const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx];
5605 const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx];
5606 const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
5607 const int bwd_is_alt = map[cpi->bwd_fb_idx] == map[cpi->alt_fb_idx];
Zoe Liue9b15e22017-07-19 15:53:01 -07005608 const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005609
Zoe Liu368bf162017-11-03 20:10:19 -07005610 // No.3 Priority: LAST2_FRAME
5611 const int last3_is_last2 =
5612 map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]];
5613 const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]];
5614 const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]];
5615 const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005616
Zoe Liu368bf162017-11-03 20:10:19 -07005617 // No.4 Priority: LAST3_FRAME
5618 const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]];
5619 const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]];
5620 const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]];
5621
5622 // No.5 Priority: GOLDEN_FRAME
5623 const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx];
5624 const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx];
5625
5626 // No.6 Priority: BWDREF_FRAME
5627 const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx];
5628
5629 // No.7 Priority: ALTREF2_FRAME
5630
Yunqing Wang9a50fec2017-11-02 17:02:00 -07005631 // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be
5632 // adjusted according to external encoder flags.
Yunqing Wangf2e7a392017-11-08 00:27:21 -08005633 int flags = cpi->ext_ref_frame_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005634
Yaowu Xuf883b422016-08-30 14:01:10 -07005635 if (cpi->rc.frames_till_gf_update_due == INT_MAX) flags &= ~AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005636
Yaowu Xuf883b422016-08-30 14:01:10 -07005637 if (alt_is_last) flags &= ~AOM_ALT_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005638
Yaowu Xuf883b422016-08-30 14:01:10 -07005639 if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005640
Zoe Liu368bf162017-11-03 20:10:19 -07005641 if (last3_is_last || last3_is_alt || last3_is_last2) flags &= ~AOM_LAST3_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005642
Zoe Liu368bf162017-11-03 20:10:19 -07005643 if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3)
5644 flags &= ~AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005645
Zoe Liu368bf162017-11-03 20:10:19 -07005646 if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 ||
5647 bwd_is_gld) &&
Yaowu Xuf883b422016-08-30 14:01:10 -07005648 (flags & AOM_BWD_FLAG))
5649 flags &= ~AOM_BWD_FLAG;
Zoe Liue9b15e22017-07-19 15:53:01 -07005650
Zoe Liu368bf162017-11-03 20:10:19 -07005651 if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 ||
5652 alt2_is_gld || alt2_is_bwd) &&
Zoe Liue9b15e22017-07-19 15:53:01 -07005653 (flags & AOM_ALT2_FLAG))
5654 flags &= ~AOM_ALT2_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005655
5656 return flags;
5657}
5658
Yaowu Xuf883b422016-08-30 14:01:10 -07005659static void set_ext_overrides(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005660 // Overrides the defaults with the externally supplied values with
Yaowu Xuf883b422016-08-30 14:01:10 -07005661 // av1_update_reference() and av1_update_entropy() calls
Yaowu Xuc27fc142016-08-22 16:08:15 -07005662 // Note: The overrides are valid only for the next frame passed
5663 // to encode_frame_to_data_rate() function
5664 if (cpi->ext_refresh_frame_context_pending) {
5665 cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context;
5666 cpi->ext_refresh_frame_context_pending = 0;
5667 }
5668 if (cpi->ext_refresh_frame_flags_pending) {
5669 cpi->refresh_last_frame = cpi->ext_refresh_last_frame;
5670 cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame;
5671 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
Yunqing Wang9a50fec2017-11-02 17:02:00 -07005672 cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame;
5673 cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005674 cpi->ext_refresh_frame_flags_pending = 0;
5675 }
5676}
5677
Yaowu Xuf883b422016-08-30 14:01:10 -07005678static int setup_interp_filter_search_mask(AV1_COMP *cpi) {
James Zern7b9407a2016-05-18 23:48:05 -07005679 InterpFilter ifilter;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005680 int ref_total[TOTAL_REFS_PER_FRAME] = { 0 };
5681 MV_REFERENCE_FRAME ref;
5682 int mask = 0;
5683 int arf_idx = ALTREF_FRAME;
5684
Zoe Liue9b15e22017-07-19 15:53:01 -07005685 if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame ||
5686 cpi->refresh_alt2_ref_frame)
Yaowu Xuc27fc142016-08-22 16:08:15 -07005687 return mask;
5688
Yaowu Xuc27fc142016-08-22 16:08:15 -07005689 for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref)
5690 for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter)
5691 ref_total[ref] += cpi->interp_filter_selected[ref][ifilter];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005692
5693 for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) {
5694 if ((ref_total[LAST_FRAME] &&
5695 cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005696 (ref_total[LAST2_FRAME] == 0 ||
5697 cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 <
5698 ref_total[LAST2_FRAME]) &&
5699 (ref_total[LAST3_FRAME] == 0 ||
5700 cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 <
5701 ref_total[LAST3_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005702 (ref_total[GOLDEN_FRAME] == 0 ||
5703 cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 <
5704 ref_total[GOLDEN_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005705 (ref_total[BWDREF_FRAME] == 0 ||
5706 cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 <
5707 ref_total[BWDREF_FRAME]) &&
Zoe Liue9b15e22017-07-19 15:53:01 -07005708 (ref_total[ALTREF2_FRAME] == 0 ||
5709 cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 <
5710 ref_total[ALTREF2_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005711 (ref_total[ALTREF_FRAME] == 0 ||
5712 cpi->interp_filter_selected[arf_idx][ifilter] * 50 <
5713 ref_total[ALTREF_FRAME]))
5714 mask |= 1 << ifilter;
5715 }
5716 return mask;
5717}
5718
5719#define DUMP_RECON_FRAMES 0
5720
5721#if DUMP_RECON_FRAMES == 1
5722// NOTE(zoeliu): For debug - Output the filtered reconstructed video.
Yaowu Xuf883b422016-08-30 14:01:10 -07005723static void dump_filtered_recon_frames(AV1_COMP *cpi) {
5724 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005725 const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005726
Zoe Liub4f31032017-11-03 23:48:35 -07005727 if (recon_buf == NULL) {
5728 printf("Frame %d is not ready.\n", cm->current_video_frame);
5729 return;
5730 }
5731
Zoe Liub4f31032017-11-03 23:48:35 -07005732 static const int flag_list[TOTAL_REFS_PER_FRAME] = { 0,
5733 AOM_LAST_FLAG,
5734 AOM_LAST2_FLAG,
5735 AOM_LAST3_FLAG,
5736 AOM_GOLD_FLAG,
5737 AOM_BWD_FLAG,
5738 AOM_ALT2_FLAG,
5739 AOM_ALT_FLAG };
5740 printf(
5741 "\n***Frame=%d (frame_offset=%d, show_frame=%d, "
5742 "show_existing_frame=%d) "
5743 "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[",
5744 cm->current_video_frame, cm->frame_offset, cm->show_frame,
5745 cm->show_existing_frame);
5746 for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
5747 const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx;
5748 const int ref_offset =
5749 (buf_idx >= 0)
5750 ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset
5751 : -1;
Zoe Liuf452fdf2017-11-02 23:08:12 -07005752 printf(
5753 " %d(%c-%d-%4.2f)", ref_offset,
5754 (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N',
5755 (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1,
5756 (buf_idx >= 0) ? rate_factor_deltas[cpi->frame_rf_level[buf_idx]] : -1);
Zoe Liub4f31032017-11-03 23:48:35 -07005757 }
5758 printf(" ]\n");
Zoe Liub4f31032017-11-03 23:48:35 -07005759
5760 if (!cm->show_frame) {
5761 printf("Frame %d is a no show frame, so no image dump.\n",
Yaowu Xuc27fc142016-08-22 16:08:15 -07005762 cm->current_video_frame);
5763 return;
5764 }
5765
Zoe Liub4f31032017-11-03 23:48:35 -07005766 int h;
5767 char file_name[256] = "/tmp/enc_filtered_recon.yuv";
5768 FILE *f_recon = NULL;
5769
Yaowu Xuc27fc142016-08-22 16:08:15 -07005770 if (cm->current_video_frame == 0) {
5771 if ((f_recon = fopen(file_name, "wb")) == NULL) {
5772 printf("Unable to open file %s to write.\n", file_name);
5773 return;
5774 }
5775 } else {
5776 if ((f_recon = fopen(file_name, "ab")) == NULL) {
5777 printf("Unable to open file %s to append.\n", file_name);
5778 return;
5779 }
5780 }
5781 printf(
Zoe Liuf40a9572017-10-13 12:37:19 -07005782 "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, "
5783 "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, "
5784 "refresh_alt_ref_frame=%d, rf_level=%d, "
5785 "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n",
Yaowu Xuc27fc142016-08-22 16:08:15 -07005786 cm->current_video_frame, cpi->twopass.gf_group.index,
5787 cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index],
Zoe Liuf40a9572017-10-13 12:37:19 -07005788 cm->frame_offset, cm->show_frame, cm->show_existing_frame,
5789 cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame,
5790 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index],
5791 recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height);
Zoe Liue9b15e22017-07-19 15:53:01 -07005792#if 0
5793 int ref_frame;
5794 printf("get_ref_frame_map_idx: [");
5795 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame)
5796 printf(" %d", get_ref_frame_map_idx(cpi, ref_frame));
5797 printf(" ]\n");
5798 printf("cm->new_fb_idx = %d\n", cm->new_fb_idx);
5799 printf("cm->ref_frame_map = [");
5800 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
5801 printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]);
5802 }
5803 printf(" ]\n");
5804#endif // 0
Yaowu Xuc27fc142016-08-22 16:08:15 -07005805
5806 // --- Y ---
5807 for (h = 0; h < cm->height; ++h) {
5808 fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width,
5809 f_recon);
5810 }
5811 // --- U ---
5812 for (h = 0; h < (cm->height >> 1); ++h) {
5813 fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1),
5814 f_recon);
5815 }
5816 // --- V ---
5817 for (h = 0; h < (cm->height >> 1); ++h) {
5818 fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1),
5819 f_recon);
5820 }
5821
5822 fclose(f_recon);
5823}
5824#endif // DUMP_RECON_FRAMES
5825
Thomas Davies4822e142017-10-10 11:30:36 +01005826static void make_update_tile_list_enc(AV1_COMP *cpi, const int start_tile,
5827 const int num_tiles,
Thomas Davies028b57f2017-02-22 16:42:11 +00005828 FRAME_CONTEXT *ec_ctxs[]) {
5829 int i;
Thomas Davies4822e142017-10-10 11:30:36 +01005830 for (i = start_tile; i < start_tile + num_tiles; ++i)
5831 ec_ctxs[i - start_tile] = &cpi->tile_data[i].tctx;
Thomas Davies028b57f2017-02-22 16:42:11 +00005832}
5833
Tom Finegane4099e32018-01-23 12:01:51 -08005834static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest,
5835 int skip_adapt,
5836 unsigned int *frame_flags) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005837 AV1_COMMON *const cm = &cpi->common;
5838 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005839 struct segmentation *const seg = &cm->seg;
Thomas Davies4822e142017-10-10 11:30:36 +01005840 const int num_bwd_ctxs = 1;
Thomas Davies4822e142017-10-10 11:30:36 +01005841
5842 FRAME_CONTEXT **tile_ctxs =
5843 aom_malloc(num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx));
5844 aom_cdf_prob **cdf_ptrs = aom_malloc(
5845 num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005846 set_ext_overrides(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005847 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005848
Fangwen Fu8d164de2016-12-14 13:40:54 -08005849 // frame type has been decided outside of this function call
5850 cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only;
Jingning Han2830fd92018-01-10 10:06:26 -08005851 cm->use_ref_frame_mvs = !cpi->oxcf.disable_tempmv &&
5852 !cm->cur_frame->intra_only &&
5853 frame_might_use_prev_frame_mvs(cm);
Jingning Hane17ebe92017-11-03 15:25:42 -07005854 cm->use_prev_frame_mvs = cm->use_ref_frame_mvs;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005855
Jingning Hand8a15a62017-10-30 10:53:42 -07005856 // Reset the frame packet stamp index.
5857 if (cm->frame_type == KEY_FRAME) cm->current_video_frame = 0;
5858
Yaowu Xuc27fc142016-08-22 16:08:15 -07005859 // NOTE:
5860 // (1) Move the setup of the ref_frame_flags upfront as it would be
5861 // determined by the current frame properties;
5862 // (2) The setup of the ref_frame_flags applies to both show_existing_frame's
5863 // and the other cases.
5864 if (cm->current_video_frame > 0)
5865 cpi->ref_frame_flags = get_ref_frame_flags(cpi);
5866
5867 if (cm->show_existing_frame) {
5868 // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current
5869 // BWDREF_FRAME in the reference frame buffer.
5870 cm->frame_type = INTER_FRAME;
5871 cm->show_frame = 1;
5872 cpi->frame_flags = *frame_flags;
5873
5874 // In the case of show_existing frame, we will not send fresh flag
5875 // to decoder. Any change in the reference frame buffer can be done by
5876 // switching the virtual indices.
5877
5878 cpi->refresh_last_frame = 0;
5879 cpi->refresh_golden_frame = 0;
5880 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07005881 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005882 cpi->refresh_alt_ref_frame = 0;
5883
5884 cpi->rc.is_bwd_ref_frame = 0;
5885 cpi->rc.is_last_bipred_frame = 0;
5886 cpi->rc.is_bipred_frame = 0;
5887
Jingning Han8f661602017-08-19 08:16:50 -07005888 restore_coding_context(cpi);
Zoe Liub4f31032017-11-03 23:48:35 -07005889
Yaowu Xuc27fc142016-08-22 16:08:15 -07005890 // Build the bitstream
Tom Finegane4099e32018-01-23 12:01:51 -08005891 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
5892 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005893
5894 // Set up frame to show to get ready for stats collection.
5895 cm->frame_to_show = get_frame_new_buffer(cm);
5896
Zoe Liub4f31032017-11-03 23:48:35 -07005897 // Update current frame offset.
5898 cm->frame_offset =
5899 cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset;
Zoe Liub4f31032017-11-03 23:48:35 -07005900
Yaowu Xuc27fc142016-08-22 16:08:15 -07005901#if DUMP_RECON_FRAMES == 1
5902 // NOTE(zoeliu): For debug - Output the filtered reconstructed video.
5903 dump_filtered_recon_frames(cpi);
5904#endif // DUMP_RECON_FRAMES
5905
5906 // Update the LAST_FRAME in the reference frame buffer.
Zoe Liue9b15e22017-07-19 15:53:01 -07005907 // NOTE:
5908 // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame
5909 // update has been done previously when handling the LAST_BIPRED_FRAME
5910 // right before BWDREF_FRAME (in the display order);
5911 // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame
5912 // update will be done when the following is called, which will exchange
5913 // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that
5914 // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and
5915 // ALTREF2_FRAME will serve as the new LAST_FRAME.
Cheng Chen46f30c72017-09-07 11:13:33 -07005916 update_reference_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005917
5918 // Update frame flags
5919 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
5920 cpi->frame_flags &= ~FRAMEFLAGS_BWDREF;
5921 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
5922
5923 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
5924
5925 // Update the frame type
5926 cm->last_frame_type = cm->frame_type;
5927
Yaowu Xuc27fc142016-08-22 16:08:15 -07005928 // Since we allocate a spot for the OVERLAY frame in the gf group, we need
5929 // to do post-encoding update accordingly.
5930 if (cpi->rc.is_src_frame_alt_ref) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005931 av1_set_target_rate(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005932 av1_rc_postencode_update(cpi, *size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005933 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005934
Yaowu Xuc27fc142016-08-22 16:08:15 -07005935 ++cm->current_video_frame;
5936
Jingning Hanf6214b92017-04-12 11:43:37 -07005937 aom_free(tile_ctxs);
5938 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08005939 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005940 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005941
5942 // Set default state for segment based loop filter update flags.
5943 cm->lf.mode_ref_delta_update = 0;
5944
5945 if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search)
5946 cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi);
5947
5948 // Set various flags etc to special state if it is a key frame.
5949 if (frame_is_intra_only(cm)) {
5950 // Reset the loop filter deltas and segmentation map.
Yaowu Xuf883b422016-08-30 14:01:10 -07005951 av1_reset_segment_features(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005952
5953 // If segmentation is enabled force a map update for key frames.
5954 if (seg->enabled) {
5955 seg->update_map = 1;
5956 seg->update_data = 1;
5957 }
5958
5959 // The alternate reference frame cannot be active for a key frame.
5960 cpi->rc.source_alt_ref_active = 0;
5961
5962 cm->error_resilient_mode = oxcf->error_resilient_mode;
5963
Thomas Daedea6a854b2017-06-22 17:49:11 -07005964#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07005965 // By default, encoder assumes decoder can use prev_mi.
5966 if (cm->error_resilient_mode) {
5967 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
5968 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
5969 } else if (cm->intra_only) {
5970 // Only reset the current context.
5971 cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT;
5972 }
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01005973#if CONFIG_EXT_TILE
5974 if (cpi->oxcf.large_scale_tile)
5975 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
5976#endif // CONFIG_EXT_TILE
5977#endif // !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07005978 }
Thomas Daviesaf6df172016-11-09 14:04:18 +00005979 if (cpi->oxcf.mtu == 0) {
5980 cm->num_tg = cpi->oxcf.num_tile_groups;
5981 } else {
Yaowu Xu859a5272016-11-10 15:32:21 -08005982 // Use a default value for the purposes of weighting costs in probability
5983 // updates
Thomas Daviesaf6df172016-11-09 14:04:18 +00005984 cm->num_tg = DEFAULT_MAX_NUM_TG;
5985 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005986
Yunqing Wangd8cd55f2017-02-27 12:16:00 -08005987#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005988 cm->large_scale_tile = cpi->oxcf.large_scale_tile;
5989 cm->single_tile_decoding = cpi->oxcf.single_tile_decoding;
Yunqing Wangb6e23bc2017-11-15 13:18:55 -08005990#if CONFIG_REFERENCE_BUFFER
5991 if (cm->large_scale_tile) cm->seq_params.frame_id_numbers_present_flag = 0;
5992#endif // CONFIG_REFERENCE_BUFFER
Yunqing Wangd8cd55f2017-02-27 12:16:00 -08005993#endif // CONFIG_EXT_TILE
5994
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08005995#if CONFIG_MONO_VIDEO
5996 cm->seq_params.monochrome = oxcf->monochrome;
5997#endif // CONFIG_MONO_VIDEO
5998
Yaowu Xuc27fc142016-08-22 16:08:15 -07005999 // For 1 pass CBR, check if we are dropping this frame.
6000 // Never drop on key frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07006001 if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07006002 cm->frame_type != KEY_FRAME) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006003 if (av1_rc_drop_frame(cpi)) {
6004 av1_rc_postencode_update_drop_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006005 ++cm->current_video_frame;
Jingning Hanf6214b92017-04-12 11:43:37 -07006006 aom_free(tile_ctxs);
6007 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006008 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006009 }
6010 }
6011
Yaowu Xuf883b422016-08-30 14:01:10 -07006012 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006013
6014#if CONFIG_INTERNAL_STATS
6015 memset(cpi->mode_chosen_counts, 0,
6016 MAX_MODES * sizeof(*cpi->mode_chosen_counts));
6017#endif
6018
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006019#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01006020 if (cm->seq_params.frame_id_numbers_present_flag) {
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006021 /* Non-normative definition of current_frame_id ("frame counter" with
Johann123e8a62017-12-28 14:40:49 -08006022 * wraparound) */
Sebastien Alaiwand418f682017-10-19 15:06:52 +02006023 const int frame_id_length = FRAME_ID_LENGTH;
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006024 if (cm->current_frame_id == -1) {
David Barker49a76562016-12-07 14:50:21 +00006025 int lsb, msb;
Yaowu Xud3e7c682017-12-21 14:08:25 -08006026 /* quasi-random initialization of current_frame_id for a key frame */
Alex Conversef77fd0b2017-04-20 11:00:24 -07006027 if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) {
6028 lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff;
6029 msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff;
David Barker49a76562016-12-07 14:50:21 +00006030 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006031 lsb = cpi->source->y_buffer[0] & 0xff;
6032 msb = cpi->source->y_buffer[1] & 0xff;
David Barker49a76562016-12-07 14:50:21 +00006033 }
Arild Fuldseth (arilfuld)788dc232016-12-20 17:55:52 +01006034 cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length);
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006035 } else {
6036 cm->current_frame_id =
Arild Fuldseth (arilfuld)788dc232016-12-20 17:55:52 +01006037 (cm->current_frame_id + 1 + (1 << frame_id_length)) %
6038 (1 << frame_id_length);
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006039 }
6040 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006041#endif // CONFIG_REFERENCE_BUFFER
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006042
Yaowu Xuc27fc142016-08-22 16:08:15 -07006043 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
6044 encode_without_recode_loop(cpi);
6045 } else {
Tom Finegane4099e32018-01-23 12:01:51 -08006046 if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK)
6047 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006048 }
6049
Yi Luo10e23002017-07-31 11:54:43 -07006050 cm->last_tile_cols = cm->tile_cols;
6051 cm->last_tile_rows = cm->tile_rows;
6052
Yaowu Xuc27fc142016-08-22 16:08:15 -07006053#ifdef OUTPUT_YUV_SKINMAP
6054 if (cpi->common.current_video_frame > 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006055 av1_compute_skin_map(cpi, yuv_skinmap_file);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006056 }
6057#endif // OUTPUT_YUV_SKINMAP
6058
6059 // Special case code to reduce pulsing when key frames are forced at a
6060 // fixed interval. Note the reconstruction error if it is the frame before
6061 // the force key frame
6062 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006063 if (cm->use_highbitdepth) {
6064 cpi->ambient_err =
Alex Conversef77fd0b2017-04-20 11:00:24 -07006065 aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006066 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006067 cpi->ambient_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006068 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006069 }
6070
6071 // If the encoder forced a KEY_FRAME decision
6072 if (cm->frame_type == KEY_FRAME) {
6073 cpi->refresh_last_frame = 1;
6074 }
6075
6076 cm->frame_to_show = get_frame_new_buffer(cm);
Andrey Norkin9e694632017-12-21 18:50:57 -08006077#if CONFIG_CICP
6078 cm->frame_to_show->color_primaries = cm->color_primaries;
6079 cm->frame_to_show->transfer_characteristics = cm->transfer_characteristics;
6080 cm->frame_to_show->matrix_coefficients = cm->matrix_coefficients;
6081#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07006082 cm->frame_to_show->color_space = cm->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08006083#endif
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08006084#if CONFIG_MONO_VIDEO
6085 cm->frame_to_show->monochrome = cm->seq_params.monochrome;
6086#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07006087#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08006088#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07006089 cm->frame_to_show->transfer_function = cm->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08006090#endif
anorkin76fb1262017-03-22 15:12:12 -07006091 cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position;
6092#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006093 cm->frame_to_show->color_range = cm->color_range;
6094 cm->frame_to_show->render_width = cm->render_width;
6095 cm->frame_to_show->render_height = cm->render_height;
6096
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006097 // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned
6098 // off.
Yaowu Xuc27fc142016-08-22 16:08:15 -07006099
6100 // Pick the loop filter level for the frame.
6101 loopfilter_frame(cpi, cm);
6102
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -07006103#ifdef OUTPUT_YUV_REC
6104 aom_write_one_yuv_frame(cm, cm->frame_to_show);
6105#endif
6106
Yaowu Xuc27fc142016-08-22 16:08:15 -07006107 // Build the bitstream
Tom Finegane4099e32018-01-23 12:01:51 -08006108 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
6109 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006110
Jingning Hanf6214b92017-04-12 11:43:37 -07006111 if (skip_adapt) {
Jingning Hanf6214b92017-04-12 11:43:37 -07006112 aom_free(tile_ctxs);
6113 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006114 return AOM_CODEC_OK;
Jingning Hanf6214b92017-04-12 11:43:37 -07006115 }
Rostislav Pehlivanov74021a52017-03-09 09:05:29 +00006116
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006117#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01006118 if (cm->seq_params.frame_id_numbers_present_flag) {
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006119 int i;
6120 /* Update reference frame id values based on the value of refresh_mask */
6121 for (i = 0; i < REF_FRAMES; i++) {
6122 if ((cm->refresh_mask >> i) & 1) {
6123 cm->ref_frame_id[i] = cm->current_frame_id;
6124 }
6125 }
6126 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006127#endif // CONFIG_REFERENCE_BUFFER
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006128
Yaowu Xuc27fc142016-08-22 16:08:15 -07006129#if DUMP_RECON_FRAMES == 1
6130 // NOTE(zoeliu): For debug - Output the filtered reconstructed video.
Zoe Liub4f31032017-11-03 23:48:35 -07006131 dump_filtered_recon_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006132#endif // DUMP_RECON_FRAMES
6133
Soo-Chul Han934af352017-10-15 15:21:51 -04006134#if CONFIG_SEGMENT_PRED_LAST
6135 if (cm->seg.enabled) {
6136 if (cm->seg.update_map) {
6137 update_reference_segmentation_map(cpi);
6138 } else {
6139 memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map,
6140 cm->mi_cols * cm->mi_rows * sizeof(uint8_t));
6141 }
6142 }
6143#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07006144 if (cm->seg.update_map) update_reference_segmentation_map(cpi);
Soo-Chul Han934af352017-10-15 15:21:51 -04006145#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006146
6147 if (frame_is_intra_only(cm) == 0) {
6148 release_scaled_references(cpi);
6149 }
6150
Cheng Chen46f30c72017-09-07 11:13:33 -07006151 update_reference_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006152
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08006153#if CONFIG_ENTROPY_STATS
6154 av1_accumulate_frame_counts(&aggregate_fc, &cm->counts);
Zoe Liua56f9162017-06-21 22:49:57 -07006155 assert(cm->frame_context_idx < FRAME_CONTEXTS);
6156 av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx],
6157 &cm->counts);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08006158#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07006159 if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
Thomas Davies4822e142017-10-10 11:30:36 +01006160 make_update_tile_list_enc(cpi, cm->largest_tile_id, 1, tile_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006161 av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006162 num_bwd_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006163 av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006164 num_bwd_ctxs);
Debargha Mukherjee43061b32017-10-13 16:50:17 -07006165 av1_average_tile_loopfilter_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
6166 num_bwd_ctxs);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006167 }
6168
6169 if (!frame_is_intra_only(cm)) {
6170 if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
Thomas Davies028b57f2017-02-22 16:42:11 +00006171 av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs,
Thomas Davies4822e142017-10-10 11:30:36 +01006172 cdf_ptrs, num_bwd_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006173 av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006174 num_bwd_ctxs);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006175 }
6176 }
6177
6178 if (cpi->refresh_golden_frame == 1)
6179 cpi->frame_flags |= FRAMEFLAGS_GOLDEN;
6180 else
6181 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
6182
6183 if (cpi->refresh_alt_ref_frame == 1)
6184 cpi->frame_flags |= FRAMEFLAGS_ALTREF;
6185 else
6186 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
6187
Yaowu Xuc27fc142016-08-22 16:08:15 -07006188 if (cpi->refresh_bwd_ref_frame == 1)
6189 cpi->frame_flags |= FRAMEFLAGS_BWDREF;
6190 else
6191 cpi->frame_flags &= ~FRAMEFLAGS_BWDREF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006192
Yaowu Xuc27fc142016-08-22 16:08:15 -07006193 cm->last_frame_type = cm->frame_type;
6194
Yaowu Xuf883b422016-08-30 14:01:10 -07006195 av1_rc_postencode_update(cpi, *size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006196
6197#if 0
6198 output_frame_level_debug_stats(cpi);
6199#endif
6200
6201 if (cm->frame_type == KEY_FRAME) {
6202 // Tell the caller that the frame was coded as a key frame
6203 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
6204 } else {
6205 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
6206 }
6207
6208 // Clear the one shot update flags for segmentation map and mode/ref loop
6209 // filter deltas.
6210 cm->seg.update_map = 0;
6211 cm->seg.update_data = 0;
6212 cm->lf.mode_ref_delta_update = 0;
6213
Yaowu Xuc27fc142016-08-22 16:08:15 -07006214 if (cm->show_frame) {
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006215 // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are
6216 // being used as reference.
Cheng Chen46f30c72017-09-07 11:13:33 -07006217 swap_mi_and_prev_mi(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006218 // Don't increment frame counters if this was an altref buffer
6219 // update not a real frame
6220 ++cm->current_video_frame;
6221 }
6222
Yaowu Xuc27fc142016-08-22 16:08:15 -07006223 // NOTE: Shall not refer to any frame not used as reference.
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006224 if (cm->is_reference_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006225 cm->prev_frame = cm->cur_frame;
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006226 // keep track of the last coded dimensions
6227 cm->last_width = cm->width;
6228 cm->last_height = cm->height;
6229
6230 // reset to normal state now that we are done.
6231 cm->last_show_frame = cm->show_frame;
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006232 }
Yi Luo10e23002017-07-31 11:54:43 -07006233
Thomas Davies493623e2017-03-31 16:12:25 +01006234 aom_free(tile_ctxs);
6235 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006236 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006237}
6238
Tom Finegane4099e32018-01-23 12:01:51 -08006239static int Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest,
6240 int skip_adapt, unsigned int *frame_flags) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006241 if (cpi->oxcf.rc_mode == AOM_CBR) {
6242 av1_rc_get_one_pass_cbr_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006243 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07006244 av1_rc_get_one_pass_vbr_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006245 }
Tom Finegane4099e32018-01-23 12:01:51 -08006246 return encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006247}
6248
Tom Finegane4099e32018-01-23 12:01:51 -08006249static int Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest,
6250 unsigned int *frame_flags) {
Angie Chiang5b5f4df2017-12-06 10:41:12 -08006251#if CONFIG_MISMATCH_DEBUG
6252 mismatch_move_frame_idx_w();
6253#endif
Angie Chiang4d55d762017-12-13 16:18:37 -08006254#if TXCOEFF_COST_TIMER
6255 AV1_COMMON *cm = &cpi->common;
6256 cm->txcoeff_cost_timer = 0;
6257 cm->txcoeff_cost_count = 0;
6258#endif
Tom Finegane4099e32018-01-23 12:01:51 -08006259
6260 if (encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags) !=
6261 AOM_CODEC_OK) {
6262 return AOM_CODEC_ERROR;
6263 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006264
Angie Chiang4d55d762017-12-13 16:18:37 -08006265#if TXCOEFF_COST_TIMER
6266 cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer;
6267 fprintf(stderr,
6268 "\ntxb coeff cost block number: %ld, frame time: %ld, cum time %ld "
6269 "in us\n",
6270 cm->txcoeff_cost_count, cm->txcoeff_cost_timer,
6271 cm->cum_txcoeff_cost_timer);
6272#endif
6273
Yaowu Xuc27fc142016-08-22 16:08:15 -07006274 // Do not do post-encoding update for those frames that do not have a spot in
6275 // a gf group, but note that an OVERLAY frame always has a spot in a gf group,
6276 // even when show_existing_frame is used.
6277 if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006278 av1_twopass_postencode_update(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006279 }
6280 check_show_existing_frame(cpi);
Tom Finegane4099e32018-01-23 12:01:51 -08006281 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006282}
6283
James Zern3e2613b2017-03-30 23:14:40 -07006284int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
Yaowu Xuf883b422016-08-30 14:01:10 -07006285 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
6286 int64_t end_time) {
6287 AV1_COMMON *const cm = &cpi->common;
6288 struct aom_usec_timer timer;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006289 int res = 0;
6290 const int subsampling_x = sd->subsampling_x;
6291 const int subsampling_y = sd->subsampling_y;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006292 const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006293
Yaowu Xuc27fc142016-08-22 16:08:15 -07006294 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006295
Yaowu Xuf883b422016-08-30 14:01:10 -07006296 aom_usec_timer_start(&timer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006297
Yaowu Xuf883b422016-08-30 14:01:10 -07006298 if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
Yaowu Xud3e7c682017-12-21 14:08:25 -08006299 use_highbitdepth, frame_flags))
Yaowu Xuc27fc142016-08-22 16:08:15 -07006300 res = -1;
Yaowu Xuf883b422016-08-30 14:01:10 -07006301 aom_usec_timer_mark(&timer);
6302 cpi->time_receive_data += aom_usec_timer_elapsed(&timer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006303
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006304 if ((cm->profile == PROFILE_0) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07006305 (subsampling_x != 1 || subsampling_y != 1)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006306 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006307 "Non-4:2:0 color format requires profile 1 or 2");
Yaowu Xuc27fc142016-08-22 16:08:15 -07006308 res = -1;
6309 }
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006310 if ((cm->profile == PROFILE_1) &&
6311 !(subsampling_x == 0 && subsampling_y == 0)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006312 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006313 "Profile 1 requires 4:4:4 color format");
6314 res = -1;
6315 }
6316 if ((cm->profile == PROFILE_2) && (cm->bit_depth <= AOM_BITS_10) &&
6317 !(subsampling_x == 1 && subsampling_y == 0)) {
6318 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
6319 "Profile 2 bit-depth < 10 requires 4:2:2 color format");
Yaowu Xuc27fc142016-08-22 16:08:15 -07006320 res = -1;
6321 }
6322
6323 return res;
6324}
6325
Yaowu Xuf883b422016-08-30 14:01:10 -07006326static int frame_is_reference(const AV1_COMP *cpi) {
6327 const AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006328
6329 return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame ||
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006330 cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame ||
6331 cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame ||
6332 !cm->error_resilient_mode || cm->lf.mode_ref_delta_update ||
6333 cm->seg.update_map || cm->seg.update_data;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006334}
6335
Yaowu Xuf883b422016-08-30 14:01:10 -07006336static void adjust_frame_rate(AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006337 const struct lookahead_entry *source) {
6338 int64_t this_duration;
6339 int step = 0;
6340
6341 if (source->ts_start == cpi->first_time_stamp_ever) {
6342 this_duration = source->ts_end - source->ts_start;
6343 step = 1;
6344 } else {
6345 int64_t last_duration =
6346 cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen;
6347
6348 this_duration = source->ts_end - cpi->last_end_time_stamp_seen;
6349
6350 // do a step update if the duration changes by 10%
6351 if (last_duration)
6352 step = (int)((this_duration - last_duration) * 10 / last_duration);
6353 }
6354
6355 if (this_duration) {
6356 if (step) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006357 av1_new_framerate(cpi, 10000000.0 / this_duration);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006358 } else {
6359 // Average this frame's rate into the last second's average
6360 // frame rate. If we haven't seen 1 second yet, then average
6361 // over the whole interval seen.
Yaowu Xuf883b422016-08-30 14:01:10 -07006362 const double interval = AOMMIN(
Yaowu Xuc27fc142016-08-22 16:08:15 -07006363 (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0);
6364 double avg_duration = 10000000.0 / cpi->framerate;
6365 avg_duration *= (interval - avg_duration + this_duration);
6366 avg_duration /= interval;
6367
Yaowu Xuf883b422016-08-30 14:01:10 -07006368 av1_new_framerate(cpi, 10000000.0 / avg_duration);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006369 }
6370 }
6371 cpi->last_time_stamp_seen = source->ts_start;
6372 cpi->last_end_time_stamp_seen = source->ts_end;
6373}
6374
6375// Returns 0 if this is not an alt ref else the offset of the source frame
6376// used as the arf midpoint.
Yaowu Xuf883b422016-08-30 14:01:10 -07006377static int get_arf_src_index(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006378 RATE_CONTROL *const rc = &cpi->rc;
6379 int arf_src_index = 0;
6380 if (is_altref_enabled(cpi)) {
6381 if (cpi->oxcf.pass == 2) {
6382 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6383 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
6384 arf_src_index = gf_group->arf_src_offset[gf_group->index];
6385 }
6386 } else if (rc->source_alt_ref_pending) {
6387 arf_src_index = rc->frames_till_gf_update_due;
6388 }
6389 }
6390 return arf_src_index;
6391}
6392
Yaowu Xuf883b422016-08-30 14:01:10 -07006393static int get_brf_src_index(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006394 int brf_src_index = 0;
6395 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6396
6397 // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup
6398 // flag.
6399 if (gf_group->bidir_pred_enabled[gf_group->index]) {
6400 if (cpi->oxcf.pass == 2) {
6401 if (gf_group->update_type[gf_group->index] == BRF_UPDATE)
6402 brf_src_index = gf_group->brf_src_offset[gf_group->index];
6403 } else {
6404 // TODO(zoeliu): To re-visit the setup for this scenario
6405 brf_src_index = cpi->rc.bipred_group_interval - 1;
6406 }
6407 }
6408
6409 return brf_src_index;
6410}
Zoe Liue9b15e22017-07-19 15:53:01 -07006411
Zoe Liue9b15e22017-07-19 15:53:01 -07006412// Returns 0 if this is not an alt ref else the offset of the source frame
6413// used as the arf midpoint.
6414static int get_arf2_src_index(AV1_COMP *cpi) {
6415 int arf2_src_index = 0;
6416 if (is_altref_enabled(cpi) && cpi->num_extra_arfs) {
6417 if (cpi->oxcf.pass == 2) {
6418 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6419 if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) {
6420 arf2_src_index = gf_group->arf_src_offset[gf_group->index];
6421 }
6422 }
6423 }
6424 return arf2_src_index;
6425}
Yaowu Xuc27fc142016-08-22 16:08:15 -07006426
Yaowu Xuf883b422016-08-30 14:01:10 -07006427static void check_src_altref(AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006428 const struct lookahead_entry *source) {
6429 RATE_CONTROL *const rc = &cpi->rc;
6430
6431 // If pass == 2, the parameters set here will be reset in
Yaowu Xuf883b422016-08-30 14:01:10 -07006432 // av1_rc_get_second_pass_params()
Yaowu Xuc27fc142016-08-22 16:08:15 -07006433
6434 if (cpi->oxcf.pass == 2) {
6435 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6436 rc->is_src_frame_alt_ref =
Yaowu Xuc27fc142016-08-22 16:08:15 -07006437 (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07006438 (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE);
Zoe Liue9b15e22017-07-19 15:53:01 -07006439 rc->is_src_frame_ext_arf =
6440 gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006441 } else {
6442 rc->is_src_frame_alt_ref =
6443 cpi->alt_ref_source && (source == cpi->alt_ref_source);
6444 }
6445
6446 if (rc->is_src_frame_alt_ref) {
6447 // Current frame is an ARF overlay frame.
6448 cpi->alt_ref_source = NULL;
6449
Zoe Liue9b15e22017-07-19 15:53:01 -07006450 if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) {
6451 // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to
6452 // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3,
6453 // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST.
6454 cpi->refresh_last_frame = 1;
6455 } else {
Zoe Liue9b15e22017-07-19 15:53:01 -07006456 // Don't refresh the last buffer for an ARF overlay frame. It will
6457 // become the GF so preserve last as an alternative prediction option.
6458 cpi->refresh_last_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006459 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006460 }
6461}
6462
6463#if CONFIG_INTERNAL_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -07006464extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch,
6465 const unsigned char *img2, int img2_pitch,
6466 int width, int height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006467
6468static void adjust_image_stat(double y, double u, double v, double all,
6469 ImageStat *s) {
6470 s->stat[Y] += y;
6471 s->stat[U] += u;
6472 s->stat[V] += v;
6473 s->stat[ALL] += all;
Yaowu Xuf883b422016-08-30 14:01:10 -07006474 s->worst = AOMMIN(s->worst, all);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006475}
6476
Angie Chiang08a22a62017-07-17 17:29:17 -07006477static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006478 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006479 double samples = 0.0;
6480 uint32_t in_bit_depth = 8;
6481 uint32_t bit_depth = 8;
6482
Angie Chiang08a22a62017-07-17 17:29:17 -07006483#if CONFIG_INTER_STATS_ONLY
Yaowu Xu1b4ffc42017-07-26 09:54:07 -07006484 if (cm->frame_type == KEY_FRAME) return; // skip key frame
Angie Chiang08a22a62017-07-17 17:29:17 -07006485#endif
6486 cpi->bytes += frame_bytes;
6487
Yaowu Xuc27fc142016-08-22 16:08:15 -07006488 if (cm->use_highbitdepth) {
6489 in_bit_depth = cpi->oxcf.input_bit_depth;
6490 bit_depth = cm->bit_depth;
6491 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006492 if (cm->show_frame) {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006493 const YV12_BUFFER_CONFIG *orig = cpi->source;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006494 const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
6495 double y, u, v, frame_all;
6496
6497 cpi->count++;
6498 if (cpi->b_calculate_psnr) {
6499 PSNR_STATS psnr;
6500 double frame_ssim2 = 0.0, weight = 0.0;
Yaowu Xuf883b422016-08-30 14:01:10 -07006501 aom_clear_system_state();
Yaowu Xud3e7c682017-12-21 14:08:25 -08006502 // TODO(yaowu): unify these two versions into one.
Yaowu Xuf883b422016-08-30 14:01:10 -07006503 aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006504
6505 adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0],
6506 &cpi->psnr);
6507 cpi->total_sq_error += psnr.sse[0];
6508 cpi->total_samples += psnr.samples[0];
6509 samples = psnr.samples[0];
Yaowu Xud3e7c682017-12-21 14:08:25 -08006510 // TODO(yaowu): unify these two versions into one.
Yaowu Xuc27fc142016-08-22 16:08:15 -07006511 if (cm->use_highbitdepth)
6512 frame_ssim2 =
Yaowu Xuf883b422016-08-30 14:01:10 -07006513 aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006514 else
Yaowu Xuf883b422016-08-30 14:01:10 -07006515 frame_ssim2 = aom_calc_ssim(orig, recon, &weight);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006516
Yaowu Xuf883b422016-08-30 14:01:10 -07006517 cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006518 cpi->summed_quality += frame_ssim2 * weight;
6519 cpi->summed_weights += weight;
6520
6521#if 0
6522 {
6523 FILE *f = fopen("q_used.stt", "a");
Zoe Liuee202be2017-11-17 12:14:33 -08006524 double y2 = psnr.psnr[1];
6525 double u2 = psnr.psnr[2];
6526 double v2 = psnr.psnr[3];
6527 double frame_psnr2 = psnr.psnr[0];
Yaowu Xuc27fc142016-08-22 16:08:15 -07006528 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 -08006529 cm->current_video_frame, y2, u2, v2,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006530 frame_psnr2, frame_ssim2);
6531 fclose(f);
6532 }
6533#endif
6534 }
6535 if (cpi->b_calculate_blockiness) {
Yaowu Xud3e7c682017-12-21 14:08:25 -08006536 if (!cm->use_highbitdepth) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006537 const double frame_blockiness =
Yaowu Xuf883b422016-08-30 14:01:10 -07006538 av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer,
6539 recon->y_stride, orig->y_width, orig->y_height);
6540 cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006541 cpi->total_blockiness += frame_blockiness;
6542 }
6543
6544 if (cpi->b_calculate_consistency) {
Yaowu Xud3e7c682017-12-21 14:08:25 -08006545 if (!cm->use_highbitdepth) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006546 const double this_inconsistency = aom_get_ssim_metrics(
Yaowu Xuc27fc142016-08-22 16:08:15 -07006547 orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride,
6548 orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1);
6549
6550 const double peak = (double)((1 << in_bit_depth) - 1);
6551 const double consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07006552 aom_sse_to_psnr(samples, peak, cpi->total_inconsistency);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006553 if (consistency > 0.0)
6554 cpi->worst_consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07006555 AOMMIN(cpi->worst_consistency, consistency);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006556 cpi->total_inconsistency += this_inconsistency;
6557 }
6558 }
6559 }
6560
6561 frame_all =
Yaowu Xuf883b422016-08-30 14:01:10 -07006562 aom_calc_fastssim(orig, recon, &y, &u, &v, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006563 adjust_image_stat(y, u, v, frame_all, &cpi->fastssim);
Yaowu Xuf883b422016-08-30 14:01:10 -07006564 frame_all = aom_psnrhvs(orig, recon, &y, &u, &v, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006565 adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs);
6566 }
6567}
6568#endif // CONFIG_INTERNAL_STATS
6569
RogerZhou3b635242017-09-19 10:06:46 -07006570#if CONFIG_AMVR
6571static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture,
6572 const YV12_BUFFER_CONFIG *last_picture,
6573 hash_table *last_hash_table) {
6574 aom_clear_system_state();
6575 // check use hash ME
6576 int k;
6577 uint32_t hash_value_1;
6578 uint32_t hash_value_2;
6579
6580 const int block_size = 8;
6581 const double threshold_current = 0.8;
6582 const double threshold_average = 0.95;
6583 const int max_history_size = 32;
6584 int T = 0; // total block
6585 int C = 0; // match with collocated block
6586 int S = 0; // smooth region but not match with collocated block
6587 int M = 0; // match with other block
6588
6589 const int pic_width = cur_picture->y_width;
6590 const int pic_height = cur_picture->y_height;
6591 for (int i = 0; i + block_size <= pic_height; i += block_size) {
6592 for (int j = 0; j + block_size <= pic_width; j += block_size) {
6593 const int x_pos = j;
6594 const int y_pos = i;
6595 int match = 1;
6596 T++;
6597
6598 // check whether collocated block match with current
6599 uint8_t *p_cur = cur_picture->y_buffer;
6600 uint8_t *p_ref = last_picture->y_buffer;
6601 int stride_cur = cur_picture->y_stride;
6602 int stride_ref = last_picture->y_stride;
6603 p_cur += (y_pos * stride_cur + x_pos);
6604 p_ref += (y_pos * stride_ref + x_pos);
6605
6606 for (int tmpY = 0; tmpY < block_size && match; tmpY++) {
6607 for (int tmpX = 0; tmpX < block_size && match; tmpX++) {
6608 if (p_cur[tmpX] != p_ref[tmpX]) {
6609 match = 0;
6610 }
6611 }
6612 p_cur += stride_cur;
6613 p_ref += stride_ref;
6614 }
6615
6616 if (match) {
6617 C++;
6618 continue;
6619 }
6620
6621 if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos,
6622 y_pos) ||
6623 av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) {
6624 S++;
6625 continue;
6626 }
6627
6628 av1_get_block_hash_value(
6629 cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur,
6630 block_size, &hash_value_1, &hash_value_2);
6631
6632 if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) {
6633 M++;
6634 }
6635 }
6636 }
6637
6638 assert(T > 0);
6639 double csm_rate = ((double)(C + S + M)) / ((double)(T));
6640 double m_rate = ((double)(M)) / ((double)(T));
6641
6642 cpi->csm_rate_array[cpi->rate_index] = csm_rate;
6643 cpi->m_rate_array[cpi->rate_index] = m_rate;
6644
6645 cpi->rate_index = (cpi->rate_index + 1) % max_history_size;
6646 cpi->rate_size++;
6647 cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size);
6648
6649 if (csm_rate < threshold_current) {
6650 return 0;
6651 }
6652
6653 if (C == T) {
6654 return 1;
6655 }
6656
6657 double csm_average = 0.0;
6658 double m_average = 0.0;
6659
6660 for (k = 0; k < cpi->rate_size; k++) {
6661 csm_average += cpi->csm_rate_array[k];
6662 m_average += cpi->m_rate_array[k];
6663 }
6664 csm_average /= cpi->rate_size;
6665 m_average /= cpi->rate_size;
6666
6667 if (csm_average < threshold_average) {
6668 return 0;
6669 }
6670
6671 if (M > (T - C - S) / 3) {
6672 return 1;
6673 }
6674
6675 if (csm_rate > 0.99 && m_rate > 0.01) {
6676 return 1;
6677 }
6678
6679 if (csm_average + m_average > 1.01) {
6680 return 1;
6681 }
6682
6683 return 0;
6684}
6685#endif
6686
Yaowu Xuf883b422016-08-30 14:01:10 -07006687int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
6688 size_t *size, uint8_t *dest, int64_t *time_stamp,
6689 int64_t *time_end, int flush) {
6690 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
6691 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006692 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006693 BufferPool *const pool = cm->buffer_pool;
6694 RATE_CONTROL *const rc = &cpi->rc;
Yaowu Xuf883b422016-08-30 14:01:10 -07006695 struct aom_usec_timer cmptimer;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006696 YV12_BUFFER_CONFIG *force_src_buffer = NULL;
6697 struct lookahead_entry *last_source = NULL;
6698 struct lookahead_entry *source = NULL;
6699 int arf_src_index;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006700 int brf_src_index;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006701 int i;
6702
6703#if CONFIG_BITSTREAM_DEBUG
6704 assert(cpi->oxcf.max_threads == 0 &&
6705 "bitstream debug tool does not support multithreading");
6706 bitstream_queue_record_write();
Angie Chiangcb9a9eb2016-09-01 16:10:50 -07006707 bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006708#endif
6709
Yaowu Xuf883b422016-08-30 14:01:10 -07006710 aom_usec_timer_start(&cmptimer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006711
RogerZhou3b635242017-09-19 10:06:46 -07006712#if CONFIG_AMVR
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07006713#if CONFIG_EIGHTH_PEL_MV_ONLY
6714 set_high_precision_mv(cpi, 1, 0);
6715#else
RogerZhou3b635242017-09-19 10:06:46 -07006716 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0);
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07006717#endif // CONFIG_EIGHTH_PEL_MV_ONLY
6718#else
6719#if CONFIG_EIGHTH_PEL_MV_ONLY
6720 set_high_precision_mv(cpi, 1);
RogerZhou3b635242017-09-19 10:06:46 -07006721#else
Cheng Chen46f30c72017-09-07 11:13:33 -07006722 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07006723#endif // CONFIG_EIGHTH_PEL_MV_ONLY
RogerZhou3b635242017-09-19 10:06:46 -07006724#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006725
6726 // Is multi-arf enabled.
6727 // Note that at the moment multi_arf is only configured for 2 pass VBR
6728 if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1))
6729 cpi->multi_arf_allowed = 1;
6730 else
6731 cpi->multi_arf_allowed = 0;
6732
Thomas Daedea6a854b2017-06-22 17:49:11 -07006733// Normal defaults
6734#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07006735 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
Thomas Daedea6a854b2017-06-22 17:49:11 -07006736#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006737 cm->refresh_frame_context =
6738 (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode)
6739 ? REFRESH_FRAME_CONTEXT_FORWARD
6740 : REFRESH_FRAME_CONTEXT_BACKWARD;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01006741#if CONFIG_EXT_TILE
6742 if (oxcf->large_scale_tile)
6743 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
6744#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07006745
6746 cpi->refresh_last_frame = 1;
6747 cpi->refresh_golden_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006748 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006749 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006750 cpi->refresh_alt_ref_frame = 0;
6751
Zoe Liub4991202017-12-21 15:31:06 -08006752#if CONFIG_FWD_KF
6753 // TODO(zoeliu@gmail.com): To support forward-KEY_FRAME and set up the
6754 // following flag accordingly.
6755 cm->reset_decoder_state = 0;
6756#endif // CONFIG_FWD_KF
6757
Yaowu Xuc27fc142016-08-22 16:08:15 -07006758 if (oxcf->pass == 2 && cm->show_existing_frame) {
6759 // Manage the source buffer and flush out the source frame that has been
6760 // coded already; Also get prepared for PSNR calculation if needed.
Yaowu Xuf883b422016-08-30 14:01:10 -07006761 if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006762 *size = 0;
6763 return -1;
6764 }
Alex Conversef77fd0b2017-04-20 11:00:24 -07006765 cpi->source = &source->img;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006766 // TODO(zoeliu): To track down to determine whether it's needed to adjust
6767 // the frame rate.
6768 *time_stamp = source->ts_start;
6769 *time_end = source->ts_end;
6770
6771 // We need to adjust frame rate for an overlay frame
Zoe Liue04abf72017-04-19 15:37:11 -07006772 if (cpi->rc.is_src_frame_alt_ref) adjust_frame_rate(cpi, source);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006773
6774 // Find a free buffer for the new frame, releasing the reference previously
6775 // held.
6776 if (cm->new_fb_idx != INVALID_IDX) {
6777 --pool->frame_bufs[cm->new_fb_idx].ref_count;
6778 }
6779 cm->new_fb_idx = get_free_fb(cm);
6780
6781 if (cm->new_fb_idx == INVALID_IDX) return -1;
6782
6783 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006784 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006785
6786 // Start with a 0 size frame.
6787 *size = 0;
6788
6789 // We need to update the gf_group for show_existing overlay frame
Zoe Liue04abf72017-04-19 15:37:11 -07006790 if (cpi->rc.is_src_frame_alt_ref) av1_rc_get_second_pass_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006791
Tom Finegane4099e32018-01-23 12:01:51 -08006792 if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK)
6793 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006794
6795 if (cpi->b_calculate_psnr) generate_psnr_packet(cpi);
6796
6797#if CONFIG_INTERNAL_STATS
Angie Chiang08a22a62017-07-17 17:29:17 -07006798 compute_internal_stats(cpi, (int)(*size));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006799#endif // CONFIG_INTERNAL_STATS
6800
6801 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006802 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006803
6804 cm->show_existing_frame = 0;
6805 return 0;
6806 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006807
6808 // Should we encode an arf frame.
6809 arf_src_index = get_arf_src_index(cpi);
6810 if (arf_src_index) {
6811 for (i = 0; i <= arf_src_index; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006812 struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006813 // Avoid creating an alt-ref if there's a forced keyframe pending.
6814 if (e == NULL) {
6815 break;
Yaowu Xuf883b422016-08-30 14:01:10 -07006816 } else if (e->flags == AOM_EFLAG_FORCE_KF) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006817 arf_src_index = 0;
6818 flush = 1;
6819 break;
6820 }
6821 }
6822 }
6823
6824 if (arf_src_index) {
6825 assert(arf_src_index <= rc->frames_to_key);
6826
Yaowu Xuf883b422016-08-30 14:01:10 -07006827 if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006828 cpi->alt_ref_source = source;
6829
6830 if (oxcf->arnr_max_frames > 0) {
Todd Nguyen302d0972017-06-16 16:16:29 -07006831// Produce the filtered ARF frame.
6832#if CONFIG_BGSPRITE
6833 int bgsprite_ret = av1_background_sprite(cpi, arf_src_index);
Todd Nguyen2fc23092017-07-11 12:00:36 -07006834 // Do temporal filter if bgsprite not generated.
6835 if (bgsprite_ret != 0)
Todd Nguyen302d0972017-06-16 16:16:29 -07006836#endif // CONFIG_BGSPRITE
Todd Nguyen8493f912017-07-20 12:45:12 -07006837 av1_temporal_filter(cpi,
6838#if CONFIG_BGSPRITE
Todd Nguyen1fd99c22017-07-31 17:50:41 -07006839 NULL, &cpi->alt_ref_buffer,
Todd Nguyen8493f912017-07-20 12:45:12 -07006840#endif // CONFIG_BGSPRITE
6841 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.
Zoe Liu3ac20932017-08-30 16:35:55 -07006882 av1_temporal_filter(cpi,
6883#if CONFIG_BGSPRITE
6884 NULL, NULL,
6885#endif // CONFIG_BGSPRITE
6886 arf_src_index);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006887 aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes);
Zoe Liue9b15e22017-07-19 15:53:01 -07006888 force_src_buffer = &cpi->alt_ref_buffer;
6889 }
6890
6891 cm->show_frame = 0;
6892 cm->intra_only = 0;
6893 cpi->refresh_alt2_ref_frame = 1;
6894 cpi->refresh_last_frame = 0;
6895 cpi->refresh_golden_frame = 0;
6896 cpi->refresh_bwd_ref_frame = 0;
6897 cpi->refresh_alt_ref_frame = 0;
6898 rc->is_src_frame_alt_ref = 0;
6899 rc->is_src_frame_ext_arf = 0;
6900 }
6901 rc->source_alt_ref_pending = 0;
6902 }
Zoe Liue9b15e22017-07-19 15:53:01 -07006903
Yaowu Xuc27fc142016-08-22 16:08:15 -07006904 rc->is_bwd_ref_frame = 0;
6905 brf_src_index = get_brf_src_index(cpi);
6906 if (brf_src_index) {
6907 assert(brf_src_index <= rc->frames_to_key);
Yaowu Xuf883b422016-08-30 14:01:10 -07006908 if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006909 cm->show_frame = 0;
6910 cm->intra_only = 0;
6911
6912 cpi->refresh_bwd_ref_frame = 1;
6913 cpi->refresh_last_frame = 0;
6914 cpi->refresh_golden_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006915 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006916 cpi->refresh_alt_ref_frame = 0;
6917
6918 rc->is_bwd_ref_frame = 1;
6919 }
6920 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006921
6922 if (!source) {
6923 // Get last frame source.
6924 if (cm->current_video_frame > 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006925 if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL)
Yaowu Xuc27fc142016-08-22 16:08:15 -07006926 return -1;
6927 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07006928 if (cm->current_video_frame > 0) assert(last_source != NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006929 // Read in the source frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07006930 source = av1_lookahead_pop(cpi->lookahead, flush);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006931
6932 if (source != NULL) {
6933 cm->show_frame = 1;
6934 cm->intra_only = 0;
6935
6936 // Check to see if the frame should be encoded as an arf overlay.
6937 check_src_altref(cpi, source);
6938 }
6939 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006940 if (source) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07006941 cpi->unscaled_source = cpi->source =
Yaowu Xuc27fc142016-08-22 16:08:15 -07006942 force_src_buffer ? force_src_buffer : &source->img;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006943 cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL;
6944
6945 *time_stamp = source->ts_start;
6946 *time_end = source->ts_end;
Yaowu Xuf883b422016-08-30 14:01:10 -07006947 *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006948
6949 } else {
6950 *size = 0;
6951 if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006952 av1_end_first_pass(cpi); /* get last stats packet */
Yaowu Xuc27fc142016-08-22 16:08:15 -07006953 cpi->twopass.first_pass_done = 1;
6954 }
6955 return -1;
6956 }
6957
6958 if (source->ts_start < cpi->first_time_stamp_ever) {
6959 cpi->first_time_stamp_ever = source->ts_start;
6960 cpi->last_end_time_stamp_seen = source->ts_start;
6961 }
6962
6963 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006964 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006965
6966 // adjust frame rates based on timestamps given
6967 if (cm->show_frame) adjust_frame_rate(cpi, source);
6968
6969 // Find a free buffer for the new frame, releasing the reference previously
6970 // held.
6971 if (cm->new_fb_idx != INVALID_IDX) {
6972 --pool->frame_bufs[cm->new_fb_idx].ref_count;
6973 }
6974 cm->new_fb_idx = get_free_fb(cm);
6975
6976 if (cm->new_fb_idx == INVALID_IDX) return -1;
6977
Zoe Liuf452fdf2017-11-02 23:08:12 -07006978 // Retain the RF_LEVEL for the current newly coded frame.
6979 cpi->frame_rf_level[cm->new_fb_idx] =
6980 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
Zoe Liuf452fdf2017-11-02 23:08:12 -07006981
Yaowu Xuc27fc142016-08-22 16:08:15 -07006982 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
Yaowu Xu9b0f7032017-07-31 11:01:19 -07006983 cm->cur_frame->buf.buf_8bit_valid = 0;
Zoe Liu6cfaff92016-10-18 17:12:11 -07006984
Yaowu Xuc27fc142016-08-22 16:08:15 -07006985 // Start with a 0 size frame.
6986 *size = 0;
6987
6988 cpi->frame_flags = *frame_flags;
6989
6990 if (oxcf->pass == 2) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006991 av1_rc_get_second_pass_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006992 } else if (oxcf->pass == 1) {
Fergus Simpsonbc189932017-05-16 17:02:39 -07006993 setup_frame_size(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006994 }
6995
6996 if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) {
6997 for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i)
6998 cpi->scaled_ref_idx[i] = INVALID_IDX;
6999 }
7000
7001#if CONFIG_AOM_QM
7002 cm->using_qmatrix = cpi->oxcf.using_qm;
7003 cm->min_qmlevel = cpi->oxcf.qm_minlevel;
7004 cm->max_qmlevel = cpi->oxcf.qm_maxlevel;
7005#endif
7006
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01007007#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01007008 if (cm->seq_params.frame_id_numbers_present_flag) {
Debargha Mukherjee778023d2017-09-26 17:50:27 -07007009 if (*time_stamp == 0) {
7010 cpi->common.current_frame_id = -1;
7011 }
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01007012 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07007013#endif // CONFIG_REFERENCE_BUFFER
RogerZhou3b635242017-09-19 10:06:46 -07007014#if CONFIG_AMVR
7015 cpi->cur_poc++;
7016 if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) {
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00007017 if (cpi->common.seq_params.force_integer_mv == 2) {
RogerZhou3b635242017-09-19 10:06:46 -07007018 struct lookahead_entry *previous_entry =
7019 cpi->lookahead->buf + cpi->previsous_index;
RogerZhou10a03802017-10-26 11:49:48 -07007020 cpi->common.cur_frame_force_integer_mv = is_integer_mv(
RogerZhou3b635242017-09-19 10:06:46 -07007021 cpi, cpi->source, &previous_entry->img, cpi->previsou_hash_table);
7022 } else {
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00007023 cpi->common.cur_frame_force_integer_mv =
7024 cpi->common.seq_params.force_integer_mv;
RogerZhou3b635242017-09-19 10:06:46 -07007025 }
7026 } else {
RogerZhou10a03802017-10-26 11:49:48 -07007027 cpi->common.cur_frame_force_integer_mv = 0;
RogerZhou3b635242017-09-19 10:06:46 -07007028 }
7029#endif
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01007030
Yaowu Xuc27fc142016-08-22 16:08:15 -07007031 if (oxcf->pass == 1) {
7032 cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf);
Yaowu Xuf883b422016-08-30 14:01:10 -07007033 av1_first_pass(cpi, source);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007034 } else if (oxcf->pass == 2) {
Tom Finegane4099e32018-01-23 12:01:51 -08007035 if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK)
7036 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007037 } else {
7038 // One pass encode
Tom Finegane4099e32018-01-23 12:01:51 -08007039 if (Pass0Encode(cpi, size, dest, 0, frame_flags) != AOM_CODEC_OK)
7040 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007041 }
RogerZhoucc5d35d2017-08-07 22:20:15 -07007042#if CONFIG_HASH_ME
7043 if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) {
RogerZhou3b635242017-09-19 10:06:46 -07007044#if CONFIG_AMVR
7045 cpi->previsou_hash_table = &cm->cur_frame->hash_table;
7046 {
7047 int l;
7048 for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) {
7049 if ((cpi->lookahead->buf + l) == source) {
7050 cpi->previsous_index = l;
7051 break;
7052 }
7053 }
7054
7055 if (l == cpi->lookahead->max_sz) {
7056 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
7057 "Failed to find last frame original buffer");
7058 }
7059 }
7060#endif
RogerZhoucc5d35d2017-08-07 22:20:15 -07007061 }
7062
7063#endif
7064
Yunqing Wang267e3272017-11-09 14:23:22 -08007065#if CONFIG_EXT_TILE
7066 if (!cm->large_scale_tile) {
7067#endif // CONFIG_EXT_TILE
Thomas Daededa4d8b92017-06-05 15:44:14 -07007068#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yunqing Wang267e3272017-11-09 14:23:22 -08007069 cm->frame_contexts[cm->new_fb_idx] = *cm->fc;
Thomas Daededa4d8b92017-06-05 15:44:14 -07007070#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07007071 if (!cm->error_resilient_mode)
7072 cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
Thomas Daededa4d8b92017-06-05 15:44:14 -07007073#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yunqing Wang267e3272017-11-09 14:23:22 -08007074#if CONFIG_EXT_TILE
7075 }
7076#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07007077
Yunqing Wangb041d8a2017-11-15 12:31:18 -08007078#if CONFIG_EXT_TILE
7079#define EXT_TILE_DEBUG 0
7080#if EXT_TILE_DEBUG
7081 if (cm->large_scale_tile && oxcf->pass == 2) {
7082 char fn[20] = "./fc";
7083 fn[4] = cm->current_video_frame / 100 + '0';
7084 fn[5] = (cm->current_video_frame % 100) / 10 + '0';
7085 fn[6] = (cm->current_video_frame % 10) + '0';
7086 fn[7] = '\0';
7087 av1_print_frame_contexts(cm->fc, fn);
7088 }
7089#endif // EXT_TILE_DEBUG
7090#undef EXT_TILE_DEBUG
7091#endif // CONFIG_EXT_TILE
7092
Yaowu Xuc27fc142016-08-22 16:08:15 -07007093 // No frame encoded, or frame was dropped, release scaled references.
7094 if ((*size == 0) && (frame_is_intra_only(cm) == 0)) {
7095 release_scaled_references(cpi);
7096 }
7097
7098 if (*size > 0) {
7099 cpi->droppable = !frame_is_reference(cpi);
7100 }
7101
Yaowu Xuf883b422016-08-30 14:01:10 -07007102 aom_usec_timer_mark(&cmptimer);
7103 cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007104
7105 if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame)
7106 generate_psnr_packet(cpi);
7107
7108#if CONFIG_INTERNAL_STATS
7109 if (oxcf->pass != 1) {
Angie Chiang08a22a62017-07-17 17:29:17 -07007110 compute_internal_stats(cpi, (int)(*size));
Yaowu Xuc27fc142016-08-22 16:08:15 -07007111 }
7112#endif // CONFIG_INTERNAL_STATS
7113
Yaowu Xuf883b422016-08-30 14:01:10 -07007114 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07007115
7116 return 0;
7117}
7118
Yaowu Xuf883b422016-08-30 14:01:10 -07007119int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) {
7120 AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007121 if (!cm->show_frame) {
7122 return -1;
7123 } else {
7124 int ret;
7125 if (cm->frame_to_show) {
7126 *dest = *cm->frame_to_show;
7127 dest->y_width = cm->width;
7128 dest->y_height = cm->height;
7129 dest->uv_width = cm->width >> cm->subsampling_x;
7130 dest->uv_height = cm->height >> cm->subsampling_y;
7131 ret = 0;
7132 } else {
7133 ret = -1;
7134 }
Yaowu Xuf883b422016-08-30 14:01:10 -07007135 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07007136 return ret;
7137 }
7138}
7139
Yaowu Xuf883b422016-08-30 14:01:10 -07007140int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07007141 if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1;
7142
7143 *frame =
7144 cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf;
7145 return 0;
7146}
7147
Yaowu Xuf883b422016-08-30 14:01:10 -07007148int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
7149 AOM_SCALING vert_mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07007150 int hr = 0, hs = 0, vr = 0, vs = 0;
7151
7152 if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1;
7153
7154 Scale2Ratio(horiz_mode, &hr, &hs);
7155 Scale2Ratio(vert_mode, &vr, &vs);
7156
7157 // always go to the next whole number
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07007158 cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs;
7159 cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007160
7161 return 0;
7162}
7163
Yaowu Xuf883b422016-08-30 14:01:10 -07007164int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007165
Yaowu Xuf883b422016-08-30 14:01:10 -07007166void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) {
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007167 // TODO(yunqingwang): For what references to use, external encoding flags
7168 // should be consistent with internal reference frame selection. Need to
7169 // ensure that there is not conflict between the two. In AV1 encoder, the
7170 // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3,
7171 // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be
7172 // LAST.
Yunqing Wangf2e7a392017-11-08 00:27:21 -08007173 cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007174 if (flags &
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007175 (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
7176 AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD |
7177 AOM_EFLAG_NO_REF_ARF2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07007178 if (flags & AOM_EFLAG_NO_REF_LAST) {
Yunqing Wangf2e7a392017-11-08 00:27:21 -08007179 cpi->ext_ref_frame_flags = 0;
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007180 } else {
7181 int ref = AOM_REFFRAME_ALL;
7182
7183 if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG;
7184 if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG;
7185
7186 if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG;
7187
7188 if (flags & AOM_EFLAG_NO_REF_ARF) {
7189 ref ^= AOM_ALT_FLAG;
7190 ref ^= AOM_BWD_FLAG;
7191 ref ^= AOM_ALT2_FLAG;
7192 } else {
7193 if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG;
7194 if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG;
7195 }
7196
7197 av1_use_as_reference(cpi, ref);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007198 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007199 }
7200
7201 if (flags &
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007202 (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07007203 int upd = AOM_REFFRAME_ALL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007204
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007205 // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag.
7206 if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007207
Yaowu Xuf883b422016-08-30 14:01:10 -07007208 if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007209
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007210 if (flags & AOM_EFLAG_NO_UPD_ARF) {
7211 upd ^= AOM_ALT_FLAG;
7212 upd ^= AOM_BWD_FLAG;
7213 upd ^= AOM_ALT2_FLAG;
7214 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007215
Yaowu Xuf883b422016-08-30 14:01:10 -07007216 av1_update_reference(cpi, upd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007217 }
7218
Yaowu Xuf883b422016-08-30 14:01:10 -07007219 if (flags & AOM_EFLAG_NO_UPD_ENTROPY) {
7220 av1_update_entropy(cpi, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007221 }
7222}