blob: 046d655f4221cd8707a93af3686998c200be86fe [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Urvang Joshi8a02d762016-07-28 15:51:12 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Urvang Joshi8a02d762016-07-28 15:51:12 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <limits.h>
13#include <math.h>
14#include <stdio.h>
15
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070017
18#include "av1/common/alloccommon.h"
Steinar Midtskogena9d41e82017-03-17 12:48:15 +010019#include "av1/common/cdef.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070020#include "av1/common/filter.h"
21#include "av1/common/idct.h"
22#include "av1/common/reconinter.h"
23#include "av1/common/reconintra.h"
Fergus Simpsond0565002017-03-27 16:51:52 -070024#include "av1/common/resize.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070025#include "av1/common/tile_common.h"
26
27#include "av1/encoder/aq_complexity.h"
28#include "av1/encoder/aq_cyclicrefresh.h"
29#include "av1/encoder/aq_variance.h"
30#include "av1/encoder/bitstream.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070031#include "av1/encoder/context_tree.h"
32#include "av1/encoder/encodeframe.h"
33#include "av1/encoder/encodemv.h"
34#include "av1/encoder/encoder.h"
Angie Chiangf0fbf9d2017-03-15 15:01:22 -070035#include "av1/encoder/encodetxb.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070036#include "av1/encoder/ethread.h"
37#include "av1/encoder/firstpass.h"
RogerZhoucc5d35d2017-08-07 22:20:15 -070038#if CONFIG_HASH_ME
39#include "av1/encoder/hash_motion.h"
40#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070041#include "av1/encoder/mbgraph.h"
42#include "av1/encoder/picklpf.h"
43#if CONFIG_LOOP_RESTORATION
44#include "av1/encoder/pickrst.h"
45#endif // CONFIG_LOOP_RESTORATION
Debargha Mukherjee7166f222017-09-05 21:32:42 -070046#include "av1/encoder/random.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070047#include "av1/encoder/ratectrl.h"
48#include "av1/encoder/rd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070049#include "av1/encoder/segmentation.h"
50#include "av1/encoder/speed_features.h"
51#include "av1/encoder/temporal_filter.h"
52
Yaowu Xuf883b422016-08-30 14:01:10 -070053#include "./av1_rtcd.h"
54#include "./aom_dsp_rtcd.h"
55#include "./aom_scale_rtcd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070056#include "aom_dsp/psnr.h"
57#if CONFIG_INTERNAL_STATS
58#include "aom_dsp/ssim.h"
59#endif
Andrey Norkin6f1c2f72018-01-15 20:08:52 -080060#if CONFIG_FILM_GRAIN
61#include "av1/encoder/grain_test_vectors.h"
62#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070063#include "aom_dsp/aom_dsp_common.h"
64#include "aom_dsp/aom_filter.h"
Jingning Han1aab8182016-06-03 11:09:06 -070065#include "aom_ports/aom_timer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070066#include "aom_ports/mem.h"
67#include "aom_ports/system_state.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070068#include "aom_scale/aom_scale.h"
Angie Chiang5b5f4df2017-12-06 10:41:12 -080069#if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -070070#include "aom_util/debug_util.h"
Angie Chiang5b5f4df2017-12-06 10:41:12 -080071#endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
Yaowu Xuc27fc142016-08-22 16:08:15 -070072
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -080073#if CONFIG_ENTROPY_STATS
74FRAME_COUNTS aggregate_fc;
Zoe Liua56f9162017-06-21 22:49:57 -070075// Aggregate frame counts per frame context type
76FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS];
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -080077#endif // CONFIG_ENTROPY_STATS
78
Yaowu Xuc27fc142016-08-22 16:08:15 -070079#define AM_SEGMENT_ID_INACTIVE 7
80#define AM_SEGMENT_ID_ACTIVE 0
81
Johannb0ef6ff2018-02-08 14:32:21 -080082// Whether to use high precision mv for altref computation.
83#define ALTREF_HIGH_PRECISION_MV 1
84
85// Q threshold for high precision mv. Choose a very high value for now so that
86// HIGH_PRECISION is always chosen.
87#define HIGH_PRECISION_MV_QTHRESH 200
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -070088
Yaowu Xuc27fc142016-08-22 16:08:15 -070089// #define OUTPUT_YUV_REC
Yaowu Xuc27fc142016-08-22 16:08:15 -070090#ifdef OUTPUT_YUV_SKINMAP
91FILE *yuv_skinmap_file = NULL;
92#endif
93#ifdef OUTPUT_YUV_REC
94FILE *yuv_rec_file;
95#define FILE_NAME_LEN 100
96#endif
97
98#if 0
99FILE *framepsnr;
100FILE *kf_list;
101FILE *keyfile;
102#endif
103
Urvang Joshib5ed3502016-10-17 16:38:05 -0700104#if CONFIG_INTERNAL_STATS
105typedef enum { Y, U, V, ALL } STAT_TYPE;
106#endif // CONFIG_INTERNAL_STATS
107
Yaowu Xuf883b422016-08-30 14:01:10 -0700108static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109 switch (mode) {
110 case NORMAL:
111 *hr = 1;
112 *hs = 1;
113 break;
114 case FOURFIVE:
115 *hr = 4;
116 *hs = 5;
117 break;
118 case THREEFIVE:
119 *hr = 3;
120 *hs = 5;
121 break;
122 case ONETWO:
123 *hr = 1;
124 *hs = 2;
125 break;
126 default:
127 *hr = 1;
128 *hs = 1;
129 assert(0);
130 break;
131 }
132}
133
134// Mark all inactive blocks as active. Other segmentation features may be set
135// so memset cannot be used, instead only inactive blocks should be reset.
Yaowu Xuf883b422016-08-30 14:01:10 -0700136static void suppress_active_map(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 unsigned char *const seg_map = cpi->segmentation_map;
138 int i;
139 if (cpi->active_map.enabled || cpi->active_map.update)
140 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
141 if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
142 seg_map[i] = AM_SEGMENT_ID_ACTIVE;
143}
144
Yaowu Xuf883b422016-08-30 14:01:10 -0700145static void apply_active_map(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700146 struct segmentation *const seg = &cpi->common.seg;
147 unsigned char *const seg_map = cpi->segmentation_map;
148 const unsigned char *const active_map = cpi->active_map.map;
149 int i;
150
151 assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE);
152
153 if (frame_is_intra_only(&cpi->common)) {
154 cpi->active_map.enabled = 0;
155 cpi->active_map.update = 1;
156 }
157
158 if (cpi->active_map.update) {
159 if (cpi->active_map.enabled) {
160 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
161 if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i];
Yaowu Xuf883b422016-08-30 14:01:10 -0700162 av1_enable_segmentation(seg);
163 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
Cheng Chend8184da2017-09-26 18:15:22 -0700164#if CONFIG_LOOPFILTER_LEVEL
165 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H);
166 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V);
167 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U);
168 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V);
169
170 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H,
171 -MAX_LOOP_FILTER);
172 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V,
173 -MAX_LOOP_FILTER);
174 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U,
175 -MAX_LOOP_FILTER);
176 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V,
177 -MAX_LOOP_FILTER);
178#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700179 av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700180 // Setting the data to -MAX_LOOP_FILTER will result in the computed loop
Yushin Chod728c212017-11-03 12:30:24 -0700181 // filter level being zero.
Yaowu Xuf883b422016-08-30 14:01:10 -0700182 av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF,
183 -MAX_LOOP_FILTER);
Cheng Chend8184da2017-09-26 18:15:22 -0700184#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700185 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700186 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
Cheng Chend8184da2017-09-26 18:15:22 -0700187#if CONFIG_LOOPFILTER_LEVEL
188 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H);
189 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V);
190 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U);
191 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V);
192#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700193 av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF);
Cheng Chend8184da2017-09-26 18:15:22 -0700194#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700195 if (seg->enabled) {
196 seg->update_data = 1;
197 seg->update_map = 1;
198 }
199 }
200 cpi->active_map.update = 0;
201 }
202}
203
Yaowu Xuf883b422016-08-30 14:01:10 -0700204int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows,
205 int cols) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700206 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
207 unsigned char *const active_map_8x8 = cpi->active_map.map;
208 const int mi_rows = cpi->common.mi_rows;
209 const int mi_cols = cpi->common.mi_cols;
Jingning Han9d533022017-04-07 10:14:42 -0700210 const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2;
211 const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 cpi->active_map.update = 1;
213 if (new_map_16x16) {
214 int r, c;
215 for (r = 0; r < mi_rows; ++r) {
216 for (c = 0; c < mi_cols; ++c) {
217 active_map_8x8[r * mi_cols + c] =
Jingning Han9d533022017-04-07 10:14:42 -0700218 new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)]
Yaowu Xuc27fc142016-08-22 16:08:15 -0700219 ? AM_SEGMENT_ID_ACTIVE
220 : AM_SEGMENT_ID_INACTIVE;
221 }
222 }
223 cpi->active_map.enabled = 1;
224 } else {
225 cpi->active_map.enabled = 0;
226 }
227 return 0;
228 } else {
229 return -1;
230 }
231}
232
Yaowu Xuf883b422016-08-30 14:01:10 -0700233int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows,
234 int cols) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700235 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols &&
236 new_map_16x16) {
237 unsigned char *const seg_map_8x8 = cpi->segmentation_map;
238 const int mi_rows = cpi->common.mi_rows;
239 const int mi_cols = cpi->common.mi_cols;
Jingning Han9d533022017-04-07 10:14:42 -0700240 const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2;
241 const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2;
242
Yaowu Xuc27fc142016-08-22 16:08:15 -0700243 memset(new_map_16x16, !cpi->active_map.enabled, rows * cols);
244 if (cpi->active_map.enabled) {
245 int r, c;
246 for (r = 0; r < mi_rows; ++r) {
247 for (c = 0; c < mi_cols; ++c) {
248 // Cyclic refresh segments are considered active despite not having
249 // AM_SEGMENT_ID_ACTIVE
Jingning Han9d533022017-04-07 10:14:42 -0700250 new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |=
Yaowu Xuc27fc142016-08-22 16:08:15 -0700251 seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE;
252 }
253 }
254 }
255 return 0;
256 } else {
257 return -1;
258 }
259}
260
RogerZhou3b635242017-09-19 10:06:46 -0700261static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv
262#if CONFIG_AMVR
263 ,
RogerZhou10a03802017-10-26 11:49:48 -0700264 int cur_frame_force_integer_mv
RogerZhou3b635242017-09-19 10:06:46 -0700265#endif
Johannb0ef6ff2018-02-08 14:32:21 -0800266) {
James Zern01a9d702017-08-25 19:09:33 +0000267 MACROBLOCK *const mb = &cpi->td.mb;
268 cpi->common.allow_high_precision_mv = allow_high_precision_mv;
269
RogerZhou3b635242017-09-19 10:06:46 -0700270#if CONFIG_AMVR
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000271 const int copy_hp =
272 cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0;
RogerZhou3b635242017-09-19 10:06:46 -0700273#else
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000274 const int copy_hp = cpi->common.allow_high_precision_mv;
RogerZhou3b635242017-09-19 10:06:46 -0700275#endif
Rupert Swarbricka84faf22017-12-11 13:56:40 +0000276 int *(*src)[2] = copy_hp ? mb->nmvcost_hp : mb->nmvcost;
277 for (int i = 0; i < NMV_CONTEXTS; ++i) {
278 mb->mv_cost_stack[i] = src[i];
James Zern01a9d702017-08-25 19:09:33 +0000279 }
280}
281
Yaowu Xuf883b422016-08-30 14:01:10 -0700282static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700283#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700284 if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285 return BLOCK_64X64;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100286#if CONFIG_FILEOPTIONS
287 if (cpi->common.options && cpi->common.options->ext_partition)
288#endif
289 if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128)
290 return BLOCK_128X128;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700291
Yaowu Xuf883b422016-08-30 14:01:10 -0700292 assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700293
Dominic Symes917d6c02017-10-11 18:00:52 +0200294#if !CONFIG_MAX_TILE
295 // for the max_tile experiment there is no common tile_width, tile_height
296 // max_tile assumes tile dimensions are in superblocks (not 64x64 units)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700297 assert(IMPLIES(cpi->common.tile_cols > 1,
298 cpi->common.tile_width % MAX_MIB_SIZE == 0));
299 assert(IMPLIES(cpi->common.tile_rows > 1,
300 cpi->common.tile_height % MAX_MIB_SIZE == 0));
Dominic Symes917d6c02017-10-11 18:00:52 +0200301#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700302
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100303// TODO(any): Possibly could improve this with a heuristic.
304#if CONFIG_FILEOPTIONS
305 if (cpi->common.options && !cpi->common.options->ext_partition)
306 return BLOCK_64X64;
307#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700308 return BLOCK_128X128;
309#else
310 (void)cpi;
311 return BLOCK_64X64;
312#endif // CONFIG_EXT_PARTITION
313}
314
Yaowu Xuf883b422016-08-30 14:01:10 -0700315static void setup_frame(AV1_COMP *cpi) {
316 AV1_COMMON *const cm = &cpi->common;
Johannb0ef6ff2018-02-08 14:32:21 -0800317 // Set up entropy context depending on frame type. The decoder mandates
318 // the use of the default context, index 0, for keyframes and inter
319 // frames where the error_resilient_mode or intra_only flag is set. For
320 // other inter-frames the encoder currently uses only two contexts;
321 // context 1 for ALTREF frames and context 0 for the others.
Soo-Chul Han85e8c792018-01-21 01:58:15 -0500322
323#if CONFIG_SEGMENT_PRED_LAST
324 if (cm->prev_frame) cm->last_frame_seg_map = cm->prev_frame->seg_map;
325 cm->current_frame_seg_map = cm->cur_frame->seg_map;
326#endif
327
Yaowu Xuc27fc142016-08-22 16:08:15 -0700328 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700329 av1_setup_past_independence(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700330 } else {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700331#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
332// Just use frame context from first signaled reference frame.
333// This will always be LAST_FRAME for now.
334#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700335 const GF_GROUP *gf_group = &cpi->twopass.gf_group;
Zoe Liue9b15e22017-07-19 15:53:01 -0700336 if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700337 cm->frame_context_idx = EXT_ARF_FRAME;
338 else if (cpi->refresh_alt_ref_frame)
339 cm->frame_context_idx = ARF_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340 else if (cpi->rc.is_src_frame_alt_ref)
341 cm->frame_context_idx = OVERLAY_FRAME;
342 else if (cpi->refresh_golden_frame)
343 cm->frame_context_idx = GLD_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700344 else if (cpi->refresh_bwd_ref_frame)
345 cm->frame_context_idx = BRF_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700346 else
347 cm->frame_context_idx = REGULAR_FRAME;
Thomas Daededa4d8b92017-06-05 15:44:14 -0700348#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700349 }
350
351 if (cm->frame_type == KEY_FRAME) {
352 cpi->refresh_golden_frame = 1;
353 cpi->refresh_alt_ref_frame = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700354 av1_zero(cpi->interp_filter_selected);
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000355 set_sb_size(&cm->seq_params, select_sb_size(cpi));
Debargha Mukherjee778023d2017-09-26 17:50:27 -0700356#if CONFIG_REFERENCE_BUFFER
357 set_use_reference_buffer(cm, 0);
358#endif // CONFIG_REFERENCE_BUFFER
David Barker11eac7b2017-12-07 12:22:36 +0000359#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
360 cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
361#else
362 cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx];
363#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -0700364 } else {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700365#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
David Barker11eac7b2017-12-07 12:22:36 +0000366 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Thomas Daededa4d8b92017-06-05 15:44:14 -0700367 *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
David Barker11eac7b2017-12-07 12:22:36 +0000368 cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700369 } else {
David Barker11eac7b2017-12-07 12:22:36 +0000370 assert(cm->frame_refs[0].idx >= 0);
Thomas Daededa4d8b92017-06-05 15:44:14 -0700371 *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx];
David Barker11eac7b2017-12-07 12:22:36 +0000372 cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700373 }
374#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700375 *cm->fc = cm->frame_contexts[cm->frame_context_idx];
David Barker11eac7b2017-12-07 12:22:36 +0000376 cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx];
Thomas Daededa4d8b92017-06-05 15:44:14 -0700377#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuf883b422016-08-30 14:01:10 -0700378 av1_zero(cpi->interp_filter_selected[0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700379 }
Zoe Liuc01dddb2017-11-07 08:44:06 -0800380#if !CONFIG_EXT_COMP_REFS // No change to bitstream
Arild Fuldseth (arilfuld)3f429082017-04-28 15:54:28 +0200381 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
382 cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame;
383 cpi->rc.is_bipred_frame = 1;
384 }
Zoe Liuc01dddb2017-11-07 08:44:06 -0800385#endif // !CONFIG_EXT_COMP_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700386
387 cpi->vaq_refresh = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700388}
389
Cheng Chen46f30c72017-09-07 11:13:33 -0700390static void enc_setup_mi(AV1_COMMON *cm) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700391 int i;
Yunqing Wang19b9f722018-02-20 16:22:01 -0800392 cm->mi = cm->mip;
393 memset(cm->mip, 0, cm->mi_stride * cm->mi_rows * sizeof(*cm->mip));
394 cm->prev_mi = cm->prev_mip;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700395 // Clear top border row
396 memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride);
397 // Clear left border column
Yunqing Wang19b9f722018-02-20 16:22:01 -0800398 for (i = 0; i < cm->mi_rows; ++i)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700399 memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip));
Yunqing Wang19b9f722018-02-20 16:22:01 -0800400 cm->mi_grid_visible = cm->mi_grid_base;
401 cm->prev_mi_grid_visible = cm->prev_mi_grid_base;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700402
403 memset(cm->mi_grid_base, 0,
Yunqing Wang19b9f722018-02-20 16:22:01 -0800404 cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base));
Frank Bossen4ef06b52018-01-18 19:51:15 -0500405
406 memset(cm->boundary_info, 0,
407 cm->boundary_info_alloc_size * sizeof(*cm->boundary_info));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700408}
409
Cheng Chen46f30c72017-09-07 11:13:33 -0700410static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700411 cm->mip = aom_calloc(mi_size, sizeof(*cm->mip));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700412 if (!cm->mip) return 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700413 cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700414 if (!cm->prev_mip) return 1;
415 cm->mi_alloc_size = mi_size;
416
Yaowu Xuf883b422016-08-30 14:01:10 -0700417 cm->mi_grid_base = (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700418 if (!cm->mi_grid_base) return 1;
419 cm->prev_mi_grid_base =
Yaowu Xuf883b422016-08-30 14:01:10 -0700420 (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700421 if (!cm->prev_mi_grid_base) return 1;
422
423 return 0;
424}
425
Cheng Chen46f30c72017-09-07 11:13:33 -0700426static void enc_free_mi(AV1_COMMON *cm) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700427 aom_free(cm->mip);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700428 cm->mip = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700429 aom_free(cm->prev_mip);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700430 cm->prev_mip = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700431 aom_free(cm->mi_grid_base);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700432 cm->mi_grid_base = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700433 aom_free(cm->prev_mi_grid_base);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700434 cm->prev_mi_grid_base = NULL;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700435 cm->mi_alloc_size = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700436}
437
Cheng Chen46f30c72017-09-07 11:13:33 -0700438static void swap_mi_and_prev_mi(AV1_COMMON *cm) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700439 // Current mip will be the prev_mip for the next frame.
440 MODE_INFO **temp_base = cm->prev_mi_grid_base;
441 MODE_INFO *temp = cm->prev_mip;
442 cm->prev_mip = cm->mip;
443 cm->mip = temp;
444
445 // Update the upper left visible macroblock ptrs.
Yunqing Wang19b9f722018-02-20 16:22:01 -0800446 cm->mi = cm->mip;
447 cm->prev_mi = cm->prev_mip;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700448
449 cm->prev_mi_grid_base = cm->mi_grid_base;
450 cm->mi_grid_base = temp_base;
Yunqing Wang19b9f722018-02-20 16:22:01 -0800451 cm->mi_grid_visible = cm->mi_grid_base;
452 cm->prev_mi_grid_visible = cm->prev_mi_grid_base;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700453}
454
Yaowu Xuf883b422016-08-30 14:01:10 -0700455void av1_initialize_enc(void) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700456 static volatile int init_done = 0;
457
458 if (!init_done) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700459 av1_rtcd();
460 aom_dsp_rtcd();
461 aom_scale_rtcd();
462 av1_init_intra_predictors();
463 av1_init_me_luts();
464 av1_rc_init_minq_luts();
Yaowu Xuf883b422016-08-30 14:01:10 -0700465 av1_init_wedge_masks();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700466 init_done = 1;
467 }
468}
469
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700470static void dealloc_context_buffers_ext(AV1_COMP *cpi) {
471 if (cpi->mbmi_ext_base) {
472 aom_free(cpi->mbmi_ext_base);
473 cpi->mbmi_ext_base = NULL;
474 }
475}
476
477static void alloc_context_buffers_ext(AV1_COMP *cpi) {
478 AV1_COMMON *cm = &cpi->common;
479 int mi_size = cm->mi_cols * cm->mi_rows;
480
481 dealloc_context_buffers_ext(cpi);
482 CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base,
483 aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base)));
484}
485
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800486#if CONFIG_FILM_GRAIN
487static void update_film_grain_parameters(struct AV1_COMP *cpi,
488 const AV1EncoderConfig *oxcf) {
489 AV1_COMMON *const cm = &cpi->common;
490 cpi->oxcf = *oxcf;
491
492 if (oxcf->film_grain_test_vector) {
493 cm->film_grain_params_present = 1;
494 if (cm->frame_type == KEY_FRAME) {
495 memcpy(&cm->film_grain_params,
496 film_grain_test_vectors + oxcf->film_grain_test_vector - 1,
497 sizeof(cm->film_grain_params));
498
499 cm->film_grain_params.bit_depth = cm->bit_depth;
500 if (cm->color_range == AOM_CR_FULL_RANGE) {
501 cm->film_grain_params.clip_to_restricted_range = 0;
502 }
503 }
504 } else {
505 cm->film_grain_params_present = 0;
506 memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params));
507 }
508}
509#endif
510
Yaowu Xuf883b422016-08-30 14:01:10 -0700511static void dealloc_compressor_data(AV1_COMP *cpi) {
512 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000513 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700514
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700515 dealloc_context_buffers_ext(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700516
Yaowu Xuf883b422016-08-30 14:01:10 -0700517 aom_free(cpi->tile_data);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700518 cpi->tile_data = NULL;
519
520 // Delete sementation map
Yaowu Xuf883b422016-08-30 14:01:10 -0700521 aom_free(cpi->segmentation_map);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700522 cpi->segmentation_map = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700523
Yaowu Xuf883b422016-08-30 14:01:10 -0700524 av1_cyclic_refresh_free(cpi->cyclic_refresh);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700525 cpi->cyclic_refresh = NULL;
526
Yaowu Xuf883b422016-08-30 14:01:10 -0700527 aom_free(cpi->active_map.map);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700528 cpi->active_map.map = NULL;
529
Jingning Hand064cf02017-06-01 10:00:39 -0700530 aom_free(cpi->td.mb.above_pred_buf);
531 cpi->td.mb.above_pred_buf = NULL;
532
533 aom_free(cpi->td.mb.left_pred_buf);
534 cpi->td.mb.left_pred_buf = NULL;
535
536 aom_free(cpi->td.mb.wsrc_buf);
537 cpi->td.mb.wsrc_buf = NULL;
538
539 aom_free(cpi->td.mb.mask_buf);
540 cpi->td.mb.mask_buf = NULL;
Jingning Hand064cf02017-06-01 10:00:39 -0700541
Jingning Han6cc1fd32017-10-13 09:05:36 -0700542#if CONFIG_MFMV
543 aom_free(cm->tpl_mvs);
544 cm->tpl_mvs = NULL;
545#endif
546
Yaowu Xuf883b422016-08-30 14:01:10 -0700547 av1_free_ref_frame_buffers(cm->buffer_pool);
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700548 av1_free_txb_buf(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -0700549 av1_free_context_buffers(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700550
Yaowu Xuf883b422016-08-30 14:01:10 -0700551 aom_free_frame_buffer(&cpi->last_frame_uf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700552#if CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -0700553 av1_free_restoration_buffers(cm);
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800554 aom_free_frame_buffer(&cpi->trial_frame_rst);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700555#endif // CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -0700556 aom_free_frame_buffer(&cpi->scaled_source);
557 aom_free_frame_buffer(&cpi->scaled_last_source);
558 aom_free_frame_buffer(&cpi->alt_ref_buffer);
559 av1_lookahead_destroy(cpi->lookahead);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700560
Yaowu Xuf883b422016-08-30 14:01:10 -0700561 aom_free(cpi->tile_tok[0][0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700562 cpi->tile_tok[0][0] = 0;
563
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000564 av1_free_pc_tree(&cpi->td, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700565
hui sud9a812b2017-07-06 14:34:37 -0700566 aom_free(cpi->td.mb.palette_buffer);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700567}
568
Yaowu Xuf883b422016-08-30 14:01:10 -0700569static void save_coding_context(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700570 CODING_CONTEXT *const cc = &cpi->coding_context;
Yaowu Xuf883b422016-08-30 14:01:10 -0700571 AV1_COMMON *cm = &cpi->common;
James Zern01a9d702017-08-25 19:09:33 +0000572 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700573
Sebastien Alaiwane140c502017-04-27 09:52:34 +0200574 // Stores a snapshot of key state variables which can subsequently be
575 // restored with a call to av1_restore_coding_context. These functions are
576 // intended for use in a re-code loop in av1_compress_frame where the
577 // quantizer value is adjusted between loop iterations.
James Zern01a9d702017-08-25 19:09:33 +0000578 for (i = 0; i < NMV_CONTEXTS; ++i) {
579 av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]);
580 av1_copy(cc->nmv_costs, cpi->nmv_costs);
581 av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp);
582 }
583
Yaowu Xuf883b422016-08-30 14:01:10 -0700584 av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas);
585 av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700586
587 cc->fc = *cm->fc;
588}
589
Yaowu Xuf883b422016-08-30 14:01:10 -0700590static void restore_coding_context(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700591 CODING_CONTEXT *const cc = &cpi->coding_context;
Yaowu Xuf883b422016-08-30 14:01:10 -0700592 AV1_COMMON *cm = &cpi->common;
James Zern01a9d702017-08-25 19:09:33 +0000593 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700594
Sebastien Alaiwane140c502017-04-27 09:52:34 +0200595 // Restore key state variables to the snapshot state stored in the
596 // previous call to av1_save_coding_context.
James Zern01a9d702017-08-25 19:09:33 +0000597 for (i = 0; i < NMV_CONTEXTS; ++i) {
598 av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]);
599 av1_copy(cpi->nmv_costs, cc->nmv_costs);
600 av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp);
601 }
602
Yaowu Xuf883b422016-08-30 14:01:10 -0700603 av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas);
604 av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700605
606 *cm->fc = cc->fc;
607}
608
Yaowu Xuf883b422016-08-30 14:01:10 -0700609static void configure_static_seg_features(AV1_COMP *cpi) {
610 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700611 const RATE_CONTROL *const rc = &cpi->rc;
612 struct segmentation *const seg = &cm->seg;
613
614 int high_q = (int)(rc->avg_q > 48.0);
615 int qi_delta;
616
617 // Disable and clear down for KF
618 if (cm->frame_type == KEY_FRAME) {
619 // Clear down the global segmentation map
620 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
621 seg->update_map = 0;
622 seg->update_data = 0;
623 cpi->static_mb_pct = 0;
624
625 // Disable segmentation
Yaowu Xuf883b422016-08-30 14:01:10 -0700626 av1_disable_segmentation(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700627
628 // Clear down the segment features.
Yaowu Xuf883b422016-08-30 14:01:10 -0700629 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700630 } else if (cpi->refresh_alt_ref_frame) {
631 // If this is an alt ref frame
632 // Clear down the global segmentation map
633 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
634 seg->update_map = 0;
635 seg->update_data = 0;
636 cpi->static_mb_pct = 0;
637
638 // Disable segmentation and individual segment features by default
Yaowu Xuf883b422016-08-30 14:01:10 -0700639 av1_disable_segmentation(seg);
640 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700641
642 // Scan frames from current to arf frame.
643 // This function re-enables segmentation if appropriate.
Yaowu Xuf883b422016-08-30 14:01:10 -0700644 av1_update_mbgraph_stats(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700645
646 // If segmentation was enabled set those features needed for the
647 // arf itself.
648 if (seg->enabled) {
649 seg->update_map = 1;
650 seg->update_data = 1;
651
652 qi_delta =
Yaowu Xuf883b422016-08-30 14:01:10 -0700653 av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth);
654 av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2);
Cheng Chend8184da2017-09-26 18:15:22 -0700655#if CONFIG_LOOPFILTER_LEVEL
656 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2);
657 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2);
658 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2);
659 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2);
660
661 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H);
662 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V);
663 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U);
664 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V);
665#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700666 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
Cheng Chend8184da2017-09-26 18:15:22 -0700667 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
668#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700669
Yaowu Xuf883b422016-08-30 14:01:10 -0700670 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700671 }
672 } else if (seg->enabled) {
673 // All other frames if segmentation has been enabled
674
675 // First normal frame in a valid gf or alt ref group
676 if (rc->frames_since_golden == 0) {
677 // Set up segment features for normal frames in an arf group
678 if (rc->source_alt_ref_active) {
679 seg->update_map = 0;
680 seg->update_data = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700681
Yaowu Xuf883b422016-08-30 14:01:10 -0700682 qi_delta =
683 av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth);
684 av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2);
685 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700686
Cheng Chend8184da2017-09-26 18:15:22 -0700687#if CONFIG_LOOPFILTER_LEVEL
688 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2);
689 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2);
690 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2);
691 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2);
692
693 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H);
694 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V);
695 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U);
696 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V);
697#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700698 av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
699 av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
Cheng Chend8184da2017-09-26 18:15:22 -0700700#endif // CONFIG_LOOPFILTER_LEVEL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700701
702 // Segment coding disabled for compred testing
703 if (high_q || (cpi->static_mb_pct == 100)) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700704 av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
705 av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
706 av1_enable_segfeature(seg, 1, SEG_LVL_SKIP);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700707 }
708 } else {
709 // Disable segmentation and clear down features if alt ref
710 // is not active for this group
711
Yaowu Xuf883b422016-08-30 14:01:10 -0700712 av1_disable_segmentation(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700713
714 memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
715
716 seg->update_map = 0;
717 seg->update_data = 0;
718
Yaowu Xuf883b422016-08-30 14:01:10 -0700719 av1_clearall_segfeatures(seg);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700720 }
721 } else if (rc->is_src_frame_alt_ref) {
722 // Special case where we are coding over the top of a previous
723 // alt ref frame.
724 // Segment coding disabled for compred testing
725
726 // Enable ref frame features for segment 0 as well
Yaowu Xuf883b422016-08-30 14:01:10 -0700727 av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME);
728 av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700729
730 // All mbs should use ALTREF_FRAME
Yaowu Xuf883b422016-08-30 14:01:10 -0700731 av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME);
732 av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
733 av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME);
734 av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700735
736 // Skip all MBs if high Q (0,0 mv and skip coeffs)
737 if (high_q) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700738 av1_enable_segfeature(seg, 0, SEG_LVL_SKIP);
739 av1_enable_segfeature(seg, 1, SEG_LVL_SKIP);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700740 }
741 // Enable data update
742 seg->update_data = 1;
743 } else {
744 // All other frames.
745
746 // No updates.. leave things as they are.
747 seg->update_map = 0;
748 seg->update_data = 0;
749 }
750 }
751}
752
Yaowu Xuf883b422016-08-30 14:01:10 -0700753static void update_reference_segmentation_map(AV1_COMP *cpi) {
754 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700755 MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible;
Soo-Chul Han934af352017-10-15 15:21:51 -0400756#if CONFIG_SEGMENT_PRED_LAST
757 uint8_t *cache_ptr = cm->current_frame_seg_map;
758#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700759 uint8_t *cache_ptr = cm->last_frame_seg_map;
Soo-Chul Han934af352017-10-15 15:21:51 -0400760#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700761 int row, col;
762
763 for (row = 0; row < cm->mi_rows; row++) {
764 MODE_INFO **mi_8x8 = mi_8x8_ptr;
765 uint8_t *cache = cache_ptr;
766 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++)
767 cache[0] = mi_8x8[0]->mbmi.segment_id;
768 mi_8x8_ptr += cm->mi_stride;
769 cache_ptr += cm->mi_cols;
770 }
771}
772
Yaowu Xuf883b422016-08-30 14:01:10 -0700773static void alloc_raw_frame_buffers(AV1_COMP *cpi) {
774 AV1_COMMON *cm = &cpi->common;
775 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700776
777 if (!cpi->lookahead)
Yaowu Xud3e7c682017-12-21 14:08:25 -0800778 cpi->lookahead = av1_lookahead_init(
779 oxcf->width, oxcf->height, cm->subsampling_x, cm->subsampling_y,
780 cm->use_highbitdepth, oxcf->lag_in_frames);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700781 if (!cpi->lookahead)
Yaowu Xuf883b422016-08-30 14:01:10 -0700782 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700783 "Failed to allocate lag buffers");
784
785 // TODO(agrange) Check if ARF is enabled and skip allocation if not.
Yaowu Xuf883b422016-08-30 14:01:10 -0700786 if (aom_realloc_frame_buffer(&cpi->alt_ref_buffer, oxcf->width, oxcf->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700787 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800788 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
789 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700790 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700791 "Failed to allocate altref buffer");
792}
793
Yaowu Xuf883b422016-08-30 14:01:10 -0700794static void alloc_util_frame_buffers(AV1_COMP *cpi) {
795 AV1_COMMON *const cm = &cpi->common;
796 if (aom_realloc_frame_buffer(&cpi->last_frame_uf, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700797 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800798 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
799 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700800 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700801 "Failed to allocate last frame buffer");
802
803#if CONFIG_LOOP_RESTORATION
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700804 if (aom_realloc_frame_buffer(
805 &cpi->trial_frame_rst,
Urvang Joshi94ad3702017-12-06 11:38:08 -0800806#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700807 cm->superres_upscaled_width, cm->superres_upscaled_height,
808#else
809 cm->width, cm->height,
Urvang Joshi94ad3702017-12-06 11:38:08 -0800810#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Yaowu Xud3e7c682017-12-21 14:08:25 -0800811 cm->subsampling_x, cm->subsampling_y, cm->use_highbitdepth,
Fergus Simpson9cd57cf2017-06-12 17:02:03 -0700812 AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL))
Debargha Mukherjee874d36d2016-12-14 16:53:17 -0800813 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800814 "Failed to allocate trial restored frame buffer");
Yaowu Xuc27fc142016-08-22 16:08:15 -0700815#endif // CONFIG_LOOP_RESTORATION
816
Yaowu Xuf883b422016-08-30 14:01:10 -0700817 if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700818 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -0800819 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
820 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -0700821 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700822 "Failed to allocate scaled source buffer");
823
Yaowu Xuf883b422016-08-30 14:01:10 -0700824 if (aom_realloc_frame_buffer(&cpi->scaled_last_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 last source buffer");
830}
831
Cheng Chen46f30c72017-09-07 11:13:33 -0700832static void alloc_compressor_data(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700833 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000834 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700835
Yaowu Xuf883b422016-08-30 14:01:10 -0700836 av1_alloc_context_buffers(cm, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700837
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700838 av1_alloc_txb_buf(cpi);
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700839
Yaowu Xuc27fc142016-08-22 16:08:15 -0700840 alloc_context_buffers_ext(cpi);
841
Yaowu Xuf883b422016-08-30 14:01:10 -0700842 aom_free(cpi->tile_tok[0][0]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700843
844 {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000845 unsigned int tokens =
846 get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700847 CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0],
Yaowu Xuf883b422016-08-30 14:01:10 -0700848 aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0])));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700849 }
850
Yaowu Xuf883b422016-08-30 14:01:10 -0700851 av1_setup_pc_tree(&cpi->common, &cpi->td);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700852}
853
Yaowu Xuf883b422016-08-30 14:01:10 -0700854void av1_new_framerate(AV1_COMP *cpi, double framerate) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700855 cpi->framerate = framerate < 0.1 ? 30 : framerate;
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700856 av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700857}
858
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200859#if CONFIG_MAX_TILE
860
861static void set_tile_info_max_tile(AV1_COMP *cpi) {
862 AV1_COMMON *const cm = &cpi->common;
Dominic Symesf58f1112017-09-25 12:47:40 +0200863 int i, start_sb;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200864
865 av1_get_tile_limits(cm);
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200866
867 // configure tile columns
Dominic Symes26ad0b22017-10-01 16:35:13 +0200868 if (cpi->oxcf.tile_width_count == 0 || cpi->oxcf.tile_height_count == 0) {
Dominic Symesf58f1112017-09-25 12:47:40 +0200869 cm->uniform_tile_spacing_flag = 1;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200870 cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols);
871 cm->log2_tile_cols = AOMMIN(cm->log2_tile_cols, cm->max_log2_tile_cols);
Dominic Symesf58f1112017-09-25 12:47:40 +0200872 } else {
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000873 int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2);
874 int sb_cols = mi_cols >> cm->seq_params.mib_size_log2;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200875 int size_sb, j = 0;
Dominic Symesf58f1112017-09-25 12:47:40 +0200876 cm->uniform_tile_spacing_flag = 0;
877 for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) {
878 cm->tile_col_start_sb[i] = start_sb;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200879 size_sb = cpi->oxcf.tile_widths[j++];
880 if (j >= cpi->oxcf.tile_width_count) j = 0;
881 start_sb += AOMMIN(size_sb, MAX_TILE_WIDTH_SB);
Dominic Symesf58f1112017-09-25 12:47:40 +0200882 }
883 cm->tile_cols = i;
884 cm->tile_col_start_sb[i] = sb_cols;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200885 }
886 av1_calculate_tile_cols(cm);
887
888 // configure tile rows
889 if (cm->uniform_tile_spacing_flag) {
890 cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows);
891 cm->log2_tile_rows = AOMMIN(cm->log2_tile_rows, cm->max_log2_tile_rows);
Dominic Symesf58f1112017-09-25 12:47:40 +0200892 } else {
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000893 int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2);
894 int sb_rows = mi_rows >> cm->seq_params.mib_size_log2;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200895 int size_sb, j = 0;
Dominic Symesf58f1112017-09-25 12:47:40 +0200896 for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) {
897 cm->tile_row_start_sb[i] = start_sb;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200898 size_sb = cpi->oxcf.tile_heights[j++];
899 if (j >= cpi->oxcf.tile_height_count) j = 0;
900 start_sb += AOMMIN(size_sb, cm->max_tile_height_sb);
Dominic Symesf58f1112017-09-25 12:47:40 +0200901 }
902 cm->tile_rows = i;
903 cm->tile_row_start_sb[i] = sb_rows;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200904 }
905 av1_calculate_tile_rows(cm);
906}
907
908#endif
909
Yaowu Xuf883b422016-08-30 14:01:10 -0700910static void set_tile_info(AV1_COMP *cpi) {
911 AV1_COMMON *const cm = &cpi->common;
Yue Chen4eba69b2017-11-09 22:37:35 -0800912 (void)cm;
Thomas Daviesb25ba502017-07-18 10:18:24 +0100913#if CONFIG_DEPENDENT_HORZTILES
Fangwen Fu73126c02017-02-08 22:37:47 -0800914 int tile_row, tile_col, num_tiles_in_tg;
915 int tg_row_start, tg_col_start;
916#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700917#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700918 if (cpi->oxcf.large_scale_tile) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700919#if CONFIG_EXT_PARTITION
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700920 if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) {
921 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32);
922 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32);
923 cm->tile_width <<= MAX_MIB_SIZE_LOG2;
924 cm->tile_height <<= MAX_MIB_SIZE_LOG2;
925 } else {
926 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64);
927 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64);
928 cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1;
929 cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1;
930 }
931#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700932 cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64);
933 cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700934 cm->tile_width <<= MAX_MIB_SIZE_LOG2;
935 cm->tile_height <<= MAX_MIB_SIZE_LOG2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700936#endif // CONFIG_EXT_PARTITION
937
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700938 cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols);
939 cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700940
Yaowu Xu8d0039c2017-10-13 07:51:46 -0700941 assert(cm->tile_width >> MAX_MIB_SIZE_LOG2 <= 32);
942 assert(cm->tile_height >> MAX_MIB_SIZE_LOG2 <= 32);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700943
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700944 // Get the number of tiles
945 cm->tile_cols = 1;
946 while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700947
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700948 cm->tile_rows = 1;
949 while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows;
Dominic Symes917d6c02017-10-11 18:00:52 +0200950#if CONFIG_MAX_TILE
951 int i;
952 for (i = 0; i <= cm->tile_cols; i++) {
953 cm->tile_col_start_sb[i] =
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000954 ((i * cm->tile_width - 1) >> cm->seq_params.mib_size_log2) + 1;
Dominic Symes917d6c02017-10-11 18:00:52 +0200955 }
956 for (i = 0; i <= cm->tile_rows; i++) {
957 cm->tile_row_start_sb[i] =
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +0000958 ((i * cm->tile_height - 1) >> cm->seq_params.mib_size_log2) + 1;
Dominic Symes917d6c02017-10-11 18:00:52 +0200959 }
960#endif // CONFIG_MAX_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700961 } else {
962#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700963
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200964#if CONFIG_MAX_TILE
965 set_tile_info_max_tile(cpi);
Sebastien Alaiwan619f4172017-11-13 17:13:42 +0100966 (void)cm;
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200967#else
968 int min_log2_tile_cols, max_log2_tile_cols;
969 av1_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700970
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200971 cm->log2_tile_cols =
972 clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols);
973 cm->log2_tile_rows = cpi->oxcf.tile_rows;
Rupert Swarbrick940942b2017-09-01 12:05:55 +0100974
Rupert Swarbrick5a010aa2017-09-26 16:16:48 +0100975 cm->tile_width =
976 get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols);
977 cm->tile_height =
978 get_tile_size(cm->mi_rows, cm->log2_tile_rows, &cm->tile_rows);
Dominic Symesdb5d66f2017-08-18 18:11:34 +0200979#endif // CONFIG_MAX_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700980#if CONFIG_EXT_TILE
981 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700982#endif // CONFIG_EXT_TILE
Ryan Lei7386eda2016-12-08 21:08:31 -0800983
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800984#if CONFIG_DEPENDENT_HORZTILES
985 cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles;
Fangwen Fu70bcb892017-05-06 17:05:19 -0700986#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700987 if (cm->large_scale_tile) {
988 // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted.
989 cm->dependent_horz_tiles = 0;
Fangwen Fu73126c02017-02-08 22:37:47 -0800990 } else {
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700991#endif // CONFIG_EXT_TILE
992 if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0;
993#if CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -0800994 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700995#endif // CONFIG_EXT_TILE
996
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700997#if CONFIG_EXT_TILE
998 if (!cm->large_scale_tile) {
999#endif // CONFIG_EXT_TILE
1000 if (cpi->oxcf.mtu == 0) {
1001 cm->num_tg = cpi->oxcf.num_tile_groups;
1002 } else {
1003 // Use a default value for the purposes of weighting costs in probability
1004 // updates
1005 cm->num_tg = DEFAULT_MAX_NUM_TG;
Fangwen Fu73126c02017-02-08 22:37:47 -08001006 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001007 num_tiles_in_tg =
1008 (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg;
1009 tg_row_start = 0;
1010 tg_col_start = 0;
1011 for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) {
1012 for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) {
1013 if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) {
1014 tg_row_start = tile_row;
1015 tg_col_start = tile_col;
1016 }
1017 cm->tile_group_start_row[tile_row][tile_col] = tg_row_start;
1018 cm->tile_group_start_col[tile_row][tile_col] = tg_col_start;
1019 }
1020 }
1021#if CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001022 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07001023#endif // CONFIG_EXT_TILE
Fangwen Fu73126c02017-02-08 22:37:47 -08001024#endif
Fangwen Fu7b9f2b32017-01-17 14:01:52 -08001025
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001026#if CONFIG_LOOPFILTERING_ACROSS_TILES
Lei7bb501d2017-12-13 15:10:34 -08001027#if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
1028 cm->loop_filter_across_tiles_v_enabled =
1029 cpi->oxcf.loop_filter_across_tiles_v_enabled;
1030 cm->loop_filter_across_tiles_h_enabled =
1031 cpi->oxcf.loop_filter_across_tiles_h_enabled;
1032#else
Ryan Lei7386eda2016-12-08 21:08:31 -08001033 cm->loop_filter_across_tiles_enabled =
1034 cpi->oxcf.loop_filter_across_tiles_enabled;
Lei7bb501d2017-12-13 15:10:34 -08001035#endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001036#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001037}
1038
Yaowu Xuf883b422016-08-30 14:01:10 -07001039static void update_frame_size(AV1_COMP *cpi) {
1040 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001041 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
1042
Yaowu Xuf883b422016-08-30 14:01:10 -07001043 av1_set_mb_mi(cm, cm->width, cm->height);
1044 av1_init_context_buffers(cm);
Luc Trudeau1e84af52017-11-25 15:00:28 -05001045 av1_init_macroblockd(cm, xd, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001046 memset(cpi->mbmi_ext_base, 0,
1047 cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base));
Yaowu Xuc27fc142016-08-22 16:08:15 -07001048 set_tile_info(cpi);
1049}
1050
Yaowu Xuf883b422016-08-30 14:01:10 -07001051static void init_buffer_indices(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001052 int fb_idx;
1053 for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx)
1054 cpi->lst_fb_idxes[fb_idx] = fb_idx;
1055 cpi->gld_fb_idx = LAST_REF_FRAMES;
1056 cpi->bwd_fb_idx = LAST_REF_FRAMES + 1;
Zoe Liue9b15e22017-07-19 15:53:01 -07001057 cpi->alt2_fb_idx = LAST_REF_FRAMES + 2;
1058 cpi->alt_fb_idx = LAST_REF_FRAMES + 3;
Zoe Liu8dd1c982017-09-11 10:14:35 -07001059 cpi->ext_fb_idx = LAST_REF_FRAMES + 4;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001060 for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx)
1061 cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx;
RogerZhou3b635242017-09-19 10:06:46 -07001062#if CONFIG_AMVR
1063 cpi->rate_index = 0;
1064 cpi->rate_size = 0;
1065 cpi->cur_poc = -1;
1066#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001067}
1068
Yaowu Xuf883b422016-08-30 14:01:10 -07001069static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) {
1070 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001071
1072 cpi->oxcf = *oxcf;
1073 cpi->framerate = oxcf->init_framerate;
1074
1075 cm->profile = oxcf->profile;
1076 cm->bit_depth = oxcf->bit_depth;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001077 cm->use_highbitdepth = oxcf->use_highbitdepth;
Andrey Norkin9e694632017-12-21 18:50:57 -08001078#if CONFIG_CICP
1079 cm->color_primaries = oxcf->color_primaries;
1080 cm->transfer_characteristics = oxcf->transfer_characteristics;
1081 cm->matrix_coefficients = oxcf->matrix_coefficients;
1082#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001083 cm->color_space = oxcf->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08001084#endif // CONFIG_CICP
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08001085#if CONFIG_MONO_VIDEO
1086 cm->seq_params.monochrome = oxcf->monochrome;
1087#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07001088#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08001089#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07001090 cm->transfer_function = oxcf->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08001091#endif
anorkin76fb1262017-03-22 15:12:12 -07001092 cm->chroma_sample_position = oxcf->chroma_sample_position;
1093#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001094 cm->color_range = oxcf->color_range;
Andrey Norkin28e9ce22018-01-08 10:11:21 -08001095#if CONFIG_TIMING_INFO_IN_SEQ_HEADERS
1096 cm->timing_info_present = oxcf->timing_info_present;
1097 cm->num_units_in_tick = oxcf->num_units_in_tick;
1098 cm->time_scale = oxcf->time_scale;
1099 cm->equal_picture_interval = oxcf->equal_picture_interval;
1100 cm->num_ticks_per_picture = oxcf->num_ticks_per_picture;
1101#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001102
1103 cm->width = oxcf->width;
1104 cm->height = oxcf->height;
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00001105 set_sb_size(&cm->seq_params,
1106 select_sb_size(cpi)); // set sb size before allocations
Cheng Chen46f30c72017-09-07 11:13:33 -07001107 alloc_compressor_data(cpi);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -08001108#if CONFIG_FILM_GRAIN
1109 update_film_grain_parameters(cpi, oxcf);
1110#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001111
1112 // Single thread case: use counts in common.
1113 cpi->td.counts = &cm->counts;
1114
1115 // change includes all joint functionality
Yaowu Xuf883b422016-08-30 14:01:10 -07001116 av1_change_config(cpi, oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001117
1118 cpi->static_mb_pct = 0;
1119 cpi->ref_frame_flags = 0;
1120
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07001121 // Reset resize pending flags
1122 cpi->resize_pending_width = 0;
1123 cpi->resize_pending_height = 0;
1124
Yaowu Xuc27fc142016-08-22 16:08:15 -07001125 init_buffer_indices(cpi);
1126}
1127
1128static void set_rc_buffer_sizes(RATE_CONTROL *rc,
Yaowu Xuf883b422016-08-30 14:01:10 -07001129 const AV1EncoderConfig *oxcf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001130 const int64_t bandwidth = oxcf->target_bandwidth;
1131 const int64_t starting = oxcf->starting_buffer_level_ms;
1132 const int64_t optimal = oxcf->optimal_buffer_level_ms;
1133 const int64_t maximum = oxcf->maximum_buffer_size_ms;
1134
1135 rc->starting_buffer_level = starting * bandwidth / 1000;
1136 rc->optimal_buffer_level =
1137 (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000;
1138 rc->maximum_buffer_size =
1139 (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000;
1140}
1141
Cheng Chenbf3d4962017-11-01 14:48:52 -07001142#if CONFIG_JNT_COMP
1143#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, \
1144 JSVAF) \
1145 cpi->fn_ptr[BT].sdf = SDF; \
1146 cpi->fn_ptr[BT].sdaf = SDAF; \
1147 cpi->fn_ptr[BT].vf = VF; \
1148 cpi->fn_ptr[BT].svf = SVF; \
1149 cpi->fn_ptr[BT].svaf = SVAF; \
1150 cpi->fn_ptr[BT].sdx3f = SDX3F; \
1151 cpi->fn_ptr[BT].sdx8f = SDX8F; \
1152 cpi->fn_ptr[BT].sdx4df = SDX4DF; \
1153 cpi->fn_ptr[BT].jsdaf = JSDAF; \
1154 cpi->fn_ptr[BT].jsvaf = JSVAF;
1155#else // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001156#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
1157 cpi->fn_ptr[BT].sdf = SDF; \
1158 cpi->fn_ptr[BT].sdaf = SDAF; \
1159 cpi->fn_ptr[BT].vf = VF; \
1160 cpi->fn_ptr[BT].svf = SVF; \
1161 cpi->fn_ptr[BT].svaf = SVAF; \
1162 cpi->fn_ptr[BT].sdx3f = SDX3F; \
1163 cpi->fn_ptr[BT].sdx8f = SDX8F; \
1164 cpi->fn_ptr[BT].sdx4df = SDX4DF;
Cheng Chenbf3d4962017-11-01 14:48:52 -07001165#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001166
1167#define MAKE_BFP_SAD_WRAPPER(fnname) \
1168 static unsigned int fnname##_bits8(const uint8_t *src_ptr, \
1169 int source_stride, \
1170 const uint8_t *ref_ptr, int ref_stride) { \
1171 return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \
1172 } \
1173 static unsigned int fnname##_bits10( \
1174 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1175 int ref_stride) { \
1176 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \
1177 } \
1178 static unsigned int fnname##_bits12( \
1179 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1180 int ref_stride) { \
1181 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \
1182 }
1183
1184#define MAKE_BFP_SADAVG_WRAPPER(fnname) \
1185 static unsigned int fnname##_bits8( \
1186 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1187 int ref_stride, const uint8_t *second_pred) { \
1188 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \
1189 } \
1190 static unsigned int fnname##_bits10( \
1191 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1192 int ref_stride, const uint8_t *second_pred) { \
1193 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
1194 2; \
1195 } \
1196 static unsigned int fnname##_bits12( \
1197 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1198 int ref_stride, const uint8_t *second_pred) { \
1199 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
1200 4; \
1201 }
1202
1203#define MAKE_BFP_SAD3_WRAPPER(fnname) \
1204 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1205 const uint8_t *ref_ptr, int ref_stride, \
1206 unsigned int *sad_array) { \
1207 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1208 } \
1209 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1210 const uint8_t *ref_ptr, int ref_stride, \
1211 unsigned int *sad_array) { \
1212 int i; \
1213 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1214 for (i = 0; i < 3; i++) sad_array[i] >>= 2; \
1215 } \
1216 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1217 const uint8_t *ref_ptr, int ref_stride, \
1218 unsigned int *sad_array) { \
1219 int i; \
1220 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1221 for (i = 0; i < 3; i++) sad_array[i] >>= 4; \
1222 }
1223
1224#define MAKE_BFP_SAD8_WRAPPER(fnname) \
1225 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1226 const uint8_t *ref_ptr, int ref_stride, \
1227 unsigned int *sad_array) { \
1228 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1229 } \
1230 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1231 const uint8_t *ref_ptr, int ref_stride, \
1232 unsigned int *sad_array) { \
1233 int i; \
1234 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1235 for (i = 0; i < 8; i++) sad_array[i] >>= 2; \
1236 } \
1237 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1238 const uint8_t *ref_ptr, int ref_stride, \
1239 unsigned int *sad_array) { \
1240 int i; \
1241 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1242 for (i = 0; i < 8; i++) sad_array[i] >>= 4; \
1243 }
1244#define MAKE_BFP_SAD4D_WRAPPER(fnname) \
1245 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
1246 const uint8_t *const ref_ptr[], int ref_stride, \
1247 unsigned int *sad_array) { \
1248 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1249 } \
1250 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
1251 const uint8_t *const ref_ptr[], int ref_stride, \
1252 unsigned int *sad_array) { \
1253 int i; \
1254 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1255 for (i = 0; i < 4; i++) sad_array[i] >>= 2; \
1256 } \
1257 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
1258 const uint8_t *const ref_ptr[], int ref_stride, \
1259 unsigned int *sad_array) { \
1260 int i; \
1261 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
1262 for (i = 0; i < 4; i++) sad_array[i] >>= 4; \
1263 }
1264
Cheng Chenbf3d4962017-11-01 14:48:52 -07001265#if CONFIG_JNT_COMP
1266#define MAKE_BFP_JSADAVG_WRAPPER(fnname) \
1267 static unsigned int fnname##_bits8( \
1268 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1269 int ref_stride, const uint8_t *second_pred, \
1270 const JNT_COMP_PARAMS *jcp_param) { \
1271 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1272 jcp_param); \
1273 } \
1274 static unsigned int fnname##_bits10( \
1275 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1276 int ref_stride, const uint8_t *second_pred, \
1277 const JNT_COMP_PARAMS *jcp_param) { \
1278 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1279 jcp_param) >> \
1280 2; \
1281 } \
1282 static unsigned int fnname##_bits12( \
1283 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1284 int ref_stride, const uint8_t *second_pred, \
1285 const JNT_COMP_PARAMS *jcp_param) { \
1286 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
1287 jcp_param) >> \
1288 4; \
1289 }
1290#endif // CONFIG_JNT_COMP
1291
Yaowu Xuc27fc142016-08-22 16:08:15 -07001292#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001293MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128)
1294MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)
1295MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3)
1296MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8)
1297MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d)
1298MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64)
1299MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg)
1300MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d)
1301MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128)
1302MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg)
1303MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001304#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001305MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16)
1306MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg)
1307MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d)
1308MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32)
1309MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg)
1310MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d)
1311MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32)
1312MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg)
1313MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d)
1314MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64)
1315MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg)
1316MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d)
1317MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32)
1318MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg)
1319MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3)
1320MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8)
1321MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d)
1322MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64)
1323MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg)
1324MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3)
1325MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8)
1326MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d)
1327MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16)
1328MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg)
1329MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3)
1330MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8)
1331MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d)
1332MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8)
1333MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg)
1334MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3)
1335MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8)
1336MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d)
1337MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16)
1338MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg)
1339MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3)
1340MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8)
1341MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d)
1342MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8)
1343MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg)
1344MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3)
1345MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8)
1346MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d)
1347MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4)
1348MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg)
1349MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8)
1350MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d)
1351MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8)
1352MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg)
1353MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8)
1354MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d)
1355MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4)
1356MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg)
1357MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3)
1358MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8)
1359MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001360
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001361#if CONFIG_EXT_PARTITION_TYPES
1362MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16)
1363MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg)
1364MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d)
1365MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4)
1366MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg)
1367MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d)
1368MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32)
1369MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg)
1370MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d)
1371MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8)
1372MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg)
1373MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001374MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64)
1375MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg)
1376MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d)
1377MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16)
1378MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg)
1379MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001380#if CONFIG_EXT_PARTITION
1381MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x128)
1382MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x128_avg)
1383MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x128x4d)
1384MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x32)
1385MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x32_avg)
1386MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x32x4d)
1387#endif // CONFIG_EXT_PARTITION
1388#endif // CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001389
Cheng Chenbf3d4962017-11-01 14:48:52 -07001390#if CONFIG_JNT_COMP
1391#if CONFIG_EXT_PARTITION
1392MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x128_avg)
1393MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x64_avg)
1394MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x128_avg)
1395#endif // CONFIG_EXT_PARTITION
1396MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x16_avg)
1397MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x32_avg)
1398MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x32_avg)
1399MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x64_avg)
1400MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x32_avg)
1401MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x64_avg)
1402MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x16_avg)
1403MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x8_avg)
1404MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x16_avg)
1405MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x8_avg)
1406MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x4_avg)
1407MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x8_avg)
1408MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x4_avg)
1409#if CONFIG_EXT_PARTITION_TYPES
1410MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x16_avg)
1411MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x4_avg)
1412MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x32_avg)
1413MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x8_avg)
1414MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x64_avg)
1415MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x16_avg)
1416#if CONFIG_EXT_PARTITION
1417MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x128_avg)
1418MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x32_avg)
1419#endif // CONFIG_EXT_PARTITION
1420#endif // CONFIG_EXT_PARTITION_TYPES
1421#endif // CONFIG_JNT_COMP
1422
David Barker0f3c94e2017-05-16 15:21:50 +01001423#define HIGHBD_MBFP(BT, MCSDF, MCSVF) \
David Barkerf19f35f2017-05-22 16:33:22 +01001424 cpi->fn_ptr[BT].msdf = MCSDF; \
1425 cpi->fn_ptr[BT].msvf = MCSVF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001426
David Barkerc155e012017-05-11 13:54:54 +01001427#define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \
1428 static unsigned int fnname##_bits8( \
1429 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1430 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1431 int m_stride, int invert_mask) { \
1432 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1433 second_pred_ptr, m, m_stride, invert_mask); \
1434 } \
1435 static unsigned int fnname##_bits10( \
1436 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1437 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1438 int m_stride, int invert_mask) { \
1439 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1440 second_pred_ptr, m, m_stride, invert_mask) >> \
1441 2; \
1442 } \
1443 static unsigned int fnname##_bits12( \
1444 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
1445 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
1446 int m_stride, int invert_mask) { \
1447 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
1448 second_pred_ptr, m, m_stride, invert_mask) >> \
1449 4; \
1450 }
1451
Yaowu Xuc27fc142016-08-22 16:08:15 -07001452#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001453MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128)
1454MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64)
1455MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001456#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001457MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64)
1458MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32)
1459MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64)
1460MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32)
1461MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16)
1462MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32)
1463MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16)
1464MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8)
1465MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16)
1466MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8)
1467MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4)
1468MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8)
1469MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001470
1471#if CONFIG_EXT_PARTITION_TYPES
1472MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16)
1473MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4)
1474MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32)
1475MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001476MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64)
1477MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001478#if CONFIG_EXT_PARTITION
1479MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x128)
1480MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x32)
1481#endif // CONFIG_EXT_PARTITION
1482#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001483
Yaowu Xuc27fc142016-08-22 16:08:15 -07001484#define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \
1485 cpi->fn_ptr[BT].osdf = OSDF; \
1486 cpi->fn_ptr[BT].ovf = OVF; \
1487 cpi->fn_ptr[BT].osvf = OSVF;
1488
1489#define MAKE_OBFP_SAD_WRAPPER(fnname) \
1490 static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \
1491 const int32_t *wsrc, \
1492 const int32_t *msk) { \
1493 return fnname(ref, ref_stride, wsrc, msk); \
1494 } \
1495 static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \
1496 const int32_t *wsrc, \
1497 const int32_t *msk) { \
1498 return fnname(ref, ref_stride, wsrc, msk) >> 2; \
1499 } \
1500 static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \
1501 const int32_t *wsrc, \
1502 const int32_t *msk) { \
1503 return fnname(ref, ref_stride, wsrc, msk) >> 4; \
1504 }
1505
1506#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001507MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128)
1508MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64)
1509MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001510#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001511MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64)
1512MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32)
1513MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64)
1514MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32)
1515MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16)
1516MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32)
1517MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16)
1518MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8)
1519MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16)
1520MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8)
1521MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4)
1522MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8)
1523MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001524
1525#if CONFIG_EXT_PARTITION_TYPES
1526MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16)
1527MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4)
1528MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32)
1529MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01001530MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64)
1531MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001532#if CONFIG_EXT_PARTITION
1533MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x128)
1534MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x32)
1535#endif // CONFIG_EXT_PARTITION
1536#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001537
Yaowu Xuf883b422016-08-30 14:01:10 -07001538static void highbd_set_var_fns(AV1_COMP *const cpi) {
1539 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001540 if (cm->use_highbitdepth) {
1541 switch (cm->bit_depth) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001542 case AOM_BITS_8:
Cheng Chenbf3d4962017-11-01 14:48:52 -07001543#if CONFIG_JNT_COMP
1544#if CONFIG_EXT_PARTITION_TYPES
1545#if CONFIG_EXT_PARTITION
1546 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8,
1547 aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32,
1548 aom_highbd_8_sub_pixel_variance128x32,
1549 aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL,
1550 aom_highbd_sad128x32x4d_bits8,
1551 aom_highbd_jnt_sad128x32_avg_bits8,
1552 aom_highbd_8_jnt_sub_pixel_avg_variance128x32)
1553
1554 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8,
1555 aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128,
1556 aom_highbd_8_sub_pixel_variance32x128,
1557 aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL,
1558 aom_highbd_sad32x128x4d_bits8,
1559 aom_highbd_jnt_sad32x128_avg_bits8,
1560 aom_highbd_8_jnt_sub_pixel_avg_variance32x128)
1561#endif // CONFIG_EXT_PARTITION
1562
1563 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8,
1564 aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16,
1565 aom_highbd_8_sub_pixel_variance64x16,
1566 aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL,
1567 aom_highbd_sad64x16x4d_bits8,
1568 aom_highbd_jnt_sad64x16_avg_bits8,
1569 aom_highbd_8_jnt_sub_pixel_avg_variance64x16)
1570
1571 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8,
1572 aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64,
1573 aom_highbd_8_sub_pixel_variance16x64,
1574 aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL,
1575 aom_highbd_sad16x64x4d_bits8,
1576 aom_highbd_jnt_sad16x64_avg_bits8,
1577 aom_highbd_8_jnt_sub_pixel_avg_variance16x64)
1578
1579 HIGHBD_BFP(
1580 BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8,
1581 aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8,
1582 aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL,
1583 aom_highbd_sad32x8x4d_bits8, aom_highbd_jnt_sad32x8_avg_bits8,
1584 aom_highbd_8_jnt_sub_pixel_avg_variance32x8)
1585
1586 HIGHBD_BFP(
1587 BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8,
1588 aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32,
1589 aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL,
1590 aom_highbd_sad8x32x4d_bits8, aom_highbd_jnt_sad8x32_avg_bits8,
1591 aom_highbd_8_jnt_sub_pixel_avg_variance8x32)
1592
1593 HIGHBD_BFP(
1594 BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8,
1595 aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4,
1596 aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL,
1597 aom_highbd_sad16x4x4d_bits8, aom_highbd_jnt_sad16x4_avg_bits8,
1598 aom_highbd_8_jnt_sub_pixel_avg_variance16x4)
1599
1600 HIGHBD_BFP(
1601 BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8,
1602 aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16,
1603 aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL,
1604 aom_highbd_sad4x16x4d_bits8, aom_highbd_jnt_sad4x16_avg_bits8,
1605 aom_highbd_8_jnt_sub_pixel_avg_variance4x16)
1606#endif
1607
1608 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8,
1609 aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16,
1610 aom_highbd_8_sub_pixel_variance32x16,
1611 aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL,
1612 aom_highbd_sad32x16x4d_bits8,
1613 aom_highbd_jnt_sad32x16_avg_bits8,
1614 aom_highbd_8_jnt_sub_pixel_avg_variance32x16)
1615
1616 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8,
1617 aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32,
1618 aom_highbd_8_sub_pixel_variance16x32,
1619 aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL,
1620 aom_highbd_sad16x32x4d_bits8,
1621 aom_highbd_jnt_sad16x32_avg_bits8,
1622 aom_highbd_8_jnt_sub_pixel_avg_variance16x32)
1623
1624 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8,
1625 aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32,
1626 aom_highbd_8_sub_pixel_variance64x32,
1627 aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL,
1628 aom_highbd_sad64x32x4d_bits8,
1629 aom_highbd_jnt_sad64x32_avg_bits8,
1630 aom_highbd_8_jnt_sub_pixel_avg_variance64x32)
1631
1632 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8,
1633 aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64,
1634 aom_highbd_8_sub_pixel_variance32x64,
1635 aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL,
1636 aom_highbd_sad32x64x4d_bits8,
1637 aom_highbd_jnt_sad32x64_avg_bits8,
1638 aom_highbd_8_jnt_sub_pixel_avg_variance32x64)
1639
1640 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8,
1641 aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32,
1642 aom_highbd_8_sub_pixel_variance32x32,
1643 aom_highbd_8_sub_pixel_avg_variance32x32,
1644 aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8,
1645 aom_highbd_sad32x32x4d_bits8,
1646 aom_highbd_jnt_sad32x32_avg_bits8,
1647 aom_highbd_8_jnt_sub_pixel_avg_variance32x32)
1648
1649 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8,
1650 aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64,
1651 aom_highbd_8_sub_pixel_variance64x64,
1652 aom_highbd_8_sub_pixel_avg_variance64x64,
1653 aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8,
1654 aom_highbd_sad64x64x4d_bits8,
1655 aom_highbd_jnt_sad64x64_avg_bits8,
1656 aom_highbd_8_jnt_sub_pixel_avg_variance64x64)
1657
1658 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8,
1659 aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16,
1660 aom_highbd_8_sub_pixel_variance16x16,
1661 aom_highbd_8_sub_pixel_avg_variance16x16,
1662 aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8,
1663 aom_highbd_sad16x16x4d_bits8,
1664 aom_highbd_jnt_sad16x16_avg_bits8,
1665 aom_highbd_8_jnt_sub_pixel_avg_variance16x16)
1666
1667 HIGHBD_BFP(
1668 BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8,
1669 aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8,
1670 aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8,
1671 aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8,
1672 aom_highbd_jnt_sad16x8_avg_bits8,
1673 aom_highbd_8_jnt_sub_pixel_avg_variance16x8)
1674
1675 HIGHBD_BFP(
1676 BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8,
1677 aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16,
1678 aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8,
1679 aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8,
1680 aom_highbd_jnt_sad8x16_avg_bits8,
1681 aom_highbd_8_jnt_sub_pixel_avg_variance8x16)
1682
1683 HIGHBD_BFP(BLOCK_8X8, aom_highbd_sad8x8_bits8,
1684 aom_highbd_sad8x8_avg_bits8, aom_highbd_8_variance8x8,
1685 aom_highbd_8_sub_pixel_variance8x8,
1686 aom_highbd_8_sub_pixel_avg_variance8x8,
1687 aom_highbd_sad8x8x3_bits8, aom_highbd_sad8x8x8_bits8,
1688 aom_highbd_sad8x8x4d_bits8, aom_highbd_jnt_sad8x8_avg_bits8,
1689 aom_highbd_8_jnt_sub_pixel_avg_variance8x8)
1690
1691 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8,
1692 aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4,
1693 aom_highbd_8_sub_pixel_variance8x4,
1694 aom_highbd_8_sub_pixel_avg_variance8x4, NULL,
1695 aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8,
1696 aom_highbd_jnt_sad8x4_avg_bits8,
1697 aom_highbd_8_jnt_sub_pixel_avg_variance8x4)
1698
1699 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8,
1700 aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8,
1701 aom_highbd_8_sub_pixel_variance4x8,
1702 aom_highbd_8_sub_pixel_avg_variance4x8, NULL,
1703 aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8,
1704 aom_highbd_jnt_sad4x8_avg_bits8,
1705 aom_highbd_8_jnt_sub_pixel_avg_variance4x8)
1706
1707 HIGHBD_BFP(BLOCK_4X4, aom_highbd_sad4x4_bits8,
1708 aom_highbd_sad4x4_avg_bits8, aom_highbd_8_variance4x4,
1709 aom_highbd_8_sub_pixel_variance4x4,
1710 aom_highbd_8_sub_pixel_avg_variance4x4,
1711 aom_highbd_sad4x4x3_bits8, aom_highbd_sad4x4x8_bits8,
1712 aom_highbd_sad4x4x4d_bits8, aom_highbd_jnt_sad4x4_avg_bits8,
1713 aom_highbd_8_jnt_sub_pixel_avg_variance4x4)
1714
Cheng Chenbf3d4962017-11-01 14:48:52 -07001715#if CONFIG_EXT_PARTITION
1716 HIGHBD_BFP(
1717 BLOCK_128X128, aom_highbd_sad128x128_bits8,
1718 aom_highbd_sad128x128_avg_bits8, aom_highbd_8_variance128x128,
1719 aom_highbd_8_sub_pixel_variance128x128,
1720 aom_highbd_8_sub_pixel_avg_variance128x128,
1721 aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8,
1722 aom_highbd_sad128x128x4d_bits8, aom_highbd_jnt_sad128x128_avg_bits8,
1723 aom_highbd_8_jnt_sub_pixel_avg_variance128x128)
1724
1725 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8,
1726 aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64,
1727 aom_highbd_8_sub_pixel_variance128x64,
1728 aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL,
1729 aom_highbd_sad128x64x4d_bits8,
1730 aom_highbd_jnt_sad128x64_avg_bits8,
1731 aom_highbd_8_jnt_sub_pixel_avg_variance128x64)
1732
1733 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8,
1734 aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128,
1735 aom_highbd_8_sub_pixel_variance64x128,
1736 aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL,
1737 aom_highbd_sad64x128x4d_bits8,
1738 aom_highbd_jnt_sad64x128_avg_bits8,
1739 aom_highbd_8_jnt_sub_pixel_avg_variance64x128)
1740#endif // CONFIG_EXT_PARTITION
1741#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001742#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001743#if CONFIG_EXT_PARTITION
1744 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8,
1745 aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32,
1746 aom_highbd_8_sub_pixel_variance128x32,
1747 aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL,
1748 aom_highbd_sad128x32x4d_bits8)
1749
1750 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8,
1751 aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128,
1752 aom_highbd_8_sub_pixel_variance32x128,
1753 aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL,
1754 aom_highbd_sad32x128x4d_bits8)
1755#endif // CONFIG_EXT_PARTITION
1756
Rupert Swarbrick72678572017-08-02 12:05:26 +01001757 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8,
1758 aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16,
1759 aom_highbd_8_sub_pixel_variance64x16,
1760 aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL,
1761 aom_highbd_sad64x16x4d_bits8)
1762
1763 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8,
1764 aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64,
1765 aom_highbd_8_sub_pixel_variance16x64,
1766 aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL,
1767 aom_highbd_sad16x64x4d_bits8)
1768
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001769 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8,
1770 aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8,
1771 aom_highbd_8_sub_pixel_variance32x8,
1772 aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL,
1773 aom_highbd_sad32x8x4d_bits8)
1774
1775 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8,
1776 aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32,
1777 aom_highbd_8_sub_pixel_variance8x32,
1778 aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL,
1779 aom_highbd_sad8x32x4d_bits8)
1780
1781 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8,
1782 aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4,
1783 aom_highbd_8_sub_pixel_variance16x4,
1784 aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL,
1785 aom_highbd_sad16x4x4d_bits8)
1786
1787 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8,
1788 aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16,
1789 aom_highbd_8_sub_pixel_variance4x16,
1790 aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL,
1791 aom_highbd_sad4x16x4d_bits8)
1792#endif
1793
Yaowu Xuf883b422016-08-30 14:01:10 -07001794 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8,
1795 aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16,
1796 aom_highbd_8_sub_pixel_variance32x16,
1797 aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL,
1798 aom_highbd_sad32x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001799
Yaowu Xuf883b422016-08-30 14:01:10 -07001800 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8,
1801 aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32,
1802 aom_highbd_8_sub_pixel_variance16x32,
1803 aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL,
1804 aom_highbd_sad16x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001805
Yaowu Xuf883b422016-08-30 14:01:10 -07001806 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8,
1807 aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32,
1808 aom_highbd_8_sub_pixel_variance64x32,
1809 aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL,
1810 aom_highbd_sad64x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001811
Yaowu Xuf883b422016-08-30 14:01:10 -07001812 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8,
1813 aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64,
1814 aom_highbd_8_sub_pixel_variance32x64,
1815 aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL,
1816 aom_highbd_sad32x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001817
Yaowu Xuf883b422016-08-30 14:01:10 -07001818 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8,
1819 aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32,
1820 aom_highbd_8_sub_pixel_variance32x32,
1821 aom_highbd_8_sub_pixel_avg_variance32x32,
1822 aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8,
1823 aom_highbd_sad32x32x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001824
Yaowu Xuf883b422016-08-30 14:01:10 -07001825 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8,
1826 aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64,
1827 aom_highbd_8_sub_pixel_variance64x64,
1828 aom_highbd_8_sub_pixel_avg_variance64x64,
1829 aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8,
1830 aom_highbd_sad64x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001831
Yaowu Xuf883b422016-08-30 14:01:10 -07001832 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8,
1833 aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16,
1834 aom_highbd_8_sub_pixel_variance16x16,
1835 aom_highbd_8_sub_pixel_avg_variance16x16,
1836 aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8,
1837 aom_highbd_sad16x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001838
1839 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001840 BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8,
1841 aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8,
1842 aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8,
1843 aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001844
1845 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001846 BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8,
1847 aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16,
1848 aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8,
1849 aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001850
1851 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001852 BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8,
1853 aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8,
1854 aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8,
1855 aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001856
Yaowu Xuf883b422016-08-30 14:01:10 -07001857 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8,
1858 aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4,
1859 aom_highbd_8_sub_pixel_variance8x4,
1860 aom_highbd_8_sub_pixel_avg_variance8x4, NULL,
1861 aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001862
Yaowu Xuf883b422016-08-30 14:01:10 -07001863 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8,
1864 aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8,
1865 aom_highbd_8_sub_pixel_variance4x8,
1866 aom_highbd_8_sub_pixel_avg_variance4x8, NULL,
1867 aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001868
1869 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07001870 BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8,
1871 aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4,
1872 aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8,
1873 aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001874
1875#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001876 HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8,
1877 aom_highbd_sad128x128_avg_bits8,
1878 aom_highbd_8_variance128x128,
1879 aom_highbd_8_sub_pixel_variance128x128,
1880 aom_highbd_8_sub_pixel_avg_variance128x128,
1881 aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8,
1882 aom_highbd_sad128x128x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001883
Yaowu Xuf883b422016-08-30 14:01:10 -07001884 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8,
1885 aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64,
1886 aom_highbd_8_sub_pixel_variance128x64,
1887 aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL,
1888 aom_highbd_sad128x64x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001889
Yaowu Xuf883b422016-08-30 14:01:10 -07001890 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8,
1891 aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128,
1892 aom_highbd_8_sub_pixel_variance64x128,
1893 aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL,
1894 aom_highbd_sad64x128x4d_bits8)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001895#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07001896#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001897
Yaowu Xuc27fc142016-08-22 16:08:15 -07001898#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001899 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8,
1900 aom_highbd_8_masked_sub_pixel_variance128x128)
1901 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8,
1902 aom_highbd_8_masked_sub_pixel_variance128x64)
1903 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8,
1904 aom_highbd_8_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001905#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01001906 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8,
1907 aom_highbd_8_masked_sub_pixel_variance64x64)
1908 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8,
1909 aom_highbd_8_masked_sub_pixel_variance64x32)
1910 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8,
1911 aom_highbd_8_masked_sub_pixel_variance32x64)
1912 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8,
1913 aom_highbd_8_masked_sub_pixel_variance32x32)
1914 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8,
1915 aom_highbd_8_masked_sub_pixel_variance32x16)
1916 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8,
1917 aom_highbd_8_masked_sub_pixel_variance16x32)
1918 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8,
1919 aom_highbd_8_masked_sub_pixel_variance16x16)
1920 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8,
1921 aom_highbd_8_masked_sub_pixel_variance8x16)
1922 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8,
1923 aom_highbd_8_masked_sub_pixel_variance16x8)
1924 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8,
1925 aom_highbd_8_masked_sub_pixel_variance8x8)
1926 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8,
1927 aom_highbd_8_masked_sub_pixel_variance4x8)
1928 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8,
1929 aom_highbd_8_masked_sub_pixel_variance8x4)
1930 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8,
1931 aom_highbd_8_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001932#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001933#if CONFIG_EXT_PARTITION
1934 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits8,
1935 aom_highbd_8_masked_sub_pixel_variance128x32)
1936
1937 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits8,
1938 aom_highbd_8_masked_sub_pixel_variance32x128)
1939#endif // CONFIG_EXT_PARTITION
1940
Rupert Swarbrick72678572017-08-02 12:05:26 +01001941 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8,
1942 aom_highbd_8_masked_sub_pixel_variance64x16)
1943
1944 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8,
1945 aom_highbd_8_masked_sub_pixel_variance16x64)
1946
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001947 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8,
1948 aom_highbd_8_masked_sub_pixel_variance32x8)
1949
1950 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8,
1951 aom_highbd_8_masked_sub_pixel_variance8x32)
1952
1953 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8,
1954 aom_highbd_8_masked_sub_pixel_variance16x4)
1955
1956 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8,
1957 aom_highbd_8_masked_sub_pixel_variance4x16)
1958#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001959#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001960 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8,
1961 aom_highbd_obmc_variance128x128,
1962 aom_highbd_obmc_sub_pixel_variance128x128)
1963 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8,
1964 aom_highbd_obmc_variance128x64,
1965 aom_highbd_obmc_sub_pixel_variance128x64)
1966 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8,
1967 aom_highbd_obmc_variance64x128,
1968 aom_highbd_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001969#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07001970 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8,
1971 aom_highbd_obmc_variance64x64,
1972 aom_highbd_obmc_sub_pixel_variance64x64)
1973 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8,
1974 aom_highbd_obmc_variance64x32,
1975 aom_highbd_obmc_sub_pixel_variance64x32)
1976 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8,
1977 aom_highbd_obmc_variance32x64,
1978 aom_highbd_obmc_sub_pixel_variance32x64)
1979 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8,
1980 aom_highbd_obmc_variance32x32,
1981 aom_highbd_obmc_sub_pixel_variance32x32)
1982 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8,
1983 aom_highbd_obmc_variance32x16,
1984 aom_highbd_obmc_sub_pixel_variance32x16)
1985 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8,
1986 aom_highbd_obmc_variance16x32,
1987 aom_highbd_obmc_sub_pixel_variance16x32)
1988 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8,
1989 aom_highbd_obmc_variance16x16,
1990 aom_highbd_obmc_sub_pixel_variance16x16)
1991 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8,
1992 aom_highbd_obmc_variance8x16,
1993 aom_highbd_obmc_sub_pixel_variance8x16)
1994 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8,
1995 aom_highbd_obmc_variance16x8,
1996 aom_highbd_obmc_sub_pixel_variance16x8)
1997 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8,
1998 aom_highbd_obmc_variance8x8,
1999 aom_highbd_obmc_sub_pixel_variance8x8)
2000 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8,
2001 aom_highbd_obmc_variance4x8,
2002 aom_highbd_obmc_sub_pixel_variance4x8)
2003 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8,
2004 aom_highbd_obmc_variance8x4,
2005 aom_highbd_obmc_sub_pixel_variance8x4)
2006 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8,
2007 aom_highbd_obmc_variance4x4,
2008 aom_highbd_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002009#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002010#if CONFIG_EXT_PARTITION
2011 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits8,
2012 aom_highbd_obmc_variance128x32,
2013 aom_highbd_obmc_sub_pixel_variance128x32)
2014
2015 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits8,
2016 aom_highbd_obmc_variance32x128,
2017 aom_highbd_obmc_sub_pixel_variance32x128)
2018#endif // CONFIG_EXT_PARTITION
2019
Rupert Swarbrick72678572017-08-02 12:05:26 +01002020 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8,
2021 aom_highbd_obmc_variance64x16,
2022 aom_highbd_obmc_sub_pixel_variance64x16)
2023
2024 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8,
2025 aom_highbd_obmc_variance16x64,
2026 aom_highbd_obmc_sub_pixel_variance16x64)
2027
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002028 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8,
2029 aom_highbd_obmc_variance32x8,
2030 aom_highbd_obmc_sub_pixel_variance32x8)
2031
2032 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8,
2033 aom_highbd_obmc_variance8x32,
2034 aom_highbd_obmc_sub_pixel_variance8x32)
2035
2036 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8,
2037 aom_highbd_obmc_variance16x4,
2038 aom_highbd_obmc_sub_pixel_variance16x4)
2039
2040 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8,
2041 aom_highbd_obmc_variance4x16,
2042 aom_highbd_obmc_sub_pixel_variance4x16)
2043#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002044 break;
2045
Yaowu Xuf883b422016-08-30 14:01:10 -07002046 case AOM_BITS_10:
Cheng Chenbf3d4962017-11-01 14:48:52 -07002047#if CONFIG_JNT_COMP
2048#if CONFIG_EXT_PARTITION_TYPES
2049#if CONFIG_EXT_PARTITION
2050 HIGHBD_BFP(
2051 BLOCK_128X32, aom_highbd_sad128x32_bits10,
2052 aom_highbd_sad128x32_avg_bits10, aom_highbd_10_variance128x32,
2053 aom_highbd_10_sub_pixel_variance128x32,
2054 aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL,
2055 aom_highbd_sad128x32x4d_bits10, aom_highbd_jnt_sad128x32_avg_bits10,
2056 aom_highbd_10_jnt_sub_pixel_avg_variance128x32);
2057
2058 HIGHBD_BFP(
2059 BLOCK_32X128, aom_highbd_sad32x128_bits10,
2060 aom_highbd_sad32x128_avg_bits10, aom_highbd_10_variance32x128,
2061 aom_highbd_10_sub_pixel_variance32x128,
2062 aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL,
2063 aom_highbd_sad32x128x4d_bits10, aom_highbd_jnt_sad32x128_avg_bits10,
2064 aom_highbd_10_jnt_sub_pixel_avg_variance32x128);
2065#endif // CONFIG_EXT_PARTITION
2066
2067 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10,
2068 aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16,
2069 aom_highbd_10_sub_pixel_variance64x16,
2070 aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL,
2071 aom_highbd_sad64x16x4d_bits10,
2072 aom_highbd_jnt_sad64x16_avg_bits10,
2073 aom_highbd_10_jnt_sub_pixel_avg_variance64x16);
2074
2075 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10,
2076 aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64,
2077 aom_highbd_10_sub_pixel_variance16x64,
2078 aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL,
2079 aom_highbd_sad16x64x4d_bits10,
2080 aom_highbd_jnt_sad16x64_avg_bits10,
2081 aom_highbd_10_jnt_sub_pixel_avg_variance16x64);
2082
2083 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10,
2084 aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8,
2085 aom_highbd_10_sub_pixel_variance32x8,
2086 aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL,
2087 aom_highbd_sad32x8x4d_bits10,
2088 aom_highbd_jnt_sad32x8_avg_bits10,
2089 aom_highbd_10_jnt_sub_pixel_avg_variance32x8);
2090
2091 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10,
2092 aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32,
2093 aom_highbd_10_sub_pixel_variance8x32,
2094 aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL,
2095 aom_highbd_sad8x32x4d_bits10,
2096 aom_highbd_jnt_sad8x32_avg_bits10,
2097 aom_highbd_10_jnt_sub_pixel_avg_variance8x32);
2098
2099 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10,
2100 aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4,
2101 aom_highbd_10_sub_pixel_variance16x4,
2102 aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL,
2103 aom_highbd_sad16x4x4d_bits10,
2104 aom_highbd_jnt_sad16x4_avg_bits10,
2105 aom_highbd_10_jnt_sub_pixel_avg_variance16x4);
2106
2107 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10,
2108 aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16,
2109 aom_highbd_10_sub_pixel_variance4x16,
2110 aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL,
2111 aom_highbd_sad4x16x4d_bits10,
2112 aom_highbd_jnt_sad4x16_avg_bits10,
2113 aom_highbd_10_jnt_sub_pixel_avg_variance4x16);
2114#endif
2115
2116 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10,
2117 aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16,
2118 aom_highbd_10_sub_pixel_variance32x16,
2119 aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL,
2120 aom_highbd_sad32x16x4d_bits10,
2121 aom_highbd_jnt_sad32x16_avg_bits10,
2122 aom_highbd_10_jnt_sub_pixel_avg_variance32x16);
2123
2124 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10,
2125 aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32,
2126 aom_highbd_10_sub_pixel_variance16x32,
2127 aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL,
2128 aom_highbd_sad16x32x4d_bits10,
2129 aom_highbd_jnt_sad16x32_avg_bits10,
2130 aom_highbd_10_jnt_sub_pixel_avg_variance16x32);
2131
2132 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10,
2133 aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32,
2134 aom_highbd_10_sub_pixel_variance64x32,
2135 aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL,
2136 aom_highbd_sad64x32x4d_bits10,
2137 aom_highbd_jnt_sad64x32_avg_bits10,
2138 aom_highbd_10_jnt_sub_pixel_avg_variance64x32);
2139
2140 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10,
2141 aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64,
2142 aom_highbd_10_sub_pixel_variance32x64,
2143 aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL,
2144 aom_highbd_sad32x64x4d_bits10,
2145 aom_highbd_jnt_sad32x64_avg_bits10,
2146 aom_highbd_10_jnt_sub_pixel_avg_variance32x64);
2147
2148 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10,
2149 aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32,
2150 aom_highbd_10_sub_pixel_variance32x32,
2151 aom_highbd_10_sub_pixel_avg_variance32x32,
2152 aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10,
2153 aom_highbd_sad32x32x4d_bits10,
2154 aom_highbd_jnt_sad32x32_avg_bits10,
2155 aom_highbd_10_jnt_sub_pixel_avg_variance32x32);
2156
2157 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10,
2158 aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64,
2159 aom_highbd_10_sub_pixel_variance64x64,
2160 aom_highbd_10_sub_pixel_avg_variance64x64,
2161 aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10,
2162 aom_highbd_sad64x64x4d_bits10,
2163 aom_highbd_jnt_sad64x64_avg_bits10,
2164 aom_highbd_10_jnt_sub_pixel_avg_variance64x64);
2165
2166 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10,
2167 aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16,
2168 aom_highbd_10_sub_pixel_variance16x16,
2169 aom_highbd_10_sub_pixel_avg_variance16x16,
2170 aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10,
2171 aom_highbd_sad16x16x4d_bits10,
2172 aom_highbd_jnt_sad16x16_avg_bits10,
2173 aom_highbd_10_jnt_sub_pixel_avg_variance16x16);
2174
2175 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10,
2176 aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8,
2177 aom_highbd_10_sub_pixel_variance16x8,
2178 aom_highbd_10_sub_pixel_avg_variance16x8,
2179 aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10,
2180 aom_highbd_sad16x8x4d_bits10,
2181 aom_highbd_jnt_sad16x8_avg_bits10,
2182 aom_highbd_10_jnt_sub_pixel_avg_variance16x8);
2183
2184 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10,
2185 aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16,
2186 aom_highbd_10_sub_pixel_variance8x16,
2187 aom_highbd_10_sub_pixel_avg_variance8x16,
2188 aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10,
2189 aom_highbd_sad8x16x4d_bits10,
2190 aom_highbd_jnt_sad8x16_avg_bits10,
2191 aom_highbd_10_jnt_sub_pixel_avg_variance8x16);
2192
2193 HIGHBD_BFP(
2194 BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10,
2195 aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8,
2196 aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10,
2197 aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10,
2198 aom_highbd_jnt_sad8x8_avg_bits10,
2199 aom_highbd_10_jnt_sub_pixel_avg_variance8x8);
2200
2201 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10,
2202 aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4,
2203 aom_highbd_10_sub_pixel_variance8x4,
2204 aom_highbd_10_sub_pixel_avg_variance8x4, NULL,
2205 aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10,
2206 aom_highbd_jnt_sad8x4_avg_bits10,
2207 aom_highbd_10_jnt_sub_pixel_avg_variance8x4);
2208
2209 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10,
2210 aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8,
2211 aom_highbd_10_sub_pixel_variance4x8,
2212 aom_highbd_10_sub_pixel_avg_variance4x8, NULL,
2213 aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10,
2214 aom_highbd_jnt_sad4x8_avg_bits10,
2215 aom_highbd_10_jnt_sub_pixel_avg_variance4x8);
2216
2217 HIGHBD_BFP(
2218 BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10,
2219 aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4,
2220 aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10,
2221 aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10,
2222 aom_highbd_jnt_sad4x4_avg_bits10,
2223 aom_highbd_10_jnt_sub_pixel_avg_variance4x4);
2224
Cheng Chenbf3d4962017-11-01 14:48:52 -07002225#if CONFIG_EXT_PARTITION
2226 HIGHBD_BFP(
2227 BLOCK_128X128, aom_highbd_sad128x128_bits10,
2228 aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128,
2229 aom_highbd_10_sub_pixel_variance128x128,
2230 aom_highbd_10_sub_pixel_avg_variance128x128,
2231 aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10,
2232 aom_highbd_sad128x128x4d_bits10,
2233 aom_highbd_jnt_sad128x128_avg_bits10,
2234 aom_highbd_10_jnt_sub_pixel_avg_variance128x128);
2235
2236 HIGHBD_BFP(
2237 BLOCK_128X64, aom_highbd_sad128x64_bits10,
2238 aom_highbd_sad128x64_avg_bits10, aom_highbd_10_variance128x64,
2239 aom_highbd_10_sub_pixel_variance128x64,
2240 aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL,
2241 aom_highbd_sad128x64x4d_bits10, aom_highbd_jnt_sad128x64_avg_bits10,
2242 aom_highbd_10_jnt_sub_pixel_avg_variance128x64);
2243
2244 HIGHBD_BFP(
2245 BLOCK_64X128, aom_highbd_sad64x128_bits10,
2246 aom_highbd_sad64x128_avg_bits10, aom_highbd_10_variance64x128,
2247 aom_highbd_10_sub_pixel_variance64x128,
2248 aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL,
2249 aom_highbd_sad64x128x4d_bits10, aom_highbd_jnt_sad64x128_avg_bits10,
2250 aom_highbd_10_jnt_sub_pixel_avg_variance64x128);
2251#endif // CONFIG_EXT_PARTITION
2252#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002253#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002254#if CONFIG_EXT_PARTITION
2255 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits10,
2256 aom_highbd_sad128x32_avg_bits10,
2257 aom_highbd_10_variance128x32,
2258 aom_highbd_10_sub_pixel_variance128x32,
2259 aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL,
2260 aom_highbd_sad128x32x4d_bits10)
2261
2262 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits10,
2263 aom_highbd_sad32x128_avg_bits10,
2264 aom_highbd_10_variance32x128,
2265 aom_highbd_10_sub_pixel_variance32x128,
2266 aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL,
2267 aom_highbd_sad32x128x4d_bits10)
2268#endif // CONFIG_EXT_PARTITION
2269
Rupert Swarbrick72678572017-08-02 12:05:26 +01002270 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10,
2271 aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16,
2272 aom_highbd_10_sub_pixel_variance64x16,
2273 aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL,
2274 aom_highbd_sad64x16x4d_bits10)
2275
2276 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10,
2277 aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64,
2278 aom_highbd_10_sub_pixel_variance16x64,
2279 aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL,
2280 aom_highbd_sad16x64x4d_bits10)
2281
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002282 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10,
2283 aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8,
2284 aom_highbd_10_sub_pixel_variance32x8,
2285 aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL,
2286 aom_highbd_sad32x8x4d_bits10)
2287
2288 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10,
2289 aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32,
2290 aom_highbd_10_sub_pixel_variance8x32,
2291 aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL,
2292 aom_highbd_sad8x32x4d_bits10)
2293
2294 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10,
2295 aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4,
2296 aom_highbd_10_sub_pixel_variance16x4,
2297 aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL,
2298 aom_highbd_sad16x4x4d_bits10)
2299
2300 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10,
2301 aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16,
2302 aom_highbd_10_sub_pixel_variance4x16,
2303 aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL,
2304 aom_highbd_sad4x16x4d_bits10)
2305#endif
2306
Yaowu Xuf883b422016-08-30 14:01:10 -07002307 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10,
2308 aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16,
2309 aom_highbd_10_sub_pixel_variance32x16,
2310 aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL,
2311 aom_highbd_sad32x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002312
Yaowu Xuf883b422016-08-30 14:01:10 -07002313 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10,
2314 aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32,
2315 aom_highbd_10_sub_pixel_variance16x32,
2316 aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL,
2317 aom_highbd_sad16x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002318
Yaowu Xuf883b422016-08-30 14:01:10 -07002319 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10,
2320 aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32,
2321 aom_highbd_10_sub_pixel_variance64x32,
2322 aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL,
2323 aom_highbd_sad64x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002324
Yaowu Xuf883b422016-08-30 14:01:10 -07002325 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10,
2326 aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64,
2327 aom_highbd_10_sub_pixel_variance32x64,
2328 aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL,
2329 aom_highbd_sad32x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002330
Yaowu Xuf883b422016-08-30 14:01:10 -07002331 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10,
2332 aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32,
2333 aom_highbd_10_sub_pixel_variance32x32,
2334 aom_highbd_10_sub_pixel_avg_variance32x32,
2335 aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10,
2336 aom_highbd_sad32x32x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002337
Yaowu Xuf883b422016-08-30 14:01:10 -07002338 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10,
2339 aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64,
2340 aom_highbd_10_sub_pixel_variance64x64,
2341 aom_highbd_10_sub_pixel_avg_variance64x64,
2342 aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10,
2343 aom_highbd_sad64x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002344
Yaowu Xuf883b422016-08-30 14:01:10 -07002345 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10,
2346 aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16,
2347 aom_highbd_10_sub_pixel_variance16x16,
2348 aom_highbd_10_sub_pixel_avg_variance16x16,
2349 aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10,
2350 aom_highbd_sad16x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002351
Yaowu Xuf883b422016-08-30 14:01:10 -07002352 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10,
2353 aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8,
2354 aom_highbd_10_sub_pixel_variance16x8,
2355 aom_highbd_10_sub_pixel_avg_variance16x8,
2356 aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10,
2357 aom_highbd_sad16x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002358
Yaowu Xuf883b422016-08-30 14:01:10 -07002359 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10,
2360 aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16,
2361 aom_highbd_10_sub_pixel_variance8x16,
2362 aom_highbd_10_sub_pixel_avg_variance8x16,
2363 aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10,
2364 aom_highbd_sad8x16x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002365
2366 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002367 BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10,
2368 aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8,
2369 aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10,
2370 aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002371
Yaowu Xuf883b422016-08-30 14:01:10 -07002372 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10,
2373 aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4,
2374 aom_highbd_10_sub_pixel_variance8x4,
2375 aom_highbd_10_sub_pixel_avg_variance8x4, NULL,
2376 aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002377
Yaowu Xuf883b422016-08-30 14:01:10 -07002378 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10,
2379 aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8,
2380 aom_highbd_10_sub_pixel_variance4x8,
2381 aom_highbd_10_sub_pixel_avg_variance4x8, NULL,
2382 aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002383
2384 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002385 BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10,
2386 aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4,
2387 aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10,
2388 aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002389
2390#if CONFIG_EXT_PARTITION
2391 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002392 BLOCK_128X128, aom_highbd_sad128x128_bits10,
2393 aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128,
2394 aom_highbd_10_sub_pixel_variance128x128,
2395 aom_highbd_10_sub_pixel_avg_variance128x128,
2396 aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10,
2397 aom_highbd_sad128x128x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002398
Yaowu Xuf883b422016-08-30 14:01:10 -07002399 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10,
2400 aom_highbd_sad128x64_avg_bits10,
2401 aom_highbd_10_variance128x64,
2402 aom_highbd_10_sub_pixel_variance128x64,
2403 aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL,
2404 aom_highbd_sad128x64x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002405
Yaowu Xuf883b422016-08-30 14:01:10 -07002406 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10,
2407 aom_highbd_sad64x128_avg_bits10,
2408 aom_highbd_10_variance64x128,
2409 aom_highbd_10_sub_pixel_variance64x128,
2410 aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL,
2411 aom_highbd_sad64x128x4d_bits10)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002412#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07002413#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002414
Yaowu Xuc27fc142016-08-22 16:08:15 -07002415#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002416 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10,
2417 aom_highbd_10_masked_sub_pixel_variance128x128)
2418 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10,
2419 aom_highbd_10_masked_sub_pixel_variance128x64)
2420 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10,
2421 aom_highbd_10_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002422#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002423 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10,
2424 aom_highbd_10_masked_sub_pixel_variance64x64)
2425 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10,
2426 aom_highbd_10_masked_sub_pixel_variance64x32)
2427 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10,
2428 aom_highbd_10_masked_sub_pixel_variance32x64)
2429 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10,
2430 aom_highbd_10_masked_sub_pixel_variance32x32)
2431 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10,
2432 aom_highbd_10_masked_sub_pixel_variance32x16)
2433 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10,
2434 aom_highbd_10_masked_sub_pixel_variance16x32)
2435 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10,
2436 aom_highbd_10_masked_sub_pixel_variance16x16)
2437 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10,
2438 aom_highbd_10_masked_sub_pixel_variance8x16)
2439 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10,
2440 aom_highbd_10_masked_sub_pixel_variance16x8)
2441 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10,
2442 aom_highbd_10_masked_sub_pixel_variance8x8)
2443 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10,
2444 aom_highbd_10_masked_sub_pixel_variance4x8)
2445 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10,
2446 aom_highbd_10_masked_sub_pixel_variance8x4)
2447 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10,
2448 aom_highbd_10_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002449#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002450#if CONFIG_EXT_PARTITION
2451 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits10,
2452 aom_highbd_10_masked_sub_pixel_variance128x32)
2453
2454 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits10,
2455 aom_highbd_10_masked_sub_pixel_variance32x128)
2456#endif // CONFIG_EXT_PARTITION
2457
Rupert Swarbrick72678572017-08-02 12:05:26 +01002458 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10,
2459 aom_highbd_10_masked_sub_pixel_variance64x16)
2460
2461 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10,
2462 aom_highbd_10_masked_sub_pixel_variance16x64)
2463
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002464 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10,
2465 aom_highbd_10_masked_sub_pixel_variance32x8)
2466
2467 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10,
2468 aom_highbd_10_masked_sub_pixel_variance8x32)
2469
2470 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10,
2471 aom_highbd_10_masked_sub_pixel_variance16x4)
2472
2473 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10,
2474 aom_highbd_10_masked_sub_pixel_variance4x16)
2475#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002476#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07002477 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10,
2478 aom_highbd_10_obmc_variance128x128,
2479 aom_highbd_10_obmc_sub_pixel_variance128x128)
2480 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10,
2481 aom_highbd_10_obmc_variance128x64,
2482 aom_highbd_10_obmc_sub_pixel_variance128x64)
2483 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10,
2484 aom_highbd_10_obmc_variance64x128,
2485 aom_highbd_10_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002486#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07002487 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10,
2488 aom_highbd_10_obmc_variance64x64,
2489 aom_highbd_10_obmc_sub_pixel_variance64x64)
2490 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10,
2491 aom_highbd_10_obmc_variance64x32,
2492 aom_highbd_10_obmc_sub_pixel_variance64x32)
2493 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10,
2494 aom_highbd_10_obmc_variance32x64,
2495 aom_highbd_10_obmc_sub_pixel_variance32x64)
2496 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10,
2497 aom_highbd_10_obmc_variance32x32,
2498 aom_highbd_10_obmc_sub_pixel_variance32x32)
2499 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10,
2500 aom_highbd_10_obmc_variance32x16,
2501 aom_highbd_10_obmc_sub_pixel_variance32x16)
2502 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10,
2503 aom_highbd_10_obmc_variance16x32,
2504 aom_highbd_10_obmc_sub_pixel_variance16x32)
2505 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10,
2506 aom_highbd_10_obmc_variance16x16,
2507 aom_highbd_10_obmc_sub_pixel_variance16x16)
2508 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10,
2509 aom_highbd_10_obmc_variance8x16,
2510 aom_highbd_10_obmc_sub_pixel_variance8x16)
2511 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10,
2512 aom_highbd_10_obmc_variance16x8,
2513 aom_highbd_10_obmc_sub_pixel_variance16x8)
2514 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10,
2515 aom_highbd_10_obmc_variance8x8,
2516 aom_highbd_10_obmc_sub_pixel_variance8x8)
2517 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10,
2518 aom_highbd_10_obmc_variance4x8,
2519 aom_highbd_10_obmc_sub_pixel_variance4x8)
2520 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10,
2521 aom_highbd_10_obmc_variance8x4,
2522 aom_highbd_10_obmc_sub_pixel_variance8x4)
2523 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10,
2524 aom_highbd_10_obmc_variance4x4,
2525 aom_highbd_10_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002526#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002527#if CONFIG_EXT_PARTITION
2528 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits10,
2529 aom_highbd_10_obmc_variance128x32,
2530 aom_highbd_10_obmc_sub_pixel_variance128x32)
2531
2532 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits10,
2533 aom_highbd_10_obmc_variance32x128,
2534 aom_highbd_10_obmc_sub_pixel_variance32x128)
2535#endif // CONFIG_EXT_PARTITION
2536
Rupert Swarbrick72678572017-08-02 12:05:26 +01002537 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10,
2538 aom_highbd_10_obmc_variance64x16,
2539 aom_highbd_10_obmc_sub_pixel_variance64x16)
2540
2541 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10,
2542 aom_highbd_10_obmc_variance16x64,
2543 aom_highbd_10_obmc_sub_pixel_variance16x64)
2544
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002545 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10,
2546 aom_highbd_10_obmc_variance32x8,
2547 aom_highbd_10_obmc_sub_pixel_variance32x8)
2548
2549 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10,
2550 aom_highbd_10_obmc_variance8x32,
2551 aom_highbd_10_obmc_sub_pixel_variance8x32)
2552
2553 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10,
2554 aom_highbd_10_obmc_variance16x4,
2555 aom_highbd_10_obmc_sub_pixel_variance16x4)
2556
2557 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10,
2558 aom_highbd_10_obmc_variance4x16,
2559 aom_highbd_10_obmc_sub_pixel_variance4x16)
2560#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002561 break;
2562
Yaowu Xuf883b422016-08-30 14:01:10 -07002563 case AOM_BITS_12:
Cheng Chenbf3d4962017-11-01 14:48:52 -07002564#if CONFIG_JNT_COMP
2565#if CONFIG_EXT_PARTITION_TYPES
2566#if CONFIG_EXT_PARTITION
2567 HIGHBD_BFP(
2568 BLOCK_128X32, aom_highbd_sad128x32_bits12,
2569 aom_highbd_sad128x32_avg_bits12, aom_highbd_12_variance128x32,
2570 aom_highbd_12_sub_pixel_variance128x32,
2571 aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL,
2572 aom_highbd_sad128x32x4d_bits12, aom_highbd_jnt_sad128x32_avg_bits12,
2573 aom_highbd_12_jnt_sub_pixel_avg_variance128x32);
2574
2575 HIGHBD_BFP(
2576 BLOCK_32X128, aom_highbd_sad32x128_bits12,
2577 aom_highbd_sad32x128_avg_bits12, aom_highbd_12_variance32x128,
2578 aom_highbd_12_sub_pixel_variance32x128,
2579 aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL,
2580 aom_highbd_sad32x128x4d_bits12, aom_highbd_jnt_sad32x128_avg_bits12,
2581 aom_highbd_12_jnt_sub_pixel_avg_variance32x128);
2582#endif // CONFIG_EXT_PARTITION
2583
2584 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12,
2585 aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16,
2586 aom_highbd_12_sub_pixel_variance64x16,
2587 aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL,
2588 aom_highbd_sad64x16x4d_bits12,
2589 aom_highbd_jnt_sad64x16_avg_bits12,
2590 aom_highbd_12_jnt_sub_pixel_avg_variance64x16);
2591
2592 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12,
2593 aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64,
2594 aom_highbd_12_sub_pixel_variance16x64,
2595 aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL,
2596 aom_highbd_sad16x64x4d_bits12,
2597 aom_highbd_jnt_sad16x64_avg_bits12,
2598 aom_highbd_12_jnt_sub_pixel_avg_variance16x64);
2599
2600 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12,
2601 aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8,
2602 aom_highbd_12_sub_pixel_variance32x8,
2603 aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL,
2604 aom_highbd_sad32x8x4d_bits12,
2605 aom_highbd_jnt_sad32x8_avg_bits12,
2606 aom_highbd_12_jnt_sub_pixel_avg_variance32x8);
2607
2608 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12,
2609 aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32,
2610 aom_highbd_12_sub_pixel_variance8x32,
2611 aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL,
2612 aom_highbd_sad8x32x4d_bits12,
2613 aom_highbd_jnt_sad8x32_avg_bits12,
2614 aom_highbd_12_jnt_sub_pixel_avg_variance8x32);
2615
2616 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12,
2617 aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4,
2618 aom_highbd_12_sub_pixel_variance16x4,
2619 aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL,
2620 aom_highbd_sad16x4x4d_bits12,
2621 aom_highbd_jnt_sad16x4_avg_bits12,
2622 aom_highbd_12_jnt_sub_pixel_avg_variance16x4);
2623
2624 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12,
2625 aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16,
2626 aom_highbd_12_sub_pixel_variance4x16,
2627 aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL,
2628 aom_highbd_sad4x16x4d_bits12,
2629 aom_highbd_jnt_sad4x16_avg_bits12,
2630 aom_highbd_12_jnt_sub_pixel_avg_variance4x16);
2631#endif
2632
2633 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12,
2634 aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16,
2635 aom_highbd_12_sub_pixel_variance32x16,
2636 aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL,
2637 aom_highbd_sad32x16x4d_bits12,
2638 aom_highbd_jnt_sad32x16_avg_bits12,
2639 aom_highbd_12_jnt_sub_pixel_avg_variance32x16);
2640
2641 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12,
2642 aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32,
2643 aom_highbd_12_sub_pixel_variance16x32,
2644 aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL,
2645 aom_highbd_sad16x32x4d_bits12,
2646 aom_highbd_jnt_sad16x32_avg_bits12,
2647 aom_highbd_12_jnt_sub_pixel_avg_variance16x32);
2648
2649 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12,
2650 aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32,
2651 aom_highbd_12_sub_pixel_variance64x32,
2652 aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL,
2653 aom_highbd_sad64x32x4d_bits12,
2654 aom_highbd_jnt_sad64x32_avg_bits12,
2655 aom_highbd_12_jnt_sub_pixel_avg_variance64x32);
2656
2657 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12,
2658 aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64,
2659 aom_highbd_12_sub_pixel_variance32x64,
2660 aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL,
2661 aom_highbd_sad32x64x4d_bits12,
2662 aom_highbd_jnt_sad32x64_avg_bits12,
2663 aom_highbd_12_jnt_sub_pixel_avg_variance32x64);
2664
2665 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12,
2666 aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32,
2667 aom_highbd_12_sub_pixel_variance32x32,
2668 aom_highbd_12_sub_pixel_avg_variance32x32,
2669 aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12,
2670 aom_highbd_sad32x32x4d_bits12,
2671 aom_highbd_jnt_sad32x32_avg_bits12,
2672 aom_highbd_12_jnt_sub_pixel_avg_variance32x32);
2673
2674 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12,
2675 aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64,
2676 aom_highbd_12_sub_pixel_variance64x64,
2677 aom_highbd_12_sub_pixel_avg_variance64x64,
2678 aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12,
2679 aom_highbd_sad64x64x4d_bits12,
2680 aom_highbd_jnt_sad64x64_avg_bits12,
2681 aom_highbd_12_jnt_sub_pixel_avg_variance64x64);
2682
2683 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12,
2684 aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16,
2685 aom_highbd_12_sub_pixel_variance16x16,
2686 aom_highbd_12_sub_pixel_avg_variance16x16,
2687 aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12,
2688 aom_highbd_sad16x16x4d_bits12,
2689 aom_highbd_jnt_sad16x16_avg_bits12,
2690 aom_highbd_12_jnt_sub_pixel_avg_variance16x16);
2691
2692 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12,
2693 aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8,
2694 aom_highbd_12_sub_pixel_variance16x8,
2695 aom_highbd_12_sub_pixel_avg_variance16x8,
2696 aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12,
2697 aom_highbd_sad16x8x4d_bits12,
2698 aom_highbd_jnt_sad16x8_avg_bits12,
2699 aom_highbd_12_jnt_sub_pixel_avg_variance16x8);
2700
2701 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12,
2702 aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16,
2703 aom_highbd_12_sub_pixel_variance8x16,
2704 aom_highbd_12_sub_pixel_avg_variance8x16,
2705 aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12,
2706 aom_highbd_sad8x16x4d_bits12,
2707 aom_highbd_jnt_sad8x16_avg_bits12,
2708 aom_highbd_12_jnt_sub_pixel_avg_variance8x16);
2709
2710 HIGHBD_BFP(
2711 BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12,
2712 aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8,
2713 aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12,
2714 aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12,
2715 aom_highbd_jnt_sad8x8_avg_bits12,
2716 aom_highbd_12_jnt_sub_pixel_avg_variance8x8);
2717
2718 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12,
2719 aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4,
2720 aom_highbd_12_sub_pixel_variance8x4,
2721 aom_highbd_12_sub_pixel_avg_variance8x4, NULL,
2722 aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12,
2723 aom_highbd_jnt_sad8x4_avg_bits12,
2724 aom_highbd_12_jnt_sub_pixel_avg_variance8x4);
2725
2726 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12,
2727 aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8,
2728 aom_highbd_12_sub_pixel_variance4x8,
2729 aom_highbd_12_sub_pixel_avg_variance4x8, NULL,
2730 aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12,
2731 aom_highbd_jnt_sad4x8_avg_bits12,
2732 aom_highbd_12_jnt_sub_pixel_avg_variance4x8);
2733
2734 HIGHBD_BFP(
2735 BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12,
2736 aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4,
2737 aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12,
2738 aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12,
2739 aom_highbd_jnt_sad4x4_avg_bits12,
2740 aom_highbd_12_jnt_sub_pixel_avg_variance4x4);
2741
Cheng Chenbf3d4962017-11-01 14:48:52 -07002742#if CONFIG_EXT_PARTITION
2743 HIGHBD_BFP(
2744 BLOCK_128X128, aom_highbd_sad128x128_bits12,
2745 aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128,
2746 aom_highbd_12_sub_pixel_variance128x128,
2747 aom_highbd_12_sub_pixel_avg_variance128x128,
2748 aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12,
2749 aom_highbd_sad128x128x4d_bits12,
2750 aom_highbd_jnt_sad128x128_avg_bits12,
2751 aom_highbd_12_jnt_sub_pixel_avg_variance128x128);
2752
2753 HIGHBD_BFP(
2754 BLOCK_128X64, aom_highbd_sad128x64_bits12,
2755 aom_highbd_sad128x64_avg_bits12, aom_highbd_12_variance128x64,
2756 aom_highbd_12_sub_pixel_variance128x64,
2757 aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL,
2758 aom_highbd_sad128x64x4d_bits12, aom_highbd_jnt_sad128x64_avg_bits12,
2759 aom_highbd_12_jnt_sub_pixel_avg_variance128x64);
2760
2761 HIGHBD_BFP(
2762 BLOCK_64X128, aom_highbd_sad64x128_bits12,
2763 aom_highbd_sad64x128_avg_bits12, aom_highbd_12_variance64x128,
2764 aom_highbd_12_sub_pixel_variance64x128,
2765 aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL,
2766 aom_highbd_sad64x128x4d_bits12, aom_highbd_jnt_sad64x128_avg_bits12,
2767 aom_highbd_12_jnt_sub_pixel_avg_variance64x128);
2768#endif // CONFIG_EXT_PARTITION
2769#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002770#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002771#if CONFIG_EXT_PARTITION
2772 HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits12,
2773 aom_highbd_sad128x32_avg_bits12,
2774 aom_highbd_12_variance128x32,
2775 aom_highbd_12_sub_pixel_variance128x32,
2776 aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL,
2777 aom_highbd_sad128x32x4d_bits12)
2778
2779 HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits12,
2780 aom_highbd_sad32x128_avg_bits12,
2781 aom_highbd_12_variance32x128,
2782 aom_highbd_12_sub_pixel_variance32x128,
2783 aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL,
2784 aom_highbd_sad32x128x4d_bits12)
2785#endif // CONFIG_EXT_PARTITION
2786
Rupert Swarbrick72678572017-08-02 12:05:26 +01002787 HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12,
2788 aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16,
2789 aom_highbd_12_sub_pixel_variance64x16,
2790 aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL,
2791 aom_highbd_sad64x16x4d_bits12)
2792
2793 HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12,
2794 aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64,
2795 aom_highbd_12_sub_pixel_variance16x64,
2796 aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL,
2797 aom_highbd_sad16x64x4d_bits12)
2798
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002799 HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12,
2800 aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8,
2801 aom_highbd_12_sub_pixel_variance32x8,
2802 aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL,
2803 aom_highbd_sad32x8x4d_bits12)
2804
2805 HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12,
2806 aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32,
2807 aom_highbd_12_sub_pixel_variance8x32,
2808 aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL,
2809 aom_highbd_sad8x32x4d_bits12)
2810
2811 HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12,
2812 aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4,
2813 aom_highbd_12_sub_pixel_variance16x4,
2814 aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL,
2815 aom_highbd_sad16x4x4d_bits12)
2816
2817 HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12,
2818 aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16,
2819 aom_highbd_12_sub_pixel_variance4x16,
2820 aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL,
2821 aom_highbd_sad4x16x4d_bits12)
2822#endif
2823
Yaowu Xuf883b422016-08-30 14:01:10 -07002824 HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12,
2825 aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16,
2826 aom_highbd_12_sub_pixel_variance32x16,
2827 aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL,
2828 aom_highbd_sad32x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002829
Yaowu Xuf883b422016-08-30 14:01:10 -07002830 HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12,
2831 aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32,
2832 aom_highbd_12_sub_pixel_variance16x32,
2833 aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL,
2834 aom_highbd_sad16x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002835
Yaowu Xuf883b422016-08-30 14:01:10 -07002836 HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12,
2837 aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32,
2838 aom_highbd_12_sub_pixel_variance64x32,
2839 aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL,
2840 aom_highbd_sad64x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002841
Yaowu Xuf883b422016-08-30 14:01:10 -07002842 HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12,
2843 aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64,
2844 aom_highbd_12_sub_pixel_variance32x64,
2845 aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL,
2846 aom_highbd_sad32x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002847
Yaowu Xuf883b422016-08-30 14:01:10 -07002848 HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12,
2849 aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32,
2850 aom_highbd_12_sub_pixel_variance32x32,
2851 aom_highbd_12_sub_pixel_avg_variance32x32,
2852 aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12,
2853 aom_highbd_sad32x32x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002854
Yaowu Xuf883b422016-08-30 14:01:10 -07002855 HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12,
2856 aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64,
2857 aom_highbd_12_sub_pixel_variance64x64,
2858 aom_highbd_12_sub_pixel_avg_variance64x64,
2859 aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12,
2860 aom_highbd_sad64x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002861
Yaowu Xuf883b422016-08-30 14:01:10 -07002862 HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12,
2863 aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16,
2864 aom_highbd_12_sub_pixel_variance16x16,
2865 aom_highbd_12_sub_pixel_avg_variance16x16,
2866 aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12,
2867 aom_highbd_sad16x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002868
Yaowu Xuf883b422016-08-30 14:01:10 -07002869 HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12,
2870 aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8,
2871 aom_highbd_12_sub_pixel_variance16x8,
2872 aom_highbd_12_sub_pixel_avg_variance16x8,
2873 aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12,
2874 aom_highbd_sad16x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002875
Yaowu Xuf883b422016-08-30 14:01:10 -07002876 HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12,
2877 aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16,
2878 aom_highbd_12_sub_pixel_variance8x16,
2879 aom_highbd_12_sub_pixel_avg_variance8x16,
2880 aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12,
2881 aom_highbd_sad8x16x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002882
2883 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002884 BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12,
2885 aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8,
2886 aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12,
2887 aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002888
Yaowu Xuf883b422016-08-30 14:01:10 -07002889 HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12,
2890 aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4,
2891 aom_highbd_12_sub_pixel_variance8x4,
2892 aom_highbd_12_sub_pixel_avg_variance8x4, NULL,
2893 aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002894
Yaowu Xuf883b422016-08-30 14:01:10 -07002895 HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12,
2896 aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8,
2897 aom_highbd_12_sub_pixel_variance4x8,
2898 aom_highbd_12_sub_pixel_avg_variance4x8, NULL,
2899 aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002900
2901 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002902 BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12,
2903 aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4,
2904 aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12,
2905 aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002906
2907#if CONFIG_EXT_PARTITION
2908 HIGHBD_BFP(
Yaowu Xuf883b422016-08-30 14:01:10 -07002909 BLOCK_128X128, aom_highbd_sad128x128_bits12,
2910 aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128,
2911 aom_highbd_12_sub_pixel_variance128x128,
2912 aom_highbd_12_sub_pixel_avg_variance128x128,
2913 aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12,
2914 aom_highbd_sad128x128x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002915
Yaowu Xuf883b422016-08-30 14:01:10 -07002916 HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12,
2917 aom_highbd_sad128x64_avg_bits12,
2918 aom_highbd_12_variance128x64,
2919 aom_highbd_12_sub_pixel_variance128x64,
2920 aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL,
2921 aom_highbd_sad128x64x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002922
Yaowu Xuf883b422016-08-30 14:01:10 -07002923 HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12,
2924 aom_highbd_sad64x128_avg_bits12,
2925 aom_highbd_12_variance64x128,
2926 aom_highbd_12_sub_pixel_variance64x128,
2927 aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL,
2928 aom_highbd_sad64x128x4d_bits12)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002929#endif // CONFIG_EXT_PARTITION
Cheng Chenbf3d4962017-11-01 14:48:52 -07002930#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07002931
Yaowu Xuc27fc142016-08-22 16:08:15 -07002932#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002933 HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12,
2934 aom_highbd_12_masked_sub_pixel_variance128x128)
2935 HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12,
2936 aom_highbd_12_masked_sub_pixel_variance128x64)
2937 HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12,
2938 aom_highbd_12_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07002939#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01002940 HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12,
2941 aom_highbd_12_masked_sub_pixel_variance64x64)
2942 HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12,
2943 aom_highbd_12_masked_sub_pixel_variance64x32)
2944 HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12,
2945 aom_highbd_12_masked_sub_pixel_variance32x64)
2946 HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12,
2947 aom_highbd_12_masked_sub_pixel_variance32x32)
2948 HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12,
2949 aom_highbd_12_masked_sub_pixel_variance32x16)
2950 HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12,
2951 aom_highbd_12_masked_sub_pixel_variance16x32)
2952 HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12,
2953 aom_highbd_12_masked_sub_pixel_variance16x16)
2954 HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12,
2955 aom_highbd_12_masked_sub_pixel_variance8x16)
2956 HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12,
2957 aom_highbd_12_masked_sub_pixel_variance16x8)
2958 HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12,
2959 aom_highbd_12_masked_sub_pixel_variance8x8)
2960 HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12,
2961 aom_highbd_12_masked_sub_pixel_variance4x8)
2962 HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12,
2963 aom_highbd_12_masked_sub_pixel_variance8x4)
2964 HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12,
2965 aom_highbd_12_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002966#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01002967#if CONFIG_EXT_PARTITION
2968 HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits12,
2969 aom_highbd_12_masked_sub_pixel_variance128x32)
2970
2971 HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits12,
2972 aom_highbd_12_masked_sub_pixel_variance32x128)
2973#endif // CONFIG_EXT_PARTITION
2974
Rupert Swarbrick72678572017-08-02 12:05:26 +01002975 HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12,
2976 aom_highbd_12_masked_sub_pixel_variance64x16)
2977
2978 HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12,
2979 aom_highbd_12_masked_sub_pixel_variance16x64)
2980
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01002981 HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12,
2982 aom_highbd_12_masked_sub_pixel_variance32x8)
2983
2984 HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12,
2985 aom_highbd_12_masked_sub_pixel_variance8x32)
2986
2987 HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12,
2988 aom_highbd_12_masked_sub_pixel_variance16x4)
2989
2990 HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12,
2991 aom_highbd_12_masked_sub_pixel_variance4x16)
2992#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07002993
Yaowu Xuc27fc142016-08-22 16:08:15 -07002994#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07002995 HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12,
2996 aom_highbd_12_obmc_variance128x128,
2997 aom_highbd_12_obmc_sub_pixel_variance128x128)
2998 HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12,
2999 aom_highbd_12_obmc_variance128x64,
3000 aom_highbd_12_obmc_sub_pixel_variance128x64)
3001 HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12,
3002 aom_highbd_12_obmc_variance64x128,
3003 aom_highbd_12_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003004#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003005 HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12,
3006 aom_highbd_12_obmc_variance64x64,
3007 aom_highbd_12_obmc_sub_pixel_variance64x64)
3008 HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12,
3009 aom_highbd_12_obmc_variance64x32,
3010 aom_highbd_12_obmc_sub_pixel_variance64x32)
3011 HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12,
3012 aom_highbd_12_obmc_variance32x64,
3013 aom_highbd_12_obmc_sub_pixel_variance32x64)
3014 HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12,
3015 aom_highbd_12_obmc_variance32x32,
3016 aom_highbd_12_obmc_sub_pixel_variance32x32)
3017 HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12,
3018 aom_highbd_12_obmc_variance32x16,
3019 aom_highbd_12_obmc_sub_pixel_variance32x16)
3020 HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12,
3021 aom_highbd_12_obmc_variance16x32,
3022 aom_highbd_12_obmc_sub_pixel_variance16x32)
3023 HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12,
3024 aom_highbd_12_obmc_variance16x16,
3025 aom_highbd_12_obmc_sub_pixel_variance16x16)
3026 HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12,
3027 aom_highbd_12_obmc_variance8x16,
3028 aom_highbd_12_obmc_sub_pixel_variance8x16)
3029 HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12,
3030 aom_highbd_12_obmc_variance16x8,
3031 aom_highbd_12_obmc_sub_pixel_variance16x8)
3032 HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12,
3033 aom_highbd_12_obmc_variance8x8,
3034 aom_highbd_12_obmc_sub_pixel_variance8x8)
3035 HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12,
3036 aom_highbd_12_obmc_variance4x8,
3037 aom_highbd_12_obmc_sub_pixel_variance4x8)
3038 HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12,
3039 aom_highbd_12_obmc_variance8x4,
3040 aom_highbd_12_obmc_sub_pixel_variance8x4)
3041 HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12,
3042 aom_highbd_12_obmc_variance4x4,
3043 aom_highbd_12_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003044#if CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003045#if CONFIG_EXT_PARTITION
3046 HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits12,
3047 aom_highbd_12_obmc_variance128x32,
3048 aom_highbd_12_obmc_sub_pixel_variance128x32)
3049
3050 HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits12,
3051 aom_highbd_12_obmc_variance32x128,
3052 aom_highbd_12_obmc_sub_pixel_variance32x128)
3053#endif // CONFIG_EXT_PARTITION
3054
Rupert Swarbrick72678572017-08-02 12:05:26 +01003055 HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12,
3056 aom_highbd_12_obmc_variance64x16,
3057 aom_highbd_12_obmc_sub_pixel_variance64x16)
3058
3059 HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12,
3060 aom_highbd_12_obmc_variance16x64,
3061 aom_highbd_12_obmc_sub_pixel_variance16x64)
3062
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003063 HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12,
3064 aom_highbd_12_obmc_variance32x8,
3065 aom_highbd_12_obmc_sub_pixel_variance32x8)
3066
3067 HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12,
3068 aom_highbd_12_obmc_variance8x32,
3069 aom_highbd_12_obmc_sub_pixel_variance8x32)
3070
3071 HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12,
3072 aom_highbd_12_obmc_variance16x4,
3073 aom_highbd_12_obmc_sub_pixel_variance16x4)
3074
3075 HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12,
3076 aom_highbd_12_obmc_variance4x16,
3077 aom_highbd_12_obmc_sub_pixel_variance4x16)
3078#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003079 break;
3080
3081 default:
3082 assert(0 &&
Yaowu Xuf883b422016-08-30 14:01:10 -07003083 "cm->bit_depth should be AOM_BITS_8, "
3084 "AOM_BITS_10 or AOM_BITS_12");
Yaowu Xuc27fc142016-08-22 16:08:15 -07003085 }
3086 }
3087}
Yaowu Xuc27fc142016-08-22 16:08:15 -07003088
Yaowu Xuf883b422016-08-30 14:01:10 -07003089static void realloc_segmentation_maps(AV1_COMP *cpi) {
3090 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003091
3092 // Create the encoder segmentation map and set all entries to 0
Yaowu Xuf883b422016-08-30 14:01:10 -07003093 aom_free(cpi->segmentation_map);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003094 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
Yaowu Xuf883b422016-08-30 14:01:10 -07003095 aom_calloc(cm->mi_rows * cm->mi_cols, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003096
3097 // Create a map used for cyclic background refresh.
Yaowu Xuf883b422016-08-30 14:01:10 -07003098 if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003099 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
Yaowu Xuf883b422016-08-30 14:01:10 -07003100 av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003101
3102 // Create a map used to mark inactive areas.
Yaowu Xuf883b422016-08-30 14:01:10 -07003103 aom_free(cpi->active_map.map);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003104 CHECK_MEM_ERROR(cm, cpi->active_map.map,
Yaowu Xuf883b422016-08-30 14:01:10 -07003105 aom_calloc(cm->mi_rows * cm->mi_cols, 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003106}
3107
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003108void set_compound_tools(AV1_COMMON *cm) {
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003109 cm->allow_interintra_compound = 1;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003110 cm->allow_masked_compound = 1;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003111}
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003112
Yaowu Xuf883b422016-08-30 14:01:10 -07003113void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) {
3114 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003115 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003116 RATE_CONTROL *const rc = &cpi->rc;
hui sud9a812b2017-07-06 14:34:37 -07003117 MACROBLOCK *const x = &cpi->td.mb;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003118
3119 if (cm->profile != oxcf->profile) cm->profile = oxcf->profile;
3120 cm->bit_depth = oxcf->bit_depth;
Andrey Norkin9e694632017-12-21 18:50:57 -08003121#if CONFIG_CICP
3122 cm->color_primaries = oxcf->color_primaries;
3123 cm->transfer_characteristics = oxcf->transfer_characteristics;
3124 cm->matrix_coefficients = oxcf->matrix_coefficients;
3125#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07003126 cm->color_space = oxcf->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08003127#endif
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08003128#if CONFIG_MONO_VIDEO
3129 cm->seq_params.monochrome = oxcf->monochrome;
3130#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07003131#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08003132#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07003133 cm->transfer_function = oxcf->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08003134#endif
anorkin76fb1262017-03-22 15:12:12 -07003135 cm->chroma_sample_position = oxcf->chroma_sample_position;
3136#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003137 cm->color_range = oxcf->color_range;
3138
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08003139 assert(IMPLIES(cm->profile <= PROFILE_1, cm->bit_depth <= AOM_BITS_10));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003140
Andrey Norkin28e9ce22018-01-08 10:11:21 -08003141#if CONFIG_TIMING_INFO_IN_SEQ_HEADERS
3142 cm->timing_info_present = oxcf->timing_info_present;
3143 cm->num_units_in_tick = oxcf->num_units_in_tick;
3144 cm->time_scale = oxcf->time_scale;
3145 cm->equal_picture_interval = oxcf->equal_picture_interval;
3146 cm->num_ticks_per_picture = oxcf->num_ticks_per_picture;
3147#endif
3148
Andrey Norkin6f1c2f72018-01-15 20:08:52 -08003149#if CONFIG_FILM_GRAIN
3150 update_film_grain_parameters(cpi, oxcf);
3151#endif
3152
Yaowu Xuc27fc142016-08-22 16:08:15 -07003153 cpi->oxcf = *oxcf;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +01003154 cpi->common.options = oxcf->cfg;
hui sud9a812b2017-07-06 14:34:37 -07003155 x->e_mbd.bd = (int)cm->bit_depth;
hui sud9a812b2017-07-06 14:34:37 -07003156 x->e_mbd.global_motion = cm->global_motion;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003157
Yaowu Xuf883b422016-08-30 14:01:10 -07003158 if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07003159 rc->baseline_gf_interval = FIXED_GF_INTERVAL;
3160 } else {
3161 rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2;
3162 }
3163
3164 cpi->refresh_last_frame = 1;
3165 cpi->refresh_golden_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003166 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07003167 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003168
3169 cm->refresh_frame_context =
3170 (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode)
3171 ? REFRESH_FRAME_CONTEXT_FORWARD
3172 : REFRESH_FRAME_CONTEXT_BACKWARD;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01003173#if CONFIG_EXT_TILE
3174 if (oxcf->large_scale_tile)
3175 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
3176#endif // CONFIG_EXT_TILE
3177
Thomas Daedea6a854b2017-06-22 17:49:11 -07003178#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07003179 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
Thomas Daedea6a854b2017-06-22 17:49:11 -07003180#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003181
Alex Converse74ad0912017-07-18 10:22:58 -07003182 if (x->palette_buffer == NULL) {
hui sud9a812b2017-07-06 14:34:37 -07003183 CHECK_MEM_ERROR(cm, x->palette_buffer,
3184 aom_memalign(16, sizeof(*x->palette_buffer)));
3185 }
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07003186 set_compound_tools(cm);
Yaowu Xuf883b422016-08-30 14:01:10 -07003187 av1_reset_segment_features(cm);
RogerZhou3b635242017-09-19 10:06:46 -07003188#if CONFIG_AMVR
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07003189 set_high_precision_mv(cpi, 1, 0);
RogerZhou3b635242017-09-19 10:06:46 -07003190#else
Debargha Mukherjeeb2147752017-11-01 07:00:45 -07003191 set_high_precision_mv(cpi, 1);
RogerZhou3b635242017-09-19 10:06:46 -07003192#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003193
Yaowu Xuc27fc142016-08-22 16:08:15 -07003194 set_rc_buffer_sizes(rc, &cpi->oxcf);
3195
3196 // Under a configuration change, where maximum_buffer_size may change,
3197 // keep buffer level clipped to the maximum allowed buffer size.
Yaowu Xuf883b422016-08-30 14:01:10 -07003198 rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size);
3199 rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003200
3201 // Set up frame rate and related parameters rate control values.
Yaowu Xuf883b422016-08-30 14:01:10 -07003202 av1_new_framerate(cpi, cpi->framerate);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003203
3204 // Set absolute upper and lower quality limits
3205 rc->worst_quality = cpi->oxcf.worst_allowed_q;
3206 rc->best_quality = cpi->oxcf.best_allowed_q;
3207
Yunqing Wangb6e23bc2017-11-15 13:18:55 -08003208#if CONFIG_EXT_TILE
3209 if (!oxcf->large_scale_tile)
3210#endif // CONFIG_EXT_TILE
3211 cm->interp_filter = cpi->sf.default_interp_filter;
3212#if CONFIG_EXT_TILE
3213 else
3214 cm->interp_filter = EIGHTTAP_REGULAR;
3215#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07003216
3217 if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) {
3218 cm->render_width = cpi->oxcf.render_width;
3219 cm->render_height = cpi->oxcf.render_height;
3220 } else {
3221 cm->render_width = cpi->oxcf.width;
3222 cm->render_height = cpi->oxcf.height;
3223 }
3224 cm->width = cpi->oxcf.width;
3225 cm->height = cpi->oxcf.height;
3226
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003227 int sb_size = cm->seq_params.sb_size;
3228 set_sb_size(&cm->seq_params, select_sb_size(cpi));
Dominic Symes917d6c02017-10-11 18:00:52 +02003229
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003230 if (cpi->initial_width || sb_size != cm->seq_params.sb_size) {
Dominic Symes917d6c02017-10-11 18:00:52 +02003231 if (cm->width > cpi->initial_width || cm->height > cpi->initial_height ||
Imdad Sardharwalla4ec84ab2018-02-06 12:20:18 +00003232 cm->seq_params.sb_size != sb_size) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003233 av1_free_context_buffers(cm);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003234 av1_free_pc_tree(&cpi->td, num_planes);
Cheng Chen46f30c72017-09-07 11:13:33 -07003235 alloc_compressor_data(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003236 realloc_segmentation_maps(cpi);
3237 cpi->initial_width = cpi->initial_height = 0;
3238 }
3239 }
3240 update_frame_size(cpi);
3241
3242 cpi->alt_ref_source = NULL;
3243 rc->is_src_frame_alt_ref = 0;
3244
Yaowu Xuc27fc142016-08-22 16:08:15 -07003245 rc->is_bwd_ref_frame = 0;
3246 rc->is_last_bipred_frame = 0;
3247 rc->is_bipred_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003248
Yaowu Xuc27fc142016-08-22 16:08:15 -07003249 set_tile_info(cpi);
3250
3251 cpi->ext_refresh_frame_flags_pending = 0;
3252 cpi->ext_refresh_frame_context_pending = 0;
3253
Yaowu Xuc27fc142016-08-22 16:08:15 -07003254 highbd_set_var_fns(cpi);
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00003255
3256 cm->seq_params.force_screen_content_tools = 2;
RogerZhou3b635242017-09-19 10:06:46 -07003257#if CONFIG_AMVR
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00003258 cm->seq_params.force_integer_mv = 2;
RogerZhou3b635242017-09-19 10:06:46 -07003259#endif
Joe Youngdb5eb4c2018-02-16 17:30:40 -08003260#if CONFIG_INTRA_EDGE2
3261 cm->disable_intra_edge_filter = 0;
3262#endif // CONFIG_INTRA_EDGE2
Yaowu Xuc27fc142016-08-22 16:08:15 -07003263}
3264
Yaowu Xuf883b422016-08-30 14:01:10 -07003265AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
3266 BufferPool *const pool) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07003267 unsigned int i;
Yaowu Xuf883b422016-08-30 14:01:10 -07003268 AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP));
3269 AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003270
3271 if (!cm) return NULL;
3272
Yaowu Xuf883b422016-08-30 14:01:10 -07003273 av1_zero(*cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003274
3275 if (setjmp(cm->error.jmp)) {
3276 cm->error.setjmp = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -07003277 av1_remove_compressor(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003278 return 0;
3279 }
3280
3281 cm->error.setjmp = 1;
Cheng Chen46f30c72017-09-07 11:13:33 -07003282 cm->alloc_mi = enc_alloc_mi;
3283 cm->free_mi = enc_free_mi;
3284 cm->setup_mi = enc_setup_mi;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003285
Angie Chianga5d96c42016-10-21 16:16:56 -07003286 CHECK_MEM_ERROR(cm, cm->fc,
3287 (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc)));
3288 CHECK_MEM_ERROR(cm, cm->frame_contexts,
3289 (FRAME_CONTEXT *)aom_memalign(
3290 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)));
3291 memset(cm->fc, 0, sizeof(*cm->fc));
3292 memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003293
3294 cpi->resize_state = 0;
3295 cpi->resize_avg_qp = 0;
3296 cpi->resize_buffer_underflow = 0;
Fergus Simpsonddc846e2017-04-24 18:09:13 -07003297
Yaowu Xuc27fc142016-08-22 16:08:15 -07003298 cpi->common.buffer_pool = pool;
3299
3300 init_config(cpi, oxcf);
Yaowu Xuf883b422016-08-30 14:01:10 -07003301 av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003302
3303 cm->current_video_frame = 0;
3304 cpi->partition_search_skippable_frame = 0;
3305 cpi->tile_data = NULL;
3306 cpi->last_show_frame_buf_idx = INVALID_IDX;
3307
3308 realloc_segmentation_maps(cpi);
3309
James Zern01a9d702017-08-25 19:09:33 +00003310 for (i = 0; i < NMV_CONTEXTS; ++i) {
3311 memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs));
3312 memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp));
3313 }
3314
Yaowu Xuc27fc142016-08-22 16:08:15 -07003315 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]));
3316 i++) {
3317 CHECK_MEM_ERROR(
3318 cm, cpi->mbgraph_stats[i].mb_stats,
Yaowu Xuf883b422016-08-30 14:01:10 -07003319 aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003320 }
3321
3322#if CONFIG_FP_MB_STATS
3323 cpi->use_fp_mb_stats = 0;
3324 if (cpi->use_fp_mb_stats) {
3325 // a place holder used to store the first pass mb stats in the first pass
3326 CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf,
Yaowu Xuf883b422016-08-30 14:01:10 -07003327 aom_calloc(cm->MBs * sizeof(uint8_t), 1));
Yaowu Xuc27fc142016-08-22 16:08:15 -07003328 } else {
3329 cpi->twopass.frame_mb_stats_buf = NULL;
3330 }
3331#endif
3332
3333 cpi->refresh_alt_ref_frame = 0;
3334 cpi->multi_arf_last_grp_enabled = 0;
3335
3336 cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
3337#if CONFIG_INTERNAL_STATS
3338 cpi->b_calculate_blockiness = 1;
3339 cpi->b_calculate_consistency = 1;
3340 cpi->total_inconsistency = 0;
3341 cpi->psnr.worst = 100.0;
3342 cpi->worst_ssim = 100.0;
3343
3344 cpi->count = 0;
3345 cpi->bytes = 0;
3346
3347 if (cpi->b_calculate_psnr) {
3348 cpi->total_sq_error = 0;
3349 cpi->total_samples = 0;
3350 cpi->tot_recode_hits = 0;
3351 cpi->summed_quality = 0;
3352 cpi->summed_weights = 0;
3353 }
3354
3355 cpi->fastssim.worst = 100.0;
3356 cpi->psnrhvs.worst = 100.0;
3357
3358 if (cpi->b_calculate_blockiness) {
3359 cpi->total_blockiness = 0;
3360 cpi->worst_blockiness = 0.0;
3361 }
3362
3363 if (cpi->b_calculate_consistency) {
3364 CHECK_MEM_ERROR(cm, cpi->ssim_vars,
Yaowu Xuf883b422016-08-30 14:01:10 -07003365 aom_malloc(sizeof(*cpi->ssim_vars) * 4 *
Yaowu Xuc27fc142016-08-22 16:08:15 -07003366 cpi->common.mi_rows * cpi->common.mi_cols));
3367 cpi->worst_consistency = 100.0;
3368 }
3369#endif
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003370#if CONFIG_ENTROPY_STATS
3371 av1_zero(aggregate_fc);
Zoe Liua56f9162017-06-21 22:49:57 -07003372 av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003373#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003374
3375 cpi->first_time_stamp_ever = INT64_MAX;
3376
James Zern01a9d702017-08-25 19:09:33 +00003377 for (i = 0; i < NMV_CONTEXTS; ++i) {
3378 cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX];
3379 cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX];
3380 cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX];
3381 cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX];
3382 }
3383
Yaowu Xuc27fc142016-08-22 16:08:15 -07003384#ifdef OUTPUT_YUV_SKINMAP
3385 yuv_skinmap_file = fopen("skinmap.yuv", "ab");
3386#endif
3387#ifdef OUTPUT_YUV_REC
3388 yuv_rec_file = fopen("rec.yuv", "wb");
3389#endif
3390
3391#if 0
3392 framepsnr = fopen("framepsnr.stt", "a");
3393 kf_list = fopen("kf_list.stt", "w");
3394#endif
3395
Yaowu Xuc27fc142016-08-22 16:08:15 -07003396 if (oxcf->pass == 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003397 av1_init_first_pass(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003398 } else if (oxcf->pass == 2) {
3399 const size_t packet_sz = sizeof(FIRSTPASS_STATS);
3400 const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
3401
3402#if CONFIG_FP_MB_STATS
3403 if (cpi->use_fp_mb_stats) {
3404 const size_t psz = cpi->common.MBs * sizeof(uint8_t);
3405 const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz);
3406
3407 cpi->twopass.firstpass_mb_stats.mb_stats_start =
3408 oxcf->firstpass_mb_stats_in.buf;
3409 cpi->twopass.firstpass_mb_stats.mb_stats_end =
3410 cpi->twopass.firstpass_mb_stats.mb_stats_start +
3411 (ps - 1) * cpi->common.MBs * sizeof(uint8_t);
3412 }
3413#endif
3414
3415 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
3416 cpi->twopass.stats_in = cpi->twopass.stats_in_start;
3417 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1];
3418
Yaowu Xuf883b422016-08-30 14:01:10 -07003419 av1_init_second_pass(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003420 }
3421
Jingning Hand064cf02017-06-01 10:00:39 -07003422 int buf_scaler = 2;
Jingning Hand064cf02017-06-01 10:00:39 -07003423 CHECK_MEM_ERROR(
3424 cm, cpi->td.mb.above_pred_buf,
Johannb0ef6ff2018-02-08 14:32:21 -08003425 (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE *
3426 sizeof(*cpi->td.mb.above_pred_buf)));
Jingning Hand064cf02017-06-01 10:00:39 -07003427 CHECK_MEM_ERROR(
3428 cm, cpi->td.mb.left_pred_buf,
Johannb0ef6ff2018-02-08 14:32:21 -08003429 (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE *
3430 sizeof(*cpi->td.mb.left_pred_buf)));
Jingning Hand064cf02017-06-01 10:00:39 -07003431
3432 CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf,
3433 (int32_t *)aom_memalign(
3434 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf)));
3435
3436 CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf,
3437 (int32_t *)aom_memalign(
3438 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf)));
3439
Yaowu Xuf883b422016-08-30 14:01:10 -07003440 av1_set_speed_features_framesize_independent(cpi);
3441 av1_set_speed_features_framesize_dependent(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003442
Cheng Chenf78632e2017-10-20 15:30:51 -07003443#if CONFIG_JNT_COMP
3444#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, JSVAF) \
3445 cpi->fn_ptr[BT].sdf = SDF; \
3446 cpi->fn_ptr[BT].sdaf = SDAF; \
3447 cpi->fn_ptr[BT].vf = VF; \
3448 cpi->fn_ptr[BT].svf = SVF; \
3449 cpi->fn_ptr[BT].svaf = SVAF; \
3450 cpi->fn_ptr[BT].sdx3f = SDX3F; \
3451 cpi->fn_ptr[BT].sdx8f = SDX8F; \
3452 cpi->fn_ptr[BT].sdx4df = SDX4DF; \
3453 cpi->fn_ptr[BT].jsdaf = JSDAF; \
3454 cpi->fn_ptr[BT].jsvaf = JSVAF;
3455#else // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07003456#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
3457 cpi->fn_ptr[BT].sdf = SDF; \
3458 cpi->fn_ptr[BT].sdaf = SDAF; \
3459 cpi->fn_ptr[BT].vf = VF; \
3460 cpi->fn_ptr[BT].svf = SVF; \
3461 cpi->fn_ptr[BT].svaf = SVAF; \
3462 cpi->fn_ptr[BT].sdx3f = SDX3F; \
3463 cpi->fn_ptr[BT].sdx8f = SDX8F; \
3464 cpi->fn_ptr[BT].sdx4df = SDX4DF;
Cheng Chenf78632e2017-10-20 15:30:51 -07003465#endif // CONFIG_JNT_COMP
Yaowu Xuc27fc142016-08-22 16:08:15 -07003466
Cheng Chenf78632e2017-10-20 15:30:51 -07003467#if CONFIG_JNT_COMP
3468#if CONFIG_EXT_PARTITION_TYPES
3469 BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16,
3470 aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003471 aom_sad4x16x4d, aom_jnt_sad4x16_avg, aom_jnt_sub_pixel_avg_variance4x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003472
3473 BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4,
3474 aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003475 aom_sad16x4x4d, aom_jnt_sad16x4_avg, aom_jnt_sub_pixel_avg_variance16x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003476
3477 BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32,
3478 aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003479 aom_sad8x32x4d, aom_jnt_sad8x32_avg, aom_jnt_sub_pixel_avg_variance8x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003480
3481 BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8,
3482 aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003483 aom_sad32x8x4d, aom_jnt_sad32x8_avg, aom_jnt_sub_pixel_avg_variance32x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003484
3485 BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64,
3486 aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003487 aom_sad16x64x4d, aom_jnt_sad16x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003488 aom_jnt_sub_pixel_avg_variance16x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003489
3490 BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16,
3491 aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003492 aom_sad64x16x4d, aom_jnt_sad64x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003493 aom_jnt_sub_pixel_avg_variance64x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003494
3495#if CONFIG_EXT_PARTITION
3496 BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128,
3497 aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003498 NULL, aom_sad32x128x4d, aom_jnt_sad32x128_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003499 aom_jnt_sub_pixel_avg_variance32x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003500
3501 BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32,
3502 aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003503 NULL, aom_sad128x32x4d, aom_jnt_sad128x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003504 aom_jnt_sub_pixel_avg_variance128x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003505#endif // CONFIG_EXT_PARTITION
3506#endif // CONFIG_EXT_PARTITION_TYPES
3507
3508#if CONFIG_EXT_PARTITION
3509 BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128,
3510 aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128,
3511 aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d,
Cheng Chend0179a62017-11-16 17:02:53 -08003512 aom_jnt_sad128x128_avg, aom_jnt_sub_pixel_avg_variance128x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003513
3514 BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64,
3515 aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003516 NULL, aom_sad128x64x4d, aom_jnt_sad128x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003517 aom_jnt_sub_pixel_avg_variance128x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003518
3519 BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128,
3520 aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003521 NULL, aom_sad64x128x4d, aom_jnt_sad64x128_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003522 aom_jnt_sub_pixel_avg_variance64x128)
Cheng Chenf78632e2017-10-20 15:30:51 -07003523#endif // CONFIG_EXT_PARTITION
3524
3525 BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16,
3526 aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003527 aom_sad32x16x4d, aom_jnt_sad32x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003528 aom_jnt_sub_pixel_avg_variance32x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003529
3530 BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32,
3531 aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003532 aom_sad16x32x4d, aom_jnt_sad16x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003533 aom_jnt_sub_pixel_avg_variance16x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003534
3535 BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32,
3536 aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003537 aom_sad64x32x4d, aom_jnt_sad64x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003538 aom_jnt_sub_pixel_avg_variance64x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003539
3540 BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64,
3541 aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003542 aom_sad32x64x4d, aom_jnt_sad32x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003543 aom_jnt_sub_pixel_avg_variance32x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003544
3545 BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32,
3546 aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32,
Cheng Chend0179a62017-11-16 17:02:53 -08003547 aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d, aom_jnt_sad32x32_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003548 aom_jnt_sub_pixel_avg_variance32x32)
Cheng Chenf78632e2017-10-20 15:30:51 -07003549
3550 BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64,
3551 aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64,
Cheng Chend0179a62017-11-16 17:02:53 -08003552 aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d, aom_jnt_sad64x64_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003553 aom_jnt_sub_pixel_avg_variance64x64)
Cheng Chenf78632e2017-10-20 15:30:51 -07003554
3555 BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16,
3556 aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16,
Cheng Chend0179a62017-11-16 17:02:53 -08003557 aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d, aom_jnt_sad16x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003558 aom_jnt_sub_pixel_avg_variance16x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003559
3560 BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8,
3561 aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003562 aom_sad16x8x8, aom_sad16x8x4d, aom_jnt_sad16x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003563 aom_jnt_sub_pixel_avg_variance16x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003564
3565 BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16,
3566 aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003567 aom_sad8x16x8, aom_sad8x16x4d, aom_jnt_sad8x16_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003568 aom_jnt_sub_pixel_avg_variance8x16)
Cheng Chenf78632e2017-10-20 15:30:51 -07003569
3570 BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8,
3571 aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003572 aom_sad8x8x8, aom_sad8x8x4d, aom_jnt_sad8x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003573 aom_jnt_sub_pixel_avg_variance8x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003574
3575 BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4,
3576 aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003577 aom_sad8x4x8, aom_sad8x4x4d, aom_jnt_sad8x4_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003578 aom_jnt_sub_pixel_avg_variance8x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003579
3580 BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8,
3581 aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL,
Cheng Chend0179a62017-11-16 17:02:53 -08003582 aom_sad4x8x8, aom_sad4x8x4d, aom_jnt_sad4x8_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003583 aom_jnt_sub_pixel_avg_variance4x8)
Cheng Chenf78632e2017-10-20 15:30:51 -07003584
3585 BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4,
3586 aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
Cheng Chend0179a62017-11-16 17:02:53 -08003587 aom_sad4x4x8, aom_sad4x4x4d, aom_jnt_sad4x4_avg,
Cheng Chend2864432017-11-17 17:59:24 -08003588 aom_jnt_sub_pixel_avg_variance4x4)
Cheng Chenf78632e2017-10-20 15:30:51 -07003589
Cheng Chenf78632e2017-10-20 15:30:51 -07003590#else // CONFIG_JNT_COMP
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003591#if CONFIG_EXT_PARTITION_TYPES
3592 BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16,
3593 aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL,
3594 aom_sad4x16x4d)
3595
3596 BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4,
3597 aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL,
3598 aom_sad16x4x4d)
3599
3600 BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32,
3601 aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL,
3602 aom_sad8x32x4d)
3603
3604 BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8,
3605 aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL,
3606 aom_sad32x8x4d)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003607
3608 BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64,
3609 aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL,
3610 aom_sad16x64x4d)
3611
3612 BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16,
3613 aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL,
3614 aom_sad64x16x4d)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003615
3616#if CONFIG_EXT_PARTITION
3617 BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128,
3618 aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL,
3619 NULL, aom_sad32x128x4d)
3620
3621 BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32,
3622 aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL,
3623 NULL, aom_sad128x32x4d)
3624#endif // CONFIG_EXT_PARTITION
3625#endif // CONFIG_EXT_PARTITION_TYPES
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003626
Yaowu Xuc27fc142016-08-22 16:08:15 -07003627#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003628 BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128,
3629 aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128,
3630 aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003631
Yaowu Xuf883b422016-08-30 14:01:10 -07003632 BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64,
3633 aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL,
3634 NULL, aom_sad128x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003635
Yaowu Xuf883b422016-08-30 14:01:10 -07003636 BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128,
3637 aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL,
3638 NULL, aom_sad64x128x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003639#endif // CONFIG_EXT_PARTITION
3640
Yaowu Xuf883b422016-08-30 14:01:10 -07003641 BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16,
3642 aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL,
3643 aom_sad32x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003644
Yaowu Xuf883b422016-08-30 14:01:10 -07003645 BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32,
3646 aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL,
3647 aom_sad16x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003648
Yaowu Xuf883b422016-08-30 14:01:10 -07003649 BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32,
3650 aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL,
3651 aom_sad64x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003652
Yaowu Xuf883b422016-08-30 14:01:10 -07003653 BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64,
3654 aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL,
3655 aom_sad32x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003656
Yaowu Xuf883b422016-08-30 14:01:10 -07003657 BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32,
3658 aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32,
3659 aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003660
Yaowu Xuf883b422016-08-30 14:01:10 -07003661 BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64,
3662 aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64,
3663 aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003664
Yaowu Xuf883b422016-08-30 14:01:10 -07003665 BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16,
3666 aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16,
3667 aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003668
Yaowu Xuf883b422016-08-30 14:01:10 -07003669 BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8,
3670 aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3,
3671 aom_sad16x8x8, aom_sad16x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003672
Yaowu Xuf883b422016-08-30 14:01:10 -07003673 BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16,
3674 aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3,
3675 aom_sad8x16x8, aom_sad8x16x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003676
Yaowu Xuf883b422016-08-30 14:01:10 -07003677 BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8,
3678 aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3,
3679 aom_sad8x8x8, aom_sad8x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003680
Yaowu Xuf883b422016-08-30 14:01:10 -07003681 BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4,
3682 aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL,
3683 aom_sad8x4x8, aom_sad8x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003684
Yaowu Xuf883b422016-08-30 14:01:10 -07003685 BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8,
3686 aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL,
3687 aom_sad4x8x8, aom_sad4x8x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003688
Yaowu Xuf883b422016-08-30 14:01:10 -07003689 BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4,
3690 aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3,
3691 aom_sad4x4x8, aom_sad4x4x4d)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003692
Cheng Chenf78632e2017-10-20 15:30:51 -07003693#endif // CONFIG_JNT_COMP
Jingning Han9e7c49f2016-12-06 11:20:10 -08003694
Yaowu Xuc27fc142016-08-22 16:08:15 -07003695#define OBFP(BT, OSDF, OVF, OSVF) \
3696 cpi->fn_ptr[BT].osdf = OSDF; \
3697 cpi->fn_ptr[BT].ovf = OVF; \
3698 cpi->fn_ptr[BT].osvf = OSVF;
3699
3700#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003701 OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128,
3702 aom_obmc_sub_pixel_variance128x128)
3703 OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64,
3704 aom_obmc_sub_pixel_variance128x64)
3705 OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128,
3706 aom_obmc_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003707#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -07003708 OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64,
3709 aom_obmc_sub_pixel_variance64x64)
3710 OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32,
3711 aom_obmc_sub_pixel_variance64x32)
3712 OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64,
3713 aom_obmc_sub_pixel_variance32x64)
3714 OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32,
3715 aom_obmc_sub_pixel_variance32x32)
3716 OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16,
3717 aom_obmc_sub_pixel_variance32x16)
3718 OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32,
3719 aom_obmc_sub_pixel_variance16x32)
3720 OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16,
3721 aom_obmc_sub_pixel_variance16x16)
3722 OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8,
3723 aom_obmc_sub_pixel_variance16x8)
3724 OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16,
3725 aom_obmc_sub_pixel_variance8x16)
3726 OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8,
3727 aom_obmc_sub_pixel_variance8x8)
3728 OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8,
3729 aom_obmc_sub_pixel_variance4x8)
3730 OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4,
3731 aom_obmc_sub_pixel_variance8x4)
3732 OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4,
3733 aom_obmc_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003734
3735#if CONFIG_EXT_PARTITION_TYPES
3736 OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16,
3737 aom_obmc_sub_pixel_variance4x16)
3738
3739 OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4,
3740 aom_obmc_sub_pixel_variance16x4)
3741
3742 OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32,
3743 aom_obmc_sub_pixel_variance8x32)
3744
3745 OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8,
3746 aom_obmc_sub_pixel_variance32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003747
3748 OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64,
3749 aom_obmc_sub_pixel_variance16x64)
3750
3751 OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16,
3752 aom_obmc_sub_pixel_variance64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003753
3754#if CONFIG_EXT_PARTITION
3755 OBFP(BLOCK_32X128, aom_obmc_sad32x128, aom_obmc_variance32x128,
3756 aom_obmc_sub_pixel_variance32x128)
3757
3758 OBFP(BLOCK_128X32, aom_obmc_sad128x32, aom_obmc_variance128x32,
3759 aom_obmc_sub_pixel_variance128x32)
3760#endif // CONFIG_EXT_PARTITION
3761#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003762
David Barkerf19f35f2017-05-22 16:33:22 +01003763#define MBFP(BT, MCSDF, MCSVF) \
3764 cpi->fn_ptr[BT].msdf = MCSDF; \
3765 cpi->fn_ptr[BT].msvf = MCSVF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003766
3767#if CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01003768 MBFP(BLOCK_128X128, aom_masked_sad128x128,
3769 aom_masked_sub_pixel_variance128x128)
3770 MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64)
3771 MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128)
Yaowu Xuc27fc142016-08-22 16:08:15 -07003772#endif // CONFIG_EXT_PARTITION
David Barkerf19f35f2017-05-22 16:33:22 +01003773 MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64)
3774 MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32)
3775 MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64)
3776 MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32)
3777 MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16)
3778 MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32)
3779 MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16)
3780 MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8)
3781 MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16)
3782 MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8)
3783 MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8)
3784 MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4)
3785 MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01003786
3787#if CONFIG_EXT_PARTITION_TYPES
3788 MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16)
3789
3790 MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4)
3791
3792 MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32)
3793
3794 MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8)
Rupert Swarbrick72678572017-08-02 12:05:26 +01003795
3796 MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64)
3797
3798 MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01003799
3800#if CONFIG_EXT_PARTITION
3801 MBFP(BLOCK_32X128, aom_masked_sad32x128, aom_masked_sub_pixel_variance32x128)
3802
3803 MBFP(BLOCK_128X32, aom_masked_sad128x32, aom_masked_sub_pixel_variance128x32)
3804#endif // CONFIG_EXT_PARTITION
3805#endif // CONFIG_EXT_PARTITION_TYPES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003806
Yaowu Xuc27fc142016-08-22 16:08:15 -07003807 highbd_set_var_fns(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003808
Yaowu Xuf883b422016-08-30 14:01:10 -07003809 /* av1_init_quantizer() is first called here. Add check in
3810 * av1_frame_init_quantizer() so that av1_init_quantizer is only
Yaowu Xuc27fc142016-08-22 16:08:15 -07003811 * called later when needed. This will avoid unnecessary calls of
Yaowu Xuf883b422016-08-30 14:01:10 -07003812 * av1_init_quantizer() for every frame.
Yaowu Xuc27fc142016-08-22 16:08:15 -07003813 */
Yaowu Xuf883b422016-08-30 14:01:10 -07003814 av1_init_quantizer(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003815#if CONFIG_AOM_QM
Zoe Liud902b742018-02-19 17:02:41 -08003816 av1_qm_init(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003817#endif
3818
Yaowu Xuf883b422016-08-30 14:01:10 -07003819 av1_loop_filter_init(cm);
Urvang Joshi94ad3702017-12-06 11:38:08 -08003820#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07003821 cm->superres_scale_denominator = SCALE_NUMERATOR;
Debargha Mukherjee29e40a62017-06-14 09:37:12 -07003822 cm->superres_upscaled_width = oxcf->width;
3823 cm->superres_upscaled_height = oxcf->height;
Urvang Joshi94ad3702017-12-06 11:38:08 -08003824#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Yaowu Xuc27fc142016-08-22 16:08:15 -07003825#if CONFIG_LOOP_RESTORATION
Yaowu Xuf883b422016-08-30 14:01:10 -07003826 av1_loop_restoration_precal();
Yaowu Xuc27fc142016-08-22 16:08:15 -07003827#endif // CONFIG_LOOP_RESTORATION
3828
3829 cm->error.setjmp = 0;
3830
3831 return cpi;
3832}
3833
3834#define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T))
3835
3836#define SNPRINT2(H, T, V) \
3837 snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V))
3838
Yaowu Xuf883b422016-08-30 14:01:10 -07003839void av1_remove_compressor(AV1_COMP *cpi) {
3840 AV1_COMMON *cm;
Yaowu Xuc27fc142016-08-22 16:08:15 -07003841 unsigned int i;
3842 int t;
3843
3844 if (!cpi) return;
3845
3846 cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003847 const int num_planes = av1_num_planes(cm);
3848
Yaowu Xuc27fc142016-08-22 16:08:15 -07003849 if (cm->current_video_frame > 0) {
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003850#if CONFIG_ENTROPY_STATS
3851 if (cpi->oxcf.pass != 1) {
3852 fprintf(stderr, "Writing counts.stt\n");
3853 FILE *f = fopen("counts.stt", "wb");
3854 fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f);
Zoe Liua56f9162017-06-21 22:49:57 -07003855 fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]),
3856 FRAME_CONTEXTS, f);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08003857 fclose(f);
3858 }
3859#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003860#if CONFIG_INTERNAL_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -07003861 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07003862
3863 if (cpi->oxcf.pass != 1) {
3864 char headings[512] = { 0 };
3865 char results[512] = { 0 };
3866 FILE *f = fopen("opsnr.stt", "a");
3867 double time_encoded =
3868 (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) /
3869 10000000.000;
3870 double total_encode_time =
3871 (cpi->time_receive_data + cpi->time_compress_data) / 1000.000;
3872 const double dr =
3873 (double)cpi->bytes * (double)8 / (double)1000 / time_encoded;
3874 const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1);
3875 const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000;
3876 const double rate_err = ((100.0 * (dr - target_rate)) / target_rate);
3877
3878 if (cpi->b_calculate_psnr) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003879 const double total_psnr = aom_sse_to_psnr(
Yaowu Xuc27fc142016-08-22 16:08:15 -07003880 (double)cpi->total_samples, peak, (double)cpi->total_sq_error);
3881 const double total_ssim =
3882 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0);
3883 snprintf(headings, sizeof(headings),
Jingning Han87651b22017-11-28 20:02:26 -08003884 "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t"
Yaowu Xuf883b422016-08-30 14:01:10 -07003885 "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t"
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003886 "WstPsnr\tWstSsim\tWstFast\tWstHVS\t"
Jingning Han87651b22017-11-28 20:02:26 -08003887 "AVPsrnY\tAPsnrCb\tAPsnrCr");
Yaowu Xuc27fc142016-08-22 16:08:15 -07003888 snprintf(results, sizeof(results),
3889 "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
3890 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003891 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
Jingning Han87651b22017-11-28 20:02:26 -08003892 "%7.3f\t%7.3f\t%7.3f",
Yaowu Xuc27fc142016-08-22 16:08:15 -07003893 dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr,
Jingning Han87651b22017-11-28 20:02:26 -08003894 cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003895 total_ssim, cpi->fastssim.stat[ALL] / cpi->count,
3896 cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst,
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003897 cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst,
Jingning Han87651b22017-11-28 20:02:26 -08003898 cpi->psnr.stat[Y] / cpi->count, cpi->psnr.stat[U] / cpi->count,
Jingning Hanbe1ae3f2017-11-27 10:27:56 -08003899 cpi->psnr.stat[V] / cpi->count);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003900
3901 if (cpi->b_calculate_blockiness) {
3902 SNPRINT(headings, "\t Block\tWstBlck");
3903 SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count);
3904 SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness);
3905 }
3906
3907 if (cpi->b_calculate_consistency) {
3908 double consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07003909 aom_sse_to_psnr((double)cpi->total_samples, peak,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003910 (double)cpi->total_inconsistency);
3911
3912 SNPRINT(headings, "\tConsist\tWstCons");
3913 SNPRINT2(results, "\t%7.3f", consistency);
3914 SNPRINT2(results, "\t%7.3f", cpi->worst_consistency);
3915 }
Sarah Parkerf97b7862016-08-25 17:42:57 -07003916 fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings);
3917 fprintf(f, "%s\t%8.0f\t%7.2f\t%7.2f\n", results, total_encode_time,
Yaowu Xuc27fc142016-08-22 16:08:15 -07003918 rate_err, fabs(rate_err));
3919 }
3920
3921 fclose(f);
3922 }
3923
3924#endif
3925
3926#if 0
3927 {
3928 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
3929 printf("\n_frames recive_data encod_mb_row compress_frame Total\n");
3930 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame,
3931 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000,
3932 cpi->time_compress_data / 1000,
3933 (cpi->time_receive_data + cpi->time_compress_data) / 1000);
3934 }
3935#endif
3936 }
3937
3938 for (t = 0; t < cpi->num_workers; ++t) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003939 AVxWorker *const worker = &cpi->workers[t];
Yaowu Xuc27fc142016-08-22 16:08:15 -07003940 EncWorkerData *const thread_data = &cpi->tile_thr_data[t];
3941
3942 // Deallocate allocated threads.
Yaowu Xuf883b422016-08-30 14:01:10 -07003943 aom_get_worker_interface()->end(worker);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003944
3945 // Deallocate allocated thread data.
3946 if (t < cpi->num_workers - 1) {
hui sud9a812b2017-07-06 14:34:37 -07003947 aom_free(thread_data->td->palette_buffer);
Jingning Hand064cf02017-06-01 10:00:39 -07003948 aom_free(thread_data->td->above_pred_buf);
3949 aom_free(thread_data->td->left_pred_buf);
3950 aom_free(thread_data->td->wsrc_buf);
3951 aom_free(thread_data->td->mask_buf);
Yaowu Xuf883b422016-08-30 14:01:10 -07003952 aom_free(thread_data->td->counts);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00003953 av1_free_pc_tree(thread_data->td, num_planes);
Yaowu Xuf883b422016-08-30 14:01:10 -07003954 aom_free(thread_data->td);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003955 }
3956 }
Yaowu Xuf883b422016-08-30 14:01:10 -07003957 aom_free(cpi->tile_thr_data);
3958 aom_free(cpi->workers);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003959
Yaowu Xuf883b422016-08-30 14:01:10 -07003960 if (cpi->num_workers > 1) av1_loop_filter_dealloc(&cpi->lf_row_sync);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003961
3962 dealloc_compressor_data(cpi);
3963
3964 for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]);
3965 ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003966 aom_free(cpi->mbgraph_stats[i].mb_stats);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003967 }
3968
3969#if CONFIG_FP_MB_STATS
3970 if (cpi->use_fp_mb_stats) {
Yaowu Xuf883b422016-08-30 14:01:10 -07003971 aom_free(cpi->twopass.frame_mb_stats_buf);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003972 cpi->twopass.frame_mb_stats_buf = NULL;
3973 }
3974#endif
Debargha Mukherjee5d157212017-01-10 14:44:47 -08003975#if CONFIG_INTERNAL_STATS
3976 aom_free(cpi->ssim_vars);
3977 cpi->ssim_vars = NULL;
3978#endif // CONFIG_INTERNAL_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07003979
Yaowu Xuf883b422016-08-30 14:01:10 -07003980 av1_remove_common(cm);
RogerZhou80d52342017-11-20 10:56:26 -08003981#if CONFIG_HASH_ME
3982 for (i = 0; i < FRAME_BUFFERS; ++i) {
3983 av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table);
3984 }
Michelle Findlay-Olynykdea531d2017-12-13 14:10:56 -08003985 if (cpi->sf.use_hash_based_trellis) hbt_destroy();
RogerZhou80d52342017-11-20 10:56:26 -08003986#endif // CONFIG_HASH_ME
Yaowu Xuf883b422016-08-30 14:01:10 -07003987 av1_free_ref_frame_buffers(cm->buffer_pool);
3988 aom_free(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07003989
3990#ifdef OUTPUT_YUV_SKINMAP
3991 fclose(yuv_skinmap_file);
3992#endif
3993#ifdef OUTPUT_YUV_REC
3994 fclose(yuv_rec_file);
3995#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07003996#if 0
3997
3998 if (keyfile)
3999 fclose(keyfile);
4000
4001 if (framepsnr)
4002 fclose(framepsnr);
4003
4004 if (kf_list)
4005 fclose(kf_list);
4006
4007#endif
4008}
4009
Yaowu Xuf883b422016-08-30 14:01:10 -07004010static void generate_psnr_packet(AV1_COMP *cpi) {
4011 struct aom_codec_cx_pkt pkt;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004012 int i;
4013 PSNR_STATS psnr;
Alex Conversef77fd0b2017-04-20 11:00:24 -07004014 aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004015 cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004016
4017 for (i = 0; i < 4; ++i) {
4018 pkt.data.psnr.samples[i] = psnr.samples[i];
4019 pkt.data.psnr.sse[i] = psnr.sse[i];
4020 pkt.data.psnr.psnr[i] = psnr.psnr[i];
4021 }
Yaowu Xuf883b422016-08-30 14:01:10 -07004022 pkt.kind = AOM_CODEC_PSNR_PKT;
4023 aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004024}
4025
Yaowu Xuf883b422016-08-30 14:01:10 -07004026int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004027 if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1;
4028
Yunqing Wangf2e7a392017-11-08 00:27:21 -08004029 cpi->ext_ref_frame_flags = ref_frame_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004030 return 0;
4031}
4032
Yunqing Wang9a50fec2017-11-02 17:02:00 -07004033void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) {
4034 cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0;
4035 cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0;
4036 cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0;
4037 cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0;
4038 cpi->ext_refresh_alt2_ref_frame = (ref_frame_upd_flags & AOM_ALT2_FLAG) != 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004039 cpi->ext_refresh_frame_flags_pending = 1;
4040}
4041
Thomas Daede497d1952017-08-08 17:33:06 -07004042int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) {
4043 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004044 const int num_planes = av1_num_planes(cm);
Thomas Daede497d1952017-08-08 17:33:06 -07004045 YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004046 if (cfg) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004047 aom_yv12_copy_frame(cfg, sd, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004048 return 0;
4049 } else {
4050 return -1;
4051 }
4052}
4053
Thomas Daede497d1952017-08-08 17:33:06 -07004054int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) {
4055 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004056 const int num_planes = av1_num_planes(cm);
Thomas Daede497d1952017-08-08 17:33:06 -07004057 YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx);
Yaowu Xuf883b422016-08-30 14:01:10 -07004058 if (cfg) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004059 aom_yv12_copy_frame(sd, cfg, num_planes);
Yaowu Xuf883b422016-08-30 14:01:10 -07004060 return 0;
4061 } else {
4062 return -1;
4063 }
4064}
4065
4066int av1_update_entropy(AV1_COMP *cpi, int update) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004067 cpi->ext_refresh_frame_context = update;
4068 cpi->ext_refresh_frame_context_pending = 1;
4069 return 0;
4070}
4071
4072#if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP)
4073// The denoiser buffer is allocated as a YUV 440 buffer. This function writes it
4074// as YUV 420. We simply use the top-left pixels of the UV buffers, since we do
4075// not denoise the UV channels at this time. If ever we implement UV channel
4076// denoising we will have to modify this.
Yaowu Xuf883b422016-08-30 14:01:10 -07004077void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004078 uint8_t *src = s->y_buffer;
4079 int h = s->y_height;
4080
4081 do {
4082 fwrite(src, s->y_width, 1, f);
4083 src += s->y_stride;
4084 } while (--h);
4085
4086 src = s->u_buffer;
4087 h = s->uv_height;
4088
4089 do {
4090 fwrite(src, s->uv_width, 1, f);
4091 src += s->uv_stride;
4092 } while (--h);
4093
4094 src = s->v_buffer;
4095 h = s->uv_height;
4096
4097 do {
4098 fwrite(src, s->uv_width, 1, f);
4099 src += s->uv_stride;
4100 } while (--h);
4101}
4102#endif
4103
Zoe Liu8dd1c982017-09-11 10:14:35 -07004104#if USE_GF16_MULTI_LAYER
4105static void check_show_existing_frame_gf16(AV1_COMP *cpi) {
4106 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
4107 AV1_COMMON *const cm = &cpi->common;
4108 const FRAME_UPDATE_TYPE next_frame_update_type =
4109 gf_group->update_type[gf_group->index];
4110
4111 if (cm->show_existing_frame == 1) {
4112 cm->show_existing_frame = 0;
4113 } else if (cpi->rc.is_last_bipred_frame) {
4114 cpi->rc.is_last_bipred_frame = 0;
4115 cm->show_existing_frame = 1;
4116 cpi->existing_fb_idx_to_show = cpi->bwd_fb_idx;
4117 } else if (next_frame_update_type == OVERLAY_UPDATE ||
4118 next_frame_update_type == INTNL_OVERLAY_UPDATE) {
4119 // Check the temporal filtering status for the next OVERLAY frame
4120 const int num_arfs_in_gf = cpi->num_extra_arfs + 1;
4121 int which_arf = 0, arf_idx;
4122 // Identify the index to the next overlay frame.
4123 for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) {
4124 if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) {
4125 which_arf = arf_idx;
4126 break;
4127 }
4128 }
4129 assert(arf_idx < num_arfs_in_gf);
4130 if (cpi->is_arf_filter_off[which_arf]) {
4131 cm->show_existing_frame = 1;
4132 cpi->rc.is_src_frame_alt_ref = 1;
4133 cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE)
4134 ? cpi->alt_fb_idx
4135 : cpi->bwd_fb_idx;
4136 cpi->is_arf_filter_off[which_arf] = 0;
4137 }
4138 }
4139 cpi->rc.is_src_frame_ext_arf = 0;
4140}
4141#endif // USE_GF16_MULTI_LAYER
4142
Yaowu Xuf883b422016-08-30 14:01:10 -07004143static void check_show_existing_frame(AV1_COMP *cpi) {
Zoe Liu8dd1c982017-09-11 10:14:35 -07004144#if USE_GF16_MULTI_LAYER
4145 if (cpi->rc.baseline_gf_interval == 16) {
4146 check_show_existing_frame_gf16(cpi);
4147 return;
4148 }
4149#endif // USE_GF16_MULTI_LAYER
4150
Yaowu Xuc27fc142016-08-22 16:08:15 -07004151 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
Yaowu Xuf883b422016-08-30 14:01:10 -07004152 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004153 const FRAME_UPDATE_TYPE next_frame_update_type =
4154 gf_group->update_type[gf_group->index];
4155 const int which_arf = gf_group->arf_update_idx[gf_group->index];
Zoe Liu5fca7242016-10-10 17:18:57 -07004156
4157 if (cm->show_existing_frame == 1) {
4158 cm->show_existing_frame = 0;
4159 } else if (cpi->rc.is_last_bipred_frame) {
Zoe Liu8dd1c982017-09-11 10:14:35 -07004160 // NOTE: If the current frame is a last bi-predictive frame, it is
4161 // needed next to show the BWDREF_FRAME, which is pointed by
4162 // the last_fb_idxes[0] after reference frame buffer update
Yaowu Xuc27fc142016-08-22 16:08:15 -07004163 cpi->rc.is_last_bipred_frame = 0;
4164 cm->show_existing_frame = 1;
4165 cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0];
4166 } else if (cpi->is_arf_filter_off[which_arf] &&
4167 (next_frame_update_type == OVERLAY_UPDATE ||
4168 next_frame_update_type == INTNL_OVERLAY_UPDATE)) {
4169 // Other parameters related to OVERLAY_UPDATE will be taken care of
Yaowu Xuf883b422016-08-30 14:01:10 -07004170 // in av1_rc_get_second_pass_params(cpi)
Yaowu Xuc27fc142016-08-22 16:08:15 -07004171 cm->show_existing_frame = 1;
4172 cpi->rc.is_src_frame_alt_ref = 1;
Zoe Liue9b15e22017-07-19 15:53:01 -07004173 cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE)
4174 ? cpi->alt_fb_idx
4175 : cpi->alt2_fb_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004176 cpi->is_arf_filter_off[which_arf] = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004177 }
4178 cpi->rc.is_src_frame_ext_arf = 0;
4179}
Yaowu Xuc27fc142016-08-22 16:08:15 -07004180
4181#ifdef OUTPUT_YUV_REC
Yaowu Xuf883b422016-08-30 14:01:10 -07004182void aom_write_one_yuv_frame(AV1_COMMON *cm, YV12_BUFFER_CONFIG *s) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004183 uint8_t *src = s->y_buffer;
4184 int h = cm->height;
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -07004185 if (yuv_rec_file == NULL) return;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004186 if (s->flags & YV12_FLAG_HIGHBITDEPTH) {
4187 uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer);
4188
4189 do {
4190 fwrite(src16, s->y_width, 2, yuv_rec_file);
4191 src16 += s->y_stride;
4192 } while (--h);
4193
4194 src16 = CONVERT_TO_SHORTPTR(s->u_buffer);
4195 h = s->uv_height;
4196
4197 do {
4198 fwrite(src16, s->uv_width, 2, yuv_rec_file);
4199 src16 += s->uv_stride;
4200 } while (--h);
4201
4202 src16 = CONVERT_TO_SHORTPTR(s->v_buffer);
4203 h = s->uv_height;
4204
4205 do {
4206 fwrite(src16, s->uv_width, 2, yuv_rec_file);
4207 src16 += s->uv_stride;
4208 } while (--h);
4209
4210 fflush(yuv_rec_file);
4211 return;
4212 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004213
4214 do {
4215 fwrite(src, s->y_width, 1, yuv_rec_file);
4216 src += s->y_stride;
4217 } while (--h);
4218
4219 src = s->u_buffer;
4220 h = s->uv_height;
4221
4222 do {
4223 fwrite(src, s->uv_width, 1, yuv_rec_file);
4224 src += s->uv_stride;
4225 } while (--h);
4226
4227 src = s->v_buffer;
4228 h = s->uv_height;
4229
4230 do {
4231 fwrite(src, s->uv_width, 1, yuv_rec_file);
4232 src += s->uv_stride;
4233 } while (--h);
4234
4235 fflush(yuv_rec_file);
4236}
4237#endif // OUTPUT_YUV_REC
4238
Debargha Mukherjee11f0e402017-03-29 07:42:40 -07004239#define GM_RECODE_LOOP_NUM4X4_FACTOR 192
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004240static int recode_loop_test_global_motion(AV1_COMP *cpi) {
4241 int i;
4242 int recode = 0;
Debargha Mukherjeea575d232017-04-28 17:46:47 -07004243 RD_COUNTS *const rdc = &cpi->td.rd_counts;
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004244 AV1_COMMON *const cm = &cpi->common;
4245 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
4246 if (cm->global_motion[i].wmtype != IDENTITY &&
Debargha Mukherjeea575d232017-04-28 17:46:47 -07004247 rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR <
Debargha Mukherjee265db6d2017-03-28 11:15:27 -07004248 cpi->gmparams_cost[i]) {
David Barkerd7c8bd52017-09-25 14:47:29 +01004249 cm->global_motion[i] = default_warp_params;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004250 assert(cm->global_motion[i].wmtype == IDENTITY);
Debargha Mukherjee265db6d2017-03-28 11:15:27 -07004251 cpi->gmparams_cost[i] = 0;
David Barker43479c62016-11-30 10:34:20 +00004252 recode = 1;
Urvang Joshi02aade82017-12-18 17:18:16 -08004253 // TODO(sarahparker): The earlier condition for recoding here was:
4254 // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something
4255 // similar to that back to speed up global motion?
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004256 }
4257 }
4258 return recode;
4259}
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004260
Yaowu Xuc27fc142016-08-22 16:08:15 -07004261// Function to test for conditions that indicate we should loop
4262// back and recode a frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07004263static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q,
4264 int maxq, int minq) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004265 const RATE_CONTROL *const rc = &cpi->rc;
Yaowu Xuf883b422016-08-30 14:01:10 -07004266 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004267 const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi);
4268 int force_recode = 0;
4269
4270 if ((rc->projected_frame_size >= rc->max_frame_bandwidth) ||
4271 (cpi->sf.recode_loop == ALLOW_RECODE) ||
4272 (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004273 // TODO(agrange) high_limit could be greater than the scale-down threshold.
4274 if ((rc->projected_frame_size > high_limit && q < maxq) ||
4275 (rc->projected_frame_size < low_limit && q > minq)) {
4276 force_recode = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -07004277 } else if (cpi->oxcf.rc_mode == AOM_CQ) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004278 // Deal with frame undershoot and whether or not we are
4279 // below the automatically set cq level.
4280 if (q > oxcf->cq_level &&
4281 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) {
4282 force_recode = 1;
4283 }
4284 }
4285 }
4286 return force_recode;
4287}
4288
Yaowu Xuc27fc142016-08-22 16:08:15 -07004289#define DUMP_REF_FRAME_IMAGES 0
4290
4291#if DUMP_REF_FRAME_IMAGES == 1
Yaowu Xuf883b422016-08-30 14:01:10 -07004292static int dump_one_image(AV1_COMMON *cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004293 const YV12_BUFFER_CONFIG *const ref_buf,
4294 char *file_name) {
4295 int h;
4296 FILE *f_ref = NULL;
4297
4298 if (ref_buf == NULL) {
4299 printf("Frame data buffer is NULL.\n");
Yaowu Xuf883b422016-08-30 14:01:10 -07004300 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004301 }
4302
4303 if ((f_ref = fopen(file_name, "wb")) == NULL) {
4304 printf("Unable to open file %s to write.\n", file_name);
Yaowu Xuf883b422016-08-30 14:01:10 -07004305 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004306 }
4307
4308 // --- Y ---
4309 for (h = 0; h < cm->height; ++h) {
4310 fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref);
4311 }
4312 // --- U ---
4313 for (h = 0; h < (cm->height >> 1); ++h) {
4314 fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1),
4315 f_ref);
4316 }
4317 // --- V ---
4318 for (h = 0; h < (cm->height >> 1); ++h) {
4319 fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1),
4320 f_ref);
4321 }
4322
4323 fclose(f_ref);
4324
Yaowu Xuf883b422016-08-30 14:01:10 -07004325 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004326}
4327
Yaowu Xuf883b422016-08-30 14:01:10 -07004328static void dump_ref_frame_images(AV1_COMP *cpi) {
4329 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004330 MV_REFERENCE_FRAME ref_frame;
4331
4332 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
4333 char file_name[256] = "";
4334 snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv",
4335 cm->current_video_frame, ref_frame);
4336 dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name);
4337 }
4338}
4339#endif // DUMP_REF_FRAME_IMAGES == 1
4340
Yaowu Xuc27fc142016-08-22 16:08:15 -07004341// This function is used to shift the virtual indices of last reference frames
4342// as follows:
4343// LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME
4344// when the LAST_FRAME is updated.
Yaowu Xuf883b422016-08-30 14:01:10 -07004345static INLINE void shift_last_ref_frames(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004346 int ref_frame;
4347 for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) {
4348 cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1];
4349
4350 // [0] is allocated to the current coded frame. The statistics for the
Zoe Liuf0e46692016-10-12 12:31:43 -07004351 // reference frames start at [LAST_FRAME], i.e. [1].
Yaowu Xuc27fc142016-08-22 16:08:15 -07004352 if (!cpi->rc.is_src_frame_alt_ref) {
Zoe Liuf0e46692016-10-12 12:31:43 -07004353 memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME],
4354 cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME],
4355 sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004356 }
4357 }
4358}
Yaowu Xuc27fc142016-08-22 16:08:15 -07004359
Zoe Liu8dd1c982017-09-11 10:14:35 -07004360#if USE_GF16_MULTI_LAYER
4361static void update_reference_frames_gf16(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004362 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004363 BufferPool *const pool = cm->buffer_pool;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004364
Zoe Liu8dd1c982017-09-11 10:14:35 -07004365 if (cm->frame_type == KEY_FRAME) {
4366 for (int ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) {
4367 ref_cnt_fb(pool->frame_bufs,
4368 &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]],
4369 cm->new_fb_idx);
4370 }
4371 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4372 cm->new_fb_idx);
4373 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4374 cm->new_fb_idx);
4375 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4376 cm->new_fb_idx);
4377 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4378 cm->new_fb_idx);
4379 } else {
4380 if (cpi->refresh_last_frame || cpi->refresh_golden_frame ||
4381 cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame ||
4382 cpi->refresh_alt_ref_frame) {
4383 assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES);
4384 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx],
4385 cm->new_fb_idx);
4386 }
4387
4388 // TODO(zoeliu): To handle cpi->interp_filter_selected[].
4389
4390 // For GF of 16, an additional ref frame index mapping needs to be handled
4391 // if this is the last frame to encode in the current GF group.
4392 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
4393 if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE)
4394 av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1);
4395 }
4396
4397#if DUMP_REF_FRAME_IMAGES == 1
4398 // Dump out all reference frame images.
4399 dump_ref_frame_images(cpi);
4400#endif // DUMP_REF_FRAME_IMAGES
4401}
4402#endif // USE_GF16_MULTI_LAYER
Zoe Liu8dd1c982017-09-11 10:14:35 -07004403
4404static void update_reference_frames(AV1_COMP *cpi) {
4405 AV1_COMMON *const cm = &cpi->common;
4406
Yaowu Xuc27fc142016-08-22 16:08:15 -07004407 // NOTE: Save the new show frame buffer index for --test-code=warn, i.e.,
4408 // for the purpose to verify no mismatch between encoder and decoder.
4409 if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx;
4410
Zoe Liu8dd1c982017-09-11 10:14:35 -07004411#if USE_GF16_MULTI_LAYER
4412 if (cpi->rc.baseline_gf_interval == 16) {
4413 update_reference_frames_gf16(cpi);
4414 return;
4415 }
4416#endif // USE_GF16_MULTI_LAYER
Zoe Liu8dd1c982017-09-11 10:14:35 -07004417
4418 BufferPool *const pool = cm->buffer_pool;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004419 // At this point the new frame has been encoded.
4420 // If any buffer copy / swapping is signaled it should be done here.
4421 if (cm->frame_type == KEY_FRAME) {
4422 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4423 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004424 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4425 cm->new_fb_idx);
Zoe Liue9b15e22017-07-19 15:53:01 -07004426 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4427 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004428 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4429 cm->new_fb_idx);
Yaowu Xuf883b422016-08-30 14:01:10 -07004430 } else if (av1_preserve_existing_gf(cpi)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004431 // We have decided to preserve the previously existing golden frame as our
4432 // new ARF frame. However, in the short term in function
Yaowu Xuf883b422016-08-30 14:01:10 -07004433 // av1_bitstream.c::get_refresh_mask() we left it in the GF slot and, if
Yaowu Xuc27fc142016-08-22 16:08:15 -07004434 // we're updating the GF with the current decoded frame, we save it to the
4435 // ARF slot instead.
4436 // We now have to update the ARF with the current frame and swap gld_fb_idx
4437 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF
4438 // slot and, if we're updating the GF, the current frame becomes the new GF.
4439 int tmp;
4440
4441 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx],
4442 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004443 tmp = cpi->alt_fb_idx;
4444 cpi->alt_fb_idx = cpi->gld_fb_idx;
4445 cpi->gld_fb_idx = tmp;
4446
Yaowu Xuc27fc142016-08-22 16:08:15 -07004447 // We need to modify the mapping accordingly
4448 cpi->arf_map[0] = cpi->alt_fb_idx;
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004449 // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to
4450 // cpi->interp_filter_selected[GOLDEN_FRAME]?
Yaowu Xuc27fc142016-08-22 16:08:15 -07004451 } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) {
4452 // Deal with the special case for showing existing internal ALTREF_FRAME
4453 // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME
4454 // by updating the virtual indices.
4455 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
Zoe Liue9b15e22017-07-19 15:53:01 -07004456 const int which_arf = gf_group->arf_ref_idx[gf_group->index];
4457 assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004458
Zoe Liue9b15e22017-07-19 15:53:01 -07004459 const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -07004460 shift_last_ref_frames(cpi);
Zoe Liue9b15e22017-07-19 15:53:01 -07004461
Zoe Liue9b15e22017-07-19 15:53:01 -07004462 cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx;
4463 cpi->alt2_fb_idx = tmp;
4464 // We need to modify the mapping accordingly
4465 cpi->arf_map[which_arf] = cpi->alt2_fb_idx;
4466
4467 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4468 cpi->interp_filter_selected[ALTREF2_FRAME],
4469 sizeof(cpi->interp_filter_selected[ALTREF2_FRAME]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004470 } else { /* For non key/golden frames */
Zoe Liue9b15e22017-07-19 15:53:01 -07004471 // === ALTREF_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004472 if (cpi->refresh_alt_ref_frame) {
4473 int arf_idx = cpi->alt_fb_idx;
4474 int which_arf = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004475 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[arf_idx], cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004476
4477 memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf],
4478 cpi->interp_filter_selected[0],
4479 sizeof(cpi->interp_filter_selected[0]));
4480 }
4481
Zoe Liue9b15e22017-07-19 15:53:01 -07004482 // === GOLDEN_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004483 if (cpi->refresh_golden_frame) {
4484 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx],
4485 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004486
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004487 memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
4488 cpi->interp_filter_selected[0],
4489 sizeof(cpi->interp_filter_selected[0]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004490 }
4491
Zoe Liue9b15e22017-07-19 15:53:01 -07004492 // === BWDREF_FRAME ===
Yaowu Xuc27fc142016-08-22 16:08:15 -07004493 if (cpi->refresh_bwd_ref_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004494 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx],
4495 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004496
4497 memcpy(cpi->interp_filter_selected[BWDREF_FRAME],
4498 cpi->interp_filter_selected[0],
4499 sizeof(cpi->interp_filter_selected[0]));
4500 }
Zoe Liue9b15e22017-07-19 15:53:01 -07004501
Zoe Liue9b15e22017-07-19 15:53:01 -07004502 // === ALTREF2_FRAME ===
4503 if (cpi->refresh_alt2_ref_frame) {
4504 ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx],
4505 cm->new_fb_idx);
4506
4507 memcpy(cpi->interp_filter_selected[ALTREF2_FRAME],
4508 cpi->interp_filter_selected[0],
4509 sizeof(cpi->interp_filter_selected[0]));
4510 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004511 }
4512
4513 if (cpi->refresh_last_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004514 // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame
4515 // reference to the reference frame buffer virtual index; and then (2) from
4516 // the virtual index to the reference frame buffer physical index:
4517 //
4518 // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME
4519 // | | |
4520 // v v v
4521 // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx
4522 // | | |
4523 // v v v
4524 // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[]
4525 //
4526 // When refresh_last_frame is set, it is intended to retire LAST3_FRAME,
4527 // have the other 2 LAST reference frames shifted as follows:
4528 // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME
4529 // , and then have LAST_FRAME refreshed by the newly coded frame.
4530 //
4531 // To fulfill it, the decoder will be notified to execute following 2 steps:
4532 //
4533 // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME
4534 // to point to the newly coded frame, i.e.
4535 // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx;
4536 //
4537 // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the
4538 // original virtual index of LAST3_FRAME and have the other mappings
4539 // shifted as follows:
4540 // LAST_FRAME, LAST2_FRAME, LAST3_FRAME
4541 // | | |
4542 // v v v
4543 // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1]
4544 int ref_frame;
Zoe Liu5fca7242016-10-10 17:18:57 -07004545
Yaowu Xuc27fc142016-08-22 16:08:15 -07004546 if (cm->frame_type == KEY_FRAME) {
4547 for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) {
4548 ref_cnt_fb(pool->frame_bufs,
4549 &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]],
4550 cm->new_fb_idx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004551 }
4552 } else {
4553 int tmp;
4554
4555 ref_cnt_fb(pool->frame_bufs,
4556 &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]],
4557 cm->new_fb_idx);
4558
Yaowu Xuc27fc142016-08-22 16:08:15 -07004559 tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
4560
4561 shift_last_ref_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004562 cpi->lst_fb_idxes[0] = tmp;
4563
Zoe Liuf0e46692016-10-12 12:31:43 -07004564 assert(cm->show_existing_frame == 0);
Zoe Liuf0e46692016-10-12 12:31:43 -07004565 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4566 cpi->interp_filter_selected[0],
4567 sizeof(cpi->interp_filter_selected[0]));
Zoe Liuaff92d52017-07-11 21:35:08 -07004568
4569 if (cpi->rc.is_last_bipred_frame) {
4570 // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the
4571 // LAST3_FRAME by updating the virtual indices.
4572 //
4573 // NOTE: The source frame for BWDREF does not have a holding position as
4574 // the OVERLAY frame for ALTREF's. Hence, to resolve the reference
4575 // virtual index reshuffling for BWDREF, the encoder always
4576 // specifies a LAST_BIPRED right before BWDREF and completes the
4577 // reshuffling job accordingly.
4578 tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1];
4579
4580 shift_last_ref_frames(cpi);
4581 cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx;
4582 cpi->bwd_fb_idx = tmp;
4583
4584 memcpy(cpi->interp_filter_selected[LAST_FRAME],
4585 cpi->interp_filter_selected[BWDREF_FRAME],
4586 sizeof(cpi->interp_filter_selected[BWDREF_FRAME]));
4587 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004588 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004589 }
4590
4591#if DUMP_REF_FRAME_IMAGES == 1
4592 // Dump out all reference frame images.
4593 dump_ref_frame_images(cpi);
4594#endif // DUMP_REF_FRAME_IMAGES
4595}
4596
Yaowu Xuf883b422016-08-30 14:01:10 -07004597static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) {
Debargha Mukherjee887069f2017-06-16 18:54:36 -07004598 assert(buffer_idx != INVALID_IDX);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004599 RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
Rupert Swarbrick1f990a62017-07-11 11:09:33 +01004600 ensure_mv_buffer(new_fb_ptr, cm);
4601 new_fb_ptr->width = cm->width;
4602 new_fb_ptr->height = cm->height;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004603}
4604
Cheng Chen46f30c72017-09-07 11:13:33 -07004605static void scale_references(AV1_COMP *cpi) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004606 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004607 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004608 MV_REFERENCE_FRAME ref_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -07004609 const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = {
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02004610 AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG,
4611 AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG
Yaowu Xuc27fc142016-08-22 16:08:15 -07004612 };
4613
4614 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004615 // Need to convert from AOM_REFFRAME to index into ref_mask (subtract 1).
Yaowu Xuc27fc142016-08-22 16:08:15 -07004616 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) {
4617 BufferPool *const pool = cm->buffer_pool;
4618 const YV12_BUFFER_CONFIG *const ref =
4619 get_ref_frame_buffer(cpi, ref_frame);
4620
4621 if (ref == NULL) {
4622 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
4623 continue;
4624 }
4625
Yaowu Xuc27fc142016-08-22 16:08:15 -07004626 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
4627 RefCntBuffer *new_fb_ptr = NULL;
4628 int force_scaling = 0;
4629 int new_fb = cpi->scaled_ref_idx[ref_frame - 1];
4630 if (new_fb == INVALID_IDX) {
4631 new_fb = get_free_fb(cm);
4632 force_scaling = 1;
4633 }
4634 if (new_fb == INVALID_IDX) return;
4635 new_fb_ptr = &pool->frame_bufs[new_fb];
4636 if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width ||
4637 new_fb_ptr->buf.y_crop_height != cm->height) {
Yaowu Xu671f2bd2016-09-30 15:07:57 -07004638 if (aom_realloc_frame_buffer(
4639 &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x,
4640 cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
4641 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -07004642 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004643 "Failed to allocate frame buffer");
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004644 av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth,
4645 num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004646 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
4647 alloc_frame_mvs(cm, new_fb);
4648 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004649 } else {
4650 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
4651 RefCntBuffer *const buf = &pool->frame_bufs[buf_idx];
4652 buf->buf.y_crop_width = ref->y_crop_width;
4653 buf->buf.y_crop_height = ref->y_crop_height;
4654 cpi->scaled_ref_idx[ref_frame - 1] = buf_idx;
4655 ++buf->ref_count;
4656 }
4657 } else {
4658 if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
4659 }
4660 }
4661}
4662
Yaowu Xuf883b422016-08-30 14:01:10 -07004663static void release_scaled_references(AV1_COMP *cpi) {
4664 AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004665 int i;
4666 if (cpi->oxcf.pass == 0) {
4667 // Only release scaled references under certain conditions:
4668 // if reference will be updated, or if scaled reference has same resolution.
4669 int refresh[INTER_REFS_PER_FRAME];
4670 refresh[0] = (cpi->refresh_last_frame) ? 1 : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004671 refresh[1] = refresh[2] = 0;
4672 refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0;
4673 refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07004674 refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0;
4675 refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004676 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
4677 const int idx = cpi->scaled_ref_idx[i - 1];
4678 RefCntBuffer *const buf =
4679 idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL;
4680 const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i);
4681 if (buf != NULL &&
4682 (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width &&
4683 buf->buf.y_crop_height == ref->y_crop_height))) {
4684 --buf->ref_count;
4685 cpi->scaled_ref_idx[i - 1] = INVALID_IDX;
4686 }
4687 }
4688 } else {
4689 for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) {
4690 const int idx = cpi->scaled_ref_idx[i];
4691 RefCntBuffer *const buf =
4692 idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL;
4693 if (buf != NULL) {
4694 --buf->ref_count;
4695 cpi->scaled_ref_idx[i] = INVALID_IDX;
4696 }
4697 }
4698 }
4699}
4700
Yaowu Xuf883b422016-08-30 14:01:10 -07004701static void set_mv_search_params(AV1_COMP *cpi) {
4702 const AV1_COMMON *const cm = &cpi->common;
4703 const unsigned int max_mv_def = AOMMIN(cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004704
4705 // Default based on max resolution.
Yaowu Xuf883b422016-08-30 14:01:10 -07004706 cpi->mv_step_param = av1_init_search_range(max_mv_def);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004707
4708 if (cpi->sf.mv.auto_mv_step_size) {
4709 if (frame_is_intra_only(cm)) {
4710 // Initialize max_mv_magnitude for use in the first INTER frame
4711 // after a key/intra-only frame.
4712 cpi->max_mv_magnitude = max_mv_def;
4713 } else {
4714 if (cm->show_frame) {
4715 // Allow mv_steps to correspond to twice the max mv magnitude found
4716 // in the previous frame, capped by the default max_mv_magnitude based
4717 // on resolution.
Yaowu Xuf883b422016-08-30 14:01:10 -07004718 cpi->mv_step_param = av1_init_search_range(
4719 AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude));
Yaowu Xuc27fc142016-08-22 16:08:15 -07004720 }
4721 cpi->max_mv_magnitude = 0;
4722 }
4723 }
4724}
4725
Yaowu Xuf883b422016-08-30 14:01:10 -07004726static void set_size_independent_vars(AV1_COMP *cpi) {
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004727 int i;
4728 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
David Barkerd7c8bd52017-09-25 14:47:29 +01004729 cpi->common.global_motion[i] = default_warp_params;
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08004730 }
4731 cpi->global_motion_search_done = 0;
Yaowu Xuf883b422016-08-30 14:01:10 -07004732 av1_set_speed_features_framesize_independent(cpi);
4733 av1_set_rd_speed_thresholds(cpi);
4734 av1_set_rd_speed_thresholds_sub8x8(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004735 cpi->common.interp_filter = cpi->sf.default_interp_filter;
Debargha Mukherjee9e2c7a62017-05-23 21:18:42 -07004736 if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004737}
4738
Yaowu Xuf883b422016-08-30 14:01:10 -07004739static void set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004740 int *top_index) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004741 AV1_COMMON *const cm = &cpi->common;
4742 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004743
4744 // Setup variables that depend on the dimensions of the frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07004745 av1_set_speed_features_framesize_dependent(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004746
Sebastien Alaiwan41cae6a2018-01-12 12:22:29 +01004747 // Decide q and q bounds.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004748 *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index,
4749 top_index);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004750
James Zern01a9d702017-08-25 19:09:33 +00004751 if (!frame_is_intra_only(cm)) {
RogerZhou3b635242017-09-19 10:06:46 -07004752#if CONFIG_AMVR
4753 set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH,
RogerZhou10a03802017-10-26 11:49:48 -07004754 cpi->common.cur_frame_force_integer_mv);
RogerZhou3b635242017-09-19 10:06:46 -07004755#else
Cheng Chen46f30c72017-09-07 11:13:33 -07004756 set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH);
RogerZhou3b635242017-09-19 10:06:46 -07004757#endif
James Zern01a9d702017-08-25 19:09:33 +00004758 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07004759
4760 // Configure experimental use of segmentation for enhanced coding of
4761 // static regions if indicated.
4762 // Only allowed in the second pass of a two pass encode, as it requires
4763 // lagged coding, and if the relevant speed feature flag is set.
4764 if (oxcf->pass == 2 && cpi->sf.static_segmentation)
4765 configure_static_seg_features(cpi);
4766}
4767
Yaowu Xuf883b422016-08-30 14:01:10 -07004768static void init_motion_estimation(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07004769 int y_stride = cpi->scaled_source.y_stride;
4770
4771 if (cpi->sf.mv.search_method == NSTEP) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004772 av1_init3smotion_compensation(&cpi->ss_cfg, y_stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004773 } else if (cpi->sf.mv.search_method == DIAMOND) {
Yaowu Xuf883b422016-08-30 14:01:10 -07004774 av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004775 }
4776}
4777
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004778#if CONFIG_LOOP_RESTORATION
Debargha Mukherjee84f567c2017-06-21 10:53:59 -07004779#define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004780static void set_restoration_unit_size(int width, int height, int sx, int sy,
4781 RestorationInfo *rst) {
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004782 (void)width;
4783 (void)height;
Debargha Mukherjee84f567c2017-06-21 10:53:59 -07004784 (void)sx;
4785 (void)sy;
4786#if COUPLED_CHROMA_FROM_LUMA_RESTORATION
4787 int s = AOMMIN(sx, sy);
4788#else
4789 int s = 0;
4790#endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION
4791
Debargha Mukherjee5f7f3672017-08-12 10:22:49 -07004792 if (width * height > 352 * 288)
4793 rst[0].restoration_unit_size = RESTORATION_TILESIZE_MAX;
4794 else
4795 rst[0].restoration_unit_size = (RESTORATION_TILESIZE_MAX >> 1);
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004796 rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s;
4797 rst[2].restoration_unit_size = rst[1].restoration_unit_size;
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004798}
4799#endif // CONFIG_LOOP_RESTORATION
4800
Cheng Chen46f30c72017-09-07 11:13:33 -07004801static void init_ref_frame_bufs(AV1_COMMON *cm) {
4802 int i;
4803 BufferPool *const pool = cm->buffer_pool;
4804 cm->new_fb_idx = INVALID_IDX;
4805 for (i = 0; i < REF_FRAMES; ++i) {
4806 cm->ref_frame_map[i] = INVALID_IDX;
4807 pool->frame_bufs[i].ref_count = 0;
4808 }
4809#if CONFIG_HASH_ME
Hui Su2d5fd742018-02-21 18:10:37 -08004810 if (av1_use_hash_me(cm)) {
4811 for (i = 0; i < FRAME_BUFFERS; ++i) {
4812 av1_hash_table_init(&pool->frame_bufs[i].hash_table);
4813 }
Cheng Chen46f30c72017-09-07 11:13:33 -07004814 }
4815#endif
4816}
4817
Yaowu Xud3e7c682017-12-21 14:08:25 -08004818static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth,
Cheng Chen46f30c72017-09-07 11:13:33 -07004819 int subsampling_x, int subsampling_y) {
4820 AV1_COMMON *const cm = &cpi->common;
4821
Yaowu Xud3e7c682017-12-21 14:08:25 -08004822 if (!cpi->initial_width || cm->use_highbitdepth != use_highbitdepth ||
Cheng Chen46f30c72017-09-07 11:13:33 -07004823 cm->subsampling_x != subsampling_x ||
4824 cm->subsampling_y != subsampling_y) {
4825 cm->subsampling_x = subsampling_x;
4826 cm->subsampling_y = subsampling_y;
Cheng Chen46f30c72017-09-07 11:13:33 -07004827 cm->use_highbitdepth = use_highbitdepth;
Cheng Chen46f30c72017-09-07 11:13:33 -07004828
4829 alloc_raw_frame_buffers(cpi);
4830 init_ref_frame_bufs(cm);
4831 alloc_util_frame_buffers(cpi);
4832
4833 init_motion_estimation(cpi); // TODO(agrange) This can be removed.
4834
4835 cpi->initial_width = cm->width;
4836 cpi->initial_height = cm->height;
4837 cpi->initial_mbs = cm->MBs;
4838 }
4839}
4840
4841// Returns 1 if the assigned width or height was <= 0.
4842static int set_size_literal(AV1_COMP *cpi, int width, int height) {
4843 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004844 const int num_planes = av1_num_planes(cm);
Cheng Chen46f30c72017-09-07 11:13:33 -07004845 check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x,
4846 cm->subsampling_y);
Cheng Chen46f30c72017-09-07 11:13:33 -07004847
4848 if (width <= 0 || height <= 0) return 1;
4849
4850 cm->width = width;
Cheng Chen46f30c72017-09-07 11:13:33 -07004851 cm->height = height;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004852
4853 if (cpi->initial_width && cpi->initial_height &&
4854 (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) {
4855 av1_free_context_buffers(cm);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004856 av1_free_pc_tree(&cpi->td, num_planes);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07004857 alloc_compressor_data(cpi);
4858 realloc_segmentation_maps(cpi);
4859 cpi->initial_width = cpi->initial_height = 0;
Cheng Chen46f30c72017-09-07 11:13:33 -07004860 }
Cheng Chen46f30c72017-09-07 11:13:33 -07004861 update_frame_size(cpi);
4862
4863 return 0;
4864}
4865
Fergus Simpsonbc189932017-05-16 17:02:39 -07004866static void set_frame_size(AV1_COMP *cpi, int width, int height) {
Fergus Simpsonbc189932017-05-16 17:02:39 -07004867 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004868 const int num_planes = av1_num_planes(cm);
Fergus Simpsonbc189932017-05-16 17:02:39 -07004869 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004870 int ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -07004871
Fergus Simpsonbc189932017-05-16 17:02:39 -07004872 if (width != cm->width || height != cm->height) {
Fergus Simpson3502d082017-04-10 12:25:07 -07004873 // There has been a change in the encoded frame size
Cheng Chen46f30c72017-09-07 11:13:33 -07004874 set_size_literal(cpi, width, height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004875 set_mv_search_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004876 }
4877
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07004878 if (cpi->oxcf.pass == 2) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004879 av1_set_target_rate(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004880 }
4881
4882 alloc_frame_mvs(cm, cm->new_fb_idx);
4883
4884 // Reset the frame pointers to the current frame size.
Yaowu Xuf883b422016-08-30 14:01:10 -07004885 if (aom_realloc_frame_buffer(get_frame_new_buffer(cm), cm->width, cm->height,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004886 cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -08004887 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS,
4888 cm->byte_alignment, NULL, NULL, NULL))
Yaowu Xuf883b422016-08-30 14:01:10 -07004889 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -07004890 "Failed to allocate frame buffer");
4891
Debargha Mukherjee1008c1e2017-03-06 19:18:43 -08004892#if CONFIG_LOOP_RESTORATION
Urvang Joshi94ad3702017-12-06 11:38:08 -08004893#if CONFIG_HORZONLY_FRAME_SUPERRES
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004894 const int frame_width = cm->superres_upscaled_width;
4895 const int frame_height = cm->superres_upscaled_height;
Fergus Simpson9cd57cf2017-06-12 17:02:03 -07004896#else
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004897 const int frame_width = cm->width;
4898 const int frame_height = cm->height;
Urvang Joshi94ad3702017-12-06 11:38:08 -08004899#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Rupert Swarbrickbcb65fe2017-10-25 17:15:28 +01004900 set_restoration_unit_size(frame_width, frame_height, cm->subsampling_x,
4901 cm->subsampling_y, cm->rst_info);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004902 for (int i = 0; i < num_planes; ++i)
Rupert Swarbrick1a96c3f2017-10-24 11:55:00 +01004903 cm->rst_info[i].frame_restoration_type = RESTORE_NONE;
Rupert Swarbrickf88bc042017-10-18 10:45:51 +01004904
4905 av1_alloc_restoration_buffers(cm);
Fergus Simpson9cd57cf2017-06-12 17:02:03 -07004906#endif // CONFIG_LOOP_RESTORATION
4907 alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways.
Yaowu Xuc27fc142016-08-22 16:08:15 -07004908 init_motion_estimation(cpi);
4909
4910 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
4911 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME];
4912 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
4913
4914 ref_buf->idx = buf_idx;
4915
4916 if (buf_idx != INVALID_IDX) {
4917 YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf;
4918 ref_buf->buf = buf;
Yaowu Xuf883b422016-08-30 14:01:10 -07004919 av1_setup_scale_factors_for_frame(
Yaowu Xuc27fc142016-08-22 16:08:15 -07004920 &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width,
4921 cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00004922 if (av1_is_scaled(&ref_buf->sf))
4923 aom_extend_frame_borders(buf, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004924 } else {
4925 ref_buf->buf = NULL;
4926 }
4927 }
Zoe Liu7b1ec7a2017-05-24 22:28:24 -07004928
Hui Su5ebd8702018-01-08 18:09:20 -08004929 av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height,
Sebastien Alaiwan1dcb7072017-05-12 11:13:05 +02004930 cm->width, cm->height,
4931 cm->use_highbitdepth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07004932
4933 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
4934}
4935
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004936static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) {
4937 // Choose an arbitrary random number
4938 static unsigned int seed = 56789;
4939 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Urvang Joshide71d142017-10-05 12:12:15 -07004940 if (oxcf->pass == 1) return SCALE_NUMERATOR;
4941 uint8_t new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004942
4943 switch (oxcf->resize_mode) {
Urvang Joshide71d142017-10-05 12:12:15 -07004944 case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004945 case RESIZE_FIXED:
4946 if (cpi->common.frame_type == KEY_FRAME)
Urvang Joshide71d142017-10-05 12:12:15 -07004947 new_denom = oxcf->resize_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004948 else
Urvang Joshide71d142017-10-05 12:12:15 -07004949 new_denom = oxcf->resize_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004950 break;
Urvang Joshide71d142017-10-05 12:12:15 -07004951 case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004952 default: assert(0);
4953 }
Urvang Joshide71d142017-10-05 12:12:15 -07004954 return new_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004955}
4956
Urvang Joshi94ad3702017-12-06 11:38:08 -08004957#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshie58b5642017-10-05 17:59:43 -07004958
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004959static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) {
4960 // Choose an arbitrary random number
4961 static unsigned int seed = 34567;
4962 const AV1EncoderConfig *oxcf = &cpi->oxcf;
Urvang Joshide71d142017-10-05 12:12:15 -07004963 if (oxcf->pass == 1) return SCALE_NUMERATOR;
4964 uint8_t new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004965 int bottom_index, top_index, q, qthresh;
4966
4967 switch (oxcf->superres_mode) {
Urvang Joshide71d142017-10-05 12:12:15 -07004968 case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004969 case SUPERRES_FIXED:
4970 if (cpi->common.frame_type == KEY_FRAME)
Urvang Joshide71d142017-10-05 12:12:15 -07004971 new_denom = oxcf->superres_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004972 else
Urvang Joshide71d142017-10-05 12:12:15 -07004973 new_denom = oxcf->superres_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004974 break;
Urvang Joshide71d142017-10-05 12:12:15 -07004975 case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004976 case SUPERRES_QTHRESH:
4977 qthresh = (cpi->common.frame_type == KEY_FRAME ? oxcf->superres_kf_qthresh
4978 : oxcf->superres_qthresh);
4979 av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height);
4980 q = av1_rc_pick_q_and_bounds(cpi, cpi->oxcf.width, cpi->oxcf.height,
4981 &bottom_index, &top_index);
4982 if (q < qthresh) {
Urvang Joshide71d142017-10-05 12:12:15 -07004983 new_denom = SCALE_NUMERATOR;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004984 } else {
Urvang Joshi28983f72017-10-25 14:41:06 -07004985 const uint8_t min_denom = SCALE_NUMERATOR + 1;
4986 const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3;
4987 const uint8_t additional_denom = (q - qthresh) / denom_step;
4988 new_denom = AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004989 }
4990 break;
4991 default: assert(0);
4992 }
Urvang Joshide71d142017-10-05 12:12:15 -07004993 return new_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07004994}
4995
Urvang Joshide71d142017-10-05 12:12:15 -07004996static int dimension_is_ok(int orig_dim, int resized_dim, int denom) {
4997 return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2);
4998}
4999
5000static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) {
Urvang Joshi94ad3702017-12-06 11:38:08 -08005001 // Only need to check the width, as scaling is horizontal only.
5002 (void)oheight;
5003 return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom);
Urvang Joshide71d142017-10-05 12:12:15 -07005004}
5005
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005006static int validate_size_scales(RESIZE_MODE resize_mode,
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005007 SUPERRES_MODE superres_mode, int owidth,
5008 int oheight, size_params_type *rsz) {
Urvang Joshide71d142017-10-05 12:12:15 -07005009 if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005010 return 1;
Urvang Joshide71d142017-10-05 12:12:15 -07005011 }
5012
Urvang Joshi69fde2e2017-10-09 15:34:18 -07005013 // Calculate current resize scale.
Urvang Joshide71d142017-10-05 12:12:15 -07005014 int resize_denom =
5015 AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width),
5016 DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height));
5017
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005018 if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005019 // Alter superres scale as needed to enforce conformity.
5020 rsz->superres_denom =
5021 (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom;
5022 if (!dimensions_are_ok(owidth, oheight, rsz)) {
5023 if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005024 }
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005025 } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005026 // Alter resize scale as needed to enforce conformity.
5027 resize_denom =
5028 (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005029 rsz->resize_width = owidth;
5030 rsz->resize_height = oheight;
5031 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005032 resize_denom);
5033 if (!dimensions_are_ok(owidth, oheight, rsz)) {
5034 if (resize_denom > SCALE_NUMERATOR) {
5035 --resize_denom;
5036 rsz->resize_width = owidth;
5037 rsz->resize_height = oheight;
5038 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
5039 resize_denom);
5040 }
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005041 }
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005042 } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) {
Urvang Joshide71d142017-10-05 12:12:15 -07005043 // Alter both resize and superres scales as needed to enforce conformity.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005044 do {
Urvang Joshide71d142017-10-05 12:12:15 -07005045 if (resize_denom > rsz->superres_denom)
5046 --resize_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005047 else
Urvang Joshide71d142017-10-05 12:12:15 -07005048 --rsz->superres_denom;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005049 rsz->resize_width = owidth;
5050 rsz->resize_height = oheight;
5051 av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005052 resize_denom);
5053 } while (!dimensions_are_ok(owidth, oheight, rsz) &&
5054 (resize_denom > SCALE_NUMERATOR ||
5055 rsz->superres_denom > SCALE_NUMERATOR));
5056 } else { // We are allowed to alter neither resize scale nor superres scale.
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005057 return 0;
5058 }
Urvang Joshide71d142017-10-05 12:12:15 -07005059 return dimensions_are_ok(owidth, oheight, rsz);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005060}
Urvang Joshi94ad3702017-12-06 11:38:08 -08005061#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005062
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005063// Calculates resize and superres params for next frame
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005064size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) {
5065 const AV1EncoderConfig *oxcf = &cpi->oxcf;
5066 size_params_type rsz = {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005067 oxcf->width,
5068 oxcf->height,
Urvang Joshi94ad3702017-12-06 11:38:08 -08005069#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07005070 SCALE_NUMERATOR
Urvang Joshi94ad3702017-12-06 11:38:08 -08005071#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005072 };
Urvang Joshide71d142017-10-05 12:12:15 -07005073 int resize_denom;
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005074 if (oxcf->pass == 1) return rsz;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005075 if (cpi->resize_pending_width && cpi->resize_pending_height) {
5076 rsz.resize_width = cpi->resize_pending_width;
5077 rsz.resize_height = cpi->resize_pending_height;
5078 cpi->resize_pending_width = cpi->resize_pending_height = 0;
5079 } else {
Urvang Joshide71d142017-10-05 12:12:15 -07005080 resize_denom = calculate_next_resize_scale(cpi);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005081 rsz.resize_width = cpi->oxcf.width;
5082 rsz.resize_height = cpi->oxcf.height;
5083 av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height,
Urvang Joshide71d142017-10-05 12:12:15 -07005084 resize_denom);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005085 }
Urvang Joshi94ad3702017-12-06 11:38:08 -08005086#if CONFIG_HORZONLY_FRAME_SUPERRES
Urvang Joshide71d142017-10-05 12:12:15 -07005087 rsz.superres_denom = calculate_next_superres_scale(cpi);
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005088 if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width,
5089 oxcf->height, &rsz))
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005090 assert(0 && "Invalid scale parameters");
Urvang Joshi94ad3702017-12-06 11:38:08 -08005091#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005092 return rsz;
5093}
5094
5095static void setup_frame_size_from_params(AV1_COMP *cpi, size_params_type *rsz) {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005096 int encode_width = rsz->resize_width;
5097 int encode_height = rsz->resize_height;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005098
Urvang Joshi94ad3702017-12-06 11:38:08 -08005099#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005100 AV1_COMMON *cm = &cpi->common;
5101 cm->superres_upscaled_width = encode_width;
5102 cm->superres_upscaled_height = encode_height;
Urvang Joshide71d142017-10-05 12:12:15 -07005103 cm->superres_scale_denominator = rsz->superres_denom;
Urvang Joshi69fde2e2017-10-09 15:34:18 -07005104 av1_calculate_scaled_superres_size(&encode_width, &encode_height,
5105 rsz->superres_denom);
Urvang Joshi94ad3702017-12-06 11:38:08 -08005106#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005107 set_frame_size(cpi, encode_width, encode_height);
5108}
5109
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005110static void setup_frame_size(AV1_COMP *cpi) {
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005111 size_params_type rsz = av1_calculate_next_size_params(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005112 setup_frame_size_from_params(cpi, &rsz);
5113}
5114
Urvang Joshi94ad3702017-12-06 11:38:08 -08005115#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005116static void superres_post_encode(AV1_COMP *cpi) {
5117 AV1_COMMON *cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005118 const int num_planes = av1_num_planes(cm);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005119
5120 if (av1_superres_unscaled(cm)) return;
5121
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005122 av1_superres_upscale(cm, NULL);
5123
5124 // If regular resizing is occurring the source will need to be downscaled to
5125 // match the upscaled superres resolution. Otherwise the original source is
5126 // used.
5127 if (av1_resize_unscaled(cm)) {
5128 cpi->source = cpi->unscaled_source;
5129 if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source;
5130 } else {
Fergus Simpsonabd43432017-06-12 15:54:43 -07005131 assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width);
5132 assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005133 // Do downscale. cm->(width|height) has been updated by av1_superres_upscale
5134 if (aom_realloc_frame_buffer(
5135 &cpi->scaled_source, cm->superres_upscaled_width,
5136 cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y,
Yaowu Xud3e7c682017-12-21 14:08:25 -08005137 cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, cm->byte_alignment,
5138 NULL, NULL, NULL))
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005139 aom_internal_error(
5140 &cm->error, AOM_CODEC_MEM_ERROR,
5141 "Failed to reallocate scaled source buffer for superres");
5142 assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width);
5143 assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005144 av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source,
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005145 (int)cm->bit_depth, num_planes);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005146 cpi->source = &cpi->scaled_source;
5147 }
5148}
Urvang Joshi94ad3702017-12-06 11:38:08 -08005149#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005150
5151static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) {
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005152 const int num_planes = av1_num_planes(cm);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005153 MACROBLOCKD *xd = &cpi->td.mb.e_mbd;
5154 struct loopfilter *lf = &cm->lf;
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005155 int no_loopfilter = 0;
Yaowu Xu35ee2342017-11-08 11:50:46 -08005156#if CONFIG_LOOP_RESTORATION
Sebastien Alaiwan1ed20242018-02-20 14:47:18 +01005157 int no_restoration = !cpi->oxcf.using_restoration;
Hui Su27a4fb62017-11-10 16:03:50 -08005158#endif // CONFIG_LOOP_RESTORATION
5159
Yaowu Xu35ee2342017-11-08 11:50:46 -08005160 if (is_lossless_requested(&cpi->oxcf)
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005161#if CONFIG_EXT_TILE
Jingning Handa11e692017-12-19 08:45:08 -08005162 || cm->large_scale_tile
Hui Su27df8342017-11-07 15:16:05 -08005163#endif // CONFIG_EXT_TILE
Johannb0ef6ff2018-02-08 14:32:21 -08005164 ) {
Yaowu Xu35ee2342017-11-08 11:50:46 -08005165 no_loopfilter = 1;
Hui Su27a4fb62017-11-10 16:03:50 -08005166#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005167 no_restoration = 1;
Hui Su27a4fb62017-11-10 16:03:50 -08005168#endif // CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005169 }
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005170
Hui Su27a4fb62017-11-10 16:03:50 -08005171 int no_cdef = 0;
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005172 if (is_lossless_requested(&cpi->oxcf) || !cpi->oxcf.using_cdef
5173#if CONFIG_EXT_TILE
Jingning Handa11e692017-12-19 08:45:08 -08005174 || cm->large_scale_tile
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005175#endif
Johannb0ef6ff2018-02-08 14:32:21 -08005176 ) {
Steinar Midtskogene44c6222017-11-09 13:22:09 +01005177 no_cdef = 1;
5178 }
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005179
5180 if (no_loopfilter) {
Cheng Chen13fc8192017-08-19 11:49:28 -07005181#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005182 lf->filter_level[0] = 0;
5183 lf->filter_level[1] = 0;
5184#else
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005185 lf->filter_level = 0;
Cheng Chen179479f2017-08-04 10:56:39 -07005186#endif
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005187 } else {
5188 struct aom_usec_timer timer;
5189
5190 aom_clear_system_state();
5191
5192 aom_usec_timer_start(&timer);
5193
5194 av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick);
5195
5196 aom_usec_timer_mark(&timer);
5197 cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer);
5198 }
5199
Cheng Chen13fc8192017-08-19 11:49:28 -07005200#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005201 if (lf->filter_level[0] || lf->filter_level[1])
5202#else
5203 if (lf->filter_level > 0)
5204#endif
5205 {
Cheng Chen13fc8192017-08-19 11:49:28 -07005206#if CONFIG_LOOPFILTER_LEVEL
Cheng Chen179479f2017-08-04 10:56:39 -07005207 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0],
5208 lf->filter_level[1], 0, 0);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00005209 if (num_planes > 1) {
5210 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u,
5211 lf->filter_level_u, 1, 0);
5212 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v,
5213 lf->filter_level_v, 2, 0);
5214 }
Cheng Chen179479f2017-08-04 10:56:39 -07005215
Cheng Chene94df5c2017-07-19 17:25:33 -07005216#else
5217 av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
Cheng Chen13fc8192017-08-19 11:49:28 -07005218#endif // CONFIG_LOOPFILTER_LEVEL
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005219 }
Debargha Mukherjeee168a782017-08-31 12:30:10 -07005220
Debargha Mukherjeea78c8f52018-01-31 11:14:38 -08005221#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005222 if (!no_restoration)
5223 av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0);
Debargha Mukherjeea78c8f52018-01-31 11:14:38 -08005224#endif // CONFIG_LOOP_RESTORATION
Ola Hugosson1e7f2d02017-09-22 21:36:26 +02005225
Yaowu Xu35ee2342017-11-08 11:50:46 -08005226 if (no_cdef) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005227 cm->cdef_bits = 0;
5228 cm->cdef_strengths[0] = 0;
5229 cm->nb_cdef_strengths = 1;
Yunqing Wangdad63d42017-12-08 12:45:07 -08005230 cm->cdef_uv_strengths[0] = 0;
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005231 } else {
Steinar Midtskogen59782122017-07-20 08:49:43 +02005232 // Find CDEF parameters
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005233 av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd,
Debargha Mukherjeed7338aa2017-11-04 07:34:50 -07005234 cpi->sf.fast_cdef_search);
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005235
5236 // Apply the filter
5237 av1_cdef_frame(cm->frame_to_show, cm, xd);
5238 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005239
Urvang Joshi94ad3702017-12-06 11:38:08 -08005240#if CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005241 superres_post_encode(cpi);
Urvang Joshi94ad3702017-12-06 11:38:08 -08005242#endif // CONFIG_HORZONLY_FRAME_SUPERRES
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005243
5244#if CONFIG_LOOP_RESTORATION
Yaowu Xu35ee2342017-11-08 11:50:46 -08005245 if (no_restoration) {
5246 cm->rst_info[0].frame_restoration_type = RESTORE_NONE;
5247 cm->rst_info[1].frame_restoration_type = RESTORE_NONE;
5248 cm->rst_info[2].frame_restoration_type = RESTORE_NONE;
5249 } else {
5250 av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1);
5251 av1_pick_filter_restoration(cpi->source, cpi);
5252 if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
5253 cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
5254 cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
Rupert Swarbrick70c399e2017-12-12 09:47:49 +00005255 av1_loop_restoration_filter_frame(cm->frame_to_show, cm);
Yaowu Xu35ee2342017-11-08 11:50:46 -08005256 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005257 }
5258#endif // CONFIG_LOOP_RESTORATION
Fergus Simpsonbc189932017-05-16 17:02:39 -07005259}
5260
Yaowu Xuf883b422016-08-30 14:01:10 -07005261static void encode_without_recode_loop(AV1_COMP *cpi) {
5262 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005263 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables.
Yaowu Xuc27fc142016-08-22 16:08:15 -07005264
Yaowu Xuf883b422016-08-30 14:01:10 -07005265 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005266
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005267 set_size_independent_vars(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005268
Fergus Simpsonbc189932017-05-16 17:02:39 -07005269 setup_frame_size(cpi);
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005270
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005271 assert(cm->width == cpi->scaled_source.y_crop_width);
5272 assert(cm->height == cpi->scaled_source.y_crop_height);
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -07005273
Yaowu Xuc27fc142016-08-22 16:08:15 -07005274 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
5275
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005276 cpi->source =
5277 av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
5278 if (cpi->unscaled_last_source != NULL)
5279 cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
5280 &cpi->scaled_last_source);
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005281 cpi->source->buf_8bit_valid = 0;
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005282 if (frame_is_intra_only(cm) == 0) {
Cheng Chen46f30c72017-09-07 11:13:33 -07005283 scale_references(cpi);
Debargha Mukherjee887069f2017-06-16 18:54:36 -07005284 }
5285
Yaowu Xuf883b422016-08-30 14:01:10 -07005286 av1_set_quantizer(cm, q);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005287 setup_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005288 suppress_active_map(cpi);
hui sued5a30f2017-04-27 16:02:49 -07005289
Yaowu Xuc27fc142016-08-22 16:08:15 -07005290 // Variance adaptive and in frame q adjustment experiments are mutually
5291 // exclusive.
5292 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005293 av1_vaq_frame_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005294 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005295 av1_setup_in_frame_q_adj(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005296 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005297 av1_cyclic_refresh_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005298 }
5299 apply_active_map(cpi);
5300
5301 // transform / motion compensation build reconstruction frame
Yaowu Xuf883b422016-08-30 14:01:10 -07005302 av1_encode_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005303
5304 // Update some stats from cyclic refresh, and check if we should not update
5305 // golden reference, for 1 pass CBR.
5306 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->frame_type != KEY_FRAME &&
Yaowu Xuf883b422016-08-30 14:01:10 -07005307 (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR))
5308 av1_cyclic_refresh_check_golden_update(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005309
5310 // Update the skip mb flag probabilities based on the distribution
5311 // seen in the last encoder iteration.
5312 // update_base_skip_probs(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005313 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005314}
5315
Tom Finegane4099e32018-01-23 12:01:51 -08005316static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005317 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005318 RATE_CONTROL *const rc = &cpi->rc;
5319 int bottom_index, top_index;
5320 int loop_count = 0;
5321 int loop_at_this_size = 0;
5322 int loop = 0;
5323 int overshoot_seen = 0;
5324 int undershoot_seen = 0;
5325 int frame_over_shoot_limit;
5326 int frame_under_shoot_limit;
5327 int q = 0, q_low = 0, q_high = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005328
5329 set_size_independent_vars(cpi);
5330
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005331 cpi->source->buf_8bit_valid = 0;
Yaowu Xu9b0f7032017-07-31 11:01:19 -07005332
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005333 aom_clear_system_state();
5334 setup_frame_size(cpi);
5335 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
5336
Yaowu Xuc27fc142016-08-22 16:08:15 -07005337 do {
Yaowu Xuf883b422016-08-30 14:01:10 -07005338 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005339
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07005340 if (loop_count == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005341 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
5342 set_mv_search_params(cpi);
5343
5344 // Reset the loop state for new frame size.
5345 overshoot_seen = 0;
5346 undershoot_seen = 0;
5347
Yaowu Xuc27fc142016-08-22 16:08:15 -07005348 q_low = bottom_index;
5349 q_high = top_index;
5350
5351 loop_at_this_size = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005352
Urvang Joshi2a74cf22017-12-18 17:21:41 -08005353 // Decide frame size bounds first time through.
Yaowu Xuf883b422016-08-30 14:01:10 -07005354 av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target,
5355 &frame_under_shoot_limit,
5356 &frame_over_shoot_limit);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005357 }
5358
Debargha Mukherjee17e7b082017-08-13 09:33:03 -07005359 // if frame was scaled calculate global_motion_search again if already done
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005360 if (loop_count > 0 && cpi->source && cpi->global_motion_search_done)
5361 if (cpi->source->y_crop_width != cm->width ||
5362 cpi->source->y_crop_height != cm->height)
5363 cpi->global_motion_search_done = 0;
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07005364 cpi->source =
5365 av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
Debargha Mukherjee17e7b082017-08-13 09:33:03 -07005366 if (cpi->unscaled_last_source != NULL)
5367 cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
5368 &cpi->scaled_last_source);
5369
Yaowu Xuc27fc142016-08-22 16:08:15 -07005370 if (frame_is_intra_only(cm) == 0) {
5371 if (loop_count > 0) {
5372 release_scaled_references(cpi);
5373 }
Cheng Chen46f30c72017-09-07 11:13:33 -07005374 scale_references(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005375 }
Yaowu Xuf883b422016-08-30 14:01:10 -07005376 av1_set_quantizer(cm, q);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005377
5378 if (loop_count == 0) setup_frame(cpi);
5379
Yaowu Xuc27fc142016-08-22 16:08:15 -07005380 // Base q-index may have changed, so we need to assign proper default coef
5381 // probs before every iteration.
5382 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005383 av1_default_coef_probs(cm);
Hui Su3694c832017-11-10 14:15:58 -08005384 av1_setup_frame_contexts(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005385 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005386
Yaowu Xuc27fc142016-08-22 16:08:15 -07005387 // Variance adaptive and in frame q adjustment experiments are mutually
5388 // exclusive.
5389 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005390 av1_vaq_frame_setup(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005391 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005392 av1_setup_in_frame_q_adj(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005393 }
5394
5395 // transform / motion compensation build reconstruction frame
Jingning Han8f661602017-08-19 08:16:50 -07005396 save_coding_context(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005397 av1_encode_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005398
5399 // Update the skip mb flag probabilities based on the distribution
5400 // seen in the last encoder iteration.
5401 // update_base_skip_probs(cpi);
5402
Yaowu Xuf883b422016-08-30 14:01:10 -07005403 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005404
5405 // Dummy pack of the bitstream using up to date stats to get an
5406 // accurate estimate of output frame size to determine if we need
5407 // to recode.
5408 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) {
Jingning Han8f661602017-08-19 08:16:50 -07005409 restore_coding_context(cpi);
Tom Finegane4099e32018-01-23 12:01:51 -08005410
5411 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
5412 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005413
5414 rc->projected_frame_size = (int)(*size) << 3;
5415 restore_coding_context(cpi);
5416
5417 if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1;
5418 }
5419
Yaowu Xuf883b422016-08-30 14:01:10 -07005420 if (cpi->oxcf.rc_mode == AOM_Q) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005421 loop = 0;
5422 } else {
5423 if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced &&
5424 (rc->projected_frame_size < rc->max_frame_bandwidth)) {
5425 int last_q = q;
5426 int64_t kf_err;
5427
5428 int64_t high_err_target = cpi->ambient_err;
5429 int64_t low_err_target = cpi->ambient_err >> 1;
5430
Yaowu Xuc27fc142016-08-22 16:08:15 -07005431 if (cm->use_highbitdepth) {
Alex Conversef77fd0b2017-04-20 11:00:24 -07005432 kf_err = aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005433 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07005434 kf_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005435 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005436 // Prevent possible divide by zero error below for perfect KF
5437 kf_err += !kf_err;
5438
5439 // The key frame is not good enough or we can afford
5440 // to make it better without undue risk of popping.
5441 if ((kf_err > high_err_target &&
5442 rc->projected_frame_size <= frame_over_shoot_limit) ||
5443 (kf_err > low_err_target &&
5444 rc->projected_frame_size <= frame_under_shoot_limit)) {
5445 // Lower q_high
5446 q_high = q > q_low ? q - 1 : q_low;
5447
5448 // Adjust Q
5449 q = (int)((q * high_err_target) / kf_err);
Yaowu Xuf883b422016-08-30 14:01:10 -07005450 q = AOMMIN(q, (q_high + q_low) >> 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005451 } else if (kf_err < low_err_target &&
5452 rc->projected_frame_size >= frame_under_shoot_limit) {
5453 // The key frame is much better than the previous frame
5454 // Raise q_low
5455 q_low = q < q_high ? q + 1 : q_high;
5456
5457 // Adjust Q
5458 q = (int)((q * low_err_target) / kf_err);
Yaowu Xuf883b422016-08-30 14:01:10 -07005459 q = AOMMIN(q, (q_high + q_low + 1) >> 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005460 }
5461
5462 // Clamp Q to upper and lower limits:
5463 q = clamp(q, q_low, q_high);
5464
5465 loop = q != last_q;
5466 } else if (recode_loop_test(cpi, frame_over_shoot_limit,
5467 frame_under_shoot_limit, q,
Yaowu Xuf883b422016-08-30 14:01:10 -07005468 AOMMAX(q_high, top_index), bottom_index)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005469 // Is the projected frame size out of range and are we allowed
5470 // to attempt to recode.
5471 int last_q = q;
5472 int retries = 0;
5473
Yaowu Xuc27fc142016-08-22 16:08:15 -07005474 // Frame size out of permitted range:
5475 // Update correction factor & compute new Q to try...
Yaowu Xuc27fc142016-08-22 16:08:15 -07005476 // Frame is too large
5477 if (rc->projected_frame_size > rc->this_frame_target) {
5478 // Special case if the projected size is > the max allowed.
5479 if (rc->projected_frame_size >= rc->max_frame_bandwidth)
5480 q_high = rc->worst_quality;
5481
5482 // Raise Qlow as to at least the current value
5483 q_low = q < q_high ? q + 1 : q_high;
5484
5485 if (undershoot_seen || loop_at_this_size > 1) {
5486 // Update rate_correction_factor unless
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005487 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005488
5489 q = (q_high + q_low + 1) / 2;
5490 } else {
5491 // Update rate_correction_factor unless
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005492 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005493
Yaowu Xuf883b422016-08-30 14:01:10 -07005494 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005495 AOMMAX(q_high, top_index), cm->width,
5496 cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005497
5498 while (q < q_low && retries < 10) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005499 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005500 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005501 AOMMAX(q_high, top_index), cm->width,
5502 cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005503 retries++;
5504 }
5505 }
5506
5507 overshoot_seen = 1;
5508 } else {
5509 // Frame is too small
5510 q_high = q > q_low ? q - 1 : q_low;
5511
5512 if (overshoot_seen || loop_at_this_size > 1) {
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 q = (q_high + q_low) / 2;
5515 } else {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005516 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005517 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005518 top_index, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005519 // Special case reset for qlow for constrained quality.
5520 // This should only trigger where there is very substantial
5521 // undershoot on a frame and the auto cq level is above
5522 // the user passsed in value.
Yaowu Xuf883b422016-08-30 14:01:10 -07005523 if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005524 q_low = q;
5525 }
5526
5527 while (q > q_high && retries < 10) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005528 av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005529 q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index,
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005530 top_index, cm->width, cm->height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005531 retries++;
5532 }
5533 }
5534
5535 undershoot_seen = 1;
5536 }
5537
5538 // Clamp Q to upper and lower limits:
5539 q = clamp(q, q_low, q_high);
5540
5541 loop = (q != last_q);
5542 } else {
5543 loop = 0;
5544 }
5545 }
5546
5547 // Special case for overlay frame.
5548 if (rc->is_src_frame_alt_ref &&
5549 rc->projected_frame_size < rc->max_frame_bandwidth)
5550 loop = 0;
5551
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08005552 if (recode_loop_test_global_motion(cpi)) {
5553 loop = 1;
5554 }
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -08005555
Yaowu Xuc27fc142016-08-22 16:08:15 -07005556 if (loop) {
5557 ++loop_count;
5558 ++loop_at_this_size;
5559
5560#if CONFIG_INTERNAL_STATS
5561 ++cpi->tot_recode_hits;
5562#endif
5563 }
5564 } while (loop);
Tom Finegane4099e32018-01-23 12:01:51 -08005565
5566 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005567}
5568
Yaowu Xuf883b422016-08-30 14:01:10 -07005569static int get_ref_frame_flags(const AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005570 const int *const map = cpi->common.ref_frame_map;
5571
Zoe Liu368bf162017-11-03 20:10:19 -07005572 // No.1 Priority: LAST_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -07005573 const int last2_is_last =
5574 map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]];
5575 const int last3_is_last =
5576 map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]];
5577 const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]];
5578 const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]];
Zoe Liu368bf162017-11-03 20:10:19 -07005579 const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005580 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]];
5581
Zoe Liu368bf162017-11-03 20:10:19 -07005582 // No.2 Priority: ALTREF_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -07005583 const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx];
5584 const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx];
5585 const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
5586 const int bwd_is_alt = map[cpi->bwd_fb_idx] == map[cpi->alt_fb_idx];
Zoe Liue9b15e22017-07-19 15:53:01 -07005587 const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005588
Zoe Liu368bf162017-11-03 20:10:19 -07005589 // No.3 Priority: LAST2_FRAME
5590 const int last3_is_last2 =
5591 map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]];
5592 const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]];
5593 const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]];
5594 const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005595
Zoe Liu368bf162017-11-03 20:10:19 -07005596 // No.4 Priority: LAST3_FRAME
5597 const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]];
5598 const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]];
5599 const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]];
5600
5601 // No.5 Priority: GOLDEN_FRAME
5602 const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx];
5603 const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx];
5604
5605 // No.6 Priority: BWDREF_FRAME
5606 const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx];
5607
5608 // No.7 Priority: ALTREF2_FRAME
5609
Yunqing Wang9a50fec2017-11-02 17:02:00 -07005610 // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be
5611 // adjusted according to external encoder flags.
Yunqing Wangf2e7a392017-11-08 00:27:21 -08005612 int flags = cpi->ext_ref_frame_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005613
Yaowu Xuf883b422016-08-30 14:01:10 -07005614 if (cpi->rc.frames_till_gf_update_due == INT_MAX) flags &= ~AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005615
Yaowu Xuf883b422016-08-30 14:01:10 -07005616 if (alt_is_last) flags &= ~AOM_ALT_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005617
Yaowu Xuf883b422016-08-30 14:01:10 -07005618 if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005619
Zoe Liu368bf162017-11-03 20:10:19 -07005620 if (last3_is_last || last3_is_alt || last3_is_last2) flags &= ~AOM_LAST3_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005621
Zoe Liu368bf162017-11-03 20:10:19 -07005622 if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3)
5623 flags &= ~AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005624
Zoe Liu368bf162017-11-03 20:10:19 -07005625 if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 ||
5626 bwd_is_gld) &&
Yaowu Xuf883b422016-08-30 14:01:10 -07005627 (flags & AOM_BWD_FLAG))
5628 flags &= ~AOM_BWD_FLAG;
Zoe Liue9b15e22017-07-19 15:53:01 -07005629
Zoe Liu368bf162017-11-03 20:10:19 -07005630 if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 ||
5631 alt2_is_gld || alt2_is_bwd) &&
Zoe Liue9b15e22017-07-19 15:53:01 -07005632 (flags & AOM_ALT2_FLAG))
5633 flags &= ~AOM_ALT2_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005634
5635 return flags;
5636}
5637
Yaowu Xuf883b422016-08-30 14:01:10 -07005638static void set_ext_overrides(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07005639 // Overrides the defaults with the externally supplied values with
Yaowu Xuf883b422016-08-30 14:01:10 -07005640 // av1_update_reference() and av1_update_entropy() calls
Yaowu Xuc27fc142016-08-22 16:08:15 -07005641 // Note: The overrides are valid only for the next frame passed
5642 // to encode_frame_to_data_rate() function
5643 if (cpi->ext_refresh_frame_context_pending) {
5644 cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context;
5645 cpi->ext_refresh_frame_context_pending = 0;
5646 }
5647 if (cpi->ext_refresh_frame_flags_pending) {
5648 cpi->refresh_last_frame = cpi->ext_refresh_last_frame;
5649 cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame;
5650 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
Yunqing Wang9a50fec2017-11-02 17:02:00 -07005651 cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame;
5652 cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005653 cpi->ext_refresh_frame_flags_pending = 0;
5654 }
5655}
5656
Yaowu Xuf883b422016-08-30 14:01:10 -07005657static int setup_interp_filter_search_mask(AV1_COMP *cpi) {
James Zern7b9407a2016-05-18 23:48:05 -07005658 InterpFilter ifilter;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005659 int ref_total[TOTAL_REFS_PER_FRAME] = { 0 };
5660 MV_REFERENCE_FRAME ref;
5661 int mask = 0;
5662 int arf_idx = ALTREF_FRAME;
5663
Zoe Liue9b15e22017-07-19 15:53:01 -07005664 if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame ||
5665 cpi->refresh_alt2_ref_frame)
Yaowu Xuc27fc142016-08-22 16:08:15 -07005666 return mask;
5667
Yaowu Xuc27fc142016-08-22 16:08:15 -07005668 for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref)
5669 for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter)
5670 ref_total[ref] += cpi->interp_filter_selected[ref][ifilter];
Yaowu Xuc27fc142016-08-22 16:08:15 -07005671
5672 for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) {
5673 if ((ref_total[LAST_FRAME] &&
5674 cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005675 (ref_total[LAST2_FRAME] == 0 ||
5676 cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 <
5677 ref_total[LAST2_FRAME]) &&
5678 (ref_total[LAST3_FRAME] == 0 ||
5679 cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 <
5680 ref_total[LAST3_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005681 (ref_total[GOLDEN_FRAME] == 0 ||
5682 cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 <
5683 ref_total[GOLDEN_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005684 (ref_total[BWDREF_FRAME] == 0 ||
5685 cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 <
5686 ref_total[BWDREF_FRAME]) &&
Zoe Liue9b15e22017-07-19 15:53:01 -07005687 (ref_total[ALTREF2_FRAME] == 0 ||
5688 cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 <
5689 ref_total[ALTREF2_FRAME]) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005690 (ref_total[ALTREF_FRAME] == 0 ||
5691 cpi->interp_filter_selected[arf_idx][ifilter] * 50 <
5692 ref_total[ALTREF_FRAME]))
5693 mask |= 1 << ifilter;
5694 }
5695 return mask;
5696}
5697
5698#define DUMP_RECON_FRAMES 0
5699
5700#if DUMP_RECON_FRAMES == 1
5701// NOTE(zoeliu): For debug - Output the filtered reconstructed video.
Yaowu Xuf883b422016-08-30 14:01:10 -07005702static void dump_filtered_recon_frames(AV1_COMP *cpi) {
5703 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005704 const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005705
Zoe Liub4f31032017-11-03 23:48:35 -07005706 if (recon_buf == NULL) {
5707 printf("Frame %d is not ready.\n", cm->current_video_frame);
5708 return;
5709 }
5710
Zoe Liub4f31032017-11-03 23:48:35 -07005711 static const int flag_list[TOTAL_REFS_PER_FRAME] = { 0,
5712 AOM_LAST_FLAG,
5713 AOM_LAST2_FLAG,
5714 AOM_LAST3_FLAG,
5715 AOM_GOLD_FLAG,
5716 AOM_BWD_FLAG,
5717 AOM_ALT2_FLAG,
5718 AOM_ALT_FLAG };
5719 printf(
5720 "\n***Frame=%d (frame_offset=%d, show_frame=%d, "
5721 "show_existing_frame=%d) "
5722 "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[",
5723 cm->current_video_frame, cm->frame_offset, cm->show_frame,
5724 cm->show_existing_frame);
5725 for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
5726 const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx;
5727 const int ref_offset =
5728 (buf_idx >= 0)
5729 ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset
5730 : -1;
Zoe Liuf452fdf2017-11-02 23:08:12 -07005731 printf(
5732 " %d(%c-%d-%4.2f)", ref_offset,
5733 (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N',
5734 (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1,
5735 (buf_idx >= 0) ? rate_factor_deltas[cpi->frame_rf_level[buf_idx]] : -1);
Zoe Liub4f31032017-11-03 23:48:35 -07005736 }
5737 printf(" ]\n");
Zoe Liub4f31032017-11-03 23:48:35 -07005738
5739 if (!cm->show_frame) {
5740 printf("Frame %d is a no show frame, so no image dump.\n",
Yaowu Xuc27fc142016-08-22 16:08:15 -07005741 cm->current_video_frame);
5742 return;
5743 }
5744
Zoe Liub4f31032017-11-03 23:48:35 -07005745 int h;
5746 char file_name[256] = "/tmp/enc_filtered_recon.yuv";
5747 FILE *f_recon = NULL;
5748
Yaowu Xuc27fc142016-08-22 16:08:15 -07005749 if (cm->current_video_frame == 0) {
5750 if ((f_recon = fopen(file_name, "wb")) == NULL) {
5751 printf("Unable to open file %s to write.\n", file_name);
5752 return;
5753 }
5754 } else {
5755 if ((f_recon = fopen(file_name, "ab")) == NULL) {
5756 printf("Unable to open file %s to append.\n", file_name);
5757 return;
5758 }
5759 }
5760 printf(
Zoe Liuf40a9572017-10-13 12:37:19 -07005761 "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, "
5762 "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, "
5763 "refresh_alt_ref_frame=%d, rf_level=%d, "
5764 "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n",
Yaowu Xuc27fc142016-08-22 16:08:15 -07005765 cm->current_video_frame, cpi->twopass.gf_group.index,
5766 cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index],
Zoe Liuf40a9572017-10-13 12:37:19 -07005767 cm->frame_offset, cm->show_frame, cm->show_existing_frame,
5768 cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame,
5769 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index],
5770 recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height);
Zoe Liue9b15e22017-07-19 15:53:01 -07005771#if 0
5772 int ref_frame;
5773 printf("get_ref_frame_map_idx: [");
5774 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame)
5775 printf(" %d", get_ref_frame_map_idx(cpi, ref_frame));
5776 printf(" ]\n");
5777 printf("cm->new_fb_idx = %d\n", cm->new_fb_idx);
5778 printf("cm->ref_frame_map = [");
5779 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
5780 printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]);
5781 }
5782 printf(" ]\n");
5783#endif // 0
Yaowu Xuc27fc142016-08-22 16:08:15 -07005784
5785 // --- Y ---
5786 for (h = 0; h < cm->height; ++h) {
5787 fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width,
5788 f_recon);
5789 }
5790 // --- U ---
5791 for (h = 0; h < (cm->height >> 1); ++h) {
5792 fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1),
5793 f_recon);
5794 }
5795 // --- V ---
5796 for (h = 0; h < (cm->height >> 1); ++h) {
5797 fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1),
5798 f_recon);
5799 }
5800
5801 fclose(f_recon);
5802}
5803#endif // DUMP_RECON_FRAMES
5804
Thomas Davies4822e142017-10-10 11:30:36 +01005805static void make_update_tile_list_enc(AV1_COMP *cpi, const int start_tile,
5806 const int num_tiles,
Thomas Davies028b57f2017-02-22 16:42:11 +00005807 FRAME_CONTEXT *ec_ctxs[]) {
5808 int i;
Thomas Davies4822e142017-10-10 11:30:36 +01005809 for (i = start_tile; i < start_tile + num_tiles; ++i)
5810 ec_ctxs[i - start_tile] = &cpi->tile_data[i].tctx;
Thomas Davies028b57f2017-02-22 16:42:11 +00005811}
5812
Tom Finegane4099e32018-01-23 12:01:51 -08005813static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest,
5814 int skip_adapt,
5815 unsigned int *frame_flags) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005816 AV1_COMMON *const cm = &cpi->common;
5817 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005818 struct segmentation *const seg = &cm->seg;
Thomas Davies4822e142017-10-10 11:30:36 +01005819 const int num_bwd_ctxs = 1;
Thomas Davies4822e142017-10-10 11:30:36 +01005820
5821 FRAME_CONTEXT **tile_ctxs =
5822 aom_malloc(num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx));
5823 aom_cdf_prob **cdf_ptrs = aom_malloc(
5824 num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0]));
Yaowu Xuc27fc142016-08-22 16:08:15 -07005825 set_ext_overrides(cpi);
Yaowu Xuf883b422016-08-30 14:01:10 -07005826 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005827
Fangwen Fu8d164de2016-12-14 13:40:54 -08005828 // frame type has been decided outside of this function call
5829 cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only;
Jingning Han2830fd92018-01-10 10:06:26 -08005830 cm->use_ref_frame_mvs = !cpi->oxcf.disable_tempmv &&
5831 !cm->cur_frame->intra_only &&
5832 frame_might_use_prev_frame_mvs(cm);
Jingning Hane17ebe92017-11-03 15:25:42 -07005833 cm->use_prev_frame_mvs = cm->use_ref_frame_mvs;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005834
Jingning Hand8a15a62017-10-30 10:53:42 -07005835 // Reset the frame packet stamp index.
5836 if (cm->frame_type == KEY_FRAME) cm->current_video_frame = 0;
5837
Yaowu Xuc27fc142016-08-22 16:08:15 -07005838 // NOTE:
5839 // (1) Move the setup of the ref_frame_flags upfront as it would be
5840 // determined by the current frame properties;
5841 // (2) The setup of the ref_frame_flags applies to both show_existing_frame's
5842 // and the other cases.
5843 if (cm->current_video_frame > 0)
5844 cpi->ref_frame_flags = get_ref_frame_flags(cpi);
5845
5846 if (cm->show_existing_frame) {
5847 // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current
5848 // BWDREF_FRAME in the reference frame buffer.
5849 cm->frame_type = INTER_FRAME;
5850 cm->show_frame = 1;
5851 cpi->frame_flags = *frame_flags;
5852
5853 // In the case of show_existing frame, we will not send fresh flag
5854 // to decoder. Any change in the reference frame buffer can be done by
5855 // switching the virtual indices.
5856
5857 cpi->refresh_last_frame = 0;
5858 cpi->refresh_golden_frame = 0;
5859 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07005860 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005861 cpi->refresh_alt_ref_frame = 0;
5862
5863 cpi->rc.is_bwd_ref_frame = 0;
5864 cpi->rc.is_last_bipred_frame = 0;
5865 cpi->rc.is_bipred_frame = 0;
5866
Jingning Han8f661602017-08-19 08:16:50 -07005867 restore_coding_context(cpi);
Zoe Liub4f31032017-11-03 23:48:35 -07005868
Yaowu Xuc27fc142016-08-22 16:08:15 -07005869 // Build the bitstream
Tom Finegane4099e32018-01-23 12:01:51 -08005870 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
5871 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005872
5873 // Set up frame to show to get ready for stats collection.
5874 cm->frame_to_show = get_frame_new_buffer(cm);
5875
Zoe Liub4f31032017-11-03 23:48:35 -07005876 // Update current frame offset.
5877 cm->frame_offset =
5878 cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset;
Zoe Liub4f31032017-11-03 23:48:35 -07005879
Yaowu Xuc27fc142016-08-22 16:08:15 -07005880#if DUMP_RECON_FRAMES == 1
5881 // NOTE(zoeliu): For debug - Output the filtered reconstructed video.
5882 dump_filtered_recon_frames(cpi);
5883#endif // DUMP_RECON_FRAMES
5884
5885 // Update the LAST_FRAME in the reference frame buffer.
Zoe Liue9b15e22017-07-19 15:53:01 -07005886 // NOTE:
5887 // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame
5888 // update has been done previously when handling the LAST_BIPRED_FRAME
5889 // right before BWDREF_FRAME (in the display order);
5890 // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame
5891 // update will be done when the following is called, which will exchange
5892 // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that
5893 // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and
5894 // ALTREF2_FRAME will serve as the new LAST_FRAME.
Cheng Chen46f30c72017-09-07 11:13:33 -07005895 update_reference_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005896
5897 // Update frame flags
5898 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
5899 cpi->frame_flags &= ~FRAMEFLAGS_BWDREF;
5900 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
5901
5902 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
5903
5904 // Update the frame type
5905 cm->last_frame_type = cm->frame_type;
5906
Yaowu Xuc27fc142016-08-22 16:08:15 -07005907 // Since we allocate a spot for the OVERLAY frame in the gf group, we need
5908 // to do post-encoding update accordingly.
5909 if (cpi->rc.is_src_frame_alt_ref) {
Debargha Mukherjee7166f222017-09-05 21:32:42 -07005910 av1_set_target_rate(cpi, cm->width, cm->height);
Yaowu Xuf883b422016-08-30 14:01:10 -07005911 av1_rc_postencode_update(cpi, *size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005912 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005913
Yaowu Xuc27fc142016-08-22 16:08:15 -07005914 ++cm->current_video_frame;
5915
Jingning Hanf6214b92017-04-12 11:43:37 -07005916 aom_free(tile_ctxs);
5917 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08005918 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005919 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005920
5921 // Set default state for segment based loop filter update flags.
5922 cm->lf.mode_ref_delta_update = 0;
5923
5924 if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search)
5925 cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi);
5926
5927 // Set various flags etc to special state if it is a key frame.
5928 if (frame_is_intra_only(cm)) {
5929 // Reset the loop filter deltas and segmentation map.
Yaowu Xuf883b422016-08-30 14:01:10 -07005930 av1_reset_segment_features(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005931
5932 // If segmentation is enabled force a map update for key frames.
5933 if (seg->enabled) {
5934 seg->update_map = 1;
5935 seg->update_data = 1;
5936 }
5937
5938 // The alternate reference frame cannot be active for a key frame.
5939 cpi->rc.source_alt_ref_active = 0;
5940
5941 cm->error_resilient_mode = oxcf->error_resilient_mode;
5942
Thomas Daedea6a854b2017-06-22 17:49:11 -07005943#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07005944 // By default, encoder assumes decoder can use prev_mi.
5945 if (cm->error_resilient_mode) {
5946 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
5947 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
5948 } else if (cm->intra_only) {
5949 // Only reset the current context.
5950 cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT;
5951 }
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01005952#if CONFIG_EXT_TILE
5953 if (cpi->oxcf.large_scale_tile)
5954 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
5955#endif // CONFIG_EXT_TILE
5956#endif // !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07005957 }
Thomas Daviesaf6df172016-11-09 14:04:18 +00005958 if (cpi->oxcf.mtu == 0) {
5959 cm->num_tg = cpi->oxcf.num_tile_groups;
5960 } else {
Yaowu Xu859a5272016-11-10 15:32:21 -08005961 // Use a default value for the purposes of weighting costs in probability
5962 // updates
Thomas Daviesaf6df172016-11-09 14:04:18 +00005963 cm->num_tg = DEFAULT_MAX_NUM_TG;
5964 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07005965
Yunqing Wangd8cd55f2017-02-27 12:16:00 -08005966#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -07005967 cm->large_scale_tile = cpi->oxcf.large_scale_tile;
5968 cm->single_tile_decoding = cpi->oxcf.single_tile_decoding;
Yunqing Wangb6e23bc2017-11-15 13:18:55 -08005969#if CONFIG_REFERENCE_BUFFER
5970 if (cm->large_scale_tile) cm->seq_params.frame_id_numbers_present_flag = 0;
5971#endif // CONFIG_REFERENCE_BUFFER
Yunqing Wangd8cd55f2017-02-27 12:16:00 -08005972#endif // CONFIG_EXT_TILE
5973
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08005974#if CONFIG_MONO_VIDEO
5975 cm->seq_params.monochrome = oxcf->monochrome;
5976#endif // CONFIG_MONO_VIDEO
5977
Yaowu Xuc27fc142016-08-22 16:08:15 -07005978 // For 1 pass CBR, check if we are dropping this frame.
5979 // Never drop on key frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07005980 if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07005981 cm->frame_type != KEY_FRAME) {
Yaowu Xuf883b422016-08-30 14:01:10 -07005982 if (av1_rc_drop_frame(cpi)) {
5983 av1_rc_postencode_update_drop_frame(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07005984 ++cm->current_video_frame;
Jingning Hanf6214b92017-04-12 11:43:37 -07005985 aom_free(tile_ctxs);
5986 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08005987 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07005988 }
5989 }
5990
Yaowu Xuf883b422016-08-30 14:01:10 -07005991 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07005992
5993#if CONFIG_INTERNAL_STATS
5994 memset(cpi->mode_chosen_counts, 0,
5995 MAX_MODES * sizeof(*cpi->mode_chosen_counts));
5996#endif
5997
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01005998#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01005999 if (cm->seq_params.frame_id_numbers_present_flag) {
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006000 /* Non-normative definition of current_frame_id ("frame counter" with
Johann123e8a62017-12-28 14:40:49 -08006001 * wraparound) */
Sebastien Alaiwand418f682017-10-19 15:06:52 +02006002 const int frame_id_length = FRAME_ID_LENGTH;
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006003 if (cm->current_frame_id == -1) {
David Barker49a76562016-12-07 14:50:21 +00006004 int lsb, msb;
Yaowu Xud3e7c682017-12-21 14:08:25 -08006005 /* quasi-random initialization of current_frame_id for a key frame */
Alex Conversef77fd0b2017-04-20 11:00:24 -07006006 if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) {
6007 lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff;
6008 msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff;
David Barker49a76562016-12-07 14:50:21 +00006009 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006010 lsb = cpi->source->y_buffer[0] & 0xff;
6011 msb = cpi->source->y_buffer[1] & 0xff;
David Barker49a76562016-12-07 14:50:21 +00006012 }
Arild Fuldseth (arilfuld)788dc232016-12-20 17:55:52 +01006013 cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length);
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006014 } else {
6015 cm->current_frame_id =
Arild Fuldseth (arilfuld)788dc232016-12-20 17:55:52 +01006016 (cm->current_frame_id + 1 + (1 << frame_id_length)) %
6017 (1 << frame_id_length);
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006018 }
6019 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006020#endif // CONFIG_REFERENCE_BUFFER
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006021
Yaowu Xuc27fc142016-08-22 16:08:15 -07006022 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
6023 encode_without_recode_loop(cpi);
6024 } else {
Tom Finegane4099e32018-01-23 12:01:51 -08006025 if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK)
6026 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006027 }
6028
Yi Luo10e23002017-07-31 11:54:43 -07006029 cm->last_tile_cols = cm->tile_cols;
6030 cm->last_tile_rows = cm->tile_rows;
6031
Yaowu Xuc27fc142016-08-22 16:08:15 -07006032#ifdef OUTPUT_YUV_SKINMAP
6033 if (cpi->common.current_video_frame > 1) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006034 av1_compute_skin_map(cpi, yuv_skinmap_file);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006035 }
6036#endif // OUTPUT_YUV_SKINMAP
6037
6038 // Special case code to reduce pulsing when key frames are forced at a
6039 // fixed interval. Note the reconstruction error if it is the frame before
6040 // the force key frame
6041 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006042 if (cm->use_highbitdepth) {
6043 cpi->ambient_err =
Alex Conversef77fd0b2017-04-20 11:00:24 -07006044 aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006045 } else {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006046 cpi->ambient_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006047 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006048 }
6049
6050 // If the encoder forced a KEY_FRAME decision
6051 if (cm->frame_type == KEY_FRAME) {
6052 cpi->refresh_last_frame = 1;
6053 }
6054
6055 cm->frame_to_show = get_frame_new_buffer(cm);
Andrey Norkin9e694632017-12-21 18:50:57 -08006056#if CONFIG_CICP
6057 cm->frame_to_show->color_primaries = cm->color_primaries;
6058 cm->frame_to_show->transfer_characteristics = cm->transfer_characteristics;
6059 cm->frame_to_show->matrix_coefficients = cm->matrix_coefficients;
6060#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07006061 cm->frame_to_show->color_space = cm->color_space;
Andrey Norkin9e694632017-12-21 18:50:57 -08006062#endif
Debargha Mukherjeef340fec2018-01-10 18:12:22 -08006063#if CONFIG_MONO_VIDEO
6064 cm->frame_to_show->monochrome = cm->seq_params.monochrome;
6065#endif // CONFIG_MONO_VIDEO
anorkin76fb1262017-03-22 15:12:12 -07006066#if CONFIG_COLORSPACE_HEADERS
Andrey Norkin9e694632017-12-21 18:50:57 -08006067#if !CONFIG_CICP
anorkin76fb1262017-03-22 15:12:12 -07006068 cm->frame_to_show->transfer_function = cm->transfer_function;
Andrey Norkin9e694632017-12-21 18:50:57 -08006069#endif
anorkin76fb1262017-03-22 15:12:12 -07006070 cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position;
6071#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006072 cm->frame_to_show->color_range = cm->color_range;
6073 cm->frame_to_show->render_width = cm->render_width;
6074 cm->frame_to_show->render_height = cm->render_height;
6075
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006076 // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned
6077 // off.
Yaowu Xuc27fc142016-08-22 16:08:15 -07006078
6079 // Pick the loop filter level for the frame.
David Barker218556e2018-02-14 14:23:12 +00006080#if CONFIG_INTRABC
6081 if (!(cm->allow_intrabc && NO_FILTER_FOR_IBC))
6082#endif
6083 loopfilter_frame(cpi, cm);
6084
6085 // TODO(debargha): Fix mv search range on encoder side
6086 // aom_extend_frame_inner_borders(cm->frame_to_show, av1_num_planes(cm));
6087 aom_extend_frame_borders(cm->frame_to_show, av1_num_planes(cm));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006088
Wei-Ting Lin01d4d8f2017-08-03 17:04:12 -07006089#ifdef OUTPUT_YUV_REC
6090 aom_write_one_yuv_frame(cm, cm->frame_to_show);
6091#endif
6092
Yaowu Xuc27fc142016-08-22 16:08:15 -07006093 // Build the bitstream
Tom Finegane4099e32018-01-23 12:01:51 -08006094 if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK)
6095 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006096
Jingning Hanf6214b92017-04-12 11:43:37 -07006097 if (skip_adapt) {
Jingning Hanf6214b92017-04-12 11:43:37 -07006098 aom_free(tile_ctxs);
6099 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006100 return AOM_CODEC_OK;
Jingning Hanf6214b92017-04-12 11:43:37 -07006101 }
Rostislav Pehlivanov74021a52017-03-09 09:05:29 +00006102
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006103#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01006104 if (cm->seq_params.frame_id_numbers_present_flag) {
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006105 int i;
6106 /* Update reference frame id values based on the value of refresh_mask */
6107 for (i = 0; i < REF_FRAMES; i++) {
6108 if ((cm->refresh_mask >> i) & 1) {
6109 cm->ref_frame_id[i] = cm->current_frame_id;
6110 }
6111 }
6112 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006113#endif // CONFIG_REFERENCE_BUFFER
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006114
Yaowu Xuc27fc142016-08-22 16:08:15 -07006115#if DUMP_RECON_FRAMES == 1
6116 // NOTE(zoeliu): For debug - Output the filtered reconstructed video.
Zoe Liub4f31032017-11-03 23:48:35 -07006117 dump_filtered_recon_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006118#endif // DUMP_RECON_FRAMES
6119
Soo-Chul Han934af352017-10-15 15:21:51 -04006120#if CONFIG_SEGMENT_PRED_LAST
6121 if (cm->seg.enabled) {
6122 if (cm->seg.update_map) {
6123 update_reference_segmentation_map(cpi);
6124 } else {
6125 memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map,
6126 cm->mi_cols * cm->mi_rows * sizeof(uint8_t));
6127 }
6128 }
6129#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07006130 if (cm->seg.update_map) update_reference_segmentation_map(cpi);
Soo-Chul Han934af352017-10-15 15:21:51 -04006131#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006132
6133 if (frame_is_intra_only(cm) == 0) {
6134 release_scaled_references(cpi);
6135 }
6136
Cheng Chen46f30c72017-09-07 11:13:33 -07006137 update_reference_frames(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006138
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08006139#if CONFIG_ENTROPY_STATS
6140 av1_accumulate_frame_counts(&aggregate_fc, &cm->counts);
Zoe Liua56f9162017-06-21 22:49:57 -07006141 assert(cm->frame_context_idx < FRAME_CONTEXTS);
6142 av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx],
6143 &cm->counts);
Debargha Mukherjee5802ebe2016-12-21 04:17:24 -08006144#endif // CONFIG_ENTROPY_STATS
Yaowu Xuc27fc142016-08-22 16:08:15 -07006145 if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
Thomas Davies4822e142017-10-10 11:30:36 +01006146 make_update_tile_list_enc(cpi, cm->largest_tile_id, 1, tile_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006147 av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006148 num_bwd_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006149 av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006150 num_bwd_ctxs);
Debargha Mukherjee43061b32017-10-13 16:50:17 -07006151 av1_average_tile_loopfilter_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
6152 num_bwd_ctxs);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006153 }
6154
6155 if (!frame_is_intra_only(cm)) {
6156 if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
Thomas Davies028b57f2017-02-22 16:42:11 +00006157 av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs,
Thomas Davies4822e142017-10-10 11:30:36 +01006158 cdf_ptrs, num_bwd_ctxs);
Thomas Davies493623e2017-03-31 16:12:25 +01006159 av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
Thomas Davies4822e142017-10-10 11:30:36 +01006160 num_bwd_ctxs);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006161 }
6162 }
6163
6164 if (cpi->refresh_golden_frame == 1)
6165 cpi->frame_flags |= FRAMEFLAGS_GOLDEN;
6166 else
6167 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
6168
6169 if (cpi->refresh_alt_ref_frame == 1)
6170 cpi->frame_flags |= FRAMEFLAGS_ALTREF;
6171 else
6172 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
6173
Yaowu Xuc27fc142016-08-22 16:08:15 -07006174 if (cpi->refresh_bwd_ref_frame == 1)
6175 cpi->frame_flags |= FRAMEFLAGS_BWDREF;
6176 else
6177 cpi->frame_flags &= ~FRAMEFLAGS_BWDREF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006178
Yaowu Xuc27fc142016-08-22 16:08:15 -07006179 cm->last_frame_type = cm->frame_type;
6180
Yaowu Xuf883b422016-08-30 14:01:10 -07006181 av1_rc_postencode_update(cpi, *size);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006182
6183#if 0
6184 output_frame_level_debug_stats(cpi);
6185#endif
6186
6187 if (cm->frame_type == KEY_FRAME) {
6188 // Tell the caller that the frame was coded as a key frame
6189 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
6190 } else {
6191 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
6192 }
6193
6194 // Clear the one shot update flags for segmentation map and mode/ref loop
6195 // filter deltas.
6196 cm->seg.update_map = 0;
6197 cm->seg.update_data = 0;
6198 cm->lf.mode_ref_delta_update = 0;
6199
Yaowu Xuc27fc142016-08-22 16:08:15 -07006200 if (cm->show_frame) {
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006201 // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are
6202 // being used as reference.
Cheng Chen46f30c72017-09-07 11:13:33 -07006203 swap_mi_and_prev_mi(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006204 // Don't increment frame counters if this was an altref buffer
6205 // update not a real frame
6206 ++cm->current_video_frame;
6207 }
6208
Yaowu Xuc27fc142016-08-22 16:08:15 -07006209 // NOTE: Shall not refer to any frame not used as reference.
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006210 if (cm->is_reference_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006211 cm->prev_frame = cm->cur_frame;
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006212 // keep track of the last coded dimensions
6213 cm->last_width = cm->width;
6214 cm->last_height = cm->height;
6215
6216 // reset to normal state now that we are done.
6217 cm->last_show_frame = cm->show_frame;
Fergus Simpson2b4ea112017-06-19 11:33:59 -07006218 }
Yi Luo10e23002017-07-31 11:54:43 -07006219
Thomas Davies493623e2017-03-31 16:12:25 +01006220 aom_free(tile_ctxs);
6221 aom_free(cdf_ptrs);
Tom Finegane4099e32018-01-23 12:01:51 -08006222 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006223}
6224
Tom Finegane4099e32018-01-23 12:01:51 -08006225static int Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest,
6226 int skip_adapt, unsigned int *frame_flags) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006227 if (cpi->oxcf.rc_mode == AOM_CBR) {
6228 av1_rc_get_one_pass_cbr_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006229 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07006230 av1_rc_get_one_pass_vbr_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006231 }
Tom Finegane4099e32018-01-23 12:01:51 -08006232 return encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006233}
6234
Tom Finegane4099e32018-01-23 12:01:51 -08006235static int Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest,
6236 unsigned int *frame_flags) {
Angie Chiang5b5f4df2017-12-06 10:41:12 -08006237#if CONFIG_MISMATCH_DEBUG
6238 mismatch_move_frame_idx_w();
6239#endif
Angie Chiang4d55d762017-12-13 16:18:37 -08006240#if TXCOEFF_COST_TIMER
6241 AV1_COMMON *cm = &cpi->common;
6242 cm->txcoeff_cost_timer = 0;
6243 cm->txcoeff_cost_count = 0;
6244#endif
Tom Finegane4099e32018-01-23 12:01:51 -08006245
6246 if (encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags) !=
6247 AOM_CODEC_OK) {
6248 return AOM_CODEC_ERROR;
6249 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006250
Angie Chiang4d55d762017-12-13 16:18:37 -08006251#if TXCOEFF_COST_TIMER
6252 cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer;
6253 fprintf(stderr,
6254 "\ntxb coeff cost block number: %ld, frame time: %ld, cum time %ld "
6255 "in us\n",
6256 cm->txcoeff_cost_count, cm->txcoeff_cost_timer,
6257 cm->cum_txcoeff_cost_timer);
6258#endif
6259
Yaowu Xuc27fc142016-08-22 16:08:15 -07006260 // Do not do post-encoding update for those frames that do not have a spot in
6261 // a gf group, but note that an OVERLAY frame always has a spot in a gf group,
6262 // even when show_existing_frame is used.
6263 if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006264 av1_twopass_postencode_update(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006265 }
6266 check_show_existing_frame(cpi);
Tom Finegane4099e32018-01-23 12:01:51 -08006267 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006268}
6269
James Zern3e2613b2017-03-30 23:14:40 -07006270int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
Yaowu Xuf883b422016-08-30 14:01:10 -07006271 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
6272 int64_t end_time) {
6273 AV1_COMMON *const cm = &cpi->common;
6274 struct aom_usec_timer timer;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006275 int res = 0;
6276 const int subsampling_x = sd->subsampling_x;
6277 const int subsampling_y = sd->subsampling_y;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006278 const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006279
Yaowu Xuc27fc142016-08-22 16:08:15 -07006280 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006281
Yaowu Xuf883b422016-08-30 14:01:10 -07006282 aom_usec_timer_start(&timer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006283
Yaowu Xuf883b422016-08-30 14:01:10 -07006284 if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
Yaowu Xud3e7c682017-12-21 14:08:25 -08006285 use_highbitdepth, frame_flags))
Yaowu Xuc27fc142016-08-22 16:08:15 -07006286 res = -1;
Yaowu Xuf883b422016-08-30 14:01:10 -07006287 aom_usec_timer_mark(&timer);
6288 cpi->time_receive_data += aom_usec_timer_elapsed(&timer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006289
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006290 if ((cm->profile == PROFILE_0) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07006291 (subsampling_x != 1 || subsampling_y != 1)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006292 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006293 "Non-4:2:0 color format requires profile 1 or 2");
Yaowu Xuc27fc142016-08-22 16:08:15 -07006294 res = -1;
6295 }
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006296 if ((cm->profile == PROFILE_1) &&
6297 !(subsampling_x == 0 && subsampling_y == 0)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006298 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
Debargha Mukherjeef9a50ea2018-01-09 22:28:20 -08006299 "Profile 1 requires 4:4:4 color format");
6300 res = -1;
6301 }
6302 if ((cm->profile == PROFILE_2) && (cm->bit_depth <= AOM_BITS_10) &&
6303 !(subsampling_x == 1 && subsampling_y == 0)) {
6304 aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
6305 "Profile 2 bit-depth < 10 requires 4:2:2 color format");
Yaowu Xuc27fc142016-08-22 16:08:15 -07006306 res = -1;
6307 }
6308
6309 return res;
6310}
6311
Yaowu Xuf883b422016-08-30 14:01:10 -07006312static int frame_is_reference(const AV1_COMP *cpi) {
6313 const AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006314
6315 return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame ||
Sebastien Alaiwan365e6442017-10-16 11:35:00 +02006316 cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame ||
6317 cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame ||
6318 !cm->error_resilient_mode || cm->lf.mode_ref_delta_update ||
6319 cm->seg.update_map || cm->seg.update_data;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006320}
6321
Yaowu Xuf883b422016-08-30 14:01:10 -07006322static void adjust_frame_rate(AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006323 const struct lookahead_entry *source) {
6324 int64_t this_duration;
6325 int step = 0;
6326
6327 if (source->ts_start == cpi->first_time_stamp_ever) {
6328 this_duration = source->ts_end - source->ts_start;
6329 step = 1;
6330 } else {
6331 int64_t last_duration =
6332 cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen;
6333
6334 this_duration = source->ts_end - cpi->last_end_time_stamp_seen;
6335
6336 // do a step update if the duration changes by 10%
6337 if (last_duration)
6338 step = (int)((this_duration - last_duration) * 10 / last_duration);
6339 }
6340
6341 if (this_duration) {
6342 if (step) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006343 av1_new_framerate(cpi, 10000000.0 / this_duration);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006344 } else {
6345 // Average this frame's rate into the last second's average
6346 // frame rate. If we haven't seen 1 second yet, then average
6347 // over the whole interval seen.
Yaowu Xuf883b422016-08-30 14:01:10 -07006348 const double interval = AOMMIN(
Yaowu Xuc27fc142016-08-22 16:08:15 -07006349 (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0);
6350 double avg_duration = 10000000.0 / cpi->framerate;
6351 avg_duration *= (interval - avg_duration + this_duration);
6352 avg_duration /= interval;
6353
Yaowu Xuf883b422016-08-30 14:01:10 -07006354 av1_new_framerate(cpi, 10000000.0 / avg_duration);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006355 }
6356 }
6357 cpi->last_time_stamp_seen = source->ts_start;
6358 cpi->last_end_time_stamp_seen = source->ts_end;
6359}
6360
6361// Returns 0 if this is not an alt ref else the offset of the source frame
6362// used as the arf midpoint.
Yaowu Xuf883b422016-08-30 14:01:10 -07006363static int get_arf_src_index(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006364 RATE_CONTROL *const rc = &cpi->rc;
6365 int arf_src_index = 0;
6366 if (is_altref_enabled(cpi)) {
6367 if (cpi->oxcf.pass == 2) {
6368 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6369 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
6370 arf_src_index = gf_group->arf_src_offset[gf_group->index];
6371 }
6372 } else if (rc->source_alt_ref_pending) {
6373 arf_src_index = rc->frames_till_gf_update_due;
6374 }
6375 }
6376 return arf_src_index;
6377}
6378
Yaowu Xuf883b422016-08-30 14:01:10 -07006379static int get_brf_src_index(AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006380 int brf_src_index = 0;
6381 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6382
6383 // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup
6384 // flag.
6385 if (gf_group->bidir_pred_enabled[gf_group->index]) {
6386 if (cpi->oxcf.pass == 2) {
6387 if (gf_group->update_type[gf_group->index] == BRF_UPDATE)
6388 brf_src_index = gf_group->brf_src_offset[gf_group->index];
6389 } else {
6390 // TODO(zoeliu): To re-visit the setup for this scenario
6391 brf_src_index = cpi->rc.bipred_group_interval - 1;
6392 }
6393 }
6394
6395 return brf_src_index;
6396}
Zoe Liue9b15e22017-07-19 15:53:01 -07006397
Zoe Liue9b15e22017-07-19 15:53:01 -07006398// Returns 0 if this is not an alt ref else the offset of the source frame
6399// used as the arf midpoint.
6400static int get_arf2_src_index(AV1_COMP *cpi) {
6401 int arf2_src_index = 0;
6402 if (is_altref_enabled(cpi) && cpi->num_extra_arfs) {
6403 if (cpi->oxcf.pass == 2) {
6404 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6405 if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) {
6406 arf2_src_index = gf_group->arf_src_offset[gf_group->index];
6407 }
6408 }
6409 }
6410 return arf2_src_index;
6411}
Yaowu Xuc27fc142016-08-22 16:08:15 -07006412
Yaowu Xuf883b422016-08-30 14:01:10 -07006413static void check_src_altref(AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006414 const struct lookahead_entry *source) {
6415 RATE_CONTROL *const rc = &cpi->rc;
6416
6417 // If pass == 2, the parameters set here will be reset in
Yaowu Xuf883b422016-08-30 14:01:10 -07006418 // av1_rc_get_second_pass_params()
Yaowu Xuc27fc142016-08-22 16:08:15 -07006419
6420 if (cpi->oxcf.pass == 2) {
6421 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
6422 rc->is_src_frame_alt_ref =
Yaowu Xuc27fc142016-08-22 16:08:15 -07006423 (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07006424 (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE);
Zoe Liue9b15e22017-07-19 15:53:01 -07006425 rc->is_src_frame_ext_arf =
6426 gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006427 } else {
6428 rc->is_src_frame_alt_ref =
6429 cpi->alt_ref_source && (source == cpi->alt_ref_source);
6430 }
6431
6432 if (rc->is_src_frame_alt_ref) {
6433 // Current frame is an ARF overlay frame.
6434 cpi->alt_ref_source = NULL;
6435
Zoe Liue9b15e22017-07-19 15:53:01 -07006436 if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) {
6437 // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to
6438 // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3,
6439 // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST.
6440 cpi->refresh_last_frame = 1;
6441 } else {
Zoe Liue9b15e22017-07-19 15:53:01 -07006442 // Don't refresh the last buffer for an ARF overlay frame. It will
6443 // become the GF so preserve last as an alternative prediction option.
6444 cpi->refresh_last_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006445 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006446 }
6447}
6448
6449#if CONFIG_INTERNAL_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -07006450extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch,
6451 const unsigned char *img2, int img2_pitch,
6452 int width, int height);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006453
6454static void adjust_image_stat(double y, double u, double v, double all,
6455 ImageStat *s) {
6456 s->stat[Y] += y;
6457 s->stat[U] += u;
6458 s->stat[V] += v;
6459 s->stat[ALL] += all;
Yaowu Xuf883b422016-08-30 14:01:10 -07006460 s->worst = AOMMIN(s->worst, all);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006461}
6462
Angie Chiang08a22a62017-07-17 17:29:17 -07006463static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006464 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006465 double samples = 0.0;
6466 uint32_t in_bit_depth = 8;
6467 uint32_t bit_depth = 8;
6468
Angie Chiang08a22a62017-07-17 17:29:17 -07006469#if CONFIG_INTER_STATS_ONLY
Yaowu Xu1b4ffc42017-07-26 09:54:07 -07006470 if (cm->frame_type == KEY_FRAME) return; // skip key frame
Angie Chiang08a22a62017-07-17 17:29:17 -07006471#endif
6472 cpi->bytes += frame_bytes;
6473
Yaowu Xuc27fc142016-08-22 16:08:15 -07006474 if (cm->use_highbitdepth) {
6475 in_bit_depth = cpi->oxcf.input_bit_depth;
6476 bit_depth = cm->bit_depth;
6477 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006478 if (cm->show_frame) {
Alex Conversef77fd0b2017-04-20 11:00:24 -07006479 const YV12_BUFFER_CONFIG *orig = cpi->source;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006480 const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
6481 double y, u, v, frame_all;
6482
6483 cpi->count++;
6484 if (cpi->b_calculate_psnr) {
6485 PSNR_STATS psnr;
6486 double frame_ssim2 = 0.0, weight = 0.0;
Yaowu Xuf883b422016-08-30 14:01:10 -07006487 aom_clear_system_state();
Yaowu Xud3e7c682017-12-21 14:08:25 -08006488 // TODO(yaowu): unify these two versions into one.
Yaowu Xuf883b422016-08-30 14:01:10 -07006489 aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006490
6491 adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0],
6492 &cpi->psnr);
6493 cpi->total_sq_error += psnr.sse[0];
6494 cpi->total_samples += psnr.samples[0];
6495 samples = psnr.samples[0];
Yaowu Xud3e7c682017-12-21 14:08:25 -08006496 // TODO(yaowu): unify these two versions into one.
Yaowu Xuc27fc142016-08-22 16:08:15 -07006497 if (cm->use_highbitdepth)
6498 frame_ssim2 =
Yaowu Xuf883b422016-08-30 14:01:10 -07006499 aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006500 else
Yaowu Xuf883b422016-08-30 14:01:10 -07006501 frame_ssim2 = aom_calc_ssim(orig, recon, &weight);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006502
Yaowu Xuf883b422016-08-30 14:01:10 -07006503 cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006504 cpi->summed_quality += frame_ssim2 * weight;
6505 cpi->summed_weights += weight;
6506
6507#if 0
6508 {
6509 FILE *f = fopen("q_used.stt", "a");
Zoe Liuee202be2017-11-17 12:14:33 -08006510 double y2 = psnr.psnr[1];
6511 double u2 = psnr.psnr[2];
6512 double v2 = psnr.psnr[3];
6513 double frame_psnr2 = psnr.psnr[0];
Yaowu Xuc27fc142016-08-22 16:08:15 -07006514 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 -08006515 cm->current_video_frame, y2, u2, v2,
Yaowu Xuc27fc142016-08-22 16:08:15 -07006516 frame_psnr2, frame_ssim2);
6517 fclose(f);
6518 }
6519#endif
6520 }
6521 if (cpi->b_calculate_blockiness) {
Yaowu Xud3e7c682017-12-21 14:08:25 -08006522 if (!cm->use_highbitdepth) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006523 const double frame_blockiness =
Yaowu Xuf883b422016-08-30 14:01:10 -07006524 av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer,
6525 recon->y_stride, orig->y_width, orig->y_height);
6526 cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006527 cpi->total_blockiness += frame_blockiness;
6528 }
6529
6530 if (cpi->b_calculate_consistency) {
Yaowu Xud3e7c682017-12-21 14:08:25 -08006531 if (!cm->use_highbitdepth) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006532 const double this_inconsistency = aom_get_ssim_metrics(
Yaowu Xuc27fc142016-08-22 16:08:15 -07006533 orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride,
6534 orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1);
6535
6536 const double peak = (double)((1 << in_bit_depth) - 1);
6537 const double consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07006538 aom_sse_to_psnr(samples, peak, cpi->total_inconsistency);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006539 if (consistency > 0.0)
6540 cpi->worst_consistency =
Yaowu Xuf883b422016-08-30 14:01:10 -07006541 AOMMIN(cpi->worst_consistency, consistency);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006542 cpi->total_inconsistency += this_inconsistency;
6543 }
6544 }
6545 }
6546
6547 frame_all =
Yaowu Xuf883b422016-08-30 14:01:10 -07006548 aom_calc_fastssim(orig, recon, &y, &u, &v, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006549 adjust_image_stat(y, u, v, frame_all, &cpi->fastssim);
Yaowu Xuf883b422016-08-30 14:01:10 -07006550 frame_all = aom_psnrhvs(orig, recon, &y, &u, &v, bit_depth, in_bit_depth);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006551 adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs);
6552 }
6553}
6554#endif // CONFIG_INTERNAL_STATS
6555
RogerZhou3b635242017-09-19 10:06:46 -07006556#if CONFIG_AMVR
6557static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture,
6558 const YV12_BUFFER_CONFIG *last_picture,
6559 hash_table *last_hash_table) {
6560 aom_clear_system_state();
6561 // check use hash ME
6562 int k;
6563 uint32_t hash_value_1;
6564 uint32_t hash_value_2;
6565
6566 const int block_size = 8;
6567 const double threshold_current = 0.8;
6568 const double threshold_average = 0.95;
6569 const int max_history_size = 32;
6570 int T = 0; // total block
6571 int C = 0; // match with collocated block
6572 int S = 0; // smooth region but not match with collocated block
6573 int M = 0; // match with other block
6574
6575 const int pic_width = cur_picture->y_width;
6576 const int pic_height = cur_picture->y_height;
6577 for (int i = 0; i + block_size <= pic_height; i += block_size) {
6578 for (int j = 0; j + block_size <= pic_width; j += block_size) {
6579 const int x_pos = j;
6580 const int y_pos = i;
6581 int match = 1;
6582 T++;
6583
6584 // check whether collocated block match with current
6585 uint8_t *p_cur = cur_picture->y_buffer;
6586 uint8_t *p_ref = last_picture->y_buffer;
6587 int stride_cur = cur_picture->y_stride;
6588 int stride_ref = last_picture->y_stride;
6589 p_cur += (y_pos * stride_cur + x_pos);
6590 p_ref += (y_pos * stride_ref + x_pos);
6591
6592 for (int tmpY = 0; tmpY < block_size && match; tmpY++) {
6593 for (int tmpX = 0; tmpX < block_size && match; tmpX++) {
6594 if (p_cur[tmpX] != p_ref[tmpX]) {
6595 match = 0;
6596 }
6597 }
6598 p_cur += stride_cur;
6599 p_ref += stride_ref;
6600 }
6601
6602 if (match) {
6603 C++;
6604 continue;
6605 }
6606
6607 if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos,
6608 y_pos) ||
6609 av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) {
6610 S++;
6611 continue;
6612 }
6613
6614 av1_get_block_hash_value(
6615 cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur,
6616 block_size, &hash_value_1, &hash_value_2);
6617
6618 if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) {
6619 M++;
6620 }
6621 }
6622 }
6623
6624 assert(T > 0);
6625 double csm_rate = ((double)(C + S + M)) / ((double)(T));
6626 double m_rate = ((double)(M)) / ((double)(T));
6627
6628 cpi->csm_rate_array[cpi->rate_index] = csm_rate;
6629 cpi->m_rate_array[cpi->rate_index] = m_rate;
6630
6631 cpi->rate_index = (cpi->rate_index + 1) % max_history_size;
6632 cpi->rate_size++;
6633 cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size);
6634
6635 if (csm_rate < threshold_current) {
6636 return 0;
6637 }
6638
6639 if (C == T) {
6640 return 1;
6641 }
6642
6643 double csm_average = 0.0;
6644 double m_average = 0.0;
6645
6646 for (k = 0; k < cpi->rate_size; k++) {
6647 csm_average += cpi->csm_rate_array[k];
6648 m_average += cpi->m_rate_array[k];
6649 }
6650 csm_average /= cpi->rate_size;
6651 m_average /= cpi->rate_size;
6652
6653 if (csm_average < threshold_average) {
6654 return 0;
6655 }
6656
6657 if (M > (T - C - S) / 3) {
6658 return 1;
6659 }
6660
6661 if (csm_rate > 0.99 && m_rate > 0.01) {
6662 return 1;
6663 }
6664
6665 if (csm_average + m_average > 1.01) {
6666 return 1;
6667 }
6668
6669 return 0;
6670}
6671#endif
6672
Yaowu Xuf883b422016-08-30 14:01:10 -07006673int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
6674 size_t *size, uint8_t *dest, int64_t *time_stamp,
6675 int64_t *time_end, int flush) {
6676 const AV1EncoderConfig *const oxcf = &cpi->oxcf;
6677 AV1_COMMON *const cm = &cpi->common;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006678 const int num_planes = av1_num_planes(cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006679 BufferPool *const pool = cm->buffer_pool;
6680 RATE_CONTROL *const rc = &cpi->rc;
Yaowu Xuf883b422016-08-30 14:01:10 -07006681 struct aom_usec_timer cmptimer;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006682 YV12_BUFFER_CONFIG *force_src_buffer = NULL;
6683 struct lookahead_entry *last_source = NULL;
6684 struct lookahead_entry *source = NULL;
6685 int arf_src_index;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006686 int brf_src_index;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006687 int i;
6688
6689#if CONFIG_BITSTREAM_DEBUG
6690 assert(cpi->oxcf.max_threads == 0 &&
6691 "bitstream debug tool does not support multithreading");
6692 bitstream_queue_record_write();
Angie Chiangcb9a9eb2016-09-01 16:10:50 -07006693 bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006694#endif
6695
Yaowu Xuf883b422016-08-30 14:01:10 -07006696 aom_usec_timer_start(&cmptimer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006697
RogerZhou3b635242017-09-19 10:06:46 -07006698#if CONFIG_AMVR
6699 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0);
6700#else
Cheng Chen46f30c72017-09-07 11:13:33 -07006701 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
RogerZhou3b635242017-09-19 10:06:46 -07006702#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006703
6704 // Is multi-arf enabled.
6705 // Note that at the moment multi_arf is only configured for 2 pass VBR
6706 if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1))
6707 cpi->multi_arf_allowed = 1;
6708 else
6709 cpi->multi_arf_allowed = 0;
6710
Thomas Daedea6a854b2017-06-22 17:49:11 -07006711// Normal defaults
6712#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -07006713 cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
Thomas Daedea6a854b2017-06-22 17:49:11 -07006714#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07006715 cm->refresh_frame_context =
6716 (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode)
6717 ? REFRESH_FRAME_CONTEXT_FORWARD
6718 : REFRESH_FRAME_CONTEXT_BACKWARD;
Rupert Swarbrick84b05ac2017-10-27 18:10:53 +01006719#if CONFIG_EXT_TILE
6720 if (oxcf->large_scale_tile)
6721 cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD;
6722#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07006723
6724 cpi->refresh_last_frame = 1;
6725 cpi->refresh_golden_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006726 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006727 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006728 cpi->refresh_alt_ref_frame = 0;
6729
Zoe Liub4991202017-12-21 15:31:06 -08006730#if CONFIG_FWD_KF
6731 // TODO(zoeliu@gmail.com): To support forward-KEY_FRAME and set up the
6732 // following flag accordingly.
6733 cm->reset_decoder_state = 0;
6734#endif // CONFIG_FWD_KF
6735
Yaowu Xuc27fc142016-08-22 16:08:15 -07006736 if (oxcf->pass == 2 && cm->show_existing_frame) {
6737 // Manage the source buffer and flush out the source frame that has been
6738 // coded already; Also get prepared for PSNR calculation if needed.
Yaowu Xuf883b422016-08-30 14:01:10 -07006739 if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006740 *size = 0;
6741 return -1;
6742 }
Alex Conversef77fd0b2017-04-20 11:00:24 -07006743 cpi->source = &source->img;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006744 // TODO(zoeliu): To track down to determine whether it's needed to adjust
6745 // the frame rate.
6746 *time_stamp = source->ts_start;
6747 *time_end = source->ts_end;
6748
6749 // We need to adjust frame rate for an overlay frame
Zoe Liue04abf72017-04-19 15:37:11 -07006750 if (cpi->rc.is_src_frame_alt_ref) adjust_frame_rate(cpi, source);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006751
6752 // Find a free buffer for the new frame, releasing the reference previously
6753 // held.
6754 if (cm->new_fb_idx != INVALID_IDX) {
6755 --pool->frame_bufs[cm->new_fb_idx].ref_count;
6756 }
6757 cm->new_fb_idx = get_free_fb(cm);
6758
6759 if (cm->new_fb_idx == INVALID_IDX) return -1;
6760
6761 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006762 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006763
6764 // Start with a 0 size frame.
6765 *size = 0;
6766
6767 // We need to update the gf_group for show_existing overlay frame
Zoe Liue04abf72017-04-19 15:37:11 -07006768 if (cpi->rc.is_src_frame_alt_ref) av1_rc_get_second_pass_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006769
Tom Finegane4099e32018-01-23 12:01:51 -08006770 if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK)
6771 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006772
6773 if (cpi->b_calculate_psnr) generate_psnr_packet(cpi);
6774
6775#if CONFIG_INTERNAL_STATS
Angie Chiang08a22a62017-07-17 17:29:17 -07006776 compute_internal_stats(cpi, (int)(*size));
Yaowu Xuc27fc142016-08-22 16:08:15 -07006777#endif // CONFIG_INTERNAL_STATS
6778
6779 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006780 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006781
6782 cm->show_existing_frame = 0;
6783 return 0;
6784 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006785
6786 // Should we encode an arf frame.
6787 arf_src_index = get_arf_src_index(cpi);
6788 if (arf_src_index) {
6789 for (i = 0; i <= arf_src_index; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006790 struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006791 // Avoid creating an alt-ref if there's a forced keyframe pending.
6792 if (e == NULL) {
6793 break;
Yaowu Xuf883b422016-08-30 14:01:10 -07006794 } else if (e->flags == AOM_EFLAG_FORCE_KF) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006795 arf_src_index = 0;
6796 flush = 1;
6797 break;
6798 }
6799 }
6800 }
6801
6802 if (arf_src_index) {
6803 assert(arf_src_index <= rc->frames_to_key);
6804
Yaowu Xuf883b422016-08-30 14:01:10 -07006805 if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006806 cpi->alt_ref_source = source;
6807
6808 if (oxcf->arnr_max_frames > 0) {
Sebastien Alaiwan6697acf2018-02-21 16:59:17 +01006809 // Produce the filtered ARF frame.
6810 av1_temporal_filter(cpi, arf_src_index);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006811 aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006812 force_src_buffer = &cpi->alt_ref_buffer;
6813 }
6814
6815 cm->show_frame = 0;
6816 cm->intra_only = 0;
6817 cpi->refresh_alt_ref_frame = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006818 cpi->refresh_last_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006819 cpi->refresh_golden_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006820 cpi->refresh_bwd_ref_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006821 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006822 rc->is_src_frame_alt_ref = 0;
6823 }
6824 rc->source_alt_ref_pending = 0;
6825 }
6826
Zoe Liue9b15e22017-07-19 15:53:01 -07006827 // Should we encode an arf2 frame.
6828 arf_src_index = get_arf2_src_index(cpi);
6829 if (arf_src_index) {
6830 for (i = 0; i <= arf_src_index; ++i) {
6831 struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i);
6832 // Avoid creating an alt-ref if there's a forced keyframe pending.
6833 if (e == NULL) {
6834 break;
6835 } else if (e->flags == AOM_EFLAG_FORCE_KF) {
6836 arf_src_index = 0;
6837 flush = 1;
6838 break;
6839 }
6840 }
6841 }
6842
6843 if (arf_src_index) {
6844 assert(arf_src_index <= rc->frames_to_key);
6845
6846 if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
6847 cpi->alt_ref_source = source;
6848
6849 if (oxcf->arnr_max_frames > 0) {
6850 // Produce the filtered ARF frame.
Sebastien Alaiwan6697acf2018-02-21 16:59:17 +01006851 av1_temporal_filter(cpi, arf_src_index);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +00006852 aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes);
Zoe Liue9b15e22017-07-19 15:53:01 -07006853 force_src_buffer = &cpi->alt_ref_buffer;
6854 }
6855
6856 cm->show_frame = 0;
6857 cm->intra_only = 0;
6858 cpi->refresh_alt2_ref_frame = 1;
6859 cpi->refresh_last_frame = 0;
6860 cpi->refresh_golden_frame = 0;
6861 cpi->refresh_bwd_ref_frame = 0;
6862 cpi->refresh_alt_ref_frame = 0;
6863 rc->is_src_frame_alt_ref = 0;
6864 rc->is_src_frame_ext_arf = 0;
6865 }
6866 rc->source_alt_ref_pending = 0;
6867 }
Zoe Liue9b15e22017-07-19 15:53:01 -07006868
Yaowu Xuc27fc142016-08-22 16:08:15 -07006869 rc->is_bwd_ref_frame = 0;
6870 brf_src_index = get_brf_src_index(cpi);
6871 if (brf_src_index) {
6872 assert(brf_src_index <= rc->frames_to_key);
Yaowu Xuf883b422016-08-30 14:01:10 -07006873 if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07006874 cm->show_frame = 0;
6875 cm->intra_only = 0;
6876
6877 cpi->refresh_bwd_ref_frame = 1;
6878 cpi->refresh_last_frame = 0;
6879 cpi->refresh_golden_frame = 0;
Zoe Liue9b15e22017-07-19 15:53:01 -07006880 cpi->refresh_alt2_ref_frame = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006881 cpi->refresh_alt_ref_frame = 0;
6882
6883 rc->is_bwd_ref_frame = 1;
6884 }
6885 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006886
6887 if (!source) {
6888 // Get last frame source.
6889 if (cm->current_video_frame > 0) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006890 if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL)
Yaowu Xuc27fc142016-08-22 16:08:15 -07006891 return -1;
6892 }
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07006893 if (cm->current_video_frame > 0) assert(last_source != NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006894 // Read in the source frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07006895 source = av1_lookahead_pop(cpi->lookahead, flush);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006896
6897 if (source != NULL) {
6898 cm->show_frame = 1;
6899 cm->intra_only = 0;
6900
6901 // Check to see if the frame should be encoded as an arf overlay.
6902 check_src_altref(cpi, source);
6903 }
6904 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07006905 if (source) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -07006906 cpi->unscaled_source = cpi->source =
Yaowu Xuc27fc142016-08-22 16:08:15 -07006907 force_src_buffer ? force_src_buffer : &source->img;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006908 cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL;
6909
6910 *time_stamp = source->ts_start;
6911 *time_end = source->ts_end;
Yaowu Xuf883b422016-08-30 14:01:10 -07006912 *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07006913
6914 } else {
6915 *size = 0;
6916 if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006917 av1_end_first_pass(cpi); /* get last stats packet */
Yaowu Xuc27fc142016-08-22 16:08:15 -07006918 cpi->twopass.first_pass_done = 1;
6919 }
6920 return -1;
6921 }
6922
6923 if (source->ts_start < cpi->first_time_stamp_ever) {
6924 cpi->first_time_stamp_ever = source->ts_start;
6925 cpi->last_end_time_stamp_seen = source->ts_start;
6926 }
6927
6928 // Clear down mmx registers
Yaowu Xuf883b422016-08-30 14:01:10 -07006929 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07006930
6931 // adjust frame rates based on timestamps given
6932 if (cm->show_frame) adjust_frame_rate(cpi, source);
6933
6934 // Find a free buffer for the new frame, releasing the reference previously
6935 // held.
6936 if (cm->new_fb_idx != INVALID_IDX) {
6937 --pool->frame_bufs[cm->new_fb_idx].ref_count;
6938 }
6939 cm->new_fb_idx = get_free_fb(cm);
6940
6941 if (cm->new_fb_idx == INVALID_IDX) return -1;
6942
Zoe Liuf452fdf2017-11-02 23:08:12 -07006943 // Retain the RF_LEVEL for the current newly coded frame.
6944 cpi->frame_rf_level[cm->new_fb_idx] =
6945 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
Zoe Liuf452fdf2017-11-02 23:08:12 -07006946
Yaowu Xuc27fc142016-08-22 16:08:15 -07006947 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
Yaowu Xu9b0f7032017-07-31 11:01:19 -07006948 cm->cur_frame->buf.buf_8bit_valid = 0;
Zoe Liu6cfaff92016-10-18 17:12:11 -07006949
Yaowu Xuc27fc142016-08-22 16:08:15 -07006950 // Start with a 0 size frame.
6951 *size = 0;
6952
6953 cpi->frame_flags = *frame_flags;
6954
6955 if (oxcf->pass == 2) {
Yaowu Xuf883b422016-08-30 14:01:10 -07006956 av1_rc_get_second_pass_params(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006957 } else if (oxcf->pass == 1) {
Fergus Simpsonbc189932017-05-16 17:02:39 -07006958 setup_frame_size(cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006959 }
6960
6961 if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) {
6962 for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i)
6963 cpi->scaled_ref_idx[i] = INVALID_IDX;
6964 }
6965
6966#if CONFIG_AOM_QM
6967 cm->using_qmatrix = cpi->oxcf.using_qm;
6968 cm->min_qmlevel = cpi->oxcf.qm_minlevel;
6969 cm->max_qmlevel = cpi->oxcf.qm_maxlevel;
6970#endif
6971
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006972#if CONFIG_REFERENCE_BUFFER
David Barker5e70a112017-10-03 14:28:17 +01006973 if (cm->seq_params.frame_id_numbers_present_flag) {
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006974 if (*time_stamp == 0) {
6975 cpi->common.current_frame_id = -1;
6976 }
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006977 }
Debargha Mukherjee778023d2017-09-26 17:50:27 -07006978#endif // CONFIG_REFERENCE_BUFFER
RogerZhou3b635242017-09-19 10:06:46 -07006979#if CONFIG_AMVR
6980 cpi->cur_poc++;
6981 if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) {
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00006982 if (cpi->common.seq_params.force_integer_mv == 2) {
RogerZhou3b635242017-09-19 10:06:46 -07006983 struct lookahead_entry *previous_entry =
6984 cpi->lookahead->buf + cpi->previsous_index;
RogerZhou10a03802017-10-26 11:49:48 -07006985 cpi->common.cur_frame_force_integer_mv = is_integer_mv(
RogerZhou3b635242017-09-19 10:06:46 -07006986 cpi, cpi->source, &previous_entry->img, cpi->previsou_hash_table);
6987 } else {
Imdad Sardharwallabf2cc012018-02-09 17:32:10 +00006988 cpi->common.cur_frame_force_integer_mv =
6989 cpi->common.seq_params.force_integer_mv;
RogerZhou3b635242017-09-19 10:06:46 -07006990 }
6991 } else {
RogerZhou10a03802017-10-26 11:49:48 -07006992 cpi->common.cur_frame_force_integer_mv = 0;
RogerZhou3b635242017-09-19 10:06:46 -07006993 }
6994#endif
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01006995
Yaowu Xuc27fc142016-08-22 16:08:15 -07006996 if (oxcf->pass == 1) {
6997 cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf);
Yaowu Xuf883b422016-08-30 14:01:10 -07006998 av1_first_pass(cpi, source);
Yaowu Xuc27fc142016-08-22 16:08:15 -07006999 } else if (oxcf->pass == 2) {
Tom Finegane4099e32018-01-23 12:01:51 -08007000 if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK)
7001 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007002 } else {
7003 // One pass encode
Tom Finegane4099e32018-01-23 12:01:51 -08007004 if (Pass0Encode(cpi, size, dest, 0, frame_flags) != AOM_CODEC_OK)
7005 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007006 }
RogerZhoucc5d35d2017-08-07 22:20:15 -07007007#if CONFIG_HASH_ME
7008 if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) {
RogerZhou3b635242017-09-19 10:06:46 -07007009#if CONFIG_AMVR
7010 cpi->previsou_hash_table = &cm->cur_frame->hash_table;
7011 {
7012 int l;
7013 for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) {
7014 if ((cpi->lookahead->buf + l) == source) {
7015 cpi->previsous_index = l;
7016 break;
7017 }
7018 }
7019
7020 if (l == cpi->lookahead->max_sz) {
7021 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
7022 "Failed to find last frame original buffer");
7023 }
7024 }
7025#endif
RogerZhoucc5d35d2017-08-07 22:20:15 -07007026 }
7027
7028#endif
7029
Yunqing Wang267e3272017-11-09 14:23:22 -08007030#if CONFIG_EXT_TILE
7031 if (!cm->large_scale_tile) {
7032#endif // CONFIG_EXT_TILE
Thomas Daededa4d8b92017-06-05 15:44:14 -07007033#if CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yunqing Wang267e3272017-11-09 14:23:22 -08007034 cm->frame_contexts[cm->new_fb_idx] = *cm->fc;
Thomas Daededa4d8b92017-06-05 15:44:14 -07007035#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07007036 if (!cm->error_resilient_mode)
7037 cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
Thomas Daededa4d8b92017-06-05 15:44:14 -07007038#endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yunqing Wang267e3272017-11-09 14:23:22 -08007039#if CONFIG_EXT_TILE
7040 }
7041#endif // CONFIG_EXT_TILE
Yaowu Xuc27fc142016-08-22 16:08:15 -07007042
Yunqing Wangb041d8a2017-11-15 12:31:18 -08007043#if CONFIG_EXT_TILE
7044#define EXT_TILE_DEBUG 0
7045#if EXT_TILE_DEBUG
7046 if (cm->large_scale_tile && oxcf->pass == 2) {
7047 char fn[20] = "./fc";
7048 fn[4] = cm->current_video_frame / 100 + '0';
7049 fn[5] = (cm->current_video_frame % 100) / 10 + '0';
7050 fn[6] = (cm->current_video_frame % 10) + '0';
7051 fn[7] = '\0';
7052 av1_print_frame_contexts(cm->fc, fn);
7053 }
7054#endif // EXT_TILE_DEBUG
7055#undef EXT_TILE_DEBUG
7056#endif // CONFIG_EXT_TILE
7057
Yaowu Xuc27fc142016-08-22 16:08:15 -07007058 // No frame encoded, or frame was dropped, release scaled references.
7059 if ((*size == 0) && (frame_is_intra_only(cm) == 0)) {
7060 release_scaled_references(cpi);
7061 }
7062
7063 if (*size > 0) {
7064 cpi->droppable = !frame_is_reference(cpi);
7065 }
7066
Yaowu Xuf883b422016-08-30 14:01:10 -07007067 aom_usec_timer_mark(&cmptimer);
7068 cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007069
7070 if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame)
7071 generate_psnr_packet(cpi);
7072
7073#if CONFIG_INTERNAL_STATS
7074 if (oxcf->pass != 1) {
Angie Chiang08a22a62017-07-17 17:29:17 -07007075 compute_internal_stats(cpi, (int)(*size));
Yaowu Xuc27fc142016-08-22 16:08:15 -07007076 }
7077#endif // CONFIG_INTERNAL_STATS
7078
Yaowu Xuf883b422016-08-30 14:01:10 -07007079 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07007080
7081 return 0;
7082}
7083
Yaowu Xuf883b422016-08-30 14:01:10 -07007084int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) {
7085 AV1_COMMON *cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007086 if (!cm->show_frame) {
7087 return -1;
7088 } else {
7089 int ret;
7090 if (cm->frame_to_show) {
7091 *dest = *cm->frame_to_show;
7092 dest->y_width = cm->width;
7093 dest->y_height = cm->height;
7094 dest->uv_width = cm->width >> cm->subsampling_x;
7095 dest->uv_height = cm->height >> cm->subsampling_y;
7096 ret = 0;
7097 } else {
7098 ret = -1;
7099 }
Yaowu Xuf883b422016-08-30 14:01:10 -07007100 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07007101 return ret;
7102 }
7103}
7104
Yaowu Xuf883b422016-08-30 14:01:10 -07007105int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07007106 if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1;
7107
7108 *frame =
7109 cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf;
7110 return 0;
7111}
7112
Yaowu Xuf883b422016-08-30 14:01:10 -07007113int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
7114 AOM_SCALING vert_mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07007115 int hr = 0, hs = 0, vr = 0, vs = 0;
7116
7117 if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1;
7118
7119 Scale2Ratio(horiz_mode, &hr, &hs);
7120 Scale2Ratio(vert_mode, &vr, &vs);
7121
7122 // always go to the next whole number
Debargha Mukherjeeccb27262017-09-25 14:19:46 -07007123 cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs;
7124 cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007125
7126 return 0;
7127}
7128
Yaowu Xuf883b422016-08-30 14:01:10 -07007129int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007130
Yaowu Xuf883b422016-08-30 14:01:10 -07007131void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) {
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007132 // TODO(yunqingwang): For what references to use, external encoding flags
7133 // should be consistent with internal reference frame selection. Need to
7134 // ensure that there is not conflict between the two. In AV1 encoder, the
7135 // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3,
7136 // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be
7137 // LAST.
Yunqing Wangf2e7a392017-11-08 00:27:21 -08007138 cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007139 if (flags &
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007140 (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
7141 AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD |
7142 AOM_EFLAG_NO_REF_ARF2)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07007143 if (flags & AOM_EFLAG_NO_REF_LAST) {
Yunqing Wangf2e7a392017-11-08 00:27:21 -08007144 cpi->ext_ref_frame_flags = 0;
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007145 } else {
7146 int ref = AOM_REFFRAME_ALL;
7147
7148 if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG;
7149 if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG;
7150
7151 if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG;
7152
7153 if (flags & AOM_EFLAG_NO_REF_ARF) {
7154 ref ^= AOM_ALT_FLAG;
7155 ref ^= AOM_BWD_FLAG;
7156 ref ^= AOM_ALT2_FLAG;
7157 } else {
7158 if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG;
7159 if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG;
7160 }
7161
7162 av1_use_as_reference(cpi, ref);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007163 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007164 }
7165
7166 if (flags &
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007167 (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF)) {
Yaowu Xuf883b422016-08-30 14:01:10 -07007168 int upd = AOM_REFFRAME_ALL;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007169
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007170 // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag.
7171 if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007172
Yaowu Xuf883b422016-08-30 14:01:10 -07007173 if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG;
Yaowu Xuc27fc142016-08-22 16:08:15 -07007174
Yunqing Wang9a50fec2017-11-02 17:02:00 -07007175 if (flags & AOM_EFLAG_NO_UPD_ARF) {
7176 upd ^= AOM_ALT_FLAG;
7177 upd ^= AOM_BWD_FLAG;
7178 upd ^= AOM_ALT2_FLAG;
7179 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07007180
Yaowu Xuf883b422016-08-30 14:01:10 -07007181 av1_update_reference(cpi, upd);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007182 }
7183
Yaowu Xuf883b422016-08-30 14:01:10 -07007184 if (flags & AOM_EFLAG_NO_UPD_ENTROPY) {
7185 av1_update_entropy(cpi, 0);
Yaowu Xuc27fc142016-08-22 16:08:15 -07007186 }
7187}