Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <limits.h> |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 13 | #include <float.h> |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | #include <math.h> |
| 15 | #include <stdio.h> |
| 16 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 17 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 18 | #include "config/aom_dsp_rtcd.h" |
| 19 | #include "config/aom_scale_rtcd.h" |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 20 | #include "config/av1_rtcd.h" |
| 21 | |
| 22 | #include "aom_dsp/aom_dsp_common.h" |
| 23 | #include "aom_dsp/aom_filter.h" |
| 24 | #if CONFIG_DENOISE |
| 25 | #include "aom_dsp/grain_table.h" |
| 26 | #include "aom_dsp/noise_util.h" |
| 27 | #include "aom_dsp/noise_model.h" |
| 28 | #endif |
| 29 | #include "aom_dsp/psnr.h" |
| 30 | #if CONFIG_INTERNAL_STATS |
| 31 | #include "aom_dsp/ssim.h" |
| 32 | #endif |
| 33 | #include "aom_ports/aom_timer.h" |
| 34 | #include "aom_ports/mem.h" |
| 35 | #include "aom_ports/system_state.h" |
| 36 | #include "aom_scale/aom_scale.h" |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 37 | #if CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 38 | #include "aom_util/debug_util.h" |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 39 | #endif // CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 40 | |
| 41 | #include "av1/common/alloccommon.h" |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 42 | #include "av1/common/cdef.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | #include "av1/common/filter.h" |
| 44 | #include "av1/common/idct.h" |
| 45 | #include "av1/common/reconinter.h" |
| 46 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 47 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | #include "av1/common/tile_common.h" |
| 49 | |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 50 | #include "av1/encoder/av1_multi_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | #include "av1/encoder/aq_complexity.h" |
| 52 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 53 | #include "av1/encoder/aq_variance.h" |
| 54 | #include "av1/encoder/bitstream.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | #include "av1/encoder/context_tree.h" |
| 56 | #include "av1/encoder/encodeframe.h" |
| 57 | #include "av1/encoder/encodemv.h" |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 58 | #include "av1/encoder/encode_strategy.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 60 | #include "av1/encoder/encodetxb.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | #include "av1/encoder/ethread.h" |
| 62 | #include "av1/encoder/firstpass.h" |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 63 | #include "av1/encoder/grain_test_vectors.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 64 | #include "av1/encoder/hash_motion.h" |
chiyotsai | c666b1f | 2019-12-20 10:44:58 -0800 | [diff] [blame] | 65 | #include "av1/encoder/mv_prec.h" |
David Turner | 0fa8c49 | 2019-02-06 16:38:13 +0000 | [diff] [blame] | 66 | #include "av1/encoder/pass2_strategy.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | #include "av1/encoder/picklpf.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | #include "av1/encoder/pickrst.h" |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 69 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 70 | #include "av1/encoder/ratectrl.h" |
| 71 | #include "av1/encoder/rd.h" |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 72 | #include "av1/encoder/rdopt.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | #include "av1/encoder/segmentation.h" |
| 74 | #include "av1/encoder/speed_features.h" |
Debargha Mukherjee | 347c64d | 2019-05-08 13:53:46 -0700 | [diff] [blame] | 75 | #include "av1/encoder/tpl_model.h" |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 76 | #include "av1/encoder/reconinter_enc.h" |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 77 | #include "av1/encoder/var_based_part.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | |
sdeng | e63f9fa | 2019-12-13 09:29:55 -0800 | [diff] [blame] | 79 | #if CONFIG_TUNE_VMAF |
| 80 | #include "av1/encoder/tune_vmaf.h" |
| 81 | #endif |
| 82 | |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 83 | #define DEFAULT_EXPLICIT_ORDER_HINT_BITS 7 |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 84 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 85 | #if CONFIG_ENTROPY_STATS |
| 86 | FRAME_COUNTS aggregate_fc; |
| 87 | #endif // CONFIG_ENTROPY_STATS |
| 88 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 89 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 90 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 91 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 93 | #ifdef OUTPUT_YUV_SKINMAP |
| 94 | FILE *yuv_skinmap_file = NULL; |
| 95 | #endif |
| 96 | #ifdef OUTPUT_YUV_REC |
| 97 | FILE *yuv_rec_file; |
| 98 | #define FILE_NAME_LEN 100 |
| 99 | #endif |
| 100 | |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 101 | const int default_tx_type_probs[FRAME_UPDATE_TYPES][TX_SIZES_ALL][TX_TYPES] = { |
| 102 | { { 221, 189, 214, 292, 0, 0, 0, 0, 0, 2, 38, 68, 0, 0, 0, 0 }, |
| 103 | { 262, 203, 216, 239, 0, 0, 0, 0, 0, 1, 37, 66, 0, 0, 0, 0 }, |
| 104 | { 315, 231, 239, 226, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0 }, |
| 105 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 106 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 107 | { 222, 188, 214, 287, 0, 0, 0, 0, 0, 2, 50, 61, 0, 0, 0, 0 }, |
| 108 | { 256, 182, 205, 282, 0, 0, 0, 0, 0, 2, 21, 76, 0, 0, 0, 0 }, |
| 109 | { 281, 214, 217, 222, 0, 0, 0, 0, 0, 1, 48, 41, 0, 0, 0, 0 }, |
| 110 | { 263, 194, 225, 225, 0, 0, 0, 0, 0, 2, 15, 100, 0, 0, 0, 0 }, |
| 111 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 112 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 113 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 114 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 115 | { 170, 192, 242, 293, 0, 0, 0, 0, 0, 1, 68, 58, 0, 0, 0, 0 }, |
| 116 | { 199, 210, 213, 291, 0, 0, 0, 0, 0, 1, 14, 96, 0, 0, 0, 0 }, |
| 117 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 118 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 119 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 120 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, |
| 121 | { { 106, 69, 107, 278, 9, 15, 20, 45, 49, 23, 23, 88, 36, 74, 25, 57 }, |
| 122 | { 105, 72, 81, 98, 45, 49, 47, 50, 56, 72, 30, 81, 33, 95, 27, 83 }, |
| 123 | { 211, 105, 109, 120, 57, 62, 43, 49, 52, 58, 42, 116, 0, 0, 0, 0 }, |
| 124 | { 1008, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0 }, |
| 125 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 126 | { 131, 57, 98, 172, 19, 40, 37, 64, 69, 22, 41, 52, 51, 77, 35, 59 }, |
| 127 | { 176, 83, 93, 202, 22, 24, 28, 47, 50, 16, 12, 93, 26, 76, 17, 59 }, |
| 128 | { 136, 72, 89, 95, 46, 59, 47, 56, 61, 68, 35, 51, 32, 82, 26, 69 }, |
| 129 | { 122, 80, 87, 105, 49, 47, 46, 46, 57, 52, 13, 90, 19, 103, 15, 93 }, |
| 130 | { 1009, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0 }, |
| 131 | { 1011, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0 }, |
| 132 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 133 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 134 | { 202, 20, 84, 114, 14, 60, 41, 79, 99, 21, 41, 15, 50, 84, 34, 66 }, |
| 135 | { 196, 44, 23, 72, 30, 22, 28, 57, 67, 13, 4, 165, 15, 148, 9, 131 }, |
| 136 | { 882, 0, 0, 0, 0, 0, 0, 0, 0, 142, 0, 0, 0, 0, 0, 0 }, |
| 137 | { 840, 0, 0, 0, 0, 0, 0, 0, 0, 184, 0, 0, 0, 0, 0, 0 }, |
| 138 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 139 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, |
| 140 | { { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 141 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 142 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 143 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 144 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 145 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 146 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 147 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 148 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 149 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 150 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 151 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 152 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 153 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 154 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 155 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 156 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 157 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 158 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 } }, |
| 159 | { { 213, 110, 141, 269, 12, 16, 15, 19, 21, 11, 38, 68, 22, 29, 16, 24 }, |
| 160 | { 216, 119, 128, 143, 38, 41, 26, 30, 31, 30, 42, 70, 23, 36, 19, 32 }, |
| 161 | { 367, 149, 154, 154, 38, 35, 17, 21, 21, 10, 22, 36, 0, 0, 0, 0 }, |
| 162 | { 1022, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, |
| 163 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 164 | { 219, 96, 127, 191, 21, 40, 25, 32, 34, 18, 45, 45, 33, 39, 26, 33 }, |
| 165 | { 296, 99, 122, 198, 23, 21, 19, 24, 25, 13, 20, 64, 23, 32, 18, 27 }, |
| 166 | { 275, 128, 142, 143, 35, 48, 23, 30, 29, 18, 42, 36, 18, 23, 14, 20 }, |
| 167 | { 239, 132, 166, 175, 36, 27, 19, 21, 24, 14, 13, 85, 9, 31, 8, 25 }, |
| 168 | { 1022, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, |
| 169 | { 1022, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, |
| 170 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 171 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 172 | { 309, 25, 79, 59, 25, 80, 34, 53, 61, 25, 49, 23, 43, 64, 36, 59 }, |
| 173 | { 270, 57, 40, 54, 50, 42, 41, 53, 56, 28, 17, 81, 45, 86, 34, 70 }, |
| 174 | { 1005, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0 }, |
| 175 | { 992, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0 }, |
| 176 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 177 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, |
| 178 | { { 133, 63, 55, 83, 57, 87, 58, 72, 68, 16, 24, 35, 29, 105, 25, 114 }, |
| 179 | { 131, 75, 74, 60, 71, 77, 65, 66, 73, 33, 21, 79, 20, 83, 18, 78 }, |
| 180 | { 276, 95, 82, 58, 86, 93, 63, 60, 64, 17, 38, 92, 0, 0, 0, 0 }, |
| 181 | { 1006, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0 }, |
| 182 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 183 | { 147, 49, 75, 78, 50, 97, 60, 67, 76, 17, 42, 35, 31, 93, 27, 80 }, |
| 184 | { 157, 49, 58, 75, 61, 52, 56, 67, 69, 12, 15, 79, 24, 119, 11, 120 }, |
| 185 | { 178, 69, 83, 77, 69, 85, 72, 77, 77, 20, 35, 40, 25, 48, 23, 46 }, |
| 186 | { 174, 55, 64, 57, 73, 68, 62, 61, 75, 15, 12, 90, 17, 99, 16, 86 }, |
| 187 | { 1008, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0 }, |
| 188 | { 1018, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0 }, |
| 189 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 190 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 191 | { 266, 31, 63, 64, 21, 52, 39, 54, 63, 30, 52, 31, 48, 89, 46, 75 }, |
| 192 | { 272, 26, 32, 44, 29, 31, 32, 53, 51, 13, 13, 88, 22, 153, 16, 149 }, |
| 193 | { 923, 0, 0, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 0, 0, 0 }, |
| 194 | { 969, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0 }, |
| 195 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 196 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, |
| 197 | { { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 198 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 199 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 200 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 201 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 202 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 203 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 204 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 205 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 206 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 207 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 208 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 209 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 210 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 211 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 212 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 213 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 214 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 215 | { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 } }, |
| 216 | { { 158, 92, 125, 298, 12, 15, 20, 29, 31, 12, 29, 67, 34, 44, 23, 35 }, |
| 217 | { 147, 94, 103, 123, 45, 48, 38, 41, 46, 48, 37, 78, 33, 63, 27, 53 }, |
| 218 | { 268, 126, 125, 136, 54, 53, 31, 38, 38, 33, 35, 87, 0, 0, 0, 0 }, |
| 219 | { 1018, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0 }, |
| 220 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 221 | { 159, 72, 103, 194, 20, 35, 37, 50, 56, 21, 39, 40, 51, 61, 38, 48 }, |
| 222 | { 259, 86, 95, 188, 32, 20, 25, 34, 37, 13, 12, 85, 25, 53, 17, 43 }, |
| 223 | { 189, 99, 113, 123, 45, 59, 37, 46, 48, 44, 39, 41, 31, 47, 26, 37 }, |
| 224 | { 175, 110, 113, 128, 58, 38, 33, 33, 43, 29, 13, 100, 14, 68, 12, 57 }, |
| 225 | { 1017, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0 }, |
| 226 | { 1019, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0 }, |
| 227 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 228 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 229 | { 208, 22, 84, 101, 21, 59, 44, 70, 90, 25, 59, 13, 64, 67, 49, 48 }, |
| 230 | { 277, 52, 32, 63, 43, 26, 33, 48, 54, 11, 6, 130, 18, 119, 11, 101 }, |
| 231 | { 963, 0, 0, 0, 0, 0, 0, 0, 0, 61, 0, 0, 0, 0, 0, 0 }, |
| 232 | { 979, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0 }, |
| 233 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 234 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } |
| 235 | }; |
| 236 | |
Yunqing Wang | 5f74dc2 | 2019-10-29 10:35:20 -0700 | [diff] [blame] | 237 | const int default_obmc_probs[FRAME_UPDATE_TYPES][BLOCK_SIZES_ALL] = { |
| 238 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 239 | { 0, 0, 0, 106, 90, 90, 97, 67, 59, 70, 28, |
| 240 | 30, 38, 16, 16, 16, 0, 0, 44, 50, 26, 25 }, |
| 241 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 242 | { 0, 0, 0, 98, 93, 97, 68, 82, 85, 33, 30, |
| 243 | 33, 16, 16, 16, 16, 0, 0, 43, 37, 26, 16 }, |
| 244 | { 0, 0, 0, 91, 80, 76, 78, 55, 49, 24, 16, |
| 245 | 16, 16, 16, 16, 16, 0, 0, 29, 45, 16, 38 }, |
| 246 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 247 | { 0, 0, 0, 103, 89, 89, 89, 62, 63, 76, 34, |
| 248 | 35, 32, 19, 16, 16, 0, 0, 49, 55, 29, 19 } |
| 249 | }; |
| 250 | |
Yunqing Wang | a09a46b | 2019-12-09 13:16:24 -0800 | [diff] [blame] | 251 | const int default_warped_probs[FRAME_UPDATE_TYPES] = { 64, 64, 64, 64, |
| 252 | 64, 64, 64 }; |
| 253 | |
Yunqing Wang | 2348c03 | 2020-01-09 18:05:49 -0800 | [diff] [blame] | 254 | // TODO(yunqing): the default probs can be trained later from better |
| 255 | // performance. |
| 256 | const int default_switchable_interp_probs[FRAME_UPDATE_TYPES] |
| 257 | [SWITCHABLE_FILTER_CONTEXTS] |
| 258 | [SWITCHABLE_FILTERS] = { |
| 259 | { { 512, 512, 512 }, |
| 260 | { 512, 512, 512 }, |
| 261 | { 512, 512, 512 }, |
| 262 | { 512, 512, 512 }, |
| 263 | { 512, 512, 512 }, |
| 264 | { 512, 512, 512 }, |
| 265 | { 512, 512, 512 }, |
| 266 | { 512, 512, 512 }, |
| 267 | { 512, 512, 512 }, |
| 268 | { 512, 512, 512 }, |
| 269 | { 512, 512, 512 }, |
| 270 | { 512, 512, 512 }, |
| 271 | { 512, 512, 512 }, |
| 272 | { 512, 512, 512 }, |
| 273 | { 512, 512, 512 }, |
| 274 | { 512, 512, 512 } }, |
| 275 | { { 512, 512, 512 }, |
| 276 | { 512, 512, 512 }, |
| 277 | { 512, 512, 512 }, |
| 278 | { 512, 512, 512 }, |
| 279 | { 512, 512, 512 }, |
| 280 | { 512, 512, 512 }, |
| 281 | { 512, 512, 512 }, |
| 282 | { 512, 512, 512 }, |
| 283 | { 512, 512, 512 }, |
| 284 | { 512, 512, 512 }, |
| 285 | { 512, 512, 512 }, |
| 286 | { 512, 512, 512 }, |
| 287 | { 512, 512, 512 }, |
| 288 | { 512, 512, 512 }, |
| 289 | { 512, 512, 512 }, |
| 290 | { 512, 512, 512 } }, |
| 291 | { { 512, 512, 512 }, |
| 292 | { 512, 512, 512 }, |
| 293 | { 512, 512, 512 }, |
| 294 | { 512, 512, 512 }, |
| 295 | { 512, 512, 512 }, |
| 296 | { 512, 512, 512 }, |
| 297 | { 512, 512, 512 }, |
| 298 | { 512, 512, 512 }, |
| 299 | { 512, 512, 512 }, |
| 300 | { 512, 512, 512 }, |
| 301 | { 512, 512, 512 }, |
| 302 | { 512, 512, 512 }, |
| 303 | { 512, 512, 512 }, |
| 304 | { 512, 512, 512 }, |
| 305 | { 512, 512, 512 }, |
| 306 | { 512, 512, 512 } }, |
| 307 | { { 512, 512, 512 }, |
| 308 | { 512, 512, 512 }, |
| 309 | { 512, 512, 512 }, |
| 310 | { 512, 512, 512 }, |
| 311 | { 512, 512, 512 }, |
| 312 | { 512, 512, 512 }, |
| 313 | { 512, 512, 512 }, |
| 314 | { 512, 512, 512 }, |
| 315 | { 512, 512, 512 }, |
| 316 | { 512, 512, 512 }, |
| 317 | { 512, 512, 512 }, |
| 318 | { 512, 512, 512 }, |
| 319 | { 512, 512, 512 }, |
| 320 | { 512, 512, 512 }, |
| 321 | { 512, 512, 512 }, |
| 322 | { 512, 512, 512 } }, |
| 323 | { { 512, 512, 512 }, |
| 324 | { 512, 512, 512 }, |
| 325 | { 512, 512, 512 }, |
| 326 | { 512, 512, 512 }, |
| 327 | { 512, 512, 512 }, |
| 328 | { 512, 512, 512 }, |
| 329 | { 512, 512, 512 }, |
| 330 | { 512, 512, 512 }, |
| 331 | { 512, 512, 512 }, |
| 332 | { 512, 512, 512 }, |
| 333 | { 512, 512, 512 }, |
| 334 | { 512, 512, 512 }, |
| 335 | { 512, 512, 512 }, |
| 336 | { 512, 512, 512 }, |
| 337 | { 512, 512, 512 }, |
| 338 | { 512, 512, 512 } }, |
| 339 | { { 512, 512, 512 }, |
| 340 | { 512, 512, 512 }, |
| 341 | { 512, 512, 512 }, |
| 342 | { 512, 512, 512 }, |
| 343 | { 512, 512, 512 }, |
| 344 | { 512, 512, 512 }, |
| 345 | { 512, 512, 512 }, |
| 346 | { 512, 512, 512 }, |
| 347 | { 512, 512, 512 }, |
| 348 | { 512, 512, 512 }, |
| 349 | { 512, 512, 512 }, |
| 350 | { 512, 512, 512 }, |
| 351 | { 512, 512, 512 }, |
| 352 | { 512, 512, 512 }, |
| 353 | { 512, 512, 512 }, |
| 354 | { 512, 512, 512 } }, |
| 355 | { { 512, 512, 512 }, |
| 356 | { 512, 512, 512 }, |
| 357 | { 512, 512, 512 }, |
| 358 | { 512, 512, 512 }, |
| 359 | { 512, 512, 512 }, |
| 360 | { 512, 512, 512 }, |
| 361 | { 512, 512, 512 }, |
| 362 | { 512, 512, 512 }, |
| 363 | { 512, 512, 512 }, |
| 364 | { 512, 512, 512 }, |
| 365 | { 512, 512, 512 }, |
| 366 | { 512, 512, 512 }, |
| 367 | { 512, 512, 512 }, |
| 368 | { 512, 512, 512 }, |
| 369 | { 512, 512, 512 }, |
| 370 | { 512, 512, 512 } } |
| 371 | }; |
| 372 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 373 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 374 | switch (mode) { |
| 375 | case NORMAL: |
| 376 | *hr = 1; |
| 377 | *hs = 1; |
| 378 | break; |
| 379 | case FOURFIVE: |
| 380 | *hr = 4; |
| 381 | *hs = 5; |
| 382 | break; |
| 383 | case THREEFIVE: |
| 384 | *hr = 3; |
| 385 | *hs = 5; |
| 386 | break; |
| 387 | case ONETWO: |
| 388 | *hr = 1; |
| 389 | *hs = 2; |
| 390 | break; |
| 391 | default: |
| 392 | *hr = 1; |
| 393 | *hs = 1; |
| 394 | assert(0); |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 400 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 401 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | unsigned char *const seg_map = cpi->segmentation_map; |
| 403 | int i; |
| 404 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 405 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 406 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 407 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 408 | } |
| 409 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 410 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | struct segmentation *const seg = &cpi->common.seg; |
| 412 | unsigned char *const seg_map = cpi->segmentation_map; |
| 413 | const unsigned char *const active_map = cpi->active_map.map; |
| 414 | int i; |
| 415 | |
| 416 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 417 | |
| 418 | if (frame_is_intra_only(&cpi->common)) { |
| 419 | cpi->active_map.enabled = 0; |
| 420 | cpi->active_map.update = 1; |
| 421 | } |
| 422 | |
| 423 | if (cpi->active_map.update) { |
| 424 | if (cpi->active_map.enabled) { |
| 425 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 426 | if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 427 | av1_enable_segmentation(seg); |
| 428 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 429 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 430 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 431 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 432 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 433 | |
| 434 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 435 | -MAX_LOOP_FILTER); |
| 436 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 437 | -MAX_LOOP_FILTER); |
| 438 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 439 | -MAX_LOOP_FILTER); |
| 440 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 441 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 442 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 443 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 444 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 445 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 446 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 447 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 448 | if (seg->enabled) { |
| 449 | seg->update_data = 1; |
| 450 | seg->update_map = 1; |
| 451 | } |
| 452 | } |
| 453 | cpi->active_map.update = 0; |
| 454 | } |
| 455 | } |
| 456 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 457 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 458 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 459 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 460 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 461 | const int mi_rows = cpi->common.mi_rows; |
| 462 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 463 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 464 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 465 | cpi->active_map.update = 1; |
| 466 | if (new_map_16x16) { |
| 467 | int r, c; |
| 468 | for (r = 0; r < mi_rows; ++r) { |
| 469 | for (c = 0; c < mi_cols; ++c) { |
| 470 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 471 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 472 | ? AM_SEGMENT_ID_ACTIVE |
| 473 | : AM_SEGMENT_ID_INACTIVE; |
| 474 | } |
| 475 | } |
| 476 | cpi->active_map.enabled = 1; |
| 477 | } else { |
| 478 | cpi->active_map.enabled = 0; |
| 479 | } |
| 480 | return 0; |
| 481 | } else { |
| 482 | return -1; |
| 483 | } |
| 484 | } |
| 485 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 486 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 487 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 488 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 489 | new_map_16x16) { |
| 490 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 491 | const int mi_rows = cpi->common.mi_rows; |
| 492 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 493 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 494 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 495 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 496 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 497 | if (cpi->active_map.enabled) { |
| 498 | int r, c; |
| 499 | for (r = 0; r < mi_rows; ++r) { |
| 500 | for (c = 0; c < mi_cols; ++c) { |
| 501 | // Cyclic refresh segments are considered active despite not having |
| 502 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 503 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 504 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | return 0; |
| 509 | } else { |
| 510 | return -1; |
| 511 | } |
| 512 | } |
| 513 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 514 | // Compute the horizontal frequency components' energy in a frame |
| 515 | // by calculuating the 16x4 Horizontal DCT. This is to be used to |
| 516 | // decide the superresolution parameters. |
Yaowu Xu | bedbf4f | 2019-05-01 17:54:36 -0700 | [diff] [blame] | 517 | static void analyze_hor_freq(const AV1_COMP *cpi, double *energy) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 518 | uint64_t freq_energy[16] = { 0 }; |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 519 | const YV12_BUFFER_CONFIG *buf = cpi->source; |
| 520 | const int bd = cpi->td.mb.e_mbd.bd; |
| 521 | const int width = buf->y_crop_width; |
| 522 | const int height = buf->y_crop_height; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 523 | DECLARE_ALIGNED(16, int32_t, coeff[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 524 | int n = 0; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 525 | memset(freq_energy, 0, sizeof(freq_energy)); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 526 | if (buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 527 | const int16_t *src16 = (const int16_t *)CONVERT_TO_SHORTPTR(buf->y_buffer); |
| 528 | for (int i = 0; i < height - 4; i += 4) { |
| 529 | for (int j = 0; j < width - 16; j += 16) { |
| 530 | av1_fwd_txfm2d_16x4(src16 + i * buf->y_stride + j, coeff, buf->y_stride, |
| 531 | H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 532 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 533 | const uint64_t this_energy = |
| 534 | ((int64_t)coeff[k] * coeff[k]) + |
| 535 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 536 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 537 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 538 | freq_energy[k] += ROUND_POWER_OF_TWO(this_energy, 2 + 2 * (bd - 8)); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 539 | } |
| 540 | n++; |
| 541 | } |
| 542 | } |
| 543 | } else { |
Debargha Mukherjee | ac28c72 | 2018-11-14 22:09:46 -0800 | [diff] [blame] | 544 | assert(bd == 8); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 545 | DECLARE_ALIGNED(16, int16_t, src16[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 546 | for (int i = 0; i < height - 4; i += 4) { |
| 547 | for (int j = 0; j < width - 16; j += 16) { |
| 548 | for (int ii = 0; ii < 4; ++ii) |
| 549 | for (int jj = 0; jj < 16; ++jj) |
| 550 | src16[ii * 16 + jj] = |
| 551 | buf->y_buffer[(i + ii) * buf->y_stride + (j + jj)]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 552 | av1_fwd_txfm2d_16x4(src16, coeff, 16, H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 553 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 554 | const uint64_t this_energy = |
| 555 | ((int64_t)coeff[k] * coeff[k]) + |
| 556 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 557 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 558 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 559 | freq_energy[k] += ROUND_POWER_OF_TWO(this_energy, 2); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 560 | } |
| 561 | n++; |
| 562 | } |
| 563 | } |
| 564 | } |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 565 | if (n) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 566 | for (int k = 1; k < 16; ++k) energy[k] = (double)freq_energy[k] / n; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 567 | // Convert to cumulative energy |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 568 | for (int k = 14; k > 0; --k) energy[k] += energy[k + 1]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 569 | } else { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 570 | for (int k = 1; k < 16; ++k) energy[k] = 1e+20; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 571 | } |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 574 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 575 | const AV1_COMMON *const cm = &cpi->common; |
James Zern | bf3ca36 | 2019-10-21 11:33:44 -0700 | [diff] [blame] | 576 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 577 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 578 | return BLOCK_64X64; |
Ryan Lei | c8b6dd6 | 2019-10-23 20:01:26 -0700 | [diff] [blame] | 579 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 580 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 581 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 582 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 583 | |
Ryan Lei | c8b6dd6 | 2019-10-23 20:01:26 -0700 | [diff] [blame] | 584 | // TODO(any): Possibly could improve this with a heuristic. |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 585 | // When superres / resize is on, 'cm->width / height' can change between |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 586 | // calls, so we don't apply this heuristic there. |
| 587 | // Things break if superblock size changes between the first pass and second |
| 588 | // pass encoding, which is why this heuristic is not configured as a |
| 589 | // speed-feature. |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 590 | if (cpi->oxcf.superres_mode == SUPERRES_NONE && |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 591 | cpi->oxcf.resize_mode == RESIZE_NONE && cpi->oxcf.speed >= 1) { |
| 592 | return AOMMIN(cm->width, cm->height) > 480 ? BLOCK_128X128 : BLOCK_64X64; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 593 | } |
| 594 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 595 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 598 | static void setup_frame(AV1_COMP *cpi) { |
| 599 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 600 | // Set up entropy context depending on frame type. The decoder mandates |
| 601 | // the use of the default context, index 0, for keyframes and inter |
| 602 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 603 | // other inter-frames the encoder currently uses only two contexts; |
| 604 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 605 | |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 606 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 607 | cpi->ext_use_primary_ref_none) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 608 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Hui Su | eb4b7de | 2019-04-03 11:00:18 -0700 | [diff] [blame] | 611 | if ((cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) || |
| 612 | frame_is_sframe(cm)) { |
| 613 | if (!cpi->seq_params_locked) { |
| 614 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
| 615 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 616 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 617 | const RefCntBuffer *const primary_ref_buf = get_primary_ref_frame_buf(cm); |
| 618 | if (primary_ref_buf == NULL) { |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 619 | av1_setup_past_independence(cm); |
| 620 | cm->seg.update_map = 1; |
| 621 | cm->seg.update_data = 1; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 622 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 623 | *cm->fc = primary_ref_buf->frame_context; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 624 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 625 | } |
| 626 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 627 | av1_zero(cm->cur_frame->interp_filter_selected); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 628 | cm->prev_frame = get_primary_ref_frame_buf(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 629 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 630 | } |
| 631 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 632 | static void enc_set_mb_mi(AV1_COMMON *cm, int width, int height) { |
| 633 | // Ensure that the decoded width and height are both multiples of |
| 634 | // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if |
| 635 | // subsampling is used). |
| 636 | // This simplifies the implementation of various experiments, |
| 637 | // eg. cdef, which operates on units of 8x8 luma pixels. |
| 638 | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
| 639 | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 640 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 641 | cm->mi_cols = aligned_width >> MI_SIZE_LOG2; |
| 642 | cm->mi_rows = aligned_height >> MI_SIZE_LOG2; |
| 643 | cm->mi_stride = calc_mi_size(cm->mi_cols); |
| 644 | |
| 645 | cm->mb_cols = (cm->mi_cols + 2) >> 2; |
| 646 | cm->mb_rows = (cm->mi_rows + 2) >> 2; |
| 647 | cm->MBs = cm->mb_rows * cm->mb_cols; |
| 648 | |
| 649 | const int is_4k_or_larger = AOMMIN(width, height) >= 2160; |
| 650 | |
| 651 | cm->mi_alloc_bsize = is_4k_or_larger ? BLOCK_8X8 : BLOCK_4X4; |
| 652 | const int mi_alloc_size_1d = mi_size_wide[cm->mi_alloc_bsize]; |
| 653 | cm->mi_alloc_rows = (cm->mi_rows + mi_alloc_size_1d - 1) / mi_alloc_size_1d; |
| 654 | cm->mi_alloc_cols = (cm->mi_cols + mi_alloc_size_1d - 1) / mi_alloc_size_1d; |
| 655 | cm->mi_alloc_stride = |
| 656 | (cm->mi_stride + mi_alloc_size_1d - 1) / mi_alloc_size_1d; |
| 657 | |
| 658 | assert(mi_size_wide[cm->mi_alloc_bsize] == mi_size_high[cm->mi_alloc_bsize]); |
| 659 | |
| 660 | #if CONFIG_LPF_MASK |
chiyotsai | a13c19f | 2019-08-15 10:12:57 -0700 | [diff] [blame] | 661 | av1_alloc_loop_filter_mask(cm); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 662 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 663 | } |
| 664 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 665 | static void enc_setup_mi(AV1_COMMON *cm) { |
| 666 | const int mi_grid_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
| 667 | memset(cm->mi, 0, cm->mi_alloc_size * sizeof(*cm->mi)); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 668 | memset(cm->mi_grid_base, 0, mi_grid_size * sizeof(*cm->mi_grid_base)); |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 669 | memset(cm->tx_type_map, 0, mi_grid_size * sizeof(*cm->tx_type_map)); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static int enc_alloc_mi(AV1_COMMON *cm) { |
| 673 | const int mi_grid_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
| 674 | const int alloc_size_1d = mi_size_wide[cm->mi_alloc_bsize]; |
| 675 | const int alloc_mi_size = |
| 676 | cm->mi_alloc_stride * (calc_mi_size(cm->mi_rows) / alloc_size_1d); |
| 677 | |
| 678 | if (cm->mi_alloc_size < alloc_mi_size || cm->mi_grid_size < mi_grid_size) { |
| 679 | cm->free_mi(cm); |
| 680 | |
| 681 | cm->mi = aom_calloc(alloc_mi_size, sizeof(*cm->mi)); |
| 682 | if (!cm->mi) return 1; |
| 683 | cm->mi_alloc_size = alloc_mi_size; |
| 684 | |
| 685 | cm->mi_grid_base = |
| 686 | (MB_MODE_INFO **)aom_calloc(mi_grid_size, sizeof(MB_MODE_INFO *)); |
| 687 | if (!cm->mi_grid_base) return 1; |
| 688 | cm->mi_grid_size = mi_grid_size; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 689 | |
| 690 | cm->tx_type_map = aom_calloc(calc_mi_size(cm->mi_rows) * cm->mi_stride, |
| 691 | sizeof(*cm->tx_type_map)); |
| 692 | if (!cm->tx_type_map) return 1; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 693 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 698 | static void enc_free_mi(AV1_COMMON *cm) { |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 699 | aom_free(cm->mi); |
| 700 | cm->mi = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 701 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | cm->mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 703 | cm->mi_alloc_size = 0; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 704 | aom_free(cm->tx_type_map); |
| 705 | cm->tx_type_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 708 | void av1_initialize_enc(void) { |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 709 | av1_rtcd(); |
| 710 | aom_dsp_rtcd(); |
| 711 | aom_scale_rtcd(); |
| 712 | av1_init_intra_predictors(); |
| 713 | av1_init_me_luts(); |
| 714 | av1_rc_init_minq_luts(); |
| 715 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 718 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 719 | if (cpi->mbmi_ext_frame_base) { |
| 720 | aom_free(cpi->mbmi_ext_frame_base); |
| 721 | cpi->mbmi_ext_frame_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | |
| 725 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 726 | AV1_COMMON *cm = &cpi->common; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 727 | const int new_ext_mi_size = cm->mi_alloc_rows * cm->mi_alloc_cols; |
chiyotsai | 426c066 | 2019-08-05 16:15:11 -0700 | [diff] [blame] | 728 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 729 | if (new_ext_mi_size > cpi->mi_ext_alloc_size) { |
| 730 | dealloc_context_buffers_ext(cpi); |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 731 | CHECK_MEM_ERROR( |
| 732 | cm, cpi->mbmi_ext_frame_base, |
| 733 | aom_calloc(new_ext_mi_size, sizeof(*cpi->mbmi_ext_frame_base))); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 734 | cpi->mi_ext_alloc_size = new_ext_mi_size; |
| 735 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 738 | static void reset_film_grain_chroma_params(aom_film_grain_t *pars) { |
| 739 | pars->num_cr_points = 0; |
| 740 | pars->cr_mult = 0; |
| 741 | pars->cr_luma_mult = 0; |
| 742 | memset(pars->scaling_points_cr, 0, sizeof(pars->scaling_points_cr)); |
| 743 | memset(pars->ar_coeffs_cr, 0, sizeof(pars->ar_coeffs_cr)); |
| 744 | pars->num_cb_points = 0; |
| 745 | pars->cb_mult = 0; |
| 746 | pars->cb_luma_mult = 0; |
Yaowu Xu | fda7dcb | 2019-01-16 13:04:33 -0800 | [diff] [blame] | 747 | pars->chroma_scaling_from_luma = 0; |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 748 | memset(pars->scaling_points_cb, 0, sizeof(pars->scaling_points_cb)); |
| 749 | memset(pars->ar_coeffs_cb, 0, sizeof(pars->ar_coeffs_cb)); |
| 750 | } |
| 751 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 752 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 753 | const AV1EncoderConfig *oxcf) { |
| 754 | AV1_COMMON *const cm = &cpi->common; |
| 755 | cpi->oxcf = *oxcf; |
| 756 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 757 | if (cpi->film_grain_table) { |
| 758 | aom_film_grain_table_free(cpi->film_grain_table); |
| 759 | aom_free(cpi->film_grain_table); |
| 760 | cpi->film_grain_table = NULL; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 761 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 762 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 763 | if (oxcf->film_grain_test_vector) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 764 | cm->seq_params.film_grain_params_present = 1; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 765 | if (cm->current_frame.frame_type == KEY_FRAME) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 766 | memcpy(&cm->film_grain_params, |
| 767 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 768 | sizeof(cm->film_grain_params)); |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 769 | if (oxcf->monochrome) |
| 770 | reset_film_grain_chroma_params(&cm->film_grain_params); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 771 | cm->film_grain_params.bit_depth = cm->seq_params.bit_depth; |
| 772 | if (cm->seq_params.color_range == AOM_CR_FULL_RANGE) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 773 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 774 | } |
| 775 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 776 | } else if (oxcf->film_grain_table_filename) { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 777 | cm->seq_params.film_grain_params_present = 1; |
| 778 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 779 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 780 | memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t)); |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 781 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 782 | aom_film_grain_table_read(cpi->film_grain_table, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 783 | oxcf->film_grain_table_filename, &cm->error); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 784 | } else { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 785 | #if CONFIG_DENOISE |
| 786 | cm->seq_params.film_grain_params_present = (cpi->oxcf.noise_level > 0); |
| 787 | #else |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 788 | cm->seq_params.film_grain_params_present = 0; |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 789 | #endif |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 790 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 791 | } |
| 792 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 794 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 795 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 796 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 798 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 799 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 800 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 801 | cpi->tile_data = NULL; |
| 802 | |
| 803 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 804 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 805 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 806 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 807 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 808 | cpi->cyclic_refresh = NULL; |
| 809 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 810 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 811 | cpi->active_map.map = NULL; |
| 812 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 813 | aom_free(cpi->ssim_rdmult_scaling_factors); |
| 814 | cpi->ssim_rdmult_scaling_factors = NULL; |
| 815 | |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 816 | aom_free(cpi->tpl_rdmult_scaling_factors); |
| 817 | cpi->tpl_rdmult_scaling_factors = NULL; |
| 818 | |
| 819 | aom_free(cpi->tpl_sb_rdmult_scaling_factors); |
| 820 | cpi->tpl_sb_rdmult_scaling_factors = NULL; |
| 821 | |
sdeng | 0195916 | 2019-12-20 10:46:24 -0800 | [diff] [blame] | 822 | #if CONFIG_TUNE_VMAF |
| 823 | aom_free(cpi->vmaf_rdmult_scaling_factors); |
| 824 | cpi->vmaf_rdmult_scaling_factors = NULL; |
| 825 | #endif |
| 826 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 827 | aom_free(cpi->td.mb.above_pred_buf); |
| 828 | cpi->td.mb.above_pred_buf = NULL; |
| 829 | |
| 830 | aom_free(cpi->td.mb.left_pred_buf); |
| 831 | cpi->td.mb.left_pred_buf = NULL; |
| 832 | |
| 833 | aom_free(cpi->td.mb.wsrc_buf); |
| 834 | cpi->td.mb.wsrc_buf = NULL; |
| 835 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 836 | aom_free(cpi->td.mb.inter_modes_info); |
| 837 | cpi->td.mb.inter_modes_info = NULL; |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 838 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 839 | for (int i = 0; i < 2; i++) |
| 840 | for (int j = 0; j < 2; j++) { |
| 841 | aom_free(cpi->td.mb.hash_value_buffer[i][j]); |
| 842 | cpi->td.mb.hash_value_buffer[i][j] = NULL; |
| 843 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 844 | aom_free(cpi->td.mb.mask_buf); |
| 845 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 846 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 847 | aom_free(cm->tpl_mvs); |
| 848 | cm->tpl_mvs = NULL; |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 849 | |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 850 | aom_free(cpi->td.mb.mbmi_ext); |
| 851 | cpi->td.mb.mbmi_ext = NULL; |
| 852 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 853 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 854 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 855 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 856 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 857 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 858 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 859 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 860 | aom_free_frame_buffer(&cpi->scaled_source); |
| 861 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 862 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 863 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 864 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 865 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 866 | cpi->tile_tok[0][0] = 0; |
| 867 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 868 | aom_free(cpi->tplist[0][0]); |
| 869 | cpi->tplist[0][0] = NULL; |
| 870 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 871 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 872 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 873 | aom_free(cpi->td.mb.palette_buffer); |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 874 | av1_release_compound_type_rd_buffers(&cpi->td.mb.comp_rd_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 875 | aom_free(cpi->td.mb.tmp_conv_dst); |
| 876 | for (int j = 0; j < 2; ++j) { |
| 877 | aom_free(cpi->td.mb.tmp_obmc_bufs[j]); |
| 878 | } |
| 879 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 880 | #if CONFIG_DENOISE |
| 881 | if (cpi->denoise_and_model) { |
| 882 | aom_denoise_and_model_free(cpi->denoise_and_model); |
| 883 | cpi->denoise_and_model = NULL; |
| 884 | } |
| 885 | #endif |
| 886 | if (cpi->film_grain_table) { |
| 887 | aom_film_grain_table_free(cpi->film_grain_table); |
| 888 | cpi->film_grain_table = NULL; |
| 889 | } |
Hui Su | c3a8d37 | 2019-05-28 15:52:45 -0700 | [diff] [blame] | 890 | |
| 891 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
| 892 | aom_free(cpi->level_info[i]); |
| 893 | } |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 894 | |
| 895 | if (cpi->use_svc) av1_free_svc_cyclic_refresh(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 898 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 899 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 900 | const RATE_CONTROL *const rc = &cpi->rc; |
| 901 | struct segmentation *const seg = &cm->seg; |
| 902 | |
| 903 | int high_q = (int)(rc->avg_q > 48.0); |
| 904 | int qi_delta; |
| 905 | |
| 906 | // Disable and clear down for KF |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 907 | if (cm->current_frame.frame_type == KEY_FRAME) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 908 | // Clear down the global segmentation map |
| 909 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 910 | seg->update_map = 0; |
| 911 | seg->update_data = 0; |
| 912 | cpi->static_mb_pct = 0; |
| 913 | |
| 914 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 915 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | |
| 917 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 918 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 919 | } else if (cpi->refresh_alt_ref_frame) { |
| 920 | // If this is an alt ref frame |
| 921 | // Clear down the global segmentation map |
| 922 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 923 | seg->update_map = 0; |
| 924 | seg->update_data = 0; |
| 925 | cpi->static_mb_pct = 0; |
| 926 | |
| 927 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 928 | av1_disable_segmentation(seg); |
| 929 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 930 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 931 | // If segmentation was enabled set those features needed for the |
| 932 | // arf itself. |
| 933 | if (seg->enabled) { |
| 934 | seg->update_map = 1; |
| 935 | seg->update_data = 1; |
| 936 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 937 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, |
| 938 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 939 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 940 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 941 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 942 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 943 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 944 | |
| 945 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 946 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 947 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 948 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 949 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 950 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | } |
| 952 | } else if (seg->enabled) { |
| 953 | // All other frames if segmentation has been enabled |
| 954 | |
| 955 | // First normal frame in a valid gf or alt ref group |
| 956 | if (rc->frames_since_golden == 0) { |
| 957 | // Set up segment features for normal frames in an arf group |
| 958 | if (rc->source_alt_ref_active) { |
| 959 | seg->update_map = 0; |
| 960 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 961 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 962 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, |
| 963 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 964 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 965 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 966 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 967 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 968 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 969 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 970 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 971 | |
| 972 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 973 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 974 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 975 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 976 | |
| 977 | // Segment coding disabled for compred testing |
| 978 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 979 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 980 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 981 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 982 | } |
| 983 | } else { |
| 984 | // Disable segmentation and clear down features if alt ref |
| 985 | // is not active for this group |
| 986 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 987 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 988 | |
| 989 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 990 | |
| 991 | seg->update_map = 0; |
| 992 | seg->update_data = 0; |
| 993 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 994 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 995 | } |
| 996 | } else if (rc->is_src_frame_alt_ref) { |
| 997 | // Special case where we are coding over the top of a previous |
| 998 | // alt ref frame. |
| 999 | // Segment coding disabled for compred testing |
| 1000 | |
| 1001 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1002 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 1003 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1004 | |
| 1005 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1006 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 1007 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 1008 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 1009 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1010 | |
| 1011 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 1012 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1013 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 1014 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1015 | } |
| 1016 | // Enable data update |
| 1017 | seg->update_data = 1; |
| 1018 | } else { |
| 1019 | // All other frames. |
| 1020 | |
| 1021 | // No updates.. leave things as they are. |
| 1022 | seg->update_map = 0; |
| 1023 | seg->update_data = 0; |
| 1024 | } |
| 1025 | } |
| 1026 | } |
| 1027 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1028 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 1029 | AV1_COMMON *const cm = &cpi->common; |
chiyotsai | 2202ba0 | 2019-07-12 16:09:21 -0700 | [diff] [blame] | 1030 | MB_MODE_INFO **mi_4x4_ptr = cm->mi_grid_base; |
David Turner | b757ce0 | 2018-11-12 15:01:28 +0000 | [diff] [blame] | 1031 | uint8_t *cache_ptr = cm->cur_frame->seg_map; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1032 | int row, col; |
| 1033 | |
| 1034 | for (row = 0; row < cm->mi_rows; row++) { |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 1035 | MB_MODE_INFO **mi_4x4 = mi_4x4_ptr; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1036 | uint8_t *cache = cache_ptr; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 1037 | for (col = 0; col < cm->mi_cols; col++, mi_4x4++, cache++) |
| 1038 | cache[0] = mi_4x4[0]->segment_id; |
| 1039 | mi_4x4_ptr += cm->mi_stride; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1040 | cache_ptr += cm->mi_cols; |
| 1041 | } |
| 1042 | } |
| 1043 | |
Mufaddal Chakera | 02ac17f | 2019-12-09 18:09:55 +0530 | [diff] [blame] | 1044 | static void alloc_altref_frame_buffer(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1045 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1046 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1047 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1048 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1049 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yunqing Wang | 1d569be | 2019-10-09 13:23:12 -0700 | [diff] [blame] | 1050 | // (yunqing)Here use same border as lookahead buffers. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1051 | if (aom_realloc_frame_buffer( |
| 1052 | &cpi->alt_ref_buffer, oxcf->width, oxcf->height, |
| 1053 | seq_params->subsampling_x, seq_params->subsampling_y, |
Jingning Han | 55ba170 | 2020-01-14 11:43:04 -0800 | [diff] [blame] | 1054 | seq_params->use_highbitdepth, AOM_ENC_NO_SCALE_BORDER, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1055 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1056 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1057 | "Failed to allocate altref buffer"); |
| 1058 | } |
| 1059 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1060 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 1061 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1062 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 1063 | if (aom_realloc_frame_buffer( |
| 1064 | &cpi->last_frame_uf, cm->width, cm->height, seq_params->subsampling_x, |
| 1065 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 1066 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1067 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1068 | "Failed to allocate last frame buffer"); |
| 1069 | |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 1070 | if (aom_realloc_frame_buffer( |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 1071 | &cpi->trial_frame_rst, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1072 | cm->superres_upscaled_height, seq_params->subsampling_x, |
| 1073 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 3b12c00 | 2018-12-19 15:27:20 +0530 | [diff] [blame] | 1074 | AOM_RESTORATION_FRAME_BORDER, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 1075 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 1076 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1077 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1078 | if (aom_realloc_frame_buffer( |
| 1079 | &cpi->scaled_source, cm->width, cm->height, seq_params->subsampling_x, |
| 1080 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 1081 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1082 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1083 | "Failed to allocate scaled source buffer"); |
| 1084 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1085 | if (aom_realloc_frame_buffer( |
| 1086 | &cpi->scaled_last_source, cm->width, cm->height, |
| 1087 | seq_params->subsampling_x, seq_params->subsampling_y, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 1088 | seq_params->use_highbitdepth, cpi->oxcf.border_in_pixels, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1089 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1090 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1091 | "Failed to allocate scaled last source buffer"); |
| 1092 | } |
| 1093 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1094 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1095 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1096 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1097 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1098 | if (av1_alloc_context_buffers(cm, cm->width, cm->height)) { |
| 1099 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 1100 | "Failed to allocate context buffers"); |
| 1101 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1102 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 1103 | int mi_rows_aligned_to_sb = |
| 1104 | ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 1105 | int sb_rows = mi_rows_aligned_to_sb >> cm->seq_params.mib_size_log2; |
| 1106 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 1107 | av1_alloc_txb_buf(cpi); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 1108 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1109 | alloc_context_buffers_ext(cpi); |
| 1110 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1111 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1112 | |
| 1113 | { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1114 | unsigned int tokens = |
| 1115 | get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1116 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1117 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1118 | } |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 1119 | aom_free(cpi->tplist[0][0]); |
| 1120 | |
| 1121 | CHECK_MEM_ERROR(cm, cpi->tplist[0][0], |
| 1122 | aom_calloc(sb_rows * MAX_TILE_ROWS * MAX_TILE_COLS, |
| 1123 | sizeof(*cpi->tplist[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1124 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1125 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1128 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1129 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 1130 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 1133 | double av1_get_compression_ratio(const AV1_COMMON *const cm, |
| 1134 | size_t encoded_frame_size) { |
| 1135 | const int upscaled_width = cm->superres_upscaled_width; |
| 1136 | const int height = cm->height; |
| 1137 | const int luma_pic_size = upscaled_width * height; |
| 1138 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 1139 | const BITSTREAM_PROFILE profile = seq_params->profile; |
| 1140 | const int pic_size_profile_factor = |
| 1141 | profile == PROFILE_0 ? 15 : (profile == PROFILE_1 ? 30 : 36); |
| 1142 | encoded_frame_size = |
| 1143 | (encoded_frame_size > 129 ? encoded_frame_size - 128 : 1); |
| 1144 | const size_t uncompressed_frame_size = |
| 1145 | (luma_pic_size * pic_size_profile_factor) >> 3; |
| 1146 | return uncompressed_frame_size / (double)encoded_frame_size; |
| 1147 | } |
| 1148 | |
Yunqing Wang | 75e20e8 | 2018-06-16 12:10:48 -0700 | [diff] [blame] | 1149 | static void set_tile_info(AV1_COMP *cpi) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1150 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1151 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1152 | |
| 1153 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1154 | |
| 1155 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1156 | if (cpi->oxcf.tile_width_count == 0 || cpi->oxcf.tile_height_count == 0) { |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1157 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1158 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 1159 | cm->log2_tile_cols = AOMMIN(cm->log2_tile_cols, cm->max_log2_tile_cols); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1160 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1161 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 1162 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1163 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1164 | cm->uniform_tile_spacing_flag = 0; |
| 1165 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 1166 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1167 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 1168 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
David Barker | 6cd5a82 | 2018-03-05 16:19:28 +0000 | [diff] [blame] | 1169 | start_sb += AOMMIN(size_sb, cm->max_tile_width_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1170 | } |
| 1171 | cm->tile_cols = i; |
| 1172 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1173 | } |
| 1174 | av1_calculate_tile_cols(cm); |
| 1175 | |
| 1176 | // configure tile rows |
| 1177 | if (cm->uniform_tile_spacing_flag) { |
| 1178 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 1179 | cm->log2_tile_rows = AOMMIN(cm->log2_tile_rows, cm->max_log2_tile_rows); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1180 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1181 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 1182 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1183 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1184 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 1185 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1186 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 1187 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 1188 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1189 | } |
| 1190 | cm->tile_rows = i; |
| 1191 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1192 | } |
| 1193 | av1_calculate_tile_rows(cm); |
| 1194 | } |
| 1195 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1196 | static void update_frame_size(AV1_COMP *cpi) { |
| 1197 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1198 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 1199 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1200 | // We need to reallocate the context buffers here in case we need more mis. |
| 1201 | if (av1_alloc_context_buffers(cm, cm->width, cm->height)) { |
| 1202 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 1203 | "Failed to allocate context buffers"); |
| 1204 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1205 | av1_init_context_buffers(cm); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1206 | |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 1207 | av1_init_macroblockd(cm, xd, NULL); |
chiyotsai | 426c066 | 2019-08-05 16:15:11 -0700 | [diff] [blame] | 1208 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1209 | const int ext_mi_size = cm->mi_alloc_rows * cm->mi_alloc_cols; |
| 1210 | alloc_context_buffers_ext(cpi); |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 1211 | memset(cpi->mbmi_ext_frame_base, 0, |
| 1212 | ext_mi_size * sizeof(*cpi->mbmi_ext_frame_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1213 | set_tile_info(cpi); |
| 1214 | } |
| 1215 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1216 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1217 | int fb_idx; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 1218 | for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 1219 | cpi->common.remapped_ref_idx[fb_idx] = fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1220 | cpi->rate_index = 0; |
| 1221 | cpi->rate_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1224 | static INLINE int does_level_match(int width, int height, double fps, |
| 1225 | int lvl_width, int lvl_height, |
| 1226 | double lvl_fps, int lvl_dim_mult) { |
| 1227 | const int64_t lvl_luma_pels = lvl_width * lvl_height; |
| 1228 | const double lvl_display_sample_rate = lvl_luma_pels * lvl_fps; |
| 1229 | const int64_t luma_pels = width * height; |
| 1230 | const double display_sample_rate = luma_pels * fps; |
| 1231 | return luma_pels <= lvl_luma_pels && |
| 1232 | display_sample_rate <= lvl_display_sample_rate && |
| 1233 | width <= lvl_width * lvl_dim_mult && |
| 1234 | height <= lvl_height * lvl_dim_mult; |
| 1235 | } |
| 1236 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1237 | static void set_bitstream_level_tier(SequenceHeader *seq, AV1_COMMON *cm, |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 1238 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1239 | // TODO(any): This is a placeholder function that only addresses dimensions |
| 1240 | // and max display sample rates. |
| 1241 | // Need to add checks for max bit rate, max decoded luma sample rate, header |
| 1242 | // rate, etc. that are not covered by this function. |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1243 | AV1_LEVEL level = SEQ_LEVEL_MAX; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1244 | if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, 512, |
| 1245 | 288, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1246 | level = SEQ_LEVEL_2_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1247 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1248 | 704, 396, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1249 | level = SEQ_LEVEL_2_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1250 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1251 | 1088, 612, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1252 | level = SEQ_LEVEL_3_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1253 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1254 | 1376, 774, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1255 | level = SEQ_LEVEL_3_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1256 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1257 | 2048, 1152, 30.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1258 | level = SEQ_LEVEL_4_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1259 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1260 | 2048, 1152, 60.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1261 | level = SEQ_LEVEL_4_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1262 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1263 | 4096, 2176, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1264 | level = SEQ_LEVEL_5_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1265 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1266 | 4096, 2176, 60.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1267 | level = SEQ_LEVEL_5_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1268 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1269 | 4096, 2176, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1270 | level = SEQ_LEVEL_5_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1271 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1272 | 8192, 4352, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1273 | level = SEQ_LEVEL_6_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1274 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1275 | 8192, 4352, 60.0, 2)) { |
Todd Nguyen | ff4c860 | 2019-11-25 13:20:21 -0800 | [diff] [blame] | 1276 | level = SEQ_LEVEL_6_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1277 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1278 | 8192, 4352, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1279 | level = SEQ_LEVEL_6_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1280 | } |
chiyotsai | aa33bbf | 2019-12-02 12:07:53 -0800 | [diff] [blame] | 1281 | |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1282 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1283 | seq->seq_level_idx[i] = level; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1284 | // Set the maximum parameters for bitrate and buffer size for this profile, |
| 1285 | // level, and tier |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 1286 | cm->op_params[i].bitrate = av1_max_level_bitrate( |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1287 | cm->seq_params.profile, seq->seq_level_idx[i], seq->tier[i]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1288 | // Level with seq_level_idx = 31 returns a high "dummy" bitrate to pass the |
| 1289 | // check |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1290 | if (cm->op_params[i].bitrate == 0) |
| 1291 | aom_internal_error( |
| 1292 | &cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 1293 | "AV1 does not support this combination of profile, level, and tier."); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1294 | // Buffer size in bits/s is bitrate in bits/s * 1 s |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1295 | cm->op_params[i].buffer_size = cm->op_params[i].bitrate; |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1299 | static void init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm, |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1300 | const AV1EncoderConfig *oxcf, int use_svc) { |
Yaowu Xu | 2a9ac43 | 2019-08-06 14:21:17 -0700 | [diff] [blame] | 1301 | seq->still_picture = (oxcf->force_video_mode == 0) && (oxcf->limit == 1); |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1302 | seq->reduced_still_picture_hdr = seq->still_picture; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 1303 | seq->reduced_still_picture_hdr &= !oxcf->full_still_picture_hdr; |
kyslov | 9424338 | 2019-05-02 15:33:32 -0700 | [diff] [blame] | 1304 | seq->force_screen_content_tools = (oxcf->mode == REALTIME) ? 0 : 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1305 | seq->force_integer_mv = 2; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1306 | seq->order_hint_info.enable_order_hint = oxcf->enable_order_hint; |
David Turner | 936235c | 2018-11-28 13:42:01 +0000 | [diff] [blame] | 1307 | seq->frame_id_numbers_present_flag = |
| 1308 | !(seq->still_picture && seq->reduced_still_picture_hdr) && |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1309 | !oxcf->large_scale_tile && oxcf->error_resilient_mode && !use_svc; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1310 | if (seq->still_picture && seq->reduced_still_picture_hdr) { |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1311 | seq->order_hint_info.enable_order_hint = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1312 | seq->force_screen_content_tools = 2; |
| 1313 | seq->force_integer_mv = 2; |
| 1314 | } |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1315 | seq->order_hint_info.order_hint_bits_minus_1 = |
| 1316 | seq->order_hint_info.enable_order_hint |
| 1317 | ? DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1 |
| 1318 | : -1; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1319 | |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 1320 | seq->max_frame_width = |
| 1321 | oxcf->forced_max_frame_width ? oxcf->forced_max_frame_width : oxcf->width; |
| 1322 | seq->max_frame_height = oxcf->forced_max_frame_height |
| 1323 | ? oxcf->forced_max_frame_height |
| 1324 | : oxcf->height; |
| 1325 | seq->num_bits_width = |
| 1326 | (seq->max_frame_width > 1) ? get_msb(seq->max_frame_width - 1) + 1 : 1; |
| 1327 | seq->num_bits_height = |
| 1328 | (seq->max_frame_height > 1) ? get_msb(seq->max_frame_height - 1) + 1 : 1; |
| 1329 | assert(seq->num_bits_width <= 16); |
| 1330 | assert(seq->num_bits_height <= 16); |
| 1331 | |
| 1332 | seq->frame_id_length = FRAME_ID_LENGTH; |
| 1333 | seq->delta_frame_id_length = DELTA_FRAME_ID_LENGTH; |
| 1334 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1335 | seq->enable_dual_filter = oxcf->enable_dual_filter; |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 1336 | seq->order_hint_info.enable_dist_wtd_comp = oxcf->enable_dist_wtd_comp; |
| 1337 | seq->order_hint_info.enable_dist_wtd_comp &= |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1338 | seq->order_hint_info.enable_order_hint; |
| 1339 | seq->order_hint_info.enable_ref_frame_mvs = oxcf->enable_ref_frame_mvs; |
| 1340 | seq->order_hint_info.enable_ref_frame_mvs &= |
| 1341 | seq->order_hint_info.enable_order_hint; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1342 | seq->enable_superres = oxcf->enable_superres; |
| 1343 | seq->enable_cdef = oxcf->enable_cdef; |
| 1344 | seq->enable_restoration = oxcf->enable_restoration; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 1345 | seq->enable_warped_motion = oxcf->enable_warped_motion; |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 1346 | seq->enable_interintra_compound = oxcf->enable_interintra_comp; |
| 1347 | seq->enable_masked_compound = oxcf->enable_masked_comp; |
Debargha Mukherjee | 03c43ba | 2018-12-14 13:08:08 -0800 | [diff] [blame] | 1348 | seq->enable_intra_edge_filter = oxcf->enable_intra_edge_filter; |
Yue Chen | 8f9ca58 | 2018-12-12 15:11:47 -0800 | [diff] [blame] | 1349 | seq->enable_filter_intra = oxcf->enable_filter_intra; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1350 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1351 | set_bitstream_level_tier(seq, cm, oxcf); |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1352 | |
| 1353 | if (seq->operating_points_cnt_minus_1 == 0) { |
| 1354 | seq->operating_point_idc[0] = 0; |
| 1355 | } else { |
Marco Paniconi | 6da983b | 2019-09-16 20:12:43 -0700 | [diff] [blame] | 1356 | // Set operating_point_idc[] such that the i=0 point corresponds to the |
| 1357 | // highest quality operating point (all layers), and subsequent |
| 1358 | // operarting points (i > 0) are lower quality corresponding to |
| 1359 | // skip decoding enhancement layers (temporal first). |
| 1360 | int i = 0; |
| 1361 | assert(seq->operating_points_cnt_minus_1 == |
| 1362 | (int)(cm->number_spatial_layers * cm->number_temporal_layers - 1)); |
| 1363 | for (unsigned int sl = 0; sl < cm->number_spatial_layers; sl++) { |
| 1364 | for (unsigned int tl = 0; tl < cm->number_temporal_layers; tl++) { |
| 1365 | seq->operating_point_idc[i] = |
| 1366 | (~(~0u << (cm->number_spatial_layers - sl)) << 8) | |
| 1367 | ~(~0u << (cm->number_temporal_layers - tl)); |
| 1368 | i++; |
| 1369 | } |
| 1370 | } |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1371 | } |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1374 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1375 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1376 | |
| 1377 | cpi->oxcf = *oxcf; |
| 1378 | cpi->framerate = oxcf->init_framerate; |
| 1379 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1380 | cm->seq_params.profile = oxcf->profile; |
| 1381 | cm->seq_params.bit_depth = oxcf->bit_depth; |
| 1382 | cm->seq_params.use_highbitdepth = oxcf->use_highbitdepth; |
| 1383 | cm->seq_params.color_primaries = oxcf->color_primaries; |
| 1384 | cm->seq_params.transfer_characteristics = oxcf->transfer_characteristics; |
| 1385 | cm->seq_params.matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1386 | cm->seq_params.monochrome = oxcf->monochrome; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1387 | cm->seq_params.chroma_sample_position = oxcf->chroma_sample_position; |
| 1388 | cm->seq_params.color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 1389 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1390 | cm->timing_info.num_units_in_display_tick = |
| 1391 | oxcf->timing_info.num_units_in_display_tick; |
| 1392 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 1393 | cm->timing_info.equal_picture_interval = |
| 1394 | oxcf->timing_info.equal_picture_interval; |
| 1395 | cm->timing_info.num_ticks_per_picture = |
| 1396 | oxcf->timing_info.num_ticks_per_picture; |
| 1397 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1398 | cm->seq_params.display_model_info_present_flag = |
| 1399 | oxcf->display_model_info_present_flag; |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1400 | cm->seq_params.decoder_model_info_present_flag = |
| 1401 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1402 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1403 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1404 | cm->buffer_model.num_units_in_decoding_tick = |
| 1405 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 1406 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1407 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 1408 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1409 | } else if (cm->timing_info_present && |
| 1410 | cm->timing_info.equal_picture_interval && |
| 1411 | !cm->seq_params.decoder_model_info_present_flag) { |
| 1412 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1413 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1414 | } else { |
| 1415 | cm->op_params[0].initial_display_delay = |
| 1416 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1417 | } |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1418 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1419 | if (cm->seq_params.monochrome) { |
| 1420 | cm->seq_params.subsampling_x = 1; |
| 1421 | cm->seq_params.subsampling_y = 1; |
| 1422 | } else if (cm->seq_params.color_primaries == AOM_CICP_CP_BT_709 && |
| 1423 | cm->seq_params.transfer_characteristics == AOM_CICP_TC_SRGB && |
| 1424 | cm->seq_params.matrix_coefficients == AOM_CICP_MC_IDENTITY) { |
| 1425 | cm->seq_params.subsampling_x = 0; |
| 1426 | cm->seq_params.subsampling_y = 0; |
| 1427 | } else { |
| 1428 | if (cm->seq_params.profile == 0) { |
| 1429 | cm->seq_params.subsampling_x = 1; |
| 1430 | cm->seq_params.subsampling_y = 1; |
| 1431 | } else if (cm->seq_params.profile == 1) { |
| 1432 | cm->seq_params.subsampling_x = 0; |
| 1433 | cm->seq_params.subsampling_y = 0; |
| 1434 | } else { |
| 1435 | if (cm->seq_params.bit_depth == AOM_BITS_12) { |
| 1436 | cm->seq_params.subsampling_x = oxcf->chroma_subsampling_x; |
| 1437 | cm->seq_params.subsampling_y = oxcf->chroma_subsampling_y; |
| 1438 | } else { |
| 1439 | cm->seq_params.subsampling_x = 1; |
| 1440 | cm->seq_params.subsampling_y = 0; |
| 1441 | } |
| 1442 | } |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1445 | cm->width = oxcf->width; |
| 1446 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1447 | set_sb_size(&cm->seq_params, |
| 1448 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1449 | alloc_compressor_data(cpi); |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 1450 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 1451 | update_film_grain_parameters(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1452 | |
| 1453 | // Single thread case: use counts in common. |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 1454 | cpi->td.counts = &cpi->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1455 | |
Marco Paniconi | 882c5ad | 2019-09-30 21:32:29 -0700 | [diff] [blame] | 1456 | // Set init SVC parameters. |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1457 | cpi->use_svc = 0; |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 1458 | cpi->svc.external_ref_frame_config = 0; |
| 1459 | cpi->svc.non_reference_frame = 0; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1460 | cm->number_spatial_layers = 1; |
| 1461 | cm->number_temporal_layers = 1; |
Marco Paniconi | 882c5ad | 2019-09-30 21:32:29 -0700 | [diff] [blame] | 1462 | cm->spatial_layer_id = 0; |
| 1463 | cm->temporal_layer_id = 0; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1464 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1465 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1466 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1467 | |
| 1468 | cpi->static_mb_pct = 0; |
| 1469 | cpi->ref_frame_flags = 0; |
| 1470 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1471 | // Reset resize pending flags |
| 1472 | cpi->resize_pending_width = 0; |
| 1473 | cpi->resize_pending_height = 0; |
| 1474 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1475 | init_buffer_indices(cpi); |
| 1476 | } |
| 1477 | |
| 1478 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1479 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1480 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1481 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1482 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1483 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1484 | |
| 1485 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1486 | rc->optimal_buffer_level = |
| 1487 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1488 | rc->maximum_buffer_size = |
| 1489 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1490 | } |
| 1491 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1492 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 1493 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1494 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1495 | cpi->fn_ptr[BT].vf = VF; \ |
| 1496 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1497 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1498 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 1499 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1500 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1501 | |
| 1502 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1503 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1504 | int source_stride, \ |
| 1505 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1506 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1507 | } \ |
| 1508 | static unsigned int fnname##_bits10( \ |
| 1509 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1510 | int ref_stride) { \ |
| 1511 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1512 | } \ |
| 1513 | static unsigned int fnname##_bits12( \ |
| 1514 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1515 | int ref_stride) { \ |
| 1516 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1517 | } |
| 1518 | |
| 1519 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1520 | static unsigned int fnname##_bits8( \ |
| 1521 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1522 | int ref_stride, const uint8_t *second_pred) { \ |
| 1523 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1524 | } \ |
| 1525 | static unsigned int fnname##_bits10( \ |
| 1526 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1527 | int ref_stride, const uint8_t *second_pred) { \ |
| 1528 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1529 | 2; \ |
| 1530 | } \ |
| 1531 | static unsigned int fnname##_bits12( \ |
| 1532 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1533 | int ref_stride, const uint8_t *second_pred) { \ |
| 1534 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1535 | 4; \ |
| 1536 | } |
| 1537 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1538 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1539 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1540 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1541 | unsigned int *sad_array) { \ |
| 1542 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1543 | } \ |
| 1544 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1545 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1546 | unsigned int *sad_array) { \ |
| 1547 | int i; \ |
| 1548 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1549 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1550 | } \ |
| 1551 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1552 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1553 | unsigned int *sad_array) { \ |
| 1554 | int i; \ |
| 1555 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1556 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1557 | } |
| 1558 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1559 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1560 | static unsigned int fnname##_bits8( \ |
| 1561 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1562 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1563 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1564 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1565 | jcp_param); \ |
| 1566 | } \ |
| 1567 | static unsigned int fnname##_bits10( \ |
| 1568 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1569 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1570 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1571 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1572 | jcp_param) >> \ |
| 1573 | 2; \ |
| 1574 | } \ |
| 1575 | static unsigned int fnname##_bits12( \ |
| 1576 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1577 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1578 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1579 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1580 | jcp_param) >> \ |
| 1581 | 4; \ |
| 1582 | } |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1583 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1584 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1585 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1586 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1587 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1588 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1589 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1590 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1591 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1592 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1593 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1594 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1595 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1596 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1597 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1598 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1599 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1600 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1601 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1602 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1603 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1604 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1605 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1606 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1607 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1608 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1609 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1610 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1611 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1612 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1613 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1614 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1615 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1616 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1617 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1618 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1619 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1620 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1621 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1622 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1623 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1624 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1625 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1626 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1627 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1628 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1629 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1630 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1631 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1632 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1633 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1634 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1635 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1636 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1637 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1638 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1639 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1640 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1641 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1642 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1643 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1644 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1645 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1646 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1647 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1648 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1649 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1650 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1651 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1652 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1653 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x128_avg) |
| 1654 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x64_avg) |
| 1655 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x128_avg) |
| 1656 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x16_avg) |
| 1657 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x32_avg) |
| 1658 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x32_avg) |
| 1659 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x64_avg) |
| 1660 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x32_avg) |
| 1661 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x64_avg) |
| 1662 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x16_avg) |
| 1663 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x8_avg) |
| 1664 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x16_avg) |
| 1665 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x8_avg) |
| 1666 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x4_avg) |
| 1667 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x8_avg) |
| 1668 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x4_avg) |
| 1669 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x16_avg) |
| 1670 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x4_avg) |
| 1671 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x32_avg) |
| 1672 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x8_avg) |
| 1673 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x64_avg) |
| 1674 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x16_avg) |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1675 | #endif // CONFIG_AV1_HIGHBITDEPTH |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1676 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1677 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1678 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1679 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1680 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1681 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1682 | static unsigned int fnname##_bits8( \ |
| 1683 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1684 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1685 | int m_stride, int invert_mask) { \ |
| 1686 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1687 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1688 | } \ |
| 1689 | static unsigned int fnname##_bits10( \ |
| 1690 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1691 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1692 | int m_stride, int invert_mask) { \ |
| 1693 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1694 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1695 | 2; \ |
| 1696 | } \ |
| 1697 | static unsigned int fnname##_bits12( \ |
| 1698 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1699 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1700 | int m_stride, int invert_mask) { \ |
| 1701 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1702 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1703 | 4; \ |
| 1704 | } |
| 1705 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1706 | #if CONFIG_AV1_HIGHBITDEPTH |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1707 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1708 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1709 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1710 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1711 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1712 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1713 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1714 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1715 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1716 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1717 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1718 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1719 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1720 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1721 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1722 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1723 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1724 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1725 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1726 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1727 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1728 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1729 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1730 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1731 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1732 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1733 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1734 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1735 | |
| 1736 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1737 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1738 | const int32_t *wsrc, \ |
| 1739 | const int32_t *msk) { \ |
| 1740 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1741 | } \ |
| 1742 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1743 | const int32_t *wsrc, \ |
| 1744 | const int32_t *msk) { \ |
| 1745 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1746 | } \ |
| 1747 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1748 | const int32_t *wsrc, \ |
| 1749 | const int32_t *msk) { \ |
| 1750 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1751 | } |
| 1752 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1753 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1754 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1755 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1756 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1757 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1758 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1759 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1760 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1761 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1762 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1763 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1764 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1765 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1766 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1767 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1768 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1769 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1770 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1771 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1772 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1773 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1774 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1775 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1776 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1777 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1778 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1779 | if (cm->seq_params.use_highbitdepth) { |
| 1780 | switch (cm->seq_params.bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1781 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1782 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1783 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1784 | aom_highbd_8_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1785 | aom_highbd_8_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1786 | aom_highbd_sad64x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1787 | aom_highbd_dist_wtd_sad64x16_avg_bits8, |
| 1788 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1789 | |
| 1790 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1791 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1792 | aom_highbd_8_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1793 | aom_highbd_8_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1794 | aom_highbd_sad16x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1795 | aom_highbd_dist_wtd_sad16x64_avg_bits8, |
| 1796 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1797 | |
| 1798 | HIGHBD_BFP( |
| 1799 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1800 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1801 | aom_highbd_8_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1802 | aom_highbd_sad32x8x4d_bits8, aom_highbd_dist_wtd_sad32x8_avg_bits8, |
| 1803 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1804 | |
| 1805 | HIGHBD_BFP( |
| 1806 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1807 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1808 | aom_highbd_8_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1809 | aom_highbd_sad8x32x4d_bits8, aom_highbd_dist_wtd_sad8x32_avg_bits8, |
| 1810 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1811 | |
| 1812 | HIGHBD_BFP( |
| 1813 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1814 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1815 | aom_highbd_8_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1816 | aom_highbd_sad16x4x4d_bits8, aom_highbd_dist_wtd_sad16x4_avg_bits8, |
| 1817 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1818 | |
| 1819 | HIGHBD_BFP( |
| 1820 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1821 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1822 | aom_highbd_8_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1823 | aom_highbd_sad4x16x4d_bits8, aom_highbd_dist_wtd_sad4x16_avg_bits8, |
| 1824 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1825 | |
| 1826 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1827 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1828 | aom_highbd_8_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1829 | aom_highbd_8_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1830 | aom_highbd_sad32x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1831 | aom_highbd_dist_wtd_sad32x16_avg_bits8, |
| 1832 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1833 | |
| 1834 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1835 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1836 | aom_highbd_8_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1837 | aom_highbd_8_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1838 | aom_highbd_sad16x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1839 | aom_highbd_dist_wtd_sad16x32_avg_bits8, |
| 1840 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1841 | |
| 1842 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1843 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1844 | aom_highbd_8_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1845 | aom_highbd_8_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1846 | aom_highbd_sad64x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1847 | aom_highbd_dist_wtd_sad64x32_avg_bits8, |
| 1848 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1849 | |
| 1850 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1851 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1852 | aom_highbd_8_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1853 | aom_highbd_8_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1854 | aom_highbd_sad32x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1855 | aom_highbd_dist_wtd_sad32x64_avg_bits8, |
| 1856 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1857 | |
| 1858 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1859 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1860 | aom_highbd_8_sub_pixel_variance32x32, |
| 1861 | aom_highbd_8_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1862 | aom_highbd_sad32x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1863 | aom_highbd_dist_wtd_sad32x32_avg_bits8, |
| 1864 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1865 | |
| 1866 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1867 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1868 | aom_highbd_8_sub_pixel_variance64x64, |
| 1869 | aom_highbd_8_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1870 | aom_highbd_sad64x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1871 | aom_highbd_dist_wtd_sad64x64_avg_bits8, |
| 1872 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1873 | |
| 1874 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1875 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1876 | aom_highbd_8_sub_pixel_variance16x16, |
| 1877 | aom_highbd_8_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1878 | aom_highbd_sad16x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1879 | aom_highbd_dist_wtd_sad16x16_avg_bits8, |
| 1880 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1881 | |
| 1882 | HIGHBD_BFP( |
| 1883 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1884 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1885 | aom_highbd_8_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1886 | aom_highbd_sad16x8x4d_bits8, aom_highbd_dist_wtd_sad16x8_avg_bits8, |
| 1887 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1888 | |
| 1889 | HIGHBD_BFP( |
| 1890 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1891 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1892 | aom_highbd_8_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1893 | aom_highbd_sad8x16x4d_bits8, aom_highbd_dist_wtd_sad8x16_avg_bits8, |
| 1894 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1895 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1896 | HIGHBD_BFP( |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1897 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1898 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1899 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x4d_bits8, |
| 1900 | aom_highbd_dist_wtd_sad8x8_avg_bits8, |
| 1901 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x8) |
| 1902 | |
| 1903 | HIGHBD_BFP( |
| 1904 | BLOCK_8X4, aom_highbd_sad8x4_bits8, aom_highbd_sad8x4_avg_bits8, |
| 1905 | aom_highbd_8_variance8x4, aom_highbd_8_sub_pixel_variance8x4, |
| 1906 | aom_highbd_8_sub_pixel_avg_variance8x4, aom_highbd_sad8x4x4d_bits8, |
| 1907 | aom_highbd_dist_wtd_sad8x4_avg_bits8, |
| 1908 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x4) |
| 1909 | |
| 1910 | HIGHBD_BFP( |
| 1911 | BLOCK_4X8, aom_highbd_sad4x8_bits8, aom_highbd_sad4x8_avg_bits8, |
| 1912 | aom_highbd_8_variance4x8, aom_highbd_8_sub_pixel_variance4x8, |
| 1913 | aom_highbd_8_sub_pixel_avg_variance4x8, aom_highbd_sad4x8x4d_bits8, |
| 1914 | aom_highbd_dist_wtd_sad4x8_avg_bits8, |
| 1915 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x8) |
| 1916 | |
| 1917 | HIGHBD_BFP( |
| 1918 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1919 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1920 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x4d_bits8, |
| 1921 | aom_highbd_dist_wtd_sad4x4_avg_bits8, |
| 1922 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x4) |
| 1923 | |
| 1924 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1925 | aom_highbd_sad128x128_avg_bits8, |
| 1926 | aom_highbd_8_variance128x128, |
| 1927 | aom_highbd_8_sub_pixel_variance128x128, |
| 1928 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1929 | aom_highbd_sad128x128x4d_bits8, |
| 1930 | aom_highbd_dist_wtd_sad128x128_avg_bits8, |
| 1931 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1932 | |
| 1933 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1934 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1935 | aom_highbd_8_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1936 | aom_highbd_8_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1937 | aom_highbd_sad128x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1938 | aom_highbd_dist_wtd_sad128x64_avg_bits8, |
| 1939 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1940 | |
| 1941 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1942 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1943 | aom_highbd_8_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1944 | aom_highbd_8_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1945 | aom_highbd_sad64x128x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1946 | aom_highbd_dist_wtd_sad64x128_avg_bits8, |
| 1947 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1948 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1949 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1950 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1951 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1952 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1953 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1954 | aom_highbd_8_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1955 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1956 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1957 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1958 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1959 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1960 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1961 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1962 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1963 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1964 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1965 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1966 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1967 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1968 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1969 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1970 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1971 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1972 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1973 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1974 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1975 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1976 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1977 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1978 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1979 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1980 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1981 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1982 | aom_highbd_8_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1983 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1984 | aom_highbd_8_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1985 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1986 | aom_highbd_8_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1987 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1988 | aom_highbd_8_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1989 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1990 | aom_highbd_8_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1991 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1992 | aom_highbd_8_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1993 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1994 | aom_highbd_obmc_variance128x128, |
| 1995 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1996 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1997 | aom_highbd_obmc_variance128x64, |
| 1998 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1999 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 2000 | aom_highbd_obmc_variance64x128, |
| 2001 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2002 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 2003 | aom_highbd_obmc_variance64x64, |
| 2004 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 2005 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 2006 | aom_highbd_obmc_variance64x32, |
| 2007 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 2008 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 2009 | aom_highbd_obmc_variance32x64, |
| 2010 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 2011 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 2012 | aom_highbd_obmc_variance32x32, |
| 2013 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 2014 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 2015 | aom_highbd_obmc_variance32x16, |
| 2016 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 2017 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 2018 | aom_highbd_obmc_variance16x32, |
| 2019 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 2020 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 2021 | aom_highbd_obmc_variance16x16, |
| 2022 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 2023 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 2024 | aom_highbd_obmc_variance8x16, |
| 2025 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 2026 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 2027 | aom_highbd_obmc_variance16x8, |
| 2028 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 2029 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 2030 | aom_highbd_obmc_variance8x8, |
| 2031 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 2032 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 2033 | aom_highbd_obmc_variance4x8, |
| 2034 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 2035 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 2036 | aom_highbd_obmc_variance8x4, |
| 2037 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 2038 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 2039 | aom_highbd_obmc_variance4x4, |
| 2040 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2041 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 2042 | aom_highbd_obmc_variance64x16, |
| 2043 | aom_highbd_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2044 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 2045 | aom_highbd_obmc_variance16x64, |
| 2046 | aom_highbd_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2047 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 2048 | aom_highbd_obmc_variance32x8, |
| 2049 | aom_highbd_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2050 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 2051 | aom_highbd_obmc_variance8x32, |
| 2052 | aom_highbd_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2053 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 2054 | aom_highbd_obmc_variance16x4, |
| 2055 | aom_highbd_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2056 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 2057 | aom_highbd_obmc_variance4x16, |
| 2058 | aom_highbd_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2059 | break; |
| 2060 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2061 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2062 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 2063 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 2064 | aom_highbd_10_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2065 | aom_highbd_10_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2066 | aom_highbd_sad64x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2067 | aom_highbd_dist_wtd_sad64x16_avg_bits10, |
| 2068 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2069 | |
| 2070 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 2071 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 2072 | aom_highbd_10_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2073 | aom_highbd_10_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2074 | aom_highbd_sad16x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2075 | aom_highbd_dist_wtd_sad16x64_avg_bits10, |
| 2076 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2077 | |
| 2078 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 2079 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 2080 | aom_highbd_10_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2081 | aom_highbd_10_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2082 | aom_highbd_sad32x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2083 | aom_highbd_dist_wtd_sad32x8_avg_bits10, |
| 2084 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2085 | |
| 2086 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 2087 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 2088 | aom_highbd_10_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2089 | aom_highbd_10_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2090 | aom_highbd_sad8x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2091 | aom_highbd_dist_wtd_sad8x32_avg_bits10, |
| 2092 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2093 | |
| 2094 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 2095 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 2096 | aom_highbd_10_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2097 | aom_highbd_10_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2098 | aom_highbd_sad16x4x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2099 | aom_highbd_dist_wtd_sad16x4_avg_bits10, |
| 2100 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2101 | |
| 2102 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 2103 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 2104 | aom_highbd_10_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2105 | aom_highbd_10_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2106 | aom_highbd_sad4x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2107 | aom_highbd_dist_wtd_sad4x16_avg_bits10, |
| 2108 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2109 | |
| 2110 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 2111 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 2112 | aom_highbd_10_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2113 | aom_highbd_10_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2114 | aom_highbd_sad32x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2115 | aom_highbd_dist_wtd_sad32x16_avg_bits10, |
| 2116 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2117 | |
| 2118 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 2119 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 2120 | aom_highbd_10_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2121 | aom_highbd_10_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2122 | aom_highbd_sad16x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2123 | aom_highbd_dist_wtd_sad16x32_avg_bits10, |
| 2124 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2125 | |
| 2126 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 2127 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 2128 | aom_highbd_10_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2129 | aom_highbd_10_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2130 | aom_highbd_sad64x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2131 | aom_highbd_dist_wtd_sad64x32_avg_bits10, |
| 2132 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2133 | |
| 2134 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 2135 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 2136 | aom_highbd_10_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2137 | aom_highbd_10_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2138 | aom_highbd_sad32x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2139 | aom_highbd_dist_wtd_sad32x64_avg_bits10, |
| 2140 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2141 | |
| 2142 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 2143 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 2144 | aom_highbd_10_sub_pixel_variance32x32, |
| 2145 | aom_highbd_10_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2146 | aom_highbd_sad32x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2147 | aom_highbd_dist_wtd_sad32x32_avg_bits10, |
| 2148 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2149 | |
| 2150 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 2151 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 2152 | aom_highbd_10_sub_pixel_variance64x64, |
| 2153 | aom_highbd_10_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2154 | aom_highbd_sad64x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2155 | aom_highbd_dist_wtd_sad64x64_avg_bits10, |
| 2156 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2157 | |
| 2158 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 2159 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 2160 | aom_highbd_10_sub_pixel_variance16x16, |
| 2161 | aom_highbd_10_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2162 | aom_highbd_sad16x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2163 | aom_highbd_dist_wtd_sad16x16_avg_bits10, |
| 2164 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2165 | |
| 2166 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 2167 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 2168 | aom_highbd_10_sub_pixel_variance16x8, |
| 2169 | aom_highbd_10_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2170 | aom_highbd_sad16x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2171 | aom_highbd_dist_wtd_sad16x8_avg_bits10, |
| 2172 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2173 | |
| 2174 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 2175 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 2176 | aom_highbd_10_sub_pixel_variance8x16, |
| 2177 | aom_highbd_10_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2178 | aom_highbd_sad8x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2179 | aom_highbd_dist_wtd_sad8x16_avg_bits10, |
| 2180 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2181 | |
| 2182 | HIGHBD_BFP( |
| 2183 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 2184 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2185 | aom_highbd_10_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2186 | aom_highbd_sad8x8x4d_bits10, aom_highbd_dist_wtd_sad8x8_avg_bits10, |
| 2187 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2188 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2189 | HIGHBD_BFP( |
| 2190 | BLOCK_8X4, aom_highbd_sad8x4_bits10, aom_highbd_sad8x4_avg_bits10, |
| 2191 | aom_highbd_10_variance8x4, aom_highbd_10_sub_pixel_variance8x4, |
| 2192 | aom_highbd_10_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2193 | aom_highbd_sad8x4x4d_bits10, aom_highbd_dist_wtd_sad8x4_avg_bits10, |
| 2194 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2195 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2196 | HIGHBD_BFP( |
| 2197 | BLOCK_4X8, aom_highbd_sad4x8_bits10, aom_highbd_sad4x8_avg_bits10, |
| 2198 | aom_highbd_10_variance4x8, aom_highbd_10_sub_pixel_variance4x8, |
| 2199 | aom_highbd_10_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2200 | aom_highbd_sad4x8x4d_bits10, aom_highbd_dist_wtd_sad4x8_avg_bits10, |
| 2201 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2202 | |
| 2203 | HIGHBD_BFP( |
| 2204 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 2205 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2206 | aom_highbd_10_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2207 | aom_highbd_sad4x4x4d_bits10, aom_highbd_dist_wtd_sad4x4_avg_bits10, |
| 2208 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2209 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2210 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 2211 | aom_highbd_sad128x128_avg_bits10, |
| 2212 | aom_highbd_10_variance128x128, |
| 2213 | aom_highbd_10_sub_pixel_variance128x128, |
| 2214 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 2215 | aom_highbd_sad128x128x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2216 | aom_highbd_dist_wtd_sad128x128_avg_bits10, |
| 2217 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2218 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2219 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 2220 | aom_highbd_sad128x64_avg_bits10, |
| 2221 | aom_highbd_10_variance128x64, |
| 2222 | aom_highbd_10_sub_pixel_variance128x64, |
| 2223 | aom_highbd_10_sub_pixel_avg_variance128x64, |
| 2224 | aom_highbd_sad128x64x4d_bits10, |
| 2225 | aom_highbd_dist_wtd_sad128x64_avg_bits10, |
| 2226 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2227 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2228 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 2229 | aom_highbd_sad64x128_avg_bits10, |
| 2230 | aom_highbd_10_variance64x128, |
| 2231 | aom_highbd_10_sub_pixel_variance64x128, |
| 2232 | aom_highbd_10_sub_pixel_avg_variance64x128, |
| 2233 | aom_highbd_sad64x128x4d_bits10, |
| 2234 | aom_highbd_dist_wtd_sad64x128_avg_bits10, |
| 2235 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2236 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2237 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 2238 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 2239 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 2240 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 2241 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 2242 | aom_highbd_10_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2243 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 2244 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 2245 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 2246 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 2247 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 2248 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 2249 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 2250 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 2251 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 2252 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 2253 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 2254 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 2255 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 2256 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 2257 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 2258 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 2259 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 2260 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 2261 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 2262 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 2263 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 2264 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 2265 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 2266 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 2267 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 2268 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2269 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 2270 | aom_highbd_10_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2271 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 2272 | aom_highbd_10_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2273 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 2274 | aom_highbd_10_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2275 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 2276 | aom_highbd_10_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2277 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 2278 | aom_highbd_10_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2279 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 2280 | aom_highbd_10_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2281 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 2282 | aom_highbd_10_obmc_variance128x128, |
| 2283 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 2284 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 2285 | aom_highbd_10_obmc_variance128x64, |
| 2286 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 2287 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 2288 | aom_highbd_10_obmc_variance64x128, |
| 2289 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2290 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 2291 | aom_highbd_10_obmc_variance64x64, |
| 2292 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2293 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2294 | aom_highbd_10_obmc_variance64x32, |
| 2295 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2296 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2297 | aom_highbd_10_obmc_variance32x64, |
| 2298 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2299 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2300 | aom_highbd_10_obmc_variance32x32, |
| 2301 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2302 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2303 | aom_highbd_10_obmc_variance32x16, |
| 2304 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2305 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2306 | aom_highbd_10_obmc_variance16x32, |
| 2307 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2308 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2309 | aom_highbd_10_obmc_variance16x16, |
| 2310 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2311 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2312 | aom_highbd_10_obmc_variance8x16, |
| 2313 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2314 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2315 | aom_highbd_10_obmc_variance16x8, |
| 2316 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2317 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2318 | aom_highbd_10_obmc_variance8x8, |
| 2319 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2320 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2321 | aom_highbd_10_obmc_variance4x8, |
| 2322 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2323 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2324 | aom_highbd_10_obmc_variance8x4, |
| 2325 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2326 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2327 | aom_highbd_10_obmc_variance4x4, |
| 2328 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2329 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2330 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2331 | aom_highbd_10_obmc_variance64x16, |
| 2332 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2333 | |
| 2334 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2335 | aom_highbd_10_obmc_variance16x64, |
| 2336 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2337 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2338 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2339 | aom_highbd_10_obmc_variance32x8, |
| 2340 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2341 | |
| 2342 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2343 | aom_highbd_10_obmc_variance8x32, |
| 2344 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2345 | |
| 2346 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2347 | aom_highbd_10_obmc_variance16x4, |
| 2348 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2349 | |
| 2350 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2351 | aom_highbd_10_obmc_variance4x16, |
| 2352 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2353 | break; |
| 2354 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2355 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2356 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2357 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2358 | aom_highbd_12_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2359 | aom_highbd_12_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2360 | aom_highbd_sad64x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2361 | aom_highbd_dist_wtd_sad64x16_avg_bits12, |
| 2362 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2363 | |
| 2364 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2365 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2366 | aom_highbd_12_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2367 | aom_highbd_12_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2368 | aom_highbd_sad16x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2369 | aom_highbd_dist_wtd_sad16x64_avg_bits12, |
| 2370 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2371 | |
| 2372 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2373 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2374 | aom_highbd_12_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2375 | aom_highbd_12_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2376 | aom_highbd_sad32x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2377 | aom_highbd_dist_wtd_sad32x8_avg_bits12, |
| 2378 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2379 | |
| 2380 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2381 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2382 | aom_highbd_12_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2383 | aom_highbd_12_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2384 | aom_highbd_sad8x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2385 | aom_highbd_dist_wtd_sad8x32_avg_bits12, |
| 2386 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2387 | |
| 2388 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2389 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2390 | aom_highbd_12_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2391 | aom_highbd_12_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2392 | aom_highbd_sad16x4x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2393 | aom_highbd_dist_wtd_sad16x4_avg_bits12, |
| 2394 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2395 | |
| 2396 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2397 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2398 | aom_highbd_12_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2399 | aom_highbd_12_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2400 | aom_highbd_sad4x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2401 | aom_highbd_dist_wtd_sad4x16_avg_bits12, |
| 2402 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2403 | |
| 2404 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2405 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2406 | aom_highbd_12_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2407 | aom_highbd_12_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2408 | aom_highbd_sad32x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2409 | aom_highbd_dist_wtd_sad32x16_avg_bits12, |
| 2410 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2411 | |
| 2412 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2413 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2414 | aom_highbd_12_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2415 | aom_highbd_12_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2416 | aom_highbd_sad16x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2417 | aom_highbd_dist_wtd_sad16x32_avg_bits12, |
| 2418 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2419 | |
| 2420 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2421 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2422 | aom_highbd_12_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2423 | aom_highbd_12_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2424 | aom_highbd_sad64x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2425 | aom_highbd_dist_wtd_sad64x32_avg_bits12, |
| 2426 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2427 | |
| 2428 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2429 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2430 | aom_highbd_12_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2431 | aom_highbd_12_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2432 | aom_highbd_sad32x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2433 | aom_highbd_dist_wtd_sad32x64_avg_bits12, |
| 2434 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2435 | |
| 2436 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2437 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2438 | aom_highbd_12_sub_pixel_variance32x32, |
| 2439 | aom_highbd_12_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2440 | aom_highbd_sad32x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2441 | aom_highbd_dist_wtd_sad32x32_avg_bits12, |
| 2442 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2443 | |
| 2444 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2445 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2446 | aom_highbd_12_sub_pixel_variance64x64, |
| 2447 | aom_highbd_12_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2448 | aom_highbd_sad64x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2449 | aom_highbd_dist_wtd_sad64x64_avg_bits12, |
| 2450 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2451 | |
| 2452 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2453 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2454 | aom_highbd_12_sub_pixel_variance16x16, |
| 2455 | aom_highbd_12_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2456 | aom_highbd_sad16x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2457 | aom_highbd_dist_wtd_sad16x16_avg_bits12, |
| 2458 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2459 | |
| 2460 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2461 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2462 | aom_highbd_12_sub_pixel_variance16x8, |
| 2463 | aom_highbd_12_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2464 | aom_highbd_sad16x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2465 | aom_highbd_dist_wtd_sad16x8_avg_bits12, |
| 2466 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2467 | |
| 2468 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2469 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2470 | aom_highbd_12_sub_pixel_variance8x16, |
| 2471 | aom_highbd_12_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2472 | aom_highbd_sad8x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2473 | aom_highbd_dist_wtd_sad8x16_avg_bits12, |
| 2474 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2475 | |
| 2476 | HIGHBD_BFP( |
| 2477 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2478 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2479 | aom_highbd_12_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2480 | aom_highbd_sad8x8x4d_bits12, aom_highbd_dist_wtd_sad8x8_avg_bits12, |
| 2481 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2482 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2483 | HIGHBD_BFP( |
| 2484 | BLOCK_8X4, aom_highbd_sad8x4_bits12, aom_highbd_sad8x4_avg_bits12, |
| 2485 | aom_highbd_12_variance8x4, aom_highbd_12_sub_pixel_variance8x4, |
| 2486 | aom_highbd_12_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2487 | aom_highbd_sad8x4x4d_bits12, aom_highbd_dist_wtd_sad8x4_avg_bits12, |
| 2488 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2489 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2490 | HIGHBD_BFP( |
| 2491 | BLOCK_4X8, aom_highbd_sad4x8_bits12, aom_highbd_sad4x8_avg_bits12, |
| 2492 | aom_highbd_12_variance4x8, aom_highbd_12_sub_pixel_variance4x8, |
| 2493 | aom_highbd_12_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2494 | aom_highbd_sad4x8x4d_bits12, aom_highbd_dist_wtd_sad4x8_avg_bits12, |
| 2495 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2496 | |
| 2497 | HIGHBD_BFP( |
| 2498 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2499 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2500 | aom_highbd_12_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2501 | aom_highbd_sad4x4x4d_bits12, aom_highbd_dist_wtd_sad4x4_avg_bits12, |
| 2502 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2503 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2504 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2505 | aom_highbd_sad128x128_avg_bits12, |
| 2506 | aom_highbd_12_variance128x128, |
| 2507 | aom_highbd_12_sub_pixel_variance128x128, |
| 2508 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2509 | aom_highbd_sad128x128x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2510 | aom_highbd_dist_wtd_sad128x128_avg_bits12, |
| 2511 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2512 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2513 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2514 | aom_highbd_sad128x64_avg_bits12, |
| 2515 | aom_highbd_12_variance128x64, |
| 2516 | aom_highbd_12_sub_pixel_variance128x64, |
| 2517 | aom_highbd_12_sub_pixel_avg_variance128x64, |
| 2518 | aom_highbd_sad128x64x4d_bits12, |
| 2519 | aom_highbd_dist_wtd_sad128x64_avg_bits12, |
| 2520 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2521 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2522 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2523 | aom_highbd_sad64x128_avg_bits12, |
| 2524 | aom_highbd_12_variance64x128, |
| 2525 | aom_highbd_12_sub_pixel_variance64x128, |
| 2526 | aom_highbd_12_sub_pixel_avg_variance64x128, |
| 2527 | aom_highbd_sad64x128x4d_bits12, |
| 2528 | aom_highbd_dist_wtd_sad64x128_avg_bits12, |
| 2529 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2530 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2531 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2532 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2533 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2534 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2535 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2536 | aom_highbd_12_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2537 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2538 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2539 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2540 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2541 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2542 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2543 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2544 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2545 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2546 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2547 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2548 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2549 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2550 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2551 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2552 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2553 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2554 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2555 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2556 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2557 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2558 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2559 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2560 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2561 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2562 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2563 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2564 | aom_highbd_12_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2565 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2566 | aom_highbd_12_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2567 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2568 | aom_highbd_12_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2569 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2570 | aom_highbd_12_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2571 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2572 | aom_highbd_12_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2573 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2574 | aom_highbd_12_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2575 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2576 | aom_highbd_12_obmc_variance128x128, |
| 2577 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2578 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2579 | aom_highbd_12_obmc_variance128x64, |
| 2580 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2581 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2582 | aom_highbd_12_obmc_variance64x128, |
| 2583 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2584 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2585 | aom_highbd_12_obmc_variance64x64, |
| 2586 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2587 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2588 | aom_highbd_12_obmc_variance64x32, |
| 2589 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2590 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2591 | aom_highbd_12_obmc_variance32x64, |
| 2592 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2593 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2594 | aom_highbd_12_obmc_variance32x32, |
| 2595 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2596 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2597 | aom_highbd_12_obmc_variance32x16, |
| 2598 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2599 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2600 | aom_highbd_12_obmc_variance16x32, |
| 2601 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2602 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2603 | aom_highbd_12_obmc_variance16x16, |
| 2604 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2605 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2606 | aom_highbd_12_obmc_variance8x16, |
| 2607 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2608 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2609 | aom_highbd_12_obmc_variance16x8, |
| 2610 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2611 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2612 | aom_highbd_12_obmc_variance8x8, |
| 2613 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2614 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2615 | aom_highbd_12_obmc_variance4x8, |
| 2616 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2617 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2618 | aom_highbd_12_obmc_variance8x4, |
| 2619 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2620 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2621 | aom_highbd_12_obmc_variance4x4, |
| 2622 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2623 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2624 | aom_highbd_12_obmc_variance64x16, |
| 2625 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2626 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2627 | aom_highbd_12_obmc_variance16x64, |
| 2628 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2629 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2630 | aom_highbd_12_obmc_variance32x8, |
| 2631 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2632 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2633 | aom_highbd_12_obmc_variance8x32, |
| 2634 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2635 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2636 | aom_highbd_12_obmc_variance16x4, |
| 2637 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2638 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2639 | aom_highbd_12_obmc_variance4x16, |
| 2640 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2641 | break; |
| 2642 | |
| 2643 | default: |
| 2644 | assert(0 && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2645 | "cm->seq_params.bit_depth should be AOM_BITS_8, " |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2646 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2647 | } |
| 2648 | } |
| 2649 | } |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 2650 | #endif // CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2651 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2652 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2653 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2654 | |
| 2655 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2656 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2657 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2658 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2659 | |
| 2660 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2661 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2662 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2663 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2664 | |
| 2665 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2666 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2667 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2668 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 2671 | static void set_tpl_stats_block_size(AV1_COMP *cpi) { |
| 2672 | AV1_COMMON *const cm = &cpi->common; |
| 2673 | const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720; |
| 2674 | |
| 2675 | // 0: 4x4, 1: 8x8, 2: 16x16 |
| 2676 | cpi->tpl_stats_block_mis_log2 = is_720p_or_larger ? 2 : 1; |
| 2677 | } |
| 2678 | |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 2679 | void av1_alloc_compound_type_rd_buffers(AV1_COMMON *const cm, |
| 2680 | CompoundTypeRdBuffers *const bufs) { |
| 2681 | CHECK_MEM_ERROR( |
| 2682 | cm, bufs->pred0, |
| 2683 | (uint8_t *)aom_memalign(16, 2 * MAX_SB_SQUARE * sizeof(*bufs->pred0))); |
| 2684 | CHECK_MEM_ERROR( |
| 2685 | cm, bufs->pred1, |
| 2686 | (uint8_t *)aom_memalign(16, 2 * MAX_SB_SQUARE * sizeof(*bufs->pred1))); |
| 2687 | CHECK_MEM_ERROR( |
| 2688 | cm, bufs->residual1, |
| 2689 | (int16_t *)aom_memalign(32, MAX_SB_SQUARE * sizeof(*bufs->residual1))); |
| 2690 | CHECK_MEM_ERROR( |
| 2691 | cm, bufs->diff10, |
| 2692 | (int16_t *)aom_memalign(32, MAX_SB_SQUARE * sizeof(*bufs->diff10))); |
| 2693 | CHECK_MEM_ERROR(cm, bufs->tmp_best_mask_buf, |
| 2694 | (uint8_t *)aom_malloc(2 * MAX_SB_SQUARE * |
| 2695 | sizeof(*bufs->tmp_best_mask_buf))); |
| 2696 | } |
| 2697 | |
| 2698 | void av1_release_compound_type_rd_buffers(CompoundTypeRdBuffers *const bufs) { |
| 2699 | aom_free(bufs->pred0); |
| 2700 | aom_free(bufs->pred1); |
| 2701 | aom_free(bufs->residual1); |
| 2702 | aom_free(bufs->diff10); |
| 2703 | aom_free(bufs->tmp_best_mask_buf); |
| 2704 | av1_zero(*bufs); // Set all pointers to NULL for safety. |
| 2705 | } |
| 2706 | |
Wan-Teh Chang | bcacb32 | 2019-09-11 14:50:20 -0700 | [diff] [blame] | 2707 | static void config_target_level(AV1_COMP *const cpi, AV1_LEVEL target_level, |
| 2708 | int tier) { |
| 2709 | aom_clear_system_state(); |
| 2710 | |
| 2711 | AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 2712 | SequenceHeader *const seq_params = &cpi->common.seq_params; |
| 2713 | |
| 2714 | // Adjust target bitrate to be no larger than 70% of level limit. |
| 2715 | const BITSTREAM_PROFILE profile = seq_params->profile; |
| 2716 | const double level_bitrate_limit = |
| 2717 | av1_get_max_bitrate_for_level(target_level, tier, profile); |
| 2718 | const int64_t max_bitrate = (int64_t)(level_bitrate_limit * 0.70); |
| 2719 | oxcf->target_bandwidth = AOMMIN(oxcf->target_bandwidth, max_bitrate); |
| 2720 | // Also need to update cpi->twopass.bits_left. |
| 2721 | TWO_PASS *const twopass = &cpi->twopass; |
Mufaddal Chakera | 74c9cbe | 2020-01-17 16:44:59 +0530 | [diff] [blame] | 2722 | FIRSTPASS_STATS *stats = twopass->total_stats; |
| 2723 | if (stats != NULL) |
| 2724 | cpi->twopass.bits_left = |
| 2725 | (int64_t)(stats->duration * cpi->oxcf.target_bandwidth / 10000000.0); |
Wan-Teh Chang | bcacb32 | 2019-09-11 14:50:20 -0700 | [diff] [blame] | 2726 | |
| 2727 | // Adjust max over-shoot percentage. |
| 2728 | oxcf->over_shoot_pct = 0; |
| 2729 | |
| 2730 | // Adjust max quantizer. |
| 2731 | oxcf->worst_allowed_q = 255; |
| 2732 | |
| 2733 | // Adjust number of tiles and tile columns to be under level limit. |
| 2734 | int max_tiles, max_tile_cols; |
| 2735 | av1_get_max_tiles_for_level(target_level, &max_tiles, &max_tile_cols); |
| 2736 | while (oxcf->tile_columns > 0 && (1 << oxcf->tile_columns) > max_tile_cols) { |
| 2737 | --oxcf->tile_columns; |
| 2738 | } |
| 2739 | const int tile_cols = (1 << oxcf->tile_columns); |
| 2740 | while (oxcf->tile_rows > 0 && |
| 2741 | tile_cols * (1 << oxcf->tile_rows) > max_tiles) { |
| 2742 | --oxcf->tile_rows; |
| 2743 | } |
| 2744 | |
| 2745 | // Adjust min compression ratio. |
| 2746 | const int still_picture = seq_params->still_picture; |
| 2747 | const double min_cr = |
| 2748 | av1_get_min_cr_for_level(target_level, tier, still_picture); |
| 2749 | oxcf->min_cr = AOMMAX(oxcf->min_cr, (unsigned int)(min_cr * 100)); |
| 2750 | } |
| 2751 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2752 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2753 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2754 | SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2755 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2756 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2757 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2758 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2759 | if (seq_params->profile != oxcf->profile) seq_params->profile = oxcf->profile; |
| 2760 | seq_params->bit_depth = oxcf->bit_depth; |
| 2761 | seq_params->color_primaries = oxcf->color_primaries; |
| 2762 | seq_params->transfer_characteristics = oxcf->transfer_characteristics; |
| 2763 | seq_params->matrix_coefficients = oxcf->matrix_coefficients; |
| 2764 | seq_params->monochrome = oxcf->monochrome; |
| 2765 | seq_params->chroma_sample_position = oxcf->chroma_sample_position; |
| 2766 | seq_params->color_range = oxcf->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2767 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2768 | assert(IMPLIES(seq_params->profile <= PROFILE_1, |
| 2769 | seq_params->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2770 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2771 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2772 | cm->timing_info.num_units_in_display_tick = |
| 2773 | oxcf->timing_info.num_units_in_display_tick; |
| 2774 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 2775 | cm->timing_info.equal_picture_interval = |
| 2776 | oxcf->timing_info.equal_picture_interval; |
| 2777 | cm->timing_info.num_ticks_per_picture = |
| 2778 | oxcf->timing_info.num_ticks_per_picture; |
| 2779 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2780 | seq_params->display_model_info_present_flag = |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2781 | oxcf->display_model_info_present_flag; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2782 | seq_params->decoder_model_info_present_flag = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2783 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2784 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2785 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2786 | cm->buffer_model.num_units_in_decoding_tick = |
| 2787 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 2788 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2789 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 2790 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2791 | } else if (cm->timing_info_present && |
| 2792 | cm->timing_info.equal_picture_interval && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2793 | !seq_params->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2794 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2795 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 2796 | } else { |
| 2797 | cm->op_params[0].initial_display_delay = |
| 2798 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2799 | } |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2800 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2801 | update_film_grain_parameters(cpi, oxcf); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2802 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2803 | cpi->oxcf = *oxcf; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2804 | x->e_mbd.bd = (int)seq_params->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2805 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2806 | |
Wan-Teh Chang | bcacb32 | 2019-09-11 14:50:20 -0700 | [diff] [blame] | 2807 | memcpy(cpi->target_seq_level_idx, cpi->oxcf.target_seq_level_idx, |
| 2808 | sizeof(cpi->target_seq_level_idx)); |
| 2809 | cpi->keep_level_stats = 0; |
| 2810 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
| 2811 | if (cpi->target_seq_level_idx[i] <= SEQ_LEVELS) { |
| 2812 | cpi->keep_level_stats |= 1u << i; |
| 2813 | if (!cpi->level_info[i]) { |
| 2814 | CHECK_MEM_ERROR(cm, cpi->level_info[i], |
| 2815 | aom_calloc(1, sizeof(*cpi->level_info[i]))); |
| 2816 | } |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | // TODO(huisu@): level targeting currently only works for the 0th operating |
| 2821 | // point, so scalable coding is not supported yet. |
| 2822 | if (cpi->target_seq_level_idx[0] < SEQ_LEVELS) { |
| 2823 | // Adjust encoder config in order to meet target level. |
| 2824 | config_target_level(cpi, cpi->target_seq_level_idx[0], seq_params->tier[0]); |
| 2825 | } |
| 2826 | |
Mufaddal Chakera | 3bcc72c | 2019-12-11 14:38:37 +0530 | [diff] [blame] | 2827 | if ((has_no_stats_stage(cpi)) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2828 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2829 | } else { |
| 2830 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2831 | } |
| 2832 | |
| 2833 | cpi->refresh_last_frame = 1; |
| 2834 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2835 | cpi->refresh_bwd_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2836 | |
Debargha Mukherjee | 229fdc8 | 2018-03-10 07:45:33 -0800 | [diff] [blame] | 2837 | cm->refresh_frame_context = (oxcf->frame_parallel_decoding_mode) |
| 2838 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 2839 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2840 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 2841 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2842 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2843 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2844 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2845 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2846 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2847 | |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 2848 | if (x->comp_rd_buffer.pred0 == NULL) { |
| 2849 | av1_alloc_compound_type_rd_buffers(cm, &x->comp_rd_buffer); |
| 2850 | } |
| 2851 | |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2852 | if (x->tmp_conv_dst == NULL) { |
| 2853 | CHECK_MEM_ERROR( |
| 2854 | cm, x->tmp_conv_dst, |
| 2855 | aom_memalign(32, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(*x->tmp_conv_dst))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2856 | x->e_mbd.tmp_conv_dst = x->tmp_conv_dst; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2857 | } |
| 2858 | for (int i = 0; i < 2; ++i) { |
| 2859 | if (x->tmp_obmc_bufs[i] == NULL) { |
| 2860 | CHECK_MEM_ERROR(cm, x->tmp_obmc_bufs[i], |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 2861 | aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE * |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2862 | sizeof(*x->tmp_obmc_bufs[i]))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2863 | x->e_mbd.tmp_obmc_bufs[i] = x->tmp_obmc_bufs[i]; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | |
Marco Paniconi | 177b8c3 | 2020-01-26 20:37:29 -0800 | [diff] [blame] | 2867 | av1_reset_segment_features(cm); |
Fyodor Kyslov | 64aaa09 | 2020-01-24 11:44:24 -0800 | [diff] [blame] | 2868 | |
chiyotsai | c666b1f | 2019-12-20 10:44:58 -0800 | [diff] [blame] | 2869 | av1_set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2870 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2871 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2872 | |
| 2873 | // Under a configuration change, where maximum_buffer_size may change, |
| 2874 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2875 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2876 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2877 | |
| 2878 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2879 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2880 | |
| 2881 | // Set absolute upper and lower quality limits |
| 2882 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2883 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2884 | |
Urvang Joshi | b55cb5e | 2018-09-12 14:50:21 -0700 | [diff] [blame] | 2885 | cm->interp_filter = oxcf->large_scale_tile ? EIGHTTAP_REGULAR : SWITCHABLE; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 2886 | cm->switchable_motion_mode = 1; |
| 2887 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2888 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2889 | cm->render_width = cpi->oxcf.render_width; |
| 2890 | cm->render_height = cpi->oxcf.render_height; |
| 2891 | } else { |
| 2892 | cm->render_width = cpi->oxcf.width; |
| 2893 | cm->render_height = cpi->oxcf.height; |
| 2894 | } |
| 2895 | cm->width = cpi->oxcf.width; |
| 2896 | cm->height = cpi->oxcf.height; |
| 2897 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2898 | int sb_size = seq_params->sb_size; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2899 | // Superblock size should not be updated after the first key frame. |
| 2900 | if (!cpi->seq_params_locked) { |
| 2901 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Hui Su | d909c2c | 2019-03-08 11:51:14 -0800 | [diff] [blame] | 2902 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) |
| 2903 | seq_params->tier[i] = (oxcf->tier_mask >> i) & 1; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2904 | } |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2905 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2906 | if (cpi->initial_width || sb_size != seq_params->sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2907 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2908 | seq_params->sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2909 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2910 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2911 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2912 | realloc_segmentation_maps(cpi); |
| 2913 | cpi->initial_width = cpi->initial_height = 0; |
| 2914 | } |
| 2915 | } |
| 2916 | update_frame_size(cpi); |
| 2917 | |
| 2918 | cpi->alt_ref_source = NULL; |
| 2919 | rc->is_src_frame_alt_ref = 0; |
| 2920 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2921 | set_tile_info(cpi); |
| 2922 | |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 2923 | if (!cpi->svc.external_ref_frame_config) |
| 2924 | cpi->ext_refresh_frame_flags_pending = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2925 | cpi->ext_refresh_frame_context_pending = 0; |
| 2926 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 2927 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2928 | highbd_set_var_fns(cpi); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 2929 | #endif |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 2930 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 2931 | // Init sequence level coding tools |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2932 | // This should not be called after the first key frame. |
| 2933 | if (!cpi->seq_params_locked) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2934 | seq_params->operating_points_cnt_minus_1 = |
Marco Paniconi | 6da983b | 2019-09-16 20:12:43 -0700 | [diff] [blame] | 2935 | (cm->number_spatial_layers > 1 || cm->number_temporal_layers > 1) |
| 2936 | ? cm->number_spatial_layers * cm->number_temporal_layers - 1 |
| 2937 | : 0; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 2938 | init_seq_coding_tools(&cm->seq_params, cm, oxcf, cpi->use_svc); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2939 | } |
Marco Paniconi | 5b1e473 | 2019-08-08 18:57:53 -0700 | [diff] [blame] | 2940 | |
| 2941 | if (cpi->use_svc) |
| 2942 | av1_update_layer_context_change_config(cpi, oxcf->target_bandwidth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Aasaipriya | bd659e4 | 2019-12-13 16:12:13 +0530 | [diff] [blame] | 2945 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, BufferPool *const pool, |
Mufaddal Chakera | 5517b28 | 2019-12-13 16:39:56 +0530 | [diff] [blame] | 2946 | FIRSTPASS_STATS *frame_stats_buf, |
Akshata Jadhav | a49be17 | 2019-12-18 00:03:53 +0530 | [diff] [blame] | 2947 | COMPRESSOR_STAGE stage, int num_lap_buffers, |
Mufaddal Chakera | 412efe2 | 2020-01-17 14:35:01 +0530 | [diff] [blame] | 2948 | int lap_lag_in_frames, |
Akshata Jadhav | a49be17 | 2019-12-18 00:03:53 +0530 | [diff] [blame] | 2949 | STATS_BUFFER_CTX *stats_buf_context) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2950 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2951 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2952 | |
| 2953 | if (!cm) return NULL; |
| 2954 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2955 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2956 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 2957 | // The jmp_buf is valid only for the duration of the function that calls |
| 2958 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 2959 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2960 | if (setjmp(cm->error.jmp)) { |
| 2961 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2962 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2963 | return 0; |
| 2964 | } |
| 2965 | |
| 2966 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2967 | cm->alloc_mi = enc_alloc_mi; |
| 2968 | cm->free_mi = enc_free_mi; |
| 2969 | cm->setup_mi = enc_setup_mi; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 2970 | cm->set_mb_mi = enc_set_mb_mi; |
| 2971 | |
| 2972 | cm->mi_alloc_bsize = BLOCK_4X4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2973 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2974 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2975 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2976 | CHECK_MEM_ERROR( |
| 2977 | cm, cm->default_frame_context, |
| 2978 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2979 | memset(cm->fc, 0, sizeof(*cm->fc)); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2980 | memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2981 | |
| 2982 | cpi->resize_state = 0; |
| 2983 | cpi->resize_avg_qp = 0; |
| 2984 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2985 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2986 | cpi->common.buffer_pool = pool; |
| 2987 | |
| 2988 | init_config(cpi, oxcf); |
Mufaddal Chakera | 5517b28 | 2019-12-13 16:39:56 +0530 | [diff] [blame] | 2989 | cpi->lap_enabled = num_lap_buffers > 0; |
| 2990 | cpi->compressor_stage = stage; |
Mufaddal Chakera | 11f284a | 2019-12-19 11:38:46 +0530 | [diff] [blame] | 2991 | if (cpi->compressor_stage == LAP_STAGE) { |
Mufaddal Chakera | 412efe2 | 2020-01-17 14:35:01 +0530 | [diff] [blame] | 2992 | cpi->oxcf.lag_in_frames = lap_lag_in_frames; |
Mufaddal Chakera | 11f284a | 2019-12-19 11:38:46 +0530 | [diff] [blame] | 2993 | } |
Mufaddal Chakera | ac82868 | 2019-12-13 16:31:42 +0530 | [diff] [blame] | 2994 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2995 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2996 | |
Jingning Han | 17af774 | 2019-09-17 16:58:03 -0700 | [diff] [blame] | 2997 | init_frame_info(&cpi->frame_info, cm); |
| 2998 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 2999 | cm->current_frame.frame_number = 0; |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 3000 | cm->current_frame_id = -1; |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 3001 | cpi->seq_params_locked = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3002 | cpi->partition_search_skippable_frame = 0; |
| 3003 | cpi->tile_data = NULL; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3004 | cpi->last_show_frame_buf = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3005 | realloc_segmentation_maps(cpi); |
| 3006 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3007 | cpi->refresh_alt_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3008 | |
| 3009 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 3010 | #if CONFIG_INTERNAL_STATS |
| 3011 | cpi->b_calculate_blockiness = 1; |
| 3012 | cpi->b_calculate_consistency = 1; |
| 3013 | cpi->total_inconsistency = 0; |
| 3014 | cpi->psnr.worst = 100.0; |
| 3015 | cpi->worst_ssim = 100.0; |
| 3016 | |
| 3017 | cpi->count = 0; |
| 3018 | cpi->bytes = 0; |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 3019 | #if CONFIG_SPEED_STATS |
| 3020 | cpi->tx_search_count = 0; |
| 3021 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3022 | |
| 3023 | if (cpi->b_calculate_psnr) { |
| 3024 | cpi->total_sq_error = 0; |
| 3025 | cpi->total_samples = 0; |
| 3026 | cpi->tot_recode_hits = 0; |
| 3027 | cpi->summed_quality = 0; |
| 3028 | cpi->summed_weights = 0; |
| 3029 | } |
| 3030 | |
| 3031 | cpi->fastssim.worst = 100.0; |
| 3032 | cpi->psnrhvs.worst = 100.0; |
| 3033 | |
| 3034 | if (cpi->b_calculate_blockiness) { |
| 3035 | cpi->total_blockiness = 0; |
| 3036 | cpi->worst_blockiness = 0.0; |
| 3037 | } |
| 3038 | |
| 3039 | if (cpi->b_calculate_consistency) { |
| 3040 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3041 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3042 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 3043 | cpi->worst_consistency = 100.0; |
| 3044 | } |
| 3045 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3046 | #if CONFIG_ENTROPY_STATS |
| 3047 | av1_zero(aggregate_fc); |
| 3048 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3049 | |
| 3050 | cpi->first_time_stamp_ever = INT64_MAX; |
| 3051 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3052 | #ifdef OUTPUT_YUV_SKINMAP |
| 3053 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 3054 | #endif |
| 3055 | #ifdef OUTPUT_YUV_REC |
| 3056 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 3057 | #endif |
| 3058 | |
Mufaddal Chakera | 5517b28 | 2019-12-13 16:39:56 +0530 | [diff] [blame] | 3059 | assert(MAX_LAP_BUFFERS >= MAX_LAG_BUFFERS); |
Akshata Jadhav | 4be6511 | 2019-12-18 00:26:25 +0530 | [diff] [blame] | 3060 | int size = get_stats_buf_size(num_lap_buffers, MAX_LAG_BUFFERS); |
| 3061 | for (int i = 0; i < size; i++) |
Aasaipriya | bd659e4 | 2019-12-13 16:12:13 +0530 | [diff] [blame] | 3062 | cpi->twopass.frame_stats_arr[i] = &frame_stats_buf[i]; |
| 3063 | |
Akshata Jadhav | a49be17 | 2019-12-18 00:03:53 +0530 | [diff] [blame] | 3064 | cpi->twopass.stats_buf_ctx = stats_buf_context; |
| 3065 | cpi->twopass.stats_in = cpi->twopass.stats_buf_ctx->stats_in_start; |
| 3066 | |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 3067 | #if !CONFIG_REALTIME_ONLY |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 3068 | if (is_stat_generation_stage(cpi)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3069 | av1_init_first_pass(cpi); |
Hamsalekha S | 37cc1d1 | 2019-12-12 19:27:41 +0530 | [diff] [blame] | 3070 | } else if (is_stat_consumption_stage(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3071 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 3072 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 3073 | |
Akshata Jadhav | 1fddf7f | 2019-12-18 00:49:25 +0530 | [diff] [blame] | 3074 | if (!cpi->lap_enabled) { |
| 3075 | /*Re-initialize to stats buffer, populated by application in the case of |
| 3076 | * two pass*/ |
| 3077 | cpi->twopass.stats_buf_ctx->stats_in_start = oxcf->two_pass_stats_in.buf; |
| 3078 | cpi->twopass.stats_in = cpi->twopass.stats_buf_ctx->stats_in_start; |
| 3079 | cpi->twopass.stats_buf_ctx->stats_in_end = |
| 3080 | &cpi->twopass.stats_buf_ctx->stats_in_start[packets - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3081 | |
Mufaddal Chakera | 74c9cbe | 2020-01-17 16:44:59 +0530 | [diff] [blame] | 3082 | av1_init_second_pass(cpi); |
| 3083 | } else { |
| 3084 | av1_init_single_pass_lap(cpi); |
| 3085 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3086 | } |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 3087 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3088 | |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 3089 | int sb_mi_size = av1_get_sb_mi_size(cm); |
| 3090 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3091 | CHECK_MEM_ERROR( |
| 3092 | cm, cpi->td.mb.above_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 3093 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 3094 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3095 | CHECK_MEM_ERROR( |
| 3096 | cm, cpi->td.mb.left_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 3097 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 3098 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3099 | |
| 3100 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 3101 | (int32_t *)aom_memalign( |
| 3102 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 3103 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3104 | CHECK_MEM_ERROR( |
| 3105 | cm, cpi->td.mb.inter_modes_info, |
| 3106 | (InterModesInfo *)aom_malloc(sizeof(*cpi->td.mb.inter_modes_info))); |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3107 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3108 | for (int x = 0; x < 2; x++) |
| 3109 | for (int y = 0; y < 2; y++) |
| 3110 | CHECK_MEM_ERROR( |
| 3111 | cm, cpi->td.mb.hash_value_buffer[x][y], |
| 3112 | (uint32_t *)aom_malloc(AOM_BUFFER_SIZE_FOR_BLOCK_HASH * |
| 3113 | sizeof(*cpi->td.mb.hash_value_buffer[0][0]))); |
| 3114 | |
| 3115 | cpi->td.mb.g_crc_initialized = 0; |
| 3116 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3117 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 3118 | (int32_t *)aom_memalign( |
| 3119 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 3120 | |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 3121 | CHECK_MEM_ERROR(cm, cpi->td.mb.mbmi_ext, |
| 3122 | aom_calloc(sb_mi_size, sizeof(*cpi->td.mb.mbmi_ext))); |
| 3123 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 3124 | av1_set_speed_features_framesize_independent(cpi, oxcf->speed); |
| 3125 | av1_set_speed_features_framesize_dependent(cpi, oxcf->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3126 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 3127 | { |
| 3128 | const int bsize = BLOCK_16X16; |
| 3129 | const int w = mi_size_wide[bsize]; |
| 3130 | const int h = mi_size_high[bsize]; |
| 3131 | const int num_cols = (cm->mi_cols + w - 1) / w; |
| 3132 | const int num_rows = (cm->mi_rows + h - 1) / h; |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 3133 | CHECK_MEM_ERROR(cm, cpi->tpl_rdmult_scaling_factors, |
| 3134 | aom_calloc(num_rows * num_cols, |
| 3135 | sizeof(*cpi->tpl_rdmult_scaling_factors))); |
| 3136 | CHECK_MEM_ERROR(cm, cpi->tpl_sb_rdmult_scaling_factors, |
| 3137 | aom_calloc(num_rows * num_cols, |
| 3138 | sizeof(*cpi->tpl_sb_rdmult_scaling_factors))); |
| 3139 | } |
| 3140 | |
| 3141 | { |
| 3142 | const int bsize = BLOCK_16X16; |
| 3143 | const int w = mi_size_wide[bsize]; |
| 3144 | const int h = mi_size_high[bsize]; |
| 3145 | const int num_cols = (cm->mi_cols + w - 1) / w; |
| 3146 | const int num_rows = (cm->mi_rows + h - 1) / h; |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 3147 | CHECK_MEM_ERROR(cm, cpi->ssim_rdmult_scaling_factors, |
| 3148 | aom_calloc(num_rows * num_cols, |
| 3149 | sizeof(*cpi->ssim_rdmult_scaling_factors))); |
| 3150 | } |
| 3151 | |
sdeng | 0195916 | 2019-12-20 10:46:24 -0800 | [diff] [blame] | 3152 | #if CONFIG_TUNE_VMAF |
| 3153 | { |
| 3154 | const int bsize = BLOCK_64X64; |
| 3155 | const int w = mi_size_wide[bsize]; |
| 3156 | const int h = mi_size_high[bsize]; |
| 3157 | const int num_cols = (cm->mi_cols + w - 1) / w; |
| 3158 | const int num_rows = (cm->mi_rows + h - 1) / h; |
| 3159 | CHECK_MEM_ERROR(cm, cpi->vmaf_rdmult_scaling_factors, |
| 3160 | aom_calloc(num_rows * num_cols, |
| 3161 | sizeof(*cpi->vmaf_rdmult_scaling_factors))); |
| 3162 | } |
| 3163 | #endif |
| 3164 | |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 3165 | set_tpl_stats_block_size(cpi); |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 3166 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 3167 | const int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 3168 | const int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 3169 | |
| 3170 | cpi->tpl_stats_buffer[frame].is_valid = 0; |
| 3171 | cpi->tpl_stats_buffer[frame].width = |
| 3172 | mi_cols >> cpi->tpl_stats_block_mis_log2; |
| 3173 | cpi->tpl_stats_buffer[frame].height = |
| 3174 | mi_rows >> cpi->tpl_stats_block_mis_log2; |
| 3175 | cpi->tpl_stats_buffer[frame].stride = cpi->tpl_stats_buffer[frame].width; |
| 3176 | cpi->tpl_stats_buffer[frame].mi_rows = cm->mi_rows; |
| 3177 | cpi->tpl_stats_buffer[frame].mi_cols = cm->mi_cols; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3178 | |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 3179 | CHECK_MEM_ERROR( |
| 3180 | cm, cpi->tpl_stats_buffer[frame].tpl_stats_ptr, |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 3181 | aom_calloc(cpi->tpl_stats_buffer[frame].width * |
| 3182 | cpi->tpl_stats_buffer[frame].height, |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 3183 | sizeof(*cpi->tpl_stats_buffer[frame].tpl_stats_ptr))); |
Jingning Han | 5e98d3b | 2019-09-23 21:59:36 -0700 | [diff] [blame] | 3184 | |
| 3185 | if (aom_alloc_frame_buffer( |
| 3186 | &cpi->tpl_stats_buffer[frame].rec_picture_buf, cm->width, |
| 3187 | cm->height, cm->seq_params.subsampling_x, |
| 3188 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
Jingning Han | 55ba170 | 2020-01-14 11:43:04 -0800 | [diff] [blame] | 3189 | AOM_ENC_NO_SCALE_BORDER, cm->byte_alignment)) |
Jingning Han | 5e98d3b | 2019-09-23 21:59:36 -0700 | [diff] [blame] | 3190 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3191 | "Failed to allocate frame buffer"); |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3192 | } |
Jingning Han | 31a0ee9 | 2019-07-15 13:56:55 -0700 | [diff] [blame] | 3193 | cpi->tpl_frame = &cpi->tpl_stats_buffer[REF_FRAMES + 1]; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3194 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 3195 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3196 | av1_zero(cpi->partition_stats); |
| 3197 | #endif |
| 3198 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3199 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 3200 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 3201 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 3202 | cpi->fn_ptr[BT].vf = VF; \ |
| 3203 | cpi->fn_ptr[BT].svf = SVF; \ |
| 3204 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 3205 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 3206 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3207 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3208 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3209 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3210 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3211 | aom_sad4x16x4d, aom_dist_wtd_sad4x16_avg, |
| 3212 | aom_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3213 | |
| 3214 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3215 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3216 | aom_sad16x4x4d, aom_dist_wtd_sad16x4_avg, |
| 3217 | aom_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3218 | |
| 3219 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3220 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3221 | aom_sad8x32x4d, aom_dist_wtd_sad8x32_avg, |
| 3222 | aom_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3223 | |
| 3224 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3225 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3226 | aom_sad32x8x4d, aom_dist_wtd_sad32x8_avg, |
| 3227 | aom_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3228 | |
| 3229 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3230 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3231 | aom_sad16x64x4d, aom_dist_wtd_sad16x64_avg, |
| 3232 | aom_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3233 | |
| 3234 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3235 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3236 | aom_sad64x16x4d, aom_dist_wtd_sad64x16_avg, |
| 3237 | aom_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3238 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3239 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 3240 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3241 | aom_sad128x128x4d, aom_dist_wtd_sad128x128_avg, |
| 3242 | aom_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3243 | |
| 3244 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3245 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3246 | aom_sad128x64x4d, aom_dist_wtd_sad128x64_avg, |
| 3247 | aom_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3248 | |
| 3249 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3250 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3251 | aom_sad64x128x4d, aom_dist_wtd_sad64x128_avg, |
| 3252 | aom_dist_wtd_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3253 | |
| 3254 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3255 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3256 | aom_sad32x16x4d, aom_dist_wtd_sad32x16_avg, |
| 3257 | aom_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3258 | |
| 3259 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3260 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3261 | aom_sad16x32x4d, aom_dist_wtd_sad16x32_avg, |
| 3262 | aom_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3263 | |
| 3264 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3265 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3266 | aom_sad64x32x4d, aom_dist_wtd_sad64x32_avg, |
| 3267 | aom_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3268 | |
| 3269 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3270 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3271 | aom_sad32x64x4d, aom_dist_wtd_sad32x64_avg, |
| 3272 | aom_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3273 | |
| 3274 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 3275 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3276 | aom_sad32x32x4d, aom_dist_wtd_sad32x32_avg, |
| 3277 | aom_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3278 | |
| 3279 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 3280 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3281 | aom_sad64x64x4d, aom_dist_wtd_sad64x64_avg, |
| 3282 | aom_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3283 | |
| 3284 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 3285 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3286 | aom_sad16x16x4d, aom_dist_wtd_sad16x16_avg, |
| 3287 | aom_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3288 | |
| 3289 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3290 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3291 | aom_sad16x8x4d, aom_dist_wtd_sad16x8_avg, |
| 3292 | aom_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3293 | |
| 3294 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3295 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3296 | aom_sad8x16x4d, aom_dist_wtd_sad8x16_avg, |
| 3297 | aom_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3298 | |
| 3299 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3300 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3301 | aom_dist_wtd_sad8x8_avg, aom_dist_wtd_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3302 | |
| 3303 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3304 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, aom_sad8x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3305 | aom_dist_wtd_sad8x4_avg, aom_dist_wtd_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3306 | |
| 3307 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3308 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, aom_sad4x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3309 | aom_dist_wtd_sad4x8_avg, aom_dist_wtd_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3310 | |
| 3311 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3312 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3313 | aom_dist_wtd_sad4x4_avg, aom_dist_wtd_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3314 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3315 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 3316 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 3317 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 3318 | cpi->fn_ptr[BT].osvf = OSVF; |
| 3319 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3320 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 3321 | aom_obmc_sub_pixel_variance128x128) |
| 3322 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 3323 | aom_obmc_sub_pixel_variance128x64) |
| 3324 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 3325 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3326 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 3327 | aom_obmc_sub_pixel_variance64x64) |
| 3328 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 3329 | aom_obmc_sub_pixel_variance64x32) |
| 3330 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 3331 | aom_obmc_sub_pixel_variance32x64) |
| 3332 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 3333 | aom_obmc_sub_pixel_variance32x32) |
| 3334 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 3335 | aom_obmc_sub_pixel_variance32x16) |
| 3336 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 3337 | aom_obmc_sub_pixel_variance16x32) |
| 3338 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 3339 | aom_obmc_sub_pixel_variance16x16) |
| 3340 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 3341 | aom_obmc_sub_pixel_variance16x8) |
| 3342 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 3343 | aom_obmc_sub_pixel_variance8x16) |
| 3344 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 3345 | aom_obmc_sub_pixel_variance8x8) |
| 3346 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 3347 | aom_obmc_sub_pixel_variance4x8) |
| 3348 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 3349 | aom_obmc_sub_pixel_variance8x4) |
| 3350 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 3351 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3352 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 3353 | aom_obmc_sub_pixel_variance4x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3354 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 3355 | aom_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3356 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 3357 | aom_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3358 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 3359 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3360 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 3361 | aom_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3362 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 3363 | aom_obmc_sub_pixel_variance64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3364 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3365 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 3366 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 3367 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3368 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3369 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 3370 | aom_masked_sub_pixel_variance128x128) |
| 3371 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 3372 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3373 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 3374 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 3375 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 3376 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 3377 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 3378 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 3379 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 3380 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 3381 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 3382 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 3383 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 3384 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 3385 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3386 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3387 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 3388 | |
| 3389 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 3390 | |
| 3391 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 3392 | |
| 3393 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3394 | |
| 3395 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 3396 | |
| 3397 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3398 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 3399 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3400 | highbd_set_var_fns(cpi); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 3401 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3402 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3403 | /* av1_init_quantizer() is first called here. Add check in |
| 3404 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3405 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3406 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3407 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3408 | av1_init_quantizer(cpi); |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 3409 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3410 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3411 | av1_loop_filter_init(cm); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3412 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3413 | cm->superres_upscaled_width = oxcf->width; |
| 3414 | cm->superres_upscaled_height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3415 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3416 | |
| 3417 | cm->error.setjmp = 0; |
| 3418 | |
| 3419 | return cpi; |
| 3420 | } |
| 3421 | |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3422 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3423 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 3424 | |
| 3425 | #define SNPRINT2(H, T, V) \ |
| 3426 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3427 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3428 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3429 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 3430 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3431 | unsigned int i; |
| 3432 | int t; |
| 3433 | |
| 3434 | if (!cpi) return; |
| 3435 | |
| 3436 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3437 | const int num_planes = av1_num_planes(cm); |
| 3438 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 3439 | if (cm->current_frame.frame_number > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3440 | #if CONFIG_ENTROPY_STATS |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 3441 | if (!is_stat_generation_stage(cpi)) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3442 | fprintf(stderr, "Writing counts.stt\n"); |
| 3443 | FILE *f = fopen("counts.stt", "wb"); |
| 3444 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 3445 | fclose(f); |
| 3446 | } |
| 3447 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3448 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3449 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3450 | |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 3451 | if (!is_stat_generation_stage(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3452 | char headings[512] = { 0 }; |
| 3453 | char results[512] = { 0 }; |
| 3454 | FILE *f = fopen("opsnr.stt", "a"); |
| 3455 | double time_encoded = |
| 3456 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3457 | 10000000.000; |
| 3458 | double total_encode_time = |
| 3459 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3460 | const double dr = |
| 3461 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3462 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3463 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3464 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3465 | |
| 3466 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3467 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3468 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3469 | const double total_ssim = |
| 3470 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3471 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3472 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3473 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3474 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3475 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3476 | snprintf(results, sizeof(results), |
| 3477 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3478 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3479 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3480 | "%7.3f\t%7.3f\t%7.3f", |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3481 | dr, cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, |
| 3482 | cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, total_ssim, |
| 3483 | total_ssim, cpi->fastssim.stat[STAT_ALL] / cpi->count, |
| 3484 | cpi->psnrhvs.stat[STAT_ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3485 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3486 | cpi->psnr.stat[STAT_Y] / cpi->count, |
| 3487 | cpi->psnr.stat[STAT_U] / cpi->count, |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3488 | cpi->psnr.stat[STAT_V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3489 | |
| 3490 | if (cpi->b_calculate_blockiness) { |
| 3491 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3492 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3493 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3494 | } |
| 3495 | |
| 3496 | if (cpi->b_calculate_consistency) { |
| 3497 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3498 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3499 | (double)cpi->total_inconsistency); |
| 3500 | |
| 3501 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3502 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3503 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3504 | } |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3505 | |
| 3506 | SNPRINT(headings, "\t Time\tRcErr\tAbsErr"); |
| 3507 | SNPRINT2(results, "\t%8.0f", total_encode_time); |
| 3508 | SNPRINT2(results, "\t%7.2f", rate_err); |
| 3509 | SNPRINT2(results, "\t%7.2f", fabs(rate_err)); |
| 3510 | |
| 3511 | fprintf(f, "%s\tAPsnr611\n", headings); |
| 3512 | fprintf(f, "%s\t%7.3f\n", results, |
| 3513 | (6 * cpi->psnr.stat[STAT_Y] + cpi->psnr.stat[STAT_U] + |
| 3514 | cpi->psnr.stat[STAT_V]) / |
| 3515 | (cpi->count * 8)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | fclose(f); |
| 3519 | } |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3520 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 3521 | #if CONFIG_SPEED_STATS |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 3522 | if (!is_stat_generation_stage(cpi)) { |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 3523 | fprintf(stdout, "tx_search_count = %d\n", cpi->tx_search_count); |
| 3524 | } |
| 3525 | #endif // CONFIG_SPEED_STATS |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3526 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 3527 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 3528 | if (!is_stat_generation_stage(cpi)) { |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3529 | av1_print_partition_stats(&cpi->partition_stats); |
| 3530 | } |
| 3531 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 3534 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 3535 | aom_free(cpi->tpl_stats_buffer[frame].tpl_stats_ptr); |
| 3536 | cpi->tpl_stats_buffer[frame].is_valid = 0; |
Jingning Han | 5e98d3b | 2019-09-23 21:59:36 -0700 | [diff] [blame] | 3537 | |
| 3538 | aom_free_frame_buffer(&cpi->tpl_stats_buffer[frame].rec_picture_buf); |
| 3539 | cpi->tpl_stats_buffer[frame].rec_picture = NULL; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3542 | for (t = cpi->num_workers - 1; t >= 0; --t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3543 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3544 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3545 | |
| 3546 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3547 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3548 | |
| 3549 | // Deallocate allocated thread data. |
Ravi Chaudhary | 4cd458b | 2019-06-04 17:42:35 +0530 | [diff] [blame] | 3550 | aom_free(thread_data->td->tctx); |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3551 | if (t > 0) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3552 | aom_free(thread_data->td->palette_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3553 | aom_free(thread_data->td->tmp_conv_dst); |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 3554 | av1_release_compound_type_rd_buffers(&thread_data->td->comp_rd_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3555 | for (int j = 0; j < 2; ++j) { |
| 3556 | aom_free(thread_data->td->tmp_obmc_bufs[j]); |
| 3557 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3558 | aom_free(thread_data->td->above_pred_buf); |
| 3559 | aom_free(thread_data->td->left_pred_buf); |
| 3560 | aom_free(thread_data->td->wsrc_buf); |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 3561 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3562 | aom_free(thread_data->td->inter_modes_info); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3563 | for (int x = 0; x < 2; x++) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3564 | for (int y = 0; y < 2; y++) { |
| 3565 | aom_free(thread_data->td->hash_value_buffer[x][y]); |
| 3566 | thread_data->td->hash_value_buffer[x][y] = NULL; |
| 3567 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3568 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3569 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3570 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3571 | av1_free_pc_tree(thread_data->td, num_planes); |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 3572 | aom_free(thread_data->td->mbmi_ext); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3573 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3574 | } |
| 3575 | } |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 3576 | #if CONFIG_MULTITHREAD |
Ravi Chaudhary | 4cd458b | 2019-06-04 17:42:35 +0530 | [diff] [blame] | 3577 | if (cpi->row_mt_mutex_ != NULL) { |
| 3578 | pthread_mutex_destroy(cpi->row_mt_mutex_); |
| 3579 | aom_free(cpi->row_mt_mutex_); |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 3580 | } |
| 3581 | #endif |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 3582 | av1_row_mt_mem_dealloc(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3583 | aom_free(cpi->tile_thr_data); |
| 3584 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3585 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3586 | if (cpi->num_workers > 1) { |
| 3587 | av1_loop_filter_dealloc(&cpi->lf_row_sync); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 3588 | av1_loop_restoration_dealloc(&cpi->lr_row_sync, cpi->num_workers); |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3589 | } |
| 3590 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3591 | dealloc_compressor_data(cpi); |
| 3592 | |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3593 | #if CONFIG_INTERNAL_STATS |
| 3594 | aom_free(cpi->ssim_vars); |
| 3595 | cpi->ssim_vars = NULL; |
| 3596 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3597 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3598 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3599 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3600 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 3601 | } |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3602 | #if CONFIG_HTB_TRELLIS |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 3603 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3604 | #endif // CONFIG_HTB_TRELLIS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3605 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Mufaddal Chakera | 74c9cbe | 2020-01-17 16:44:59 +0530 | [diff] [blame] | 3606 | |
| 3607 | aom_free(cpi->twopass.total_stats); |
| 3608 | aom_free(cpi->twopass.total_left_stats); |
| 3609 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3610 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3611 | |
| 3612 | #ifdef OUTPUT_YUV_SKINMAP |
| 3613 | fclose(yuv_skinmap_file); |
| 3614 | #endif |
| 3615 | #ifdef OUTPUT_YUV_REC |
| 3616 | fclose(yuv_rec_file); |
| 3617 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3620 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3621 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3622 | int i; |
| 3623 | PSNR_STATS psnr; |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 3624 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | e75b58a | 2020-01-03 12:56:12 -0800 | [diff] [blame] | 3625 | const uint32_t in_bit_depth = cpi->oxcf.input_bit_depth; |
| 3626 | const uint32_t bit_depth = cpi->td.mb.e_mbd.bd; |
| 3627 | aom_calc_highbd_psnr(cpi->source, &cpi->common.cur_frame->buf, &psnr, |
| 3628 | bit_depth, in_bit_depth); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 3629 | #else |
| 3630 | aom_calc_psnr(cpi->source, &cpi->common.cur_frame->buf, &psnr); |
| 3631 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3632 | |
| 3633 | for (i = 0; i < 4; ++i) { |
| 3634 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3635 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3636 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3637 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3638 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3639 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3642 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3643 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3644 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 3645 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3646 | return 0; |
| 3647 | } |
| 3648 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3649 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3650 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3651 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3652 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3653 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3654 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3655 | return 0; |
| 3656 | } else { |
| 3657 | return -1; |
| 3658 | } |
| 3659 | } |
| 3660 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3661 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3662 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3663 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3664 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3665 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3666 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3667 | return 0; |
| 3668 | } else { |
| 3669 | return -1; |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3674 | cpi->ext_refresh_frame_context = update; |
| 3675 | cpi->ext_refresh_frame_context_pending = 1; |
| 3676 | return 0; |
| 3677 | } |
| 3678 | |
| 3679 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3680 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3681 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3682 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3683 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3684 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3685 | uint8_t *src = s->y_buffer; |
| 3686 | int h = s->y_height; |
| 3687 | |
| 3688 | do { |
| 3689 | fwrite(src, s->y_width, 1, f); |
| 3690 | src += s->y_stride; |
| 3691 | } while (--h); |
| 3692 | |
| 3693 | src = s->u_buffer; |
| 3694 | h = s->uv_height; |
| 3695 | |
| 3696 | do { |
| 3697 | fwrite(src, s->uv_width, 1, f); |
| 3698 | src += s->uv_stride; |
| 3699 | } while (--h); |
| 3700 | |
| 3701 | src = s->v_buffer; |
| 3702 | h = s->uv_height; |
| 3703 | |
| 3704 | do { |
| 3705 | fwrite(src, s->uv_width, 1, f); |
| 3706 | src += s->uv_stride; |
| 3707 | } while (--h); |
| 3708 | } |
| 3709 | #endif |
| 3710 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3711 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3712 | void aom_write_one_yuv_frame(AV1_COMMON *cm, YV12_BUFFER_CONFIG *s) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3713 | uint8_t *src = s->y_buffer; |
| 3714 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3715 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3716 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3717 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3718 | |
| 3719 | do { |
| 3720 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3721 | src16 += s->y_stride; |
| 3722 | } while (--h); |
| 3723 | |
| 3724 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3725 | h = s->uv_height; |
| 3726 | |
| 3727 | do { |
| 3728 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3729 | src16 += s->uv_stride; |
| 3730 | } while (--h); |
| 3731 | |
| 3732 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3733 | h = s->uv_height; |
| 3734 | |
| 3735 | do { |
| 3736 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3737 | src16 += s->uv_stride; |
| 3738 | } while (--h); |
| 3739 | |
| 3740 | fflush(yuv_rec_file); |
| 3741 | return; |
| 3742 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3743 | |
| 3744 | do { |
| 3745 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3746 | src += s->y_stride; |
| 3747 | } while (--h); |
| 3748 | |
| 3749 | src = s->u_buffer; |
| 3750 | h = s->uv_height; |
| 3751 | |
| 3752 | do { |
| 3753 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3754 | src += s->uv_stride; |
| 3755 | } while (--h); |
| 3756 | |
| 3757 | src = s->v_buffer; |
| 3758 | h = s->uv_height; |
| 3759 | |
| 3760 | do { |
| 3761 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3762 | src += s->uv_stride; |
| 3763 | } while (--h); |
| 3764 | |
| 3765 | fflush(yuv_rec_file); |
| 3766 | } |
| 3767 | #endif // OUTPUT_YUV_REC |
| 3768 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3769 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3770 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3771 | int i; |
| 3772 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3773 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3774 | AV1_COMMON *const cm = &cpi->common; |
| 3775 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3776 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3777 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3778 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3779 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3780 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3781 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3782 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 3783 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 3784 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 3785 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3786 | } |
| 3787 | } |
| 3788 | return recode; |
| 3789 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3790 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3791 | // Function to test for conditions that indicate we should loop |
| 3792 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3793 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3794 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3795 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3796 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3797 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3798 | int force_recode = 0; |
| 3799 | |
| 3800 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
chiyotsai | 6b43013 | 2019-12-18 10:33:51 -0800 | [diff] [blame] | 3801 | (cpi->sf.hl_sf.recode_loop == ALLOW_RECODE) || |
| 3802 | (frame_is_kfgfarf && |
| 3803 | (cpi->sf.hl_sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3804 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3805 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3806 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3807 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3808 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3809 | // Deal with frame undershoot and whether or not we are |
| 3810 | // below the automatically set cq level. |
| 3811 | if (q > oxcf->cq_level && |
| 3812 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3813 | force_recode = 1; |
| 3814 | } |
| 3815 | } |
| 3816 | } |
| 3817 | return force_recode; |
| 3818 | } |
| 3819 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3820 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3821 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3822 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3823 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3824 | |
| 3825 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3826 | // Need to convert from AOM_REFFRAME to index into ref_mask (subtract 1). |
Jingning Han | 667561a | 2019-07-22 15:48:01 -0700 | [diff] [blame] | 3827 | if (cpi->ref_frame_flags & av1_ref_frame_flag_list[ref_frame]) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3828 | BufferPool *const pool = cm->buffer_pool; |
| 3829 | const YV12_BUFFER_CONFIG *const ref = |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3830 | get_ref_frame_yv12_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3831 | |
| 3832 | if (ref == NULL) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3833 | cpi->scaled_ref_buf[ref_frame - 1] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3834 | continue; |
| 3835 | } |
| 3836 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3837 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
Debargha Mukherjee | 13cccf2 | 2019-03-27 23:49:14 -0700 | [diff] [blame] | 3838 | // Replace the reference buffer with a copy having a thicker border, |
| 3839 | // if the reference buffer is higher resolution than the current |
| 3840 | // frame, and the border is thin. |
| 3841 | if ((ref->y_crop_width > cm->width || |
| 3842 | ref->y_crop_height > cm->height) && |
| 3843 | ref->border < AOM_BORDER_IN_PIXELS) { |
| 3844 | RefCntBuffer *ref_fb = get_ref_frame_buf(cm, ref_frame); |
| 3845 | if (aom_yv12_realloc_with_new_border( |
| 3846 | &ref_fb->buf, AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3847 | num_planes) != 0) { |
| 3848 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3849 | "Failed to allocate frame buffer"); |
| 3850 | } |
| 3851 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3852 | int force_scaling = 0; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3853 | RefCntBuffer *new_fb = cpi->scaled_ref_buf[ref_frame - 1]; |
| 3854 | if (new_fb == NULL) { |
| 3855 | const int new_fb_idx = get_free_fb(cm); |
| 3856 | if (new_fb_idx == INVALID_IDX) { |
Wan-Teh Chang | 4a8c004 | 2018-10-05 09:41:52 -0700 | [diff] [blame] | 3857 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3858 | "Unable to find free frame buffer"); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3859 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3860 | force_scaling = 1; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3861 | new_fb = &pool->frame_bufs[new_fb_idx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3862 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3863 | |
| 3864 | if (force_scaling || new_fb->buf.y_crop_width != cm->width || |
| 3865 | new_fb->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3866 | if (aom_realloc_frame_buffer( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3867 | &new_fb->buf, cm->width, cm->height, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3868 | cm->seq_params.subsampling_x, cm->seq_params.subsampling_y, |
Debargha Mukherjee | fa946af | 2019-03-26 16:58:55 -0700 | [diff] [blame] | 3869 | cm->seq_params.use_highbitdepth, AOM_BORDER_IN_PIXELS, |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3870 | cm->byte_alignment, NULL, NULL, NULL)) { |
| 3871 | if (force_scaling) { |
| 3872 | // Release the reference acquired in the get_free_fb() call above. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3873 | --new_fb->ref_count; |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3874 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3875 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3876 | "Failed to allocate frame buffer"); |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3877 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3878 | av1_resize_and_extend_frame( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3879 | ref, &new_fb->buf, (int)cm->seq_params.bit_depth, num_planes); |
| 3880 | cpi->scaled_ref_buf[ref_frame - 1] = new_fb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3881 | alloc_frame_mvs(cm, new_fb); |
| 3882 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3883 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3884 | RefCntBuffer *buf = get_ref_frame_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3885 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3886 | buf->buf.y_crop_height = ref->y_crop_height; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3887 | cpi->scaled_ref_buf[ref_frame - 1] = buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3888 | ++buf->ref_count; |
| 3889 | } |
| 3890 | } else { |
Mufaddal Chakera | 3bcc72c | 2019-12-11 14:38:37 +0530 | [diff] [blame] | 3891 | if (!has_no_stats_stage(cpi)) cpi->scaled_ref_buf[ref_frame - 1] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | } |
| 3895 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3896 | static void release_scaled_references(AV1_COMP *cpi) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3897 | // TODO(isbs): only refresh the necessary frames, rather than all of them |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3898 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 3899 | RefCntBuffer *const buf = cpi->scaled_ref_buf[i]; |
| 3900 | if (buf != NULL) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3901 | --buf->ref_count; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3902 | cpi->scaled_ref_buf[i] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3903 | } |
| 3904 | } |
| 3905 | } |
| 3906 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3907 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3908 | const AV1_COMMON *const cm = &cpi->common; |
Yunqing Wang | 4b7bf40 | 2020-01-28 15:20:53 -0800 | [diff] [blame] | 3909 | const int max_mv_def = AOMMAX(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3910 | |
| 3911 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3912 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3913 | |
chiyotsai | 8cc054a | 2019-12-12 14:57:43 -0800 | [diff] [blame] | 3914 | if (cpi->sf.mv_sf.auto_mv_step_size) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3915 | if (frame_is_intra_only(cm)) { |
| 3916 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3917 | // after a key/intra-only frame. |
| 3918 | cpi->max_mv_magnitude = max_mv_def; |
| 3919 | } else { |
Yunqing Wang | 4b7bf40 | 2020-01-28 15:20:53 -0800 | [diff] [blame] | 3920 | // Use cpi->max_mv_magnitude == -1 to exclude first pass case. |
| 3921 | if (cm->show_frame && cpi->max_mv_magnitude != -1) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3922 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3923 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3924 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3925 | cpi->mv_step_param = av1_init_search_range( |
| 3926 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3927 | } |
Yunqing Wang | 4b7bf40 | 2020-01-28 15:20:53 -0800 | [diff] [blame] | 3928 | cpi->max_mv_magnitude = -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3929 | } |
| 3930 | } |
| 3931 | } |
| 3932 | |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3933 | static void set_screen_content_options(AV1_COMP *cpi) { |
| 3934 | AV1_COMMON *cm = &cpi->common; |
| 3935 | |
| 3936 | if (cm->seq_params.force_screen_content_tools != 2) { |
| 3937 | cm->allow_screen_content_tools = cm->allow_intrabc = |
| 3938 | cm->seq_params.force_screen_content_tools; |
| 3939 | return; |
| 3940 | } |
| 3941 | |
| 3942 | if (cpi->oxcf.content == AOM_CONTENT_SCREEN) { |
| 3943 | cm->allow_screen_content_tools = cm->allow_intrabc = 1; |
| 3944 | return; |
| 3945 | } |
| 3946 | |
| 3947 | // Estimate if the source frame is screen content, based on the portion of |
| 3948 | // blocks that have few luma colors. |
Cheng Chen | 4f666ca | 2019-11-18 17:05:03 -0800 | [diff] [blame] | 3949 | const uint8_t *src = cpi->unfiltered_source->y_buffer; |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3950 | assert(src != NULL); |
Cheng Chen | 4f666ca | 2019-11-18 17:05:03 -0800 | [diff] [blame] | 3951 | const int use_hbd = cpi->unfiltered_source->flags & YV12_FLAG_HIGHBITDEPTH; |
| 3952 | const int stride = cpi->unfiltered_source->y_stride; |
| 3953 | const int width = cpi->unfiltered_source->y_width; |
| 3954 | const int height = cpi->unfiltered_source->y_height; |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3955 | const int bd = cm->seq_params.bit_depth; |
| 3956 | const int blk_w = 16; |
| 3957 | const int blk_h = 16; |
| 3958 | // These threshold values are selected experimentally. |
| 3959 | const int color_thresh = 4; |
| 3960 | const unsigned int var_thresh = 0; |
| 3961 | // Counts of blocks with no more than color_thresh colors. |
| 3962 | int counts_1 = 0; |
| 3963 | // Counts of blocks with no more than color_thresh colors and variance larger |
| 3964 | // than var_thresh. |
| 3965 | int counts_2 = 0; |
| 3966 | |
| 3967 | for (int r = 0; r + blk_h <= height; r += blk_h) { |
| 3968 | for (int c = 0; c + blk_w <= width; c += blk_w) { |
| 3969 | int count_buf[1 << 12]; // Maximum (1 << 12) color levels. |
| 3970 | const uint8_t *const this_src = src + r * stride + c; |
| 3971 | const int n_colors = |
| 3972 | use_hbd ? av1_count_colors_highbd(this_src, stride, blk_w, blk_h, bd, |
| 3973 | count_buf) |
| 3974 | : av1_count_colors(this_src, stride, blk_w, blk_h, count_buf); |
| 3975 | if (n_colors > 1 && n_colors <= color_thresh) { |
| 3976 | ++counts_1; |
| 3977 | struct buf_2d buf; |
| 3978 | buf.stride = stride; |
| 3979 | buf.buf = (uint8_t *)this_src; |
| 3980 | const unsigned int var = |
| 3981 | use_hbd |
| 3982 | ? av1_high_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16, bd) |
| 3983 | : av1_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16); |
| 3984 | if (var > var_thresh) ++counts_2; |
| 3985 | } |
| 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | // The threshold values are selected experimentally. |
| 3990 | cm->allow_screen_content_tools = |
| 3991 | counts_1 * blk_h * blk_w * 10 > width * height; |
| 3992 | // IntraBC would force loop filters off, so we use more strict rules that also |
| 3993 | // requires that the block has high variance. |
| 3994 | cm->allow_intrabc = cm->allow_screen_content_tools && |
Hui Su | 64a2ffb | 2019-04-11 16:47:13 -0700 | [diff] [blame] | 3995 | counts_2 * blk_h * blk_w * 12 > width * height; |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3996 | } |
| 3997 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3998 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3999 | int i; |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 4000 | AV1_COMMON *cm = &cpi->common; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4001 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 4002 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4003 | } |
| 4004 | cpi->global_motion_search_done = 0; |
Yunqing Wang | 9411e43 | 2019-03-14 15:53:23 -0700 | [diff] [blame] | 4005 | |
| 4006 | if (frame_is_intra_only(cm)) set_screen_content_options(cpi); |
| 4007 | cpi->is_screen_content_type = (cm->allow_screen_content_tools != 0); |
| 4008 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 4009 | av1_set_speed_features_framesize_independent(cpi, cpi->speed); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4010 | av1_set_rd_speed_thresholds(cpi); |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 4011 | cm->interp_filter = SWITCHABLE; |
| 4012 | cm->switchable_motion_mode = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4015 | #if !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 4016 | static int get_gfu_boost_from_r0(double r0, int frames_to_key) { |
| 4017 | double factor = sqrt((double)frames_to_key); |
| 4018 | factor = AOMMIN(factor, 10.0); |
| 4019 | factor = AOMMAX(factor, 4.0); |
| 4020 | const int boost = (int)rint((200.0 + 10.0 * factor) / r0); |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4021 | return boost; |
| 4022 | } |
| 4023 | |
Debargha Mukherjee | afd3cc2 | 2019-06-10 11:35:17 -0700 | [diff] [blame] | 4024 | static int get_kf_boost_from_r0(double r0, int frames_to_key) { |
| 4025 | double factor = sqrt((double)frames_to_key); |
| 4026 | factor = AOMMIN(factor, 10.0); |
| 4027 | factor = AOMMAX(factor, 4.0); |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 4028 | const int boost = (int)rint((75.0 + 14.0 * factor) / r0); |
| 4029 | return boost; |
| 4030 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4031 | #endif |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 4032 | |
| 4033 | int combine_prior_with_tpl_boost(int prior_boost, int tpl_boost, |
| 4034 | int frames_to_key) { |
| 4035 | double factor = sqrt((double)frames_to_key); |
| 4036 | factor = AOMMIN(factor, 12.0); |
| 4037 | factor = AOMMAX(factor, 4.0); |
| 4038 | factor -= 4.0; |
| 4039 | int boost = (int)((factor * prior_boost + (8.0 - factor) * tpl_boost) / 8.0); |
Debargha Mukherjee | afd3cc2 | 2019-06-10 11:35:17 -0700 | [diff] [blame] | 4040 | return boost; |
| 4041 | } |
| 4042 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4043 | #if !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4044 | static void process_tpl_stats_frame(AV1_COMP *cpi) { |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 4045 | const GF_GROUP *const gf_group = &cpi->gf_group; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4046 | AV1_COMMON *const cm = &cpi->common; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4047 | |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 4048 | assert(IMPLIES(gf_group->size > 0, gf_group->index < gf_group->size)); |
Jingning Han | 31a0ee9 | 2019-07-15 13:56:55 -0700 | [diff] [blame] | 4049 | |
| 4050 | const int tpl_idx = gf_group->index; |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 4051 | TplDepFrame *tpl_frame = &cpi->tpl_frame[tpl_idx]; |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4052 | TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4053 | |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4054 | if (tpl_frame->is_valid) { |
| 4055 | int tpl_stride = tpl_frame->stride; |
| 4056 | int64_t intra_cost_base = 0; |
| 4057 | int64_t mc_dep_cost_base = 0; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 4058 | #if !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4059 | int64_t mc_saved_base = 0; |
| 4060 | int64_t mc_count_base = 0; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 4061 | #endif // !USE_TPL_CLASSIC_MODEL |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 4062 | const int step = 1 << cpi->tpl_stats_block_mis_log2; |
Debargha Mukherjee | edfa4fe | 2019-07-08 14:23:39 -0700 | [diff] [blame] | 4063 | const int mi_cols_sr = av1_pixels_to_mi(cm->superres_upscaled_width); |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 4064 | |
| 4065 | for (int row = 0; row < cm->mi_rows; row += step) { |
| 4066 | for (int col = 0; col < mi_cols_sr; col += step) { |
| 4067 | TplDepStats *this_stats = |
| 4068 | &tpl_stats[av1_tpl_ptr_pos(cpi, row, col, tpl_stride)]; |
Jingning Han | 40e870f | 2019-10-02 16:05:39 -0700 | [diff] [blame] | 4069 | int64_t mc_dep_delta = |
| 4070 | RDCOST(tpl_frame->base_rdmult, this_stats->mc_dep_rate, |
| 4071 | this_stats->mc_dep_dist); |
| 4072 | intra_cost_base += (this_stats->recrf_dist << RDDIV_BITS); |
| 4073 | mc_dep_cost_base += |
| 4074 | (this_stats->recrf_dist << RDDIV_BITS) + mc_dep_delta; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 4075 | #if !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4076 | mc_count_base += this_stats->mc_count; |
| 4077 | mc_saved_base += this_stats->mc_saved; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 4078 | #endif // !USE_TPL_CLASSIC_MODEL |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4079 | } |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4080 | } |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4081 | |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4082 | if (mc_dep_cost_base == 0) { |
| 4083 | tpl_frame->is_valid = 0; |
| 4084 | } else { |
| 4085 | aom_clear_system_state(); |
| 4086 | cpi->rd.r0 = (double)intra_cost_base / mc_dep_cost_base; |
Jingning Han | 44a573b | 2019-09-04 14:01:22 -0700 | [diff] [blame] | 4087 | if (is_frame_arf_and_tpl_eligible(gf_group)) { |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4088 | cpi->rd.arf_r0 = cpi->rd.r0; |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 4089 | const int gfu_boost = |
| 4090 | get_gfu_boost_from_r0(cpi->rd.arf_r0, cpi->rc.frames_to_key); |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4091 | // printf("old boost %d new boost %d\n", cpi->rc.gfu_boost, |
Debargha Mukherjee | afd3cc2 | 2019-06-10 11:35:17 -0700 | [diff] [blame] | 4092 | // gfu_boost); |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 4093 | cpi->rc.gfu_boost = combine_prior_with_tpl_boost( |
| 4094 | cpi->rc.gfu_boost, gfu_boost, cpi->rc.frames_to_key); |
Debargha Mukherjee | afd3cc2 | 2019-06-10 11:35:17 -0700 | [diff] [blame] | 4095 | } else if (frame_is_intra_only(cm)) { |
Debargha Mukherjee | 0a121a9 | 2019-06-19 13:12:46 -0700 | [diff] [blame] | 4096 | // TODO(debargha): Turn off q adjustment for kf temporarily to |
| 4097 | // reduce impact on speed of encoding. Need to investigate how |
| 4098 | // to mitigate the issue. |
| 4099 | if (cpi->oxcf.rc_mode == AOM_Q) { |
| 4100 | const int kf_boost = |
| 4101 | get_kf_boost_from_r0(cpi->rd.r0, cpi->rc.frames_to_key); |
| 4102 | // printf("old kf boost %d new kf boost %d [%d]\n", cpi->rc.kf_boost, |
| 4103 | // kf_boost, cpi->rc.frames_to_key); |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 4104 | cpi->rc.kf_boost = combine_prior_with_tpl_boost( |
| 4105 | cpi->rc.kf_boost, kf_boost, cpi->rc.frames_to_key); |
Debargha Mukherjee | 0a121a9 | 2019-06-19 13:12:46 -0700 | [diff] [blame] | 4106 | } |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4107 | } |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 4108 | #if !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4109 | cpi->rd.mc_count_base = |
| 4110 | (double)mc_count_base / (cm->mi_rows * cm->mi_cols); |
| 4111 | cpi->rd.mc_saved_base = |
| 4112 | (double)mc_saved_base / (cm->mi_rows * cm->mi_cols); |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 4113 | #endif // !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4114 | aom_clear_system_state(); |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4115 | } |
| 4116 | } |
| 4117 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4118 | #endif // !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4119 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4120 | static void set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4121 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4122 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4123 | |
| 4124 | // Setup variables that depend on the dimensions of the frame. |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 4125 | av1_set_speed_features_framesize_dependent(cpi, cpi->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4126 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4127 | #if !CONFIG_REALTIME_ONLY |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4128 | if (cpi->oxcf.enable_tpl_model && cpi->tpl_model_pass == 0 && |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 4129 | is_frame_tpl_eligible(cpi)) { |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4130 | process_tpl_stats_frame(cpi); |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 4131 | av1_tpl_rdmult_setup(cpi); |
| 4132 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4133 | #endif |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4134 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 4135 | // Decide q and q bounds. |
Angie Chiang | 958904c | 2019-09-19 16:03:35 -0700 | [diff] [blame] | 4136 | *q = av1_rc_pick_q_and_bounds(cpi, &cpi->rc, cm->width, cm->height, |
| 4137 | cpi->gf_group.index, bottom_index, top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4138 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4139 | // Configure experimental use of segmentation for enhanced coding of |
| 4140 | // static regions if indicated. |
| 4141 | // Only allowed in the second pass of a two pass encode, as it requires |
| 4142 | // lagged coding, and if the relevant speed feature flag is set. |
chiyotsai | 6b43013 | 2019-12-18 10:33:51 -0800 | [diff] [blame] | 4143 | if (is_stat_consumption_stage_twopass(cpi) && |
| 4144 | cpi->sf.hl_sf.static_segmentation) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4145 | configure_static_seg_features(cpi); |
| 4146 | } |
| 4147 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4148 | static void init_motion_estimation(AV1_COMP *cpi) { |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4149 | AV1_COMMON *const cm = &cpi->common; |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4150 | const int y_stride = cpi->scaled_source.y_stride; |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4151 | const int y_stride_src = |
| 4152 | ((cpi->oxcf.width != cm->width || cpi->oxcf.height != cm->height) || |
| 4153 | av1_superres_scaled(cm)) |
| 4154 | ? y_stride |
| 4155 | : cpi->lookahead->buf->img.y_stride; |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4156 | // Update if ss_cfg is uninitialized or the current frame has a new stride |
| 4157 | const int should_update = !cpi->ss_cfg[SS_CFG_SRC].stride || |
| 4158 | !cpi->ss_cfg[SS_CFG_LOOKAHEAD].stride || |
| 4159 | (y_stride != cpi->ss_cfg[SS_CFG_SRC].stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4160 | |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4161 | if (!should_update) { |
| 4162 | return; |
| 4163 | } |
| 4164 | |
chiyotsai | 8cc054a | 2019-12-12 14:57:43 -0800 | [diff] [blame] | 4165 | if (cpi->sf.mv_sf.search_method == DIAMOND) { |
Satish Kumar Suman | e6d0be5 | 2019-02-14 14:33:28 +0530 | [diff] [blame] | 4166 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 4167 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], |
| 4168 | y_stride_src); |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4169 | } else { |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4170 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 4171 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], y_stride_src); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4172 | } |
Jingning Han | 969a8d4 | 2019-12-16 19:40:14 -0800 | [diff] [blame] | 4173 | av1_init_motion_fpf(&cpi->ss_cfg[SS_CFG_FPF], y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4176 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4177 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 4178 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4179 | (void)width; |
| 4180 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4181 | (void)sx; |
| 4182 | (void)sy; |
| 4183 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4184 | int s = AOMMIN(sx, sy); |
| 4185 | #else |
| 4186 | int s = 0; |
| 4187 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4188 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 4189 | if (width * height > 352 * 288) |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 4190 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 4191 | else |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 4192 | rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4193 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 4194 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4195 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4196 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 4197 | static void init_ref_frame_bufs(AV1_COMP *cpi) { |
| 4198 | AV1_COMMON *const cm = &cpi->common; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4199 | int i; |
| 4200 | BufferPool *const pool = cm->buffer_pool; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4201 | cm->cur_frame = NULL; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4202 | for (i = 0; i < REF_FRAMES; ++i) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4203 | cm->ref_frame_map[i] = NULL; |
Wan-Teh Chang | d05e033 | 2018-10-03 12:00:43 -0700 | [diff] [blame] | 4204 | } |
| 4205 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4206 | pool->frame_bufs[i].ref_count = 0; |
| 4207 | } |
RogerZhou | 86902d0 | 2018-02-28 15:29:16 -0800 | [diff] [blame] | 4208 | if (cm->seq_params.force_screen_content_tools) { |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 4209 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 4210 | av1_hash_table_init(&pool->frame_bufs[i].hash_table, &cpi->td.mb); |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 4211 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4212 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
Mufaddal Chakera | 02ac17f | 2019-12-09 18:09:55 +0530 | [diff] [blame] | 4215 | void av1_check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
| 4216 | int subsampling_x, int subsampling_y) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4217 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4218 | SequenceHeader *const seq_params = &cm->seq_params; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4219 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4220 | if (!cpi->initial_width || seq_params->use_highbitdepth != use_highbitdepth || |
| 4221 | seq_params->subsampling_x != subsampling_x || |
| 4222 | seq_params->subsampling_y != subsampling_y) { |
| 4223 | seq_params->subsampling_x = subsampling_x; |
| 4224 | seq_params->subsampling_y = subsampling_y; |
| 4225 | seq_params->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4226 | |
Jingning Han | 183b2a8 | 2019-12-18 16:03:41 -0800 | [diff] [blame] | 4227 | av1_set_speed_features_framesize_independent(cpi, cpi->oxcf.speed); |
| 4228 | av1_set_speed_features_framesize_dependent(cpi, cpi->oxcf.speed); |
| 4229 | |
Mufaddal Chakera | 02ac17f | 2019-12-09 18:09:55 +0530 | [diff] [blame] | 4230 | alloc_altref_frame_buffer(cpi); |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 4231 | init_ref_frame_bufs(cpi); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4232 | alloc_util_frame_buffers(cpi); |
| 4233 | |
| 4234 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 4235 | |
| 4236 | cpi->initial_width = cm->width; |
| 4237 | cpi->initial_height = cm->height; |
| 4238 | cpi->initial_mbs = cm->MBs; |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | // Returns 1 if the assigned width or height was <= 0. |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 4243 | int av1_set_size_literal(AV1_COMP *cpi, int width, int height) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4244 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4245 | const int num_planes = av1_num_planes(cm); |
Mufaddal Chakera | 02ac17f | 2019-12-09 18:09:55 +0530 | [diff] [blame] | 4246 | av1_check_initial_width(cpi, cm->seq_params.use_highbitdepth, |
| 4247 | cm->seq_params.subsampling_x, |
| 4248 | cm->seq_params.subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4249 | |
| 4250 | if (width <= 0 || height <= 0) return 1; |
| 4251 | |
| 4252 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4253 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4254 | |
| 4255 | if (cpi->initial_width && cpi->initial_height && |
| 4256 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 4257 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4258 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4259 | alloc_compressor_data(cpi); |
| 4260 | realloc_segmentation_maps(cpi); |
| 4261 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4262 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4263 | update_frame_size(cpi); |
| 4264 | |
| 4265 | return 0; |
| 4266 | } |
| 4267 | |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4268 | void av1_set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4269 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4270 | const SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4271 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4272 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4273 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4274 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4275 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 4276 | // There has been a change in the encoded frame size |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 4277 | av1_set_size_literal(cpi, width, height); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4278 | // Recalculate 'all_lossless' in case super-resolution was (un)selected. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4279 | cm->all_lossless = cm->coded_lossless && !av1_superres_scaled(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4280 | } |
Yunqing Wang | 4b7bf40 | 2020-01-28 15:20:53 -0800 | [diff] [blame] | 4281 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4282 | |
Hamsalekha S | 37cc1d1 | 2019-12-12 19:27:41 +0530 | [diff] [blame] | 4283 | if (is_stat_consumption_stage(cpi)) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4284 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4287 | alloc_frame_mvs(cm, cm->cur_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4288 | |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 4289 | // Allocate above context buffers |
Cherma Rajan A | f147908 | 2018-05-09 14:26:34 +0530 | [diff] [blame] | 4290 | if (cm->num_allocated_above_context_planes < av1_num_planes(cm) || |
| 4291 | cm->num_allocated_above_context_mi_col < cm->mi_cols || |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 4292 | cm->num_allocated_above_contexts < cm->tile_rows) { |
| 4293 | av1_free_above_context_buffers(cm, cm->num_allocated_above_contexts); |
| 4294 | if (av1_alloc_above_context_buffers(cm, cm->tile_rows)) |
| 4295 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 4296 | "Failed to allocate context buffers"); |
| 4297 | } |
| 4298 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4299 | // Reset the frame pointers to the current frame size. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4300 | if (aom_realloc_frame_buffer( |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4301 | &cm->cur_frame->buf, cm->width, cm->height, seq_params->subsampling_x, |
| 4302 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 4303 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4304 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4305 | "Failed to allocate frame buffer"); |
| 4306 | |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4307 | const int frame_width = cm->superres_upscaled_width; |
| 4308 | const int frame_height = cm->superres_upscaled_height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4309 | set_restoration_unit_size(frame_width, frame_height, |
| 4310 | seq_params->subsampling_x, |
| 4311 | seq_params->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4312 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 4313 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4314 | |
| 4315 | av1_alloc_restoration_buffers(cm); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4316 | alloc_util_frame_buffers(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4317 | init_motion_estimation(cpi); |
| 4318 | |
| 4319 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4320 | RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4321 | if (buf != NULL) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4322 | struct scale_factors *sf = get_ref_scale_factors(cm, ref_frame); |
| 4323 | av1_setup_scale_factors_for_frame(sf, buf->buf.y_crop_width, |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 4324 | buf->buf.y_crop_height, cm->width, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 4325 | cm->height); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4326 | if (av1_is_scaled(sf)) aom_extend_frame_borders(&buf->buf, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4327 | } |
| 4328 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4329 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 4330 | av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 4331 | cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4332 | |
| 4333 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4334 | } |
| 4335 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4336 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 4337 | // Choose an arbitrary random number |
| 4338 | static unsigned int seed = 56789; |
| 4339 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 4340 | if (is_stat_generation_stage(cpi)) return SCALE_NUMERATOR; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4341 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4342 | |
Debargha Mukherjee | 2b7c2b3 | 2018-04-10 07:35:28 -0700 | [diff] [blame] | 4343 | if (cpi->common.seq_params.reduced_still_picture_hdr) return SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4344 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4345 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4346 | case RESIZE_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4347 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4348 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4349 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4350 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4351 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4352 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4353 | default: assert(0); |
| 4354 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4355 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4356 | } |
| 4357 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 4358 | #if CONFIG_SUPERRES_IN_RECODE |
| 4359 | static int superres_in_recode_allowed(const AV1_COMP *const cpi) { |
| 4360 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 4361 | // Empirically found to not be beneficial for AOM_Q mode and images coding. |
| 4362 | return oxcf->superres_mode == SUPERRES_AUTO && |
| 4363 | (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) && |
| 4364 | cpi->rc.frames_to_key > 1; |
| 4365 | } |
| 4366 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 4367 | |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4368 | #define SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME_SOLO 0.012 |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4369 | #define SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME 0.008 |
| 4370 | #define SUPERRES_ENERGY_BY_Q2_THRESH_ARFFRAME 0.008 |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4371 | #define SUPERRES_ENERGY_BY_AC_THRESH 0.2 |
| 4372 | |
| 4373 | static double get_energy_by_q2_thresh(const GF_GROUP *gf_group, |
| 4374 | const RATE_CONTROL *rc) { |
| 4375 | // TODO(now): Return keyframe thresh * factor based on frame type / pyramid |
| 4376 | // level. |
| 4377 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 4378 | return SUPERRES_ENERGY_BY_Q2_THRESH_ARFFRAME; |
| 4379 | } else if (gf_group->update_type[gf_group->index] == KF_UPDATE) { |
| 4380 | if (rc->frames_to_key <= 1) |
| 4381 | return SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME_SOLO; |
| 4382 | else |
| 4383 | return SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME; |
| 4384 | } else { |
| 4385 | assert(0); |
| 4386 | } |
| 4387 | return 0; |
| 4388 | } |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4389 | |
| 4390 | static uint8_t get_superres_denom_from_qindex_energy(int qindex, double *energy, |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4391 | double threshq, |
| 4392 | double threshp) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4393 | const double q = av1_convert_qindex_to_q(qindex, AOM_BITS_8); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4394 | const double tq = threshq * q * q; |
| 4395 | const double tp = threshp * energy[1]; |
| 4396 | const double thresh = AOMMIN(tq, tp); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4397 | int k; |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4398 | for (k = SCALE_NUMERATOR * 2; k > SCALE_NUMERATOR; --k) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4399 | if (energy[k - 1] > thresh) break; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4400 | } |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4401 | return 3 * SCALE_NUMERATOR - k; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4402 | } |
| 4403 | |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4404 | static uint8_t get_superres_denom_for_qindex(const AV1_COMP *cpi, int qindex, |
| 4405 | int sr_kf, int sr_arf) { |
| 4406 | // Use superres for Key-frames and Alt-ref frames only. |
| 4407 | const GF_GROUP *gf_group = &cpi->gf_group; |
| 4408 | if (gf_group->update_type[gf_group->index] != KF_UPDATE && |
| 4409 | gf_group->update_type[gf_group->index] != ARF_UPDATE) { |
| 4410 | return SCALE_NUMERATOR; |
| 4411 | } |
| 4412 | if (gf_group->update_type[gf_group->index] == KF_UPDATE && !sr_kf) { |
| 4413 | return SCALE_NUMERATOR; |
| 4414 | } |
| 4415 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE && !sr_arf) { |
| 4416 | return SCALE_NUMERATOR; |
| 4417 | } |
| 4418 | |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4419 | double energy[16]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4420 | analyze_hor_freq(cpi, energy); |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4421 | |
| 4422 | const double energy_by_q2_thresh = |
| 4423 | get_energy_by_q2_thresh(gf_group, &cpi->rc); |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 4424 | int denom = get_superres_denom_from_qindex_energy( |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4425 | qindex, energy, energy_by_q2_thresh, SUPERRES_ENERGY_BY_AC_THRESH); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4426 | /* |
| 4427 | printf("\nenergy = ["); |
| 4428 | for (int k = 1; k < 16; ++k) printf("%f, ", energy[k]); |
| 4429 | printf("]\n"); |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4430 | printf("boost = %d\n", |
| 4431 | (gf_group->update_type[gf_group->index] == KF_UPDATE) |
| 4432 | ? cpi->rc.kf_boost |
| 4433 | : cpi->rc.gfu_boost); |
| 4434 | printf("denom = %d\n", denom); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4435 | */ |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 4436 | #if CONFIG_SUPERRES_IN_RECODE |
| 4437 | if (superres_in_recode_allowed(cpi)) { |
| 4438 | // Force superres to be tried in the recode loop, as full-res is also going |
| 4439 | // to be tried anyway. |
| 4440 | denom = AOMMAX(denom, SCALE_NUMERATOR + 1); |
| 4441 | } |
| 4442 | #endif // CONFIG_SUPERRES_IN_RECODE |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4443 | return denom; |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 4444 | } |
| 4445 | |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 4446 | // If true, SUPERRES_AUTO mode will exhaustively search over all superres |
| 4447 | // denominators for all frames (except overlay and internal overlay frames). |
| 4448 | #define SUPERRES_RECODE_ALL_RATIOS 0 |
| 4449 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4450 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 4451 | // Choose an arbitrary random number |
| 4452 | static unsigned int seed = 34567; |
| 4453 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 4454 | if (is_stat_generation_stage(cpi)) return SCALE_NUMERATOR; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4455 | uint8_t new_denom = SCALE_NUMERATOR; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4456 | |
| 4457 | // Make sure that superres mode of the frame is consistent with the |
| 4458 | // sequence-level flag. |
| 4459 | assert(IMPLIES(oxcf->superres_mode != SUPERRES_NONE, |
| 4460 | cpi->common.seq_params.enable_superres)); |
| 4461 | assert(IMPLIES(!cpi->common.seq_params.enable_superres, |
| 4462 | oxcf->superres_mode == SUPERRES_NONE)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4463 | |
| 4464 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4465 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4466 | case SUPERRES_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4467 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4468 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4469 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4470 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4471 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4472 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4473 | case SUPERRES_QTHRESH: { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 4474 | // Do not use superres when screen content tools are used. |
| 4475 | if (cpi->common.allow_screen_content_tools) break; |
Debargha Mukherjee | 2b2c5fd | 2018-11-14 13:21:24 -0800 | [diff] [blame] | 4476 | if (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) |
| 4477 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4478 | |
| 4479 | // Now decide the use of superres based on 'q'. |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4480 | int bottom_index, top_index; |
| 4481 | const int q = av1_rc_pick_q_and_bounds( |
Angie Chiang | 958904c | 2019-09-19 16:03:35 -0700 | [diff] [blame] | 4482 | cpi, &cpi->rc, cpi->oxcf.width, cpi->oxcf.height, cpi->gf_group.index, |
Jingning Han | 2e02987 | 2019-08-02 10:54:19 -0700 | [diff] [blame] | 4483 | &bottom_index, &top_index); |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 4484 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4485 | const int qthresh = (frame_is_intra_only(&cpi->common)) |
| 4486 | ? oxcf->superres_kf_qthresh |
| 4487 | : oxcf->superres_qthresh; |
Urvang Joshi | b17e0a6 | 2019-01-11 16:11:54 -0800 | [diff] [blame] | 4488 | if (q <= qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4489 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4490 | } else { |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4491 | new_denom = get_superres_denom_for_qindex(cpi, q, 1, 1); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4492 | } |
| 4493 | break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4494 | } |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4495 | case SUPERRES_AUTO: { |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4496 | // Do not use superres when screen content tools are used. |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4497 | if (cpi->common.allow_screen_content_tools) break; |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4498 | if (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) |
| 4499 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4500 | |
| 4501 | // Now decide the use of superres based on 'q'. |
| 4502 | int bottom_index, top_index; |
| 4503 | const int q = av1_rc_pick_q_and_bounds( |
Angie Chiang | 958904c | 2019-09-19 16:03:35 -0700 | [diff] [blame] | 4504 | cpi, &cpi->rc, cpi->oxcf.width, cpi->oxcf.height, cpi->gf_group.index, |
Jingning Han | 2e02987 | 2019-08-02 10:54:19 -0700 | [diff] [blame] | 4505 | &bottom_index, &top_index); |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4506 | |
| 4507 | const int qthresh = 128; |
| 4508 | if (q <= qthresh) { |
| 4509 | new_denom = SCALE_NUMERATOR; |
| 4510 | } else { |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 4511 | #if SUPERRES_RECODE_ALL_RATIOS |
| 4512 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
| 4513 | new_denom = oxcf->superres_kf_scale_denominator; |
| 4514 | else |
| 4515 | new_denom = oxcf->superres_scale_denominator; |
| 4516 | #else |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4517 | new_denom = get_superres_denom_for_qindex(cpi, q, 1, 1); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 4518 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4519 | } |
| 4520 | break; |
| 4521 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4522 | default: assert(0); |
| 4523 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4524 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4527 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4528 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4529 | } |
| 4530 | |
| 4531 | static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) { |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 4532 | // Only need to check the width, as scaling is horizontal only. |
| 4533 | (void)oheight; |
| 4534 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4537 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4538 | SUPERRES_MODE superres_mode, int owidth, |
| 4539 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4540 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4541 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4542 | } |
| 4543 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4544 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4545 | int resize_denom = |
| 4546 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 4547 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 4548 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4549 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4550 | // Alter superres scale as needed to enforce conformity. |
| 4551 | rsz->superres_denom = |
| 4552 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 4553 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4554 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4555 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4556 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4557 | // Alter resize scale as needed to enforce conformity. |
| 4558 | resize_denom = |
| 4559 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4560 | rsz->resize_width = owidth; |
| 4561 | rsz->resize_height = oheight; |
| 4562 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4563 | resize_denom); |
| 4564 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4565 | if (resize_denom > SCALE_NUMERATOR) { |
| 4566 | --resize_denom; |
| 4567 | rsz->resize_width = owidth; |
| 4568 | rsz->resize_height = oheight; |
| 4569 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 4570 | resize_denom); |
| 4571 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4572 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4573 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4574 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4575 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4576 | if (resize_denom > rsz->superres_denom) |
| 4577 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4578 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4579 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4580 | rsz->resize_width = owidth; |
| 4581 | rsz->resize_height = oheight; |
| 4582 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4583 | resize_denom); |
| 4584 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 4585 | (resize_denom > SCALE_NUMERATOR || |
| 4586 | rsz->superres_denom > SCALE_NUMERATOR)); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4587 | } else { // We are allowed to alter neither resize scale nor superres |
| 4588 | // scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4589 | return 0; |
| 4590 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4591 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4592 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4593 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4594 | // Calculates resize and superres params for next frame |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4595 | static size_params_type calculate_next_size_params(AV1_COMP *cpi) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4596 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 4597 | size_params_type rsz = { oxcf->width, oxcf->height, SCALE_NUMERATOR }; |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4598 | int resize_denom = SCALE_NUMERATOR; |
Mufaddal Chakera | 3bcc72c | 2019-12-11 14:38:37 +0530 | [diff] [blame] | 4599 | if (has_no_stats_stage(cpi) && cpi->use_svc && |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 4600 | cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1) { |
| 4601 | rsz.resize_width = cpi->common.width; |
| 4602 | rsz.resize_height = cpi->common.height; |
| 4603 | return rsz; |
| 4604 | } |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 4605 | if (is_stat_generation_stage(cpi)) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4606 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 4607 | rsz.resize_width = cpi->resize_pending_width; |
| 4608 | rsz.resize_height = cpi->resize_pending_height; |
| 4609 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 4610 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4611 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4612 | rsz.resize_width = cpi->oxcf.width; |
| 4613 | rsz.resize_height = cpi->oxcf.height; |
| 4614 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4615 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4616 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4617 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4618 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 4619 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4620 | assert(0 && "Invalid scale parameters"); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4621 | return rsz; |
| 4622 | } |
| 4623 | |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 4624 | static void setup_frame_size_from_params(AV1_COMP *cpi, |
| 4625 | const size_params_type *rsz) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4626 | int encode_width = rsz->resize_width; |
| 4627 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4628 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4629 | AV1_COMMON *cm = &cpi->common; |
| 4630 | cm->superres_upscaled_width = encode_width; |
| 4631 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4632 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4633 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 4634 | rsz->superres_denom); |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4635 | av1_set_frame_size(cpi, encode_width, encode_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 4638 | void av1_setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 4639 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 4640 | // Reset superres params from previous frame. |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 4641 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4642 | const size_params_type rsz = calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4643 | setup_frame_size_from_params(cpi, &rsz); |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 4644 | |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 4645 | assert(av1_is_min_tile_width_satisfied(cm)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4646 | } |
| 4647 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4648 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4649 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4650 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4651 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4652 | if (!av1_superres_scaled(cm)) return; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4653 | |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4654 | assert(cpi->oxcf.enable_superres); |
| 4655 | assert(!is_lossless_requested(&cpi->oxcf)); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4656 | assert(!cm->all_lossless); |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4657 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4658 | av1_superres_upscale(cm, NULL); |
| 4659 | |
| 4660 | // If regular resizing is occurring the source will need to be downscaled to |
| 4661 | // match the upscaled superres resolution. Otherwise the original source is |
| 4662 | // used. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4663 | if (!av1_resize_scaled(cm)) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4664 | cpi->source = cpi->unscaled_source; |
| 4665 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4666 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4667 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4668 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4669 | // Do downscale. cm->(width|height) has been updated by |
| 4670 | // av1_superres_upscale |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4671 | if (aom_realloc_frame_buffer( |
| 4672 | &cpi->scaled_source, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4673 | cm->superres_upscaled_height, cm->seq_params.subsampling_x, |
| 4674 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
| 4675 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4676 | aom_internal_error( |
| 4677 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4678 | "Failed to reallocate scaled source buffer for superres"); |
| 4679 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4680 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4681 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4682 | (int)cm->seq_params.bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4683 | cpi->source = &cpi->scaled_source; |
| 4684 | } |
| 4685 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4686 | |
Yue Chen | 92271e1 | 2019-07-09 16:28:02 -0700 | [diff] [blame] | 4687 | static void cdef_restoration_frame(AV1_COMP *cpi, AV1_COMMON *cm, |
| 4688 | MACROBLOCKD *xd, int use_restoration, |
| 4689 | int use_cdef) { |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4690 | if (use_restoration) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4691 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4692 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4693 | if (use_cdef) { |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4694 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4695 | start_timing(cpi, cdef_time); |
| 4696 | #endif |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4697 | // Find CDEF parameters |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4698 | av1_cdef_search(&cm->cur_frame->buf, cpi->source, cm, xd, |
chiyotsai | d2f7b41 | 2019-12-18 10:16:42 -0800 | [diff] [blame] | 4699 | cpi->sf.lpf_sf.cdef_pick_method, cpi->td.mb.rdmult); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4700 | |
| 4701 | // Apply the filter |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4702 | av1_cdef_frame(&cm->cur_frame->buf, cm, xd); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4703 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4704 | end_timing(cpi, cdef_time); |
| 4705 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4706 | } else { |
| 4707 | cm->cdef_info.cdef_bits = 0; |
| 4708 | cm->cdef_info.cdef_strengths[0] = 0; |
| 4709 | cm->cdef_info.nb_cdef_strengths = 1; |
| 4710 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4711 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4712 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4713 | superres_post_encode(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4714 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4715 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4716 | start_timing(cpi, loop_restoration_time); |
| 4717 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4718 | if (use_restoration) { |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4719 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 1); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4720 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4721 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4722 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4723 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4724 | if (cpi->num_workers > 1) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4725 | av1_loop_restoration_filter_frame_mt(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4726 | cpi->workers, cpi->num_workers, |
| 4727 | &cpi->lr_row_sync, &cpi->lr_ctxt); |
| 4728 | else |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4729 | av1_loop_restoration_filter_frame(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4730 | &cpi->lr_ctxt); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4731 | } |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4732 | } else { |
| 4733 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4734 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4735 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4736 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4737 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4738 | end_timing(cpi, loop_restoration_time); |
| 4739 | #endif |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
Yue Chen | 92271e1 | 2019-07-09 16:28:02 -0700 | [diff] [blame] | 4742 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 4743 | const int num_planes = av1_num_planes(cm); |
| 4744 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 4745 | |
| 4746 | assert(IMPLIES(is_lossless_requested(&cpi->oxcf), |
| 4747 | cm->coded_lossless && cm->all_lossless)); |
| 4748 | |
| 4749 | const int use_loopfilter = !cm->coded_lossless && !cm->large_scale_tile; |
| 4750 | const int use_cdef = cm->seq_params.enable_cdef && !cm->coded_lossless && |
| 4751 | !cm->large_scale_tile; |
| 4752 | const int use_restoration = cm->seq_params.enable_restoration && |
| 4753 | !cm->all_lossless && !cm->large_scale_tile; |
| 4754 | |
| 4755 | struct loopfilter *lf = &cm->lf; |
| 4756 | |
| 4757 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4758 | start_timing(cpi, loop_filter_time); |
| 4759 | #endif |
| 4760 | if (use_loopfilter) { |
| 4761 | aom_clear_system_state(); |
chiyotsai | d2f7b41 | 2019-12-18 10:16:42 -0800 | [diff] [blame] | 4762 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_sf.lpf_pick); |
Yue Chen | 92271e1 | 2019-07-09 16:28:02 -0700 | [diff] [blame] | 4763 | } else { |
| 4764 | lf->filter_level[0] = 0; |
| 4765 | lf->filter_level[1] = 0; |
| 4766 | } |
| 4767 | |
| 4768 | if (lf->filter_level[0] || lf->filter_level[1]) { |
| 4769 | if (cpi->num_workers > 1) |
| 4770 | av1_loop_filter_frame_mt(&cm->cur_frame->buf, cm, xd, 0, num_planes, 0, |
| 4771 | #if CONFIG_LPF_MASK |
| 4772 | 0, |
| 4773 | #endif |
| 4774 | cpi->workers, cpi->num_workers, |
| 4775 | &cpi->lf_row_sync); |
| 4776 | else |
| 4777 | av1_loop_filter_frame(&cm->cur_frame->buf, cm, xd, |
| 4778 | #if CONFIG_LPF_MASK |
| 4779 | 0, |
| 4780 | #endif |
| 4781 | 0, num_planes, 0); |
| 4782 | } |
| 4783 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4784 | end_timing(cpi, loop_filter_time); |
| 4785 | #endif |
| 4786 | |
| 4787 | cdef_restoration_frame(cpi, cm, xd, use_restoration, use_cdef); |
| 4788 | } |
| 4789 | |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4790 | static void fix_interp_filter(InterpFilter *const interp_filter, |
| 4791 | const FRAME_COUNTS *const counts) { |
| 4792 | if (*interp_filter == SWITCHABLE) { |
| 4793 | // Check to see if only one of the filters is actually used |
| 4794 | int count[SWITCHABLE_FILTERS] = { 0 }; |
| 4795 | int num_filters_used = 0; |
| 4796 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4797 | for (int j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) |
| 4798 | count[i] += counts->switchable_interp[j][i]; |
| 4799 | num_filters_used += (count[i] > 0); |
| 4800 | } |
| 4801 | if (num_filters_used == 1) { |
| 4802 | // Only one filter is used. So set the filter at frame level |
| 4803 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4804 | if (count[i]) { |
| 4805 | if (i == EIGHTTAP_REGULAR) *interp_filter = i; |
| 4806 | break; |
| 4807 | } |
| 4808 | } |
| 4809 | } |
| 4810 | } |
| 4811 | } |
| 4812 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4813 | static void finalize_encoded_frame(AV1_COMP *const cpi) { |
| 4814 | AV1_COMMON *const cm = &cpi->common; |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4815 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4816 | |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4817 | if (!cm->seq_params.reduced_still_picture_hdr && |
| 4818 | encode_show_existing_frame(cm)) { |
| 4819 | RefCntBuffer *const frame_to_show = |
| 4820 | cm->ref_frame_map[cpi->existing_fb_idx_to_show]; |
| 4821 | |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4822 | if (frame_to_show == NULL) { |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4823 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 4824 | "Buffer does not contain a reconstructed frame"); |
| 4825 | } |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4826 | assert(frame_to_show->ref_count > 0); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4827 | assign_frame_buffer_p(&cm->cur_frame, frame_to_show); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4828 | } |
David Turner | 08f909c | 2018-12-18 13:29:14 +0000 | [diff] [blame] | 4829 | |
| 4830 | if (!encode_show_existing_frame(cm) && |
| 4831 | cm->seq_params.film_grain_params_present && |
| 4832 | (cm->show_frame || cm->showable_frame)) { |
| 4833 | // Copy the current frame's film grain params to the its corresponding |
| 4834 | // RefCntBuffer slot. |
| 4835 | cm->cur_frame->film_grain_params = cm->film_grain_params; |
| 4836 | |
| 4837 | // We must update the parameters if this is not an INTER_FRAME |
| 4838 | if (current_frame->frame_type != INTER_FRAME) |
| 4839 | cm->cur_frame->film_grain_params.update_parameters = 1; |
| 4840 | |
| 4841 | // Iterate the random seed for the next frame. |
| 4842 | cm->film_grain_params.random_seed += 3381; |
| 4843 | if (cm->film_grain_params.random_seed == 0) |
| 4844 | cm->film_grain_params.random_seed = 7391; |
| 4845 | } |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4846 | |
| 4847 | // Initialise all tiles' contexts from the global frame context |
| 4848 | for (int tile_col = 0; tile_col < cm->tile_cols; tile_col++) { |
| 4849 | for (int tile_row = 0; tile_row < cm->tile_rows; tile_row++) { |
| 4850 | const int tile_idx = tile_row * cm->tile_cols + tile_col; |
| 4851 | cpi->tile_data[tile_idx].tctx = *cm->fc; |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | fix_interp_filter(&cm->interp_filter, cpi->td.counts); |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4856 | } |
| 4857 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4858 | static int get_regulated_q_overshoot(AV1_COMP *const cpi, int q_low, int q_high, |
| 4859 | int top_index, int bottom_index) { |
| 4860 | const AV1_COMMON *const cm = &cpi->common; |
| 4861 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4862 | |
| 4863 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4864 | |
| 4865 | int q_regulated = |
| 4866 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4867 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4868 | |
| 4869 | int retries = 0; |
| 4870 | while (q_regulated < q_low && retries < 10) { |
| 4871 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4872 | q_regulated = |
| 4873 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4874 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4875 | retries++; |
| 4876 | } |
| 4877 | return q_regulated; |
| 4878 | } |
| 4879 | |
| 4880 | static int get_regulated_q_undershoot(AV1_COMP *const cpi, int q_high, |
| 4881 | int top_index, int bottom_index) { |
| 4882 | const AV1_COMMON *const cm = &cpi->common; |
| 4883 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4884 | |
| 4885 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4886 | int q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4887 | top_index, cm->width, cm->height); |
| 4888 | |
| 4889 | int retries = 0; |
| 4890 | while (q_regulated > q_high && retries < 10) { |
| 4891 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4892 | q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4893 | top_index, cm->width, cm->height); |
| 4894 | retries++; |
| 4895 | } |
| 4896 | return q_regulated; |
| 4897 | } |
| 4898 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4899 | // Called after encode_with_recode_loop() has just encoded a frame and packed |
| 4900 | // its bitstream. This function works out whether we under- or over-shot |
| 4901 | // our bitrate target and adjusts q as appropriate. Also decides whether |
| 4902 | // or not we should do another recode loop, indicated by *loop |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4903 | static void recode_loop_update_q( |
| 4904 | AV1_COMP *const cpi, int *const loop, int *const q, int *const q_low, |
| 4905 | int *const q_high, const int top_index, const int bottom_index, |
| 4906 | int *const undershoot_seen, int *const overshoot_seen, |
| 4907 | int *const low_cr_seen, const int loop_at_this_size) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4908 | AV1_COMMON *const cm = &cpi->common; |
| 4909 | RATE_CONTROL *const rc = &cpi->rc; |
| 4910 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4911 | const int min_cr = cpi->oxcf.min_cr; |
| 4912 | if (min_cr > 0) { |
| 4913 | aom_clear_system_state(); |
| 4914 | const double compression_ratio = |
| 4915 | av1_get_compression_ratio(cm, rc->projected_frame_size >> 3); |
| 4916 | const double target_cr = min_cr / 100.0; |
| 4917 | if (compression_ratio < target_cr) { |
| 4918 | *low_cr_seen = 1; |
| 4919 | if (*q < rc->worst_quality) { |
| 4920 | const double cr_ratio = target_cr / compression_ratio; |
| 4921 | const int projected_q = AOMMAX(*q + 1, (int)(*q * cr_ratio * cr_ratio)); |
| 4922 | *q = AOMMIN(AOMMIN(projected_q, *q + 32), rc->worst_quality); |
| 4923 | *q_low = AOMMAX(*q, *q_low); |
| 4924 | *q_high = AOMMAX(*q, *q_high); |
| 4925 | *loop = 1; |
| 4926 | } |
| 4927 | } |
| 4928 | if (*low_cr_seen) return; |
| 4929 | } |
| 4930 | |
| 4931 | if (cpi->oxcf.rc_mode == AOM_Q) return; |
| 4932 | |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4933 | const int last_q = *q; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4934 | int frame_over_shoot_limit = 0, frame_under_shoot_limit = 0; |
| 4935 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4936 | &frame_under_shoot_limit, |
| 4937 | &frame_over_shoot_limit); |
| 4938 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4939 | |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4940 | if (cm->current_frame.frame_type == KEY_FRAME && rc->this_key_frame_forced && |
| 4941 | rc->projected_frame_size < rc->max_frame_bandwidth) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4942 | int64_t kf_err; |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4943 | const int64_t high_err_target = cpi->ambient_err; |
| 4944 | const int64_t low_err_target = cpi->ambient_err >> 1; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4945 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 4946 | #if CONFIG_AV1_HIGHBITDEPTH |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4947 | if (cm->seq_params.use_highbitdepth) { |
| 4948 | kf_err = aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4949 | } else { |
| 4950 | kf_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4951 | } |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 4952 | #else |
| 4953 | kf_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4954 | #endif |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4955 | // Prevent possible divide by zero error below for perfect KF |
| 4956 | kf_err += !kf_err; |
| 4957 | |
| 4958 | // The key frame is not good enough or we can afford |
| 4959 | // to make it better without undue risk of popping. |
| 4960 | if ((kf_err > high_err_target && |
| 4961 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4962 | (kf_err > low_err_target && |
| 4963 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4964 | // Lower q_high |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4965 | *q_high = AOMMAX(*q - 1, *q_low); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4966 | |
| 4967 | // Adjust Q |
| 4968 | *q = (int)((*q * high_err_target) / kf_err); |
| 4969 | *q = AOMMIN(*q, (*q_high + *q_low) >> 1); |
| 4970 | } else if (kf_err < low_err_target && |
| 4971 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4972 | // The key frame is much better than the previous frame |
| 4973 | // Raise q_low |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4974 | *q_low = AOMMIN(*q + 1, *q_high); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4975 | |
| 4976 | // Adjust Q |
| 4977 | *q = (int)((*q * low_err_target) / kf_err); |
| 4978 | *q = AOMMIN(*q, (*q_high + *q_low + 1) >> 1); |
| 4979 | } |
| 4980 | |
| 4981 | // Clamp Q to upper and lower limits: |
| 4982 | *q = clamp(*q, *q_low, *q_high); |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4983 | *loop = (*q != last_q); |
| 4984 | return; |
| 4985 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4986 | |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4987 | if (recode_loop_test(cpi, frame_over_shoot_limit, frame_under_shoot_limit, *q, |
| 4988 | AOMMAX(*q_high, top_index), bottom_index)) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4989 | // Is the projected frame size out of range and are we allowed |
| 4990 | // to attempt to recode. |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4991 | |
| 4992 | // Frame size out of permitted range: |
| 4993 | // Update correction factor & compute new Q to try... |
| 4994 | // Frame is too large |
| 4995 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4996 | // Special case if the projected size is > the max allowed. |
Urvang Joshi | 7344d3e | 2019-07-25 17:24:57 -0700 | [diff] [blame] | 4997 | if (*q == *q_high && |
| 4998 | rc->projected_frame_size >= rc->max_frame_bandwidth) { |
| 4999 | const double q_val_high_current = |
| 5000 | av1_convert_qindex_to_q(*q_high, cm->seq_params.bit_depth); |
| 5001 | const double q_val_high_new = |
| 5002 | q_val_high_current * |
| 5003 | ((double)rc->projected_frame_size / rc->max_frame_bandwidth); |
| 5004 | *q_high = av1_find_qindex(q_val_high_new, cm->seq_params.bit_depth, |
| 5005 | rc->best_quality, rc->worst_quality); |
| 5006 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5007 | |
| 5008 | // Raise Qlow as to at least the current value |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 5009 | *q_low = AOMMIN(*q + 1, *q_high); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5010 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 5011 | if (*undershoot_seen || loop_at_this_size > 2 || |
| 5012 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5013 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 5014 | |
| 5015 | *q = (*q_high + *q_low + 1) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 5016 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 5017 | const int q_mid = (*q_high + *q_low + 1) / 2; |
| 5018 | const int q_regulated = get_regulated_q_overshoot( |
| 5019 | cpi, *q_low, *q_high, top_index, bottom_index); |
| 5020 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 5021 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 5022 | *q = (q_mid + q_regulated + 1) / 2; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5023 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 5024 | *q = get_regulated_q_overshoot(cpi, *q_low, *q_high, top_index, |
| 5025 | bottom_index); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | *overshoot_seen = 1; |
| 5029 | } else { |
| 5030 | // Frame is too small |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 5031 | *q_high = AOMMAX(*q - 1, *q_low); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5032 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 5033 | if (*overshoot_seen || loop_at_this_size > 2 || |
| 5034 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5035 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 5036 | *q = (*q_high + *q_low) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 5037 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 5038 | const int q_mid = (*q_high + *q_low) / 2; |
| 5039 | const int q_regulated = |
| 5040 | get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 5041 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 5042 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 5043 | *q = (q_mid + q_regulated) / 2; |
| 5044 | |
| 5045 | // Special case reset for qlow for constrained quality. |
| 5046 | // This should only trigger where there is very substantial |
| 5047 | // undershoot on a frame and the auto cq level is above |
| 5048 | // the user passsed in value. |
| 5049 | if (cpi->oxcf.rc_mode == AOM_CQ && q_regulated < *q_low) { |
| 5050 | *q_low = *q; |
| 5051 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5052 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 5053 | *q = get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 5054 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5055 | // Special case reset for qlow for constrained quality. |
| 5056 | // This should only trigger where there is very substantial |
| 5057 | // undershoot on a frame and the auto cq level is above |
| 5058 | // the user passsed in value. |
| 5059 | if (cpi->oxcf.rc_mode == AOM_CQ && *q < *q_low) { |
| 5060 | *q_low = *q; |
| 5061 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | *undershoot_seen = 1; |
| 5065 | } |
| 5066 | |
| 5067 | // Clamp Q to upper and lower limits: |
| 5068 | *q = clamp(*q, *q_low, *q_high); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5069 | } |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 5070 | |
| 5071 | *loop = (*q != last_q); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5074 | static int get_interp_filter_selected(const AV1_COMMON *const cm, |
| 5075 | MV_REFERENCE_FRAME ref, |
| 5076 | InterpFilter ifilter) { |
| 5077 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref); |
| 5078 | if (buf == NULL) return 0; |
| 5079 | return buf->interp_filter_selected[ifilter]; |
| 5080 | } |
| 5081 | |
Satish Kumar Suman | 0389a49 | 2019-07-31 13:35:58 +0530 | [diff] [blame] | 5082 | static uint16_t setup_interp_filter_search_mask(AV1_COMP *cpi) { |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5083 | const AV1_COMMON *const cm = &cpi->common; |
| 5084 | int ref_total[REF_FRAMES] = { 0 }; |
Satish Kumar Suman | 0389a49 | 2019-07-31 13:35:58 +0530 | [diff] [blame] | 5085 | uint16_t mask = ALLOW_ALL_INTERP_FILT_MASK; |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5086 | |
| 5087 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame) |
Satish Kumar Suman | 0389a49 | 2019-07-31 13:35:58 +0530 | [diff] [blame] | 5088 | return mask; |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5089 | |
| 5090 | for (MV_REFERENCE_FRAME ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) { |
| 5091 | for (InterpFilter ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 5092 | ++ifilter) { |
| 5093 | ref_total[ref] += get_interp_filter_selected(cm, ref, ifilter); |
| 5094 | } |
| 5095 | } |
| 5096 | int ref_total_total = (ref_total[LAST2_FRAME] + ref_total[LAST3_FRAME] + |
| 5097 | ref_total[GOLDEN_FRAME] + ref_total[BWDREF_FRAME] + |
| 5098 | ref_total[ALTREF2_FRAME] + ref_total[ALTREF_FRAME]); |
| 5099 | |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5100 | for (InterpFilter ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 5101 | ++ifilter) { |
| 5102 | int last_score = get_interp_filter_selected(cm, LAST_FRAME, ifilter) * 30; |
| 5103 | if (ref_total[LAST_FRAME] && last_score <= ref_total[LAST_FRAME]) { |
| 5104 | int filter_score = |
| 5105 | get_interp_filter_selected(cm, LAST2_FRAME, ifilter) * 20 + |
| 5106 | get_interp_filter_selected(cm, LAST3_FRAME, ifilter) * 20 + |
| 5107 | get_interp_filter_selected(cm, GOLDEN_FRAME, ifilter) * 20 + |
| 5108 | get_interp_filter_selected(cm, BWDREF_FRAME, ifilter) * 10 + |
| 5109 | get_interp_filter_selected(cm, ALTREF2_FRAME, ifilter) * 10 + |
| 5110 | get_interp_filter_selected(cm, ALTREF_FRAME, ifilter) * 10; |
Satish Kumar Suman | 0389a49 | 2019-07-31 13:35:58 +0530 | [diff] [blame] | 5111 | if (filter_score < ref_total_total) { |
| 5112 | DUAL_FILTER_TYPE filt_type = ifilter + SWITCHABLE_FILTERS * ifilter; |
| 5113 | reset_interp_filter_allowed_mask(&mask, filt_type); |
| 5114 | } |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5115 | } |
| 5116 | } |
| 5117 | return mask; |
| 5118 | } |
| 5119 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5120 | static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5121 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5122 | RATE_CONTROL *const rc = &cpi->rc; |
chiyotsai | 6b43013 | 2019-12-18 10:33:51 -0800 | [diff] [blame] | 5123 | const int allow_recode = (cpi->sf.hl_sf.recode_loop != DISALLOW_RECODE); |
Hui Su | a1d7184 | 2019-07-31 12:02:24 -0700 | [diff] [blame] | 5124 | // Must allow recode if minimum compression ratio is set. |
| 5125 | assert(IMPLIES(cpi->oxcf.min_cr > 0, allow_recode)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5126 | |
| 5127 | set_size_independent_vars(cpi); |
Hamsalekha S | 37cc1d1 | 2019-12-12 19:27:41 +0530 | [diff] [blame] | 5128 | if (is_stat_consumption_stage_twopass(cpi) && |
chiyotsai | cbf1d11 | 2019-12-16 11:28:47 -0800 | [diff] [blame] | 5129 | cpi->sf.interp_sf.adaptive_interp_filter_search) |
Yunqing Wang | c3ab927 | 2019-11-01 17:43:58 -0700 | [diff] [blame] | 5130 | cpi->interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5131 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5132 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5133 | av1_setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5134 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5135 | #if CONFIG_SUPERRES_IN_RECODE |
| 5136 | if (superres_in_recode_allowed(cpi) && |
| 5137 | cm->superres_scale_denominator == SCALE_NUMERATOR) { |
| 5138 | // Superres won't be picked, so no need to try, as we will go through |
| 5139 | // another recode loop for full-resolution after this anyway. |
| 5140 | return -1; |
| 5141 | } |
| 5142 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 5143 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5144 | int top_index = 0, bottom_index = 0; |
| 5145 | int q = 0, q_low = 0, q_high = 0; |
| 5146 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 5147 | q_low = bottom_index; |
| 5148 | q_high = top_index; |
| 5149 | |
chiyotsai | dcc2e01 | 2019-12-17 10:29:32 -0800 | [diff] [blame] | 5150 | if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats && |
Yunqing Wang | 80a7af6 | 2019-08-22 16:07:44 -0700 | [diff] [blame] | 5151 | cm->current_frame.frame_type == KEY_FRAME) { |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 5152 | av1_copy(cpi->tx_type_probs, default_tx_type_probs); |
| 5153 | |
Yunqing Wang | 2348c03 | 2020-01-09 18:05:49 -0800 | [diff] [blame] | 5154 | const int thr[2][2] = { { 15, 10 }, { 17, 10 } }; |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 5155 | for (int f = 0; f < FRAME_UPDATE_TYPES; f++) { |
Yunqing Wang | eb7c218 | 2019-08-22 18:15:48 -0700 | [diff] [blame] | 5156 | int kf_arf_update = (f == KF_UPDATE || f == ARF_UPDATE); |
| 5157 | cpi->tx_type_probs_thresh[f] = |
chiyotsai | dcc2e01 | 2019-12-17 10:29:32 -0800 | [diff] [blame] | 5158 | thr[cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats - 1] |
Yunqing Wang | eb7c218 | 2019-08-22 18:15:48 -0700 | [diff] [blame] | 5159 | [kf_arf_update]; |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 5160 | } |
| 5161 | } |
| 5162 | |
chiyotsai | 868dc90 | 2019-12-12 15:32:52 -0800 | [diff] [blame] | 5163 | if (!cpi->sf.inter_sf.disable_obmc && |
| 5164 | cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 && |
Yunqing Wang | 5f74dc2 | 2019-10-29 10:35:20 -0700 | [diff] [blame] | 5165 | cm->current_frame.frame_type == KEY_FRAME) { |
| 5166 | av1_copy(cpi->obmc_probs, default_obmc_probs); |
Yunqing Wang | 5f74dc2 | 2019-10-29 10:35:20 -0700 | [diff] [blame] | 5167 | } |
chiyotsai | 868dc90 | 2019-12-12 15:32:52 -0800 | [diff] [blame] | 5168 | if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0 && |
Yunqing Wang | a09a46b | 2019-12-09 13:16:24 -0800 | [diff] [blame] | 5169 | cm->current_frame.frame_type == KEY_FRAME) { |
| 5170 | av1_copy(cpi->warped_probs, default_warped_probs); |
| 5171 | } |
Yunqing Wang | 5f74dc2 | 2019-10-29 10:35:20 -0700 | [diff] [blame] | 5172 | |
Yunqing Wang | 2348c03 | 2020-01-09 18:05:49 -0800 | [diff] [blame] | 5173 | if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2 && |
| 5174 | cm->current_frame.frame_type == KEY_FRAME) { |
| 5175 | av1_copy(cpi->switchable_interp_probs, default_switchable_interp_probs); |
| 5176 | |
| 5177 | const int thr[7] = { 0, 8, 8, 8, 8, 0, 8 }; |
| 5178 | for (int f = 0; f < FRAME_UPDATE_TYPES; f++) { |
| 5179 | cpi->switchable_interp_thresh[f] = thr[f]; |
| 5180 | } |
| 5181 | } |
| 5182 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5183 | // Loop variables |
| 5184 | int loop_count = 0; |
| 5185 | int loop_at_this_size = 0; |
| 5186 | int loop = 0; |
| 5187 | int overshoot_seen = 0; |
| 5188 | int undershoot_seen = 0; |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 5189 | int low_cr_seen = 0; |
chiyotsai | 8b7cef8 | 2020-01-21 16:52:54 -0800 | [diff] [blame] | 5190 | int last_loop_allow_hp = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5191 | |
| 5192 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5193 | printf("\n Encoding a frame:"); |
| 5194 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5195 | do { |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5196 | loop = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5197 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5198 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5199 | // if frame was scaled calculate global_motion_search again if already |
| 5200 | // done |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5201 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5202 | if (cpi->source->y_crop_width != cm->width || |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5203 | cpi->source->y_crop_height != cm->height) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5204 | cpi->global_motion_search_done = 0; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5205 | } |
| 5206 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5207 | cpi->source = |
| 5208 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5209 | if (cpi->unscaled_last_source != NULL) { |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 5210 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 5211 | &cpi->scaled_last_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5212 | } |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 5213 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5214 | if (!frame_is_intra_only(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5215 | if (loop_count > 0) { |
| 5216 | release_scaled_references(cpi); |
| 5217 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5218 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5219 | } |
sdeng | 3cd9eec | 2020-01-23 15:49:50 -0800 | [diff] [blame] | 5220 | #if CONFIG_TUNE_VMAF |
| 5221 | if (cpi->oxcf.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING || |
sdeng | 615dc24 | 2020-02-04 16:06:14 -0800 | [diff] [blame^] | 5222 | cpi->oxcf.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING || |
| 5223 | cpi->oxcf.tuning == AOM_TUNE_VMAF_MAX_GAIN) { |
sdeng | 3cd9eec | 2020-01-23 15:49:50 -0800 | [diff] [blame] | 5224 | av1_set_quantizer(cm, av1_get_vmaf_base_qindex(cpi, q)); |
| 5225 | } else { |
| 5226 | #endif |
| 5227 | av1_set_quantizer(cm, q); |
| 5228 | #if CONFIG_TUNE_VMAF |
| 5229 | } |
| 5230 | #endif |
| 5231 | |
Fyodor Kyslov | 25daf5d | 2019-10-23 10:33:26 -0700 | [diff] [blame] | 5232 | if (cpi->oxcf.deltaq_mode != NO_DELTA_Q) av1_init_quantizer(cpi); |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 5233 | |
| 5234 | av1_set_variance_partition_thresholds(cpi, q, 0); |
| 5235 | |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 5236 | // printf("Frame %d/%d: q = %d, frame_type = %d superres_denom = %d\n", |
| 5237 | // cm->current_frame.frame_number, cm->show_frame, q, |
| 5238 | // cm->current_frame.frame_type, cm->superres_scale_denominator); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5239 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5240 | if (loop_count == 0) { |
| 5241 | setup_frame(cpi); |
| 5242 | } else if (get_primary_ref_frame_buf(cm) == NULL) { |
| 5243 | // Base q-index may have changed, so we need to assign proper default coef |
| 5244 | // probs before every iteration. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5245 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 5246 | av1_setup_frame_contexts(cm); |
David Barker | fc91b39 | 2018-03-09 15:32:03 +0000 | [diff] [blame] | 5247 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5248 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5249 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5250 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5251 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5252 | av1_setup_in_frame_q_adj(cpi); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5253 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && !allow_recode) { |
| 5254 | suppress_active_map(cpi); |
| 5255 | av1_cyclic_refresh_setup(cpi); |
| 5256 | apply_active_map(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5257 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5258 | |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 5259 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 5260 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 5261 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
Jerome Jiang | b23571d | 2019-10-23 14:15:55 -0700 | [diff] [blame] | 5262 | cm->seg.enabled = cm->prev_frame->seg.enabled; |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 5263 | } else { |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 5264 | av1_calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 5265 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 5266 | } else { |
| 5267 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 5268 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 5269 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Jerome Jiang | b23571d | 2019-10-23 14:15:55 -0700 | [diff] [blame] | 5270 | cm->cur_frame->seg.enabled = cm->seg.enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5271 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5272 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5273 | start_timing(cpi, av1_encode_frame_time); |
| 5274 | #endif |
chiyotsai | 8b7cef8 | 2020-01-21 16:52:54 -0800 | [diff] [blame] | 5275 | // Set the motion vector precision based on mv stats from the last coded |
| 5276 | // frame. |
| 5277 | if (!frame_is_intra_only(cm)) { |
| 5278 | av1_pick_and_set_high_precision_mv(cpi, q); |
| 5279 | |
| 5280 | // If the precision has changed during different iteration of the loop, |
| 5281 | // then we need to reset the global motion vectors |
| 5282 | if (loop_count > 0 && cm->allow_high_precision_mv != last_loop_allow_hp) { |
| 5283 | cpi->global_motion_search_done = 0; |
| 5284 | } |
| 5285 | last_loop_allow_hp = cm->allow_high_precision_mv; |
| 5286 | } |
chiyotsai | c666b1f | 2019-12-20 10:44:58 -0800 | [diff] [blame] | 5287 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5288 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5289 | av1_encode_frame(cpi); |
chiyotsai | 51bd648 | 2019-12-20 10:49:34 -0800 | [diff] [blame] | 5290 | |
| 5291 | #if !CONFIG_REALTIME_ONLY |
| 5292 | // Reset the mv_stats in case we are interrupted by an intraframe or an |
| 5293 | // overlay frame. |
| 5294 | if (cpi->mv_stats.valid) { |
| 5295 | av1_zero(cpi->mv_stats); |
| 5296 | } |
| 5297 | // Gather the mv_stats for the next frame |
| 5298 | if (cpi->sf.hl_sf.high_precision_mv_usage == LAST_MV_DATA && |
| 5299 | av1_frame_allows_smart_mv(cpi)) { |
| 5300 | av1_collect_mv_stats(cpi, q); |
| 5301 | } |
| 5302 | #endif // !CONFIG_REALTIME_ONLY |
| 5303 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5304 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5305 | end_timing(cpi, av1_encode_frame_time); |
| 5306 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5307 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5308 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5309 | |
| 5310 | // Dummy pack of the bitstream using up to date stats to get an |
| 5311 | // accurate estimate of output frame size to determine if we need |
| 5312 | // to recode. |
chiyotsai | 6b43013 | 2019-12-18 10:33:51 -0800 | [diff] [blame] | 5313 | const int do_dummy_pack = |
| 5314 | (cpi->sf.hl_sf.recode_loop >= ALLOW_RECODE_KFARFGF && |
| 5315 | cpi->oxcf.rc_mode != AOM_Q) || |
| 5316 | cpi->oxcf.min_cr > 0; |
Hui Su | a1d7184 | 2019-07-31 12:02:24 -0700 | [diff] [blame] | 5317 | if (do_dummy_pack) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5318 | finalize_encoded_frame(cpi); |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5319 | int largest_tile_id = 0; // Output from bitstream: unused here |
chiyotsai | c666b1f | 2019-12-20 10:44:58 -0800 | [diff] [blame] | 5320 | if (av1_pack_bitstream(cpi, dest, size, &largest_tile_id) != |
| 5321 | AOM_CODEC_OK) { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5322 | return AOM_CODEC_ERROR; |
chiyotsai | c666b1f | 2019-12-20 10:44:58 -0800 | [diff] [blame] | 5323 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5324 | |
| 5325 | rc->projected_frame_size = (int)(*size) << 3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5326 | } |
| 5327 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 5328 | if (allow_recode) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5329 | // Update q and decide whether to do a recode loop |
| 5330 | recode_loop_update_q(cpi, &loop, &q, &q_low, &q_high, top_index, |
| 5331 | bottom_index, &undershoot_seen, &overshoot_seen, |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 5332 | &low_cr_seen, loop_at_this_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | // Special case for overlay frame. |
Hui Su | 7e3eeaa | 2019-09-11 15:50:41 -0700 | [diff] [blame] | 5336 | if (loop && rc->is_src_frame_alt_ref && |
| 5337 | rc->projected_frame_size < rc->max_frame_bandwidth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5338 | loop = 0; |
Hui Su | 7e3eeaa | 2019-09-11 15:50:41 -0700 | [diff] [blame] | 5339 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5340 | |
chiyotsai | 76cd265 | 2019-12-18 10:26:36 -0800 | [diff] [blame] | 5341 | if (allow_recode && !cpi->sf.gm_sf.gm_disable_recode && |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5342 | recode_loop_test_global_motion(cpi)) { |
| 5343 | loop = 1; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5344 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5345 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 5346 | #if !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5347 | if (cpi->tpl_model_pass == 1) { |
| 5348 | assert(cpi->oxcf.enable_tpl_model == 2); |
Debargha Mukherjee | 347c64d | 2019-05-08 13:53:46 -0700 | [diff] [blame] | 5349 | av1_tpl_setup_forward_stats(cpi); |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5350 | cpi->tpl_model_pass = 0; |
| 5351 | loop = 1; |
| 5352 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 5353 | #endif |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5354 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5355 | if (loop) { |
| 5356 | ++loop_count; |
| 5357 | ++loop_at_this_size; |
| 5358 | |
| 5359 | #if CONFIG_INTERNAL_STATS |
| 5360 | ++cpi->tot_recode_hits; |
| 5361 | #endif |
| 5362 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5363 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5364 | if (loop) printf("\n Recoding:"); |
| 5365 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5366 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5367 | |
Marco Paniconi | 574e59e | 2019-10-23 15:47:28 -0700 | [diff] [blame] | 5368 | // Update some stats from cyclic refresh. |
Marco Paniconi | 5141551 | 2019-11-27 12:38:24 -0800 | [diff] [blame] | 5369 | if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && !frame_is_intra_only(cm)) |
Marco Paniconi | 574e59e | 2019-10-23 15:47:28 -0700 | [diff] [blame] | 5370 | av1_cyclic_refresh_postencode(cpi); |
| 5371 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5372 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5373 | } |
| 5374 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5375 | static int encode_with_recode_loop_and_filter(AV1_COMP *cpi, size_t *size, |
| 5376 | uint8_t *dest, int64_t *sse, |
| 5377 | int64_t *rate, |
| 5378 | int *largest_tile_id) { |
| 5379 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5380 | start_timing(cpi, encode_with_recode_loop_time); |
| 5381 | #endif |
| 5382 | int err = encode_with_recode_loop(cpi, size, dest); |
| 5383 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5384 | end_timing(cpi, encode_with_recode_loop_time); |
| 5385 | #endif |
| 5386 | if (err != AOM_CODEC_OK) { |
| 5387 | if (err == -1) { |
| 5388 | // special case as described in encode_with_recode_loop(). |
| 5389 | // Encoding was skipped. |
| 5390 | err = AOM_CODEC_OK; |
| 5391 | if (sse != NULL) *sse = INT64_MAX; |
| 5392 | if (rate != NULL) *rate = INT64_MAX; |
| 5393 | *largest_tile_id = 0; |
| 5394 | } |
| 5395 | return err; |
| 5396 | } |
| 5397 | |
| 5398 | #ifdef OUTPUT_YUV_SKINMAP |
| 5399 | if (cpi->common.current_frame.frame_number > 1) { |
| 5400 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
| 5401 | } |
| 5402 | #endif // OUTPUT_YUV_SKINMAP |
| 5403 | |
| 5404 | AV1_COMMON *const cm = &cpi->common; |
| 5405 | SequenceHeader *const seq_params = &cm->seq_params; |
| 5406 | |
| 5407 | // Special case code to reduce pulsing when key frames are forced at a |
| 5408 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5409 | // the force key frame |
| 5410 | if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 5411 | #if CONFIG_AV1_HIGHBITDEPTH |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5412 | if (seq_params->use_highbitdepth) { |
| 5413 | cpi->ambient_err = aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5414 | } else { |
| 5415 | cpi->ambient_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5416 | } |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 5417 | #else |
| 5418 | cpi->ambient_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5419 | #endif |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | cm->cur_frame->buf.color_primaries = seq_params->color_primaries; |
| 5423 | cm->cur_frame->buf.transfer_characteristics = |
| 5424 | seq_params->transfer_characteristics; |
| 5425 | cm->cur_frame->buf.matrix_coefficients = seq_params->matrix_coefficients; |
| 5426 | cm->cur_frame->buf.monochrome = seq_params->monochrome; |
| 5427 | cm->cur_frame->buf.chroma_sample_position = |
| 5428 | seq_params->chroma_sample_position; |
| 5429 | cm->cur_frame->buf.color_range = seq_params->color_range; |
| 5430 | cm->cur_frame->buf.render_width = cm->render_width; |
| 5431 | cm->cur_frame->buf.render_height = cm->render_height; |
| 5432 | |
| 5433 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5434 | // off. |
| 5435 | |
| 5436 | // Pick the loop filter level for the frame. |
| 5437 | if (!cm->allow_intrabc) { |
| 5438 | loopfilter_frame(cpi, cm); |
| 5439 | } else { |
| 5440 | cm->lf.filter_level[0] = 0; |
| 5441 | cm->lf.filter_level[1] = 0; |
| 5442 | cm->cdef_info.cdef_bits = 0; |
| 5443 | cm->cdef_info.cdef_strengths[0] = 0; |
| 5444 | cm->cdef_info.nb_cdef_strengths = 1; |
| 5445 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
| 5446 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5447 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5448 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
| 5449 | } |
| 5450 | |
| 5451 | // TODO(debargha): Fix mv search range on encoder side |
| 5452 | // aom_extend_frame_inner_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
| 5453 | aom_extend_frame_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
| 5454 | |
| 5455 | #ifdef OUTPUT_YUV_REC |
| 5456 | aom_write_one_yuv_frame(cm, &cm->cur_frame->buf); |
| 5457 | #endif |
| 5458 | |
| 5459 | finalize_encoded_frame(cpi); |
| 5460 | // Build the bitstream |
| 5461 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5462 | start_timing(cpi, av1_pack_bitstream_final_time); |
| 5463 | #endif |
| 5464 | if (av1_pack_bitstream(cpi, dest, size, largest_tile_id) != AOM_CODEC_OK) |
| 5465 | return AOM_CODEC_ERROR; |
| 5466 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5467 | end_timing(cpi, av1_pack_bitstream_final_time); |
| 5468 | #endif |
| 5469 | |
| 5470 | // Compute sse and rate. |
| 5471 | if (sse != NULL) { |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 5472 | #if CONFIG_AV1_HIGHBITDEPTH |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5473 | *sse = (seq_params->use_highbitdepth) |
| 5474 | ? aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf) |
| 5475 | : aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 5476 | #else |
| 5477 | *sse = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5478 | #endif |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5479 | } |
| 5480 | if (rate != NULL) { |
| 5481 | const int64_t bits = (*size << 3); |
| 5482 | *rate = (bits << 5); // To match scale. |
| 5483 | } |
| 5484 | return AOM_CODEC_OK; |
| 5485 | } |
| 5486 | |
| 5487 | #if CONFIG_SUPERRES_IN_RECODE |
| 5488 | |
| 5489 | static void save_cur_buf(AV1_COMP *cpi) { |
| 5490 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5491 | AV1_COMMON *cm = &cpi->common; |
| 5492 | const YV12_BUFFER_CONFIG *ybf = &cm->cur_frame->buf; |
| 5493 | memset(&cc->copy_buffer, 0, sizeof(cc->copy_buffer)); |
| 5494 | if (aom_alloc_frame_buffer(&cc->copy_buffer, ybf->y_crop_width, |
| 5495 | ybf->y_crop_height, ybf->subsampling_x, |
| 5496 | ybf->subsampling_y, |
| 5497 | ybf->flags & YV12_FLAG_HIGHBITDEPTH, ybf->border, |
| 5498 | cm->byte_alignment) != AOM_CODEC_OK) { |
| 5499 | aom_internal_error( |
| 5500 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 5501 | "Failed to allocate copy buffer for saving coding context"); |
| 5502 | } |
| 5503 | aom_yv12_copy_frame(ybf, &cc->copy_buffer, av1_num_planes(cm)); |
| 5504 | } |
| 5505 | |
| 5506 | // Coding context that only needs to be saved when recode loop includes |
| 5507 | // filtering (deblocking, CDEF, superres post-encode upscale and/or loop |
| 5508 | // restoraton). |
| 5509 | static void save_extra_coding_context(AV1_COMP *cpi) { |
| 5510 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5511 | AV1_COMMON *cm = &cpi->common; |
| 5512 | |
| 5513 | cc->lf = cm->lf; |
| 5514 | cc->cdef_info = cm->cdef_info; |
| 5515 | cc->rc = cpi->rc; |
| 5516 | } |
| 5517 | |
| 5518 | static void save_all_coding_context(AV1_COMP *cpi) { |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5519 | save_cur_buf(cpi); |
| 5520 | save_extra_coding_context(cpi); |
| 5521 | if (!frame_is_intra_only(&cpi->common)) release_scaled_references(cpi); |
| 5522 | } |
| 5523 | |
| 5524 | static void restore_cur_buf(AV1_COMP *cpi) { |
| 5525 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5526 | AV1_COMMON *cm = &cpi->common; |
| 5527 | aom_yv12_copy_frame(&cc->copy_buffer, &cm->cur_frame->buf, |
| 5528 | av1_num_planes(cm)); |
| 5529 | } |
| 5530 | |
| 5531 | // Coding context that only needs to be restored when recode loop includes |
| 5532 | // filtering (deblocking, CDEF, superres post-encode upscale and/or loop |
| 5533 | // restoraton). |
| 5534 | static void restore_extra_coding_context(AV1_COMP *cpi) { |
| 5535 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5536 | AV1_COMMON *cm = &cpi->common; |
| 5537 | cm->lf = cc->lf; |
| 5538 | cm->cdef_info = cc->cdef_info; |
| 5539 | cpi->rc = cc->rc; |
| 5540 | } |
| 5541 | |
| 5542 | static void restore_all_coding_context(AV1_COMP *cpi) { |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5543 | restore_cur_buf(cpi); |
| 5544 | restore_extra_coding_context(cpi); |
| 5545 | if (!frame_is_intra_only(&cpi->common)) release_scaled_references(cpi); |
| 5546 | } |
| 5547 | |
| 5548 | static int encode_with_and_without_superres(AV1_COMP *cpi, size_t *size, |
| 5549 | uint8_t *dest, |
| 5550 | int *largest_tile_id) { |
| 5551 | const AV1_COMMON *const cm = &cpi->common; |
| 5552 | AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5553 | assert(cm->seq_params.enable_superres); |
| 5554 | assert(superres_in_recode_allowed(cpi)); |
| 5555 | aom_codec_err_t err = AOM_CODEC_OK; |
| 5556 | save_all_coding_context(cpi); |
| 5557 | |
| 5558 | // Encode with superres. |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5559 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5560 | int64_t superres_sses[SCALE_NUMERATOR]; |
| 5561 | int64_t superres_rates[SCALE_NUMERATOR]; |
| 5562 | int superres_largest_tile_ids[SCALE_NUMERATOR]; |
| 5563 | // Use superres for Key-frames and Alt-ref frames only. |
| 5564 | const GF_GROUP *const gf_group = &cpi->gf_group; |
| 5565 | if (gf_group->update_type[gf_group->index] != OVERLAY_UPDATE && |
| 5566 | gf_group->update_type[gf_group->index] != INTNL_OVERLAY_UPDATE) { |
| 5567 | for (int denom = SCALE_NUMERATOR + 1; denom <= 2 * SCALE_NUMERATOR; |
| 5568 | ++denom) { |
| 5569 | oxcf->superres_scale_denominator = denom; |
| 5570 | oxcf->superres_kf_scale_denominator = denom; |
| 5571 | const int this_index = denom - (SCALE_NUMERATOR + 1); |
| 5572 | err = encode_with_recode_loop_and_filter( |
| 5573 | cpi, size, dest, &superres_sses[this_index], |
| 5574 | &superres_rates[this_index], &superres_largest_tile_ids[this_index]); |
| 5575 | if (err != AOM_CODEC_OK) return err; |
| 5576 | restore_all_coding_context(cpi); |
| 5577 | } |
| 5578 | // Reset. |
| 5579 | oxcf->superres_scale_denominator = SCALE_NUMERATOR; |
| 5580 | oxcf->superres_kf_scale_denominator = SCALE_NUMERATOR; |
| 5581 | } else { |
| 5582 | for (int denom = SCALE_NUMERATOR + 1; denom <= 2 * SCALE_NUMERATOR; |
| 5583 | ++denom) { |
| 5584 | const int this_index = denom - (SCALE_NUMERATOR + 1); |
| 5585 | superres_sses[this_index] = INT64_MAX; |
| 5586 | superres_rates[this_index] = INT64_MAX; |
| 5587 | } |
| 5588 | } |
| 5589 | #else |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5590 | int64_t sse1 = INT64_MAX; |
| 5591 | int64_t rate1 = INT64_MAX; |
| 5592 | int largest_tile_id1; |
| 5593 | err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse1, &rate1, |
| 5594 | &largest_tile_id1); |
| 5595 | if (err != AOM_CODEC_OK) return err; |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5596 | restore_all_coding_context(cpi); |
| 5597 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5598 | |
| 5599 | // Encode without superres. |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5600 | int64_t sse2 = INT64_MAX; |
| 5601 | int64_t rate2 = INT64_MAX; |
| 5602 | int largest_tile_id2; |
| 5603 | oxcf->superres_mode = SUPERRES_NONE; // To force full-res. |
| 5604 | err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse2, &rate2, |
| 5605 | &largest_tile_id2); |
| 5606 | oxcf->superres_mode = SUPERRES_AUTO; // Reset. |
| 5607 | if (err != AOM_CODEC_OK) return err; |
| 5608 | |
| 5609 | // Note: Both use common rdmult based on base qindex of fullres. |
| 5610 | const int64_t rdmult = |
| 5611 | av1_compute_rd_mult_based_on_qindex(cpi, cm->base_qindex); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5612 | |
| 5613 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5614 | // Find the best rdcost among all superres denoms. |
| 5615 | double proj_rdcost1 = DBL_MAX; |
| 5616 | int64_t sse1 = INT64_MAX; |
| 5617 | int64_t rate1 = INT64_MAX; |
| 5618 | int largest_tile_id1 = 0; |
| 5619 | (void)sse1; |
| 5620 | (void)rate1; |
| 5621 | (void)largest_tile_id1; |
| 5622 | int best_denom = -1; |
| 5623 | for (int denom = SCALE_NUMERATOR + 1; denom <= 2 * SCALE_NUMERATOR; ++denom) { |
| 5624 | const int this_index = denom - (SCALE_NUMERATOR + 1); |
| 5625 | const int64_t this_sse = superres_sses[this_index]; |
| 5626 | const int64_t this_rate = superres_rates[this_index]; |
| 5627 | const int this_largest_tile_id = superres_largest_tile_ids[this_index]; |
| 5628 | const double this_rdcost = RDCOST_DBL(rdmult, this_rate, this_sse); |
| 5629 | if (this_rdcost < proj_rdcost1) { |
| 5630 | sse1 = this_sse; |
| 5631 | rate1 = this_rate; |
| 5632 | largest_tile_id1 = this_largest_tile_id; |
| 5633 | proj_rdcost1 = this_rdcost; |
| 5634 | best_denom = denom; |
| 5635 | } |
| 5636 | } |
| 5637 | #else |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5638 | const double proj_rdcost1 = RDCOST_DBL(rdmult, rate1, sse1); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5639 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5640 | const double proj_rdcost2 = RDCOST_DBL(rdmult, rate2, sse2); |
| 5641 | |
| 5642 | // Re-encode with superres if it's better. |
| 5643 | if (proj_rdcost1 < proj_rdcost2) { |
| 5644 | restore_all_coding_context(cpi); |
| 5645 | // TODO(urvang): We should avoid rerunning the recode loop by saving |
| 5646 | // previous output+state, or running encode only for the selected 'q' in |
| 5647 | // previous step. |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5648 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5649 | // Again, temporarily force the best denom. |
| 5650 | oxcf->superres_scale_denominator = best_denom; |
| 5651 | oxcf->superres_kf_scale_denominator = best_denom; |
| 5652 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5653 | int64_t sse3 = INT64_MAX; |
| 5654 | int64_t rate3 = INT64_MAX; |
| 5655 | err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse3, &rate3, |
| 5656 | largest_tile_id); |
| 5657 | assert(sse1 == sse3); |
| 5658 | assert(rate1 == rate3); |
| 5659 | assert(largest_tile_id1 == *largest_tile_id); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5660 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5661 | // Reset. |
| 5662 | oxcf->superres_scale_denominator = SCALE_NUMERATOR; |
| 5663 | oxcf->superres_kf_scale_denominator = SCALE_NUMERATOR; |
| 5664 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5665 | } else { |
| 5666 | *largest_tile_id = largest_tile_id2; |
| 5667 | } |
| 5668 | |
| 5669 | return err; |
| 5670 | } |
| 5671 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 5672 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5673 | #define DUMP_RECON_FRAMES 0 |
| 5674 | |
| 5675 | #if DUMP_RECON_FRAMES == 1 |
| 5676 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5677 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 5678 | AV1_COMMON *const cm = &cpi->common; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5679 | const CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5680 | const YV12_BUFFER_CONFIG *recon_buf = &cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5681 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5682 | if (recon_buf == NULL) { |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5683 | printf("Frame %d is not ready.\n", current_frame->frame_number); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5684 | return; |
| 5685 | } |
| 5686 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 5687 | static const int flag_list[REF_FRAMES] = { 0, |
| 5688 | AOM_LAST_FLAG, |
| 5689 | AOM_LAST2_FLAG, |
| 5690 | AOM_LAST3_FLAG, |
| 5691 | AOM_GOLD_FLAG, |
| 5692 | AOM_BWD_FLAG, |
| 5693 | AOM_ALT2_FLAG, |
| 5694 | AOM_ALT_FLAG }; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5695 | printf( |
| 5696 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 5697 | "show_existing_frame=%d) " |
| 5698 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5699 | current_frame->frame_number, current_frame->order_hint, cm->show_frame, |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5700 | cm->show_existing_frame); |
| 5701 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 5702 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
| 5703 | const int ref_offset = buf != NULL ? (int)buf->order_hint : -1; |
Urvang Joshi | b6f1767 | 2019-03-05 11:51:02 -0800 | [diff] [blame] | 5704 | printf(" %d(%c)", ref_offset, |
| 5705 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N'); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5706 | } |
| 5707 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5708 | |
| 5709 | if (!cm->show_frame) { |
| 5710 | printf("Frame %d is a no show frame, so no image dump.\n", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5711 | current_frame->frame_number); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5712 | return; |
| 5713 | } |
| 5714 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5715 | int h; |
| 5716 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 5717 | FILE *f_recon = NULL; |
| 5718 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5719 | if (current_frame->frame_number == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5720 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 5721 | printf("Unable to open file %s to write.\n", file_name); |
| 5722 | return; |
| 5723 | } |
| 5724 | } else { |
| 5725 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 5726 | printf("Unable to open file %s to append.\n", file_name); |
| 5727 | return; |
| 5728 | } |
| 5729 | } |
| 5730 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 5731 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 5732 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
Urvang Joshi | 7a89023 | 2019-03-22 17:00:31 -0700 | [diff] [blame] | 5733 | "refresh_alt_ref_frame=%d, " |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 5734 | "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n", |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 5735 | current_frame->frame_number, cpi->gf_group.index, |
| 5736 | cpi->gf_group.update_type[cpi->gf_group.index], current_frame->order_hint, |
| 5737 | cm->show_frame, cm->show_existing_frame, cpi->rc.source_alt_ref_active, |
| 5738 | cpi->refresh_alt_ref_frame, recon_buf->y_stride, recon_buf->uv_stride, |
| 5739 | cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5740 | #if 0 |
| 5741 | int ref_frame; |
| 5742 | printf("get_ref_frame_map_idx: ["); |
| 5743 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 5744 | printf(" %d", get_ref_frame_map_idx(cm, ref_frame)); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5745 | printf(" ]\n"); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5746 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5747 | |
| 5748 | // --- Y --- |
| 5749 | for (h = 0; h < cm->height; ++h) { |
| 5750 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 5751 | f_recon); |
| 5752 | } |
| 5753 | // --- U --- |
| 5754 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5755 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5756 | f_recon); |
| 5757 | } |
| 5758 | // --- V --- |
| 5759 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5760 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5761 | f_recon); |
| 5762 | } |
| 5763 | |
| 5764 | fclose(f_recon); |
| 5765 | } |
| 5766 | #endif // DUMP_RECON_FRAMES |
| 5767 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5768 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 5769 | const YV12_BUFFER_CONFIG *last_picture, |
| 5770 | hash_table *last_hash_table) { |
| 5771 | aom_clear_system_state(); |
| 5772 | // check use hash ME |
| 5773 | int k; |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5774 | |
Ranjit Kumar Tulabandu | 9f26c99 | 2019-10-24 12:24:52 +0530 | [diff] [blame] | 5775 | const int block_size = FORCE_INT_MV_DECISION_BLOCK_SIZE; |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5776 | const double threshold_current = 0.8; |
| 5777 | const double threshold_average = 0.95; |
| 5778 | const int max_history_size = 32; |
| 5779 | int T = 0; // total block |
| 5780 | int C = 0; // match with collocated block |
| 5781 | int S = 0; // smooth region but not match with collocated block |
| 5782 | int M = 0; // match with other block |
| 5783 | |
| 5784 | const int pic_width = cur_picture->y_width; |
| 5785 | const int pic_height = cur_picture->y_height; |
| 5786 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 5787 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 5788 | const int x_pos = j; |
| 5789 | const int y_pos = i; |
| 5790 | int match = 1; |
| 5791 | T++; |
| 5792 | |
| 5793 | // check whether collocated block match with current |
| 5794 | uint8_t *p_cur = cur_picture->y_buffer; |
| 5795 | uint8_t *p_ref = last_picture->y_buffer; |
| 5796 | int stride_cur = cur_picture->y_stride; |
| 5797 | int stride_ref = last_picture->y_stride; |
| 5798 | p_cur += (y_pos * stride_cur + x_pos); |
| 5799 | p_ref += (y_pos * stride_ref + x_pos); |
| 5800 | |
| 5801 | if (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5802 | uint16_t *p16_cur = CONVERT_TO_SHORTPTR(p_cur); |
| 5803 | uint16_t *p16_ref = CONVERT_TO_SHORTPTR(p_ref); |
| 5804 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5805 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5806 | if (p16_cur[tmpX] != p16_ref[tmpX]) { |
| 5807 | match = 0; |
| 5808 | } |
| 5809 | } |
| 5810 | p16_cur += stride_cur; |
| 5811 | p16_ref += stride_ref; |
| 5812 | } |
| 5813 | } else { |
| 5814 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5815 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5816 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 5817 | match = 0; |
| 5818 | } |
| 5819 | } |
| 5820 | p_cur += stride_cur; |
| 5821 | p_ref += stride_ref; |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | if (match) { |
| 5826 | C++; |
| 5827 | continue; |
| 5828 | } |
| 5829 | |
| 5830 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 5831 | y_pos) || |
| 5832 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 5833 | S++; |
| 5834 | continue; |
| 5835 | } |
Remya | a14a458 | 2019-11-05 13:17:36 +0530 | [diff] [blame] | 5836 | if (av1_use_hash_me(cpi)) { |
| 5837 | uint32_t hash_value_1; |
| 5838 | uint32_t hash_value_2; |
| 5839 | av1_get_block_hash_value( |
| 5840 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 5841 | block_size, &hash_value_1, &hash_value_2, |
| 5842 | (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb); |
| 5843 | // Hashing does not work for highbitdepth currently. |
| 5844 | // TODO(Roger): Make it work for highbitdepth. |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5845 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 5846 | M++; |
| 5847 | } |
| 5848 | } |
| 5849 | } |
| 5850 | } |
| 5851 | |
| 5852 | assert(T > 0); |
| 5853 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 5854 | double m_rate = ((double)(M)) / ((double)(T)); |
| 5855 | |
| 5856 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 5857 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 5858 | |
| 5859 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 5860 | cpi->rate_size++; |
| 5861 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 5862 | |
| 5863 | if (csm_rate < threshold_current) { |
| 5864 | return 0; |
| 5865 | } |
| 5866 | |
| 5867 | if (C == T) { |
| 5868 | return 1; |
| 5869 | } |
| 5870 | |
| 5871 | double csm_average = 0.0; |
| 5872 | double m_average = 0.0; |
| 5873 | |
| 5874 | for (k = 0; k < cpi->rate_size; k++) { |
| 5875 | csm_average += cpi->csm_rate_array[k]; |
| 5876 | m_average += cpi->m_rate_array[k]; |
| 5877 | } |
| 5878 | csm_average /= cpi->rate_size; |
| 5879 | m_average /= cpi->rate_size; |
| 5880 | |
| 5881 | if (csm_average < threshold_average) { |
| 5882 | return 0; |
| 5883 | } |
| 5884 | |
| 5885 | if (M > (T - C - S) / 3) { |
| 5886 | return 1; |
| 5887 | } |
| 5888 | |
| 5889 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 5890 | return 1; |
| 5891 | } |
| 5892 | |
| 5893 | if (csm_average + m_average > 1.01) { |
| 5894 | return 1; |
| 5895 | } |
| 5896 | |
| 5897 | return 0; |
| 5898 | } |
| 5899 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5900 | // Refresh reference frame buffers according to refresh_frame_flags. |
| 5901 | static void refresh_reference_frames(AV1_COMP *cpi) { |
| 5902 | AV1_COMMON *const cm = &cpi->common; |
| 5903 | // All buffers are refreshed for shown keyframes and S-frames. |
| 5904 | |
| 5905 | for (int ref_frame = 0; ref_frame < REF_FRAMES; ref_frame++) { |
| 5906 | if (((cm->current_frame.refresh_frame_flags >> ref_frame) & 1) == 1) { |
| 5907 | assign_frame_buffer_p(&cm->ref_frame_map[ref_frame], cm->cur_frame); |
| 5908 | } |
| 5909 | } |
| 5910 | } |
| 5911 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 5912 | static void set_mb_ssim_rdmult_scaling(AV1_COMP *cpi) { |
| 5913 | AV1_COMMON *cm = &cpi->common; |
| 5914 | ThreadData *td = &cpi->td; |
| 5915 | MACROBLOCK *x = &td->mb; |
| 5916 | MACROBLOCKD *xd = &x->e_mbd; |
| 5917 | uint8_t *y_buffer = cpi->source->y_buffer; |
| 5918 | const int y_stride = cpi->source->y_stride; |
| 5919 | const int block_size = BLOCK_16X16; |
| 5920 | |
| 5921 | const int num_mi_w = mi_size_wide[block_size]; |
| 5922 | const int num_mi_h = mi_size_high[block_size]; |
| 5923 | const int num_cols = (cm->mi_cols + num_mi_w - 1) / num_mi_w; |
| 5924 | const int num_rows = (cm->mi_rows + num_mi_h - 1) / num_mi_h; |
| 5925 | double log_sum = 0.0; |
| 5926 | int row, col; |
| 5927 | const int use_hbd = cpi->source->flags & YV12_FLAG_HIGHBITDEPTH; |
| 5928 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 5929 | // Loop through each 16x16 block. |
| 5930 | for (row = 0; row < num_rows; ++row) { |
| 5931 | for (col = 0; col < num_cols; ++col) { |
| 5932 | int mi_row, mi_col; |
| 5933 | double var = 0.0, num_of_var = 0.0; |
| 5934 | const int index = row * num_cols + col; |
| 5935 | |
| 5936 | // Loop through each 8x8 block. |
| 5937 | for (mi_row = row * num_mi_h; |
| 5938 | mi_row < cm->mi_rows && mi_row < (row + 1) * num_mi_h; mi_row += 2) { |
| 5939 | for (mi_col = col * num_mi_w; |
| 5940 | mi_col < cm->mi_cols && mi_col < (col + 1) * num_mi_w; |
| 5941 | mi_col += 2) { |
| 5942 | struct buf_2d buf; |
| 5943 | const int row_offset_y = mi_row << 2; |
| 5944 | const int col_offset_y = mi_col << 2; |
| 5945 | |
| 5946 | buf.buf = y_buffer + row_offset_y * y_stride + col_offset_y; |
| 5947 | buf.stride = y_stride; |
| 5948 | |
| 5949 | if (use_hbd) { |
| 5950 | var += av1_high_get_sby_perpixel_variance(cpi, &buf, BLOCK_8X8, |
| 5951 | xd->bd); |
| 5952 | } else { |
| 5953 | var += av1_get_sby_perpixel_variance(cpi, &buf, BLOCK_8X8); |
| 5954 | } |
| 5955 | |
| 5956 | num_of_var += 1.0; |
| 5957 | } |
| 5958 | } |
sdeng | 32185d1 | 2019-06-19 14:47:09 -0700 | [diff] [blame] | 5959 | var = var / num_of_var; |
sdeng | bdc0cd2 | 2019-11-11 15:09:34 -0800 | [diff] [blame] | 5960 | |
| 5961 | // Curve fitting with an exponential model on all 16x16 blocks from the |
| 5962 | // midres dataset. |
| 5963 | var = 67.035434 * (1 - exp(-0.0021489 * var)) + 17.492222; |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 5964 | cpi->ssim_rdmult_scaling_factors[index] = var; |
| 5965 | log_sum += log(var); |
| 5966 | } |
| 5967 | } |
| 5968 | log_sum = exp(log_sum / (double)(num_rows * num_cols)); |
| 5969 | |
| 5970 | for (row = 0; row < num_rows; ++row) { |
| 5971 | for (col = 0; col < num_cols; ++col) { |
| 5972 | const int index = row * num_cols + col; |
| 5973 | cpi->ssim_rdmult_scaling_factors[index] /= log_sum; |
| 5974 | } |
| 5975 | } |
| 5976 | |
| 5977 | (void)xd; |
| 5978 | } |
| 5979 | |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 5980 | #if CONFIG_DEBUG |
| 5981 | static int hash_me_has_at_most_two_refs(RefCntBuffer *frame_bufs) { |
| 5982 | int total_count = 0; |
| 5983 | for (int frame_idx = 0; frame_idx < FRAME_BUFFERS; ++frame_idx) { |
| 5984 | if (frame_bufs[frame_idx].hash_table.has_content > 1) { |
| 5985 | return 0; |
| 5986 | } |
| 5987 | total_count += frame_bufs[frame_idx].hash_table.has_content; |
| 5988 | } |
| 5989 | |
| 5990 | return total_count <= 2; |
| 5991 | } |
| 5992 | #endif |
| 5993 | |
Yunqing Wang | d8fd9e7 | 2019-12-26 15:36:31 -0800 | [diff] [blame] | 5994 | extern void av1_print_frame_contexts(const FRAME_CONTEXT *fc, |
| 5995 | const char *filename); |
| 5996 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5997 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, |
| 5998 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5999 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6000 | SequenceHeader *const seq_params = &cm->seq_params; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6001 | CurrentFrame *const current_frame = &cm->current_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6002 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6003 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 6004 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6005 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 6006 | start_timing(cpi, encode_frame_to_data_rate_time); |
| 6007 | #endif |
| 6008 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 6009 | // frame type has been decided outside of this function call |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6010 | cm->cur_frame->frame_type = current_frame->frame_type; |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 6011 | |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 6012 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 6013 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 6014 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6015 | cm->allow_ref_frame_mvs &= frame_might_allow_ref_frame_mvs(cm); |
Yunqing Wang | d48fb16 | 2018-06-15 10:55:28 -0700 | [diff] [blame] | 6016 | // cm->allow_ref_frame_mvs needs to be written into the frame header while |
| 6017 | // cm->large_scale_tile is 1, therefore, "cm->large_scale_tile=1" case is |
| 6018 | // separated from frame_might_allow_ref_frame_mvs(). |
| 6019 | cm->allow_ref_frame_mvs &= !cm->large_scale_tile; |
| 6020 | |
Debargha Mukherjee | 1d7217e | 2018-03-26 13:32:13 -0700 | [diff] [blame] | 6021 | cm->allow_warped_motion = |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 6022 | cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6023 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 6024 | cm->last_frame_type = current_frame->frame_type; |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 6025 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 6026 | if (encode_show_existing_frame(cm)) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 6027 | finalize_encoded_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6028 | // Build the bitstream |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 6029 | int largest_tile_id = 0; // Output from bitstream: unused here |
| 6030 | if (av1_pack_bitstream(cpi, dest, size, &largest_tile_id) != AOM_CODEC_OK) |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6031 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6032 | |
David Turner | 9031186 | 2018-11-29 13:34:36 +0000 | [diff] [blame] | 6033 | if (seq_params->frame_id_numbers_present_flag && |
| 6034 | current_frame->frame_type == KEY_FRAME) { |
| 6035 | // Displaying a forward key-frame, so reset the ref buffer IDs |
| 6036 | int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show]; |
| 6037 | for (int i = 0; i < REF_FRAMES; i++) |
| 6038 | cm->ref_frame_id[i] = display_frame_id; |
| 6039 | } |
| 6040 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 6041 | cpi->seq_params_locked = 1; |
| 6042 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6043 | #if DUMP_RECON_FRAMES == 1 |
| 6044 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 6045 | dump_filtered_recon_frames(cpi); |
| 6046 | #endif // DUMP_RECON_FRAMES |
| 6047 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6048 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 6049 | // for the purpose to verify no mismatch between encoder and decoder. |
| 6050 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6051 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6052 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6053 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6054 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 6055 | // to do post-encoding update accordingly. |
| 6056 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 6057 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6058 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6059 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6060 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6061 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6062 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6063 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6064 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6065 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 6066 | // Work out whether to force_integer_mv this frame |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6067 | if (!is_stat_generation_stage(cpi) && |
| 6068 | cpi->common.allow_screen_content_tools && !frame_is_intra_only(cm)) { |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 6069 | if (cpi->common.seq_params.force_integer_mv == 2) { |
| 6070 | // Adaptive mode: see what previous frame encoded did |
| 6071 | if (cpi->unscaled_last_source != NULL) { |
| 6072 | cm->cur_frame_force_integer_mv = |
| 6073 | is_integer_mv(cpi, cpi->source, cpi->unscaled_last_source, |
| 6074 | cpi->previous_hash_table); |
| 6075 | } else { |
| 6076 | cpi->common.cur_frame_force_integer_mv = 0; |
| 6077 | } |
| 6078 | } else { |
| 6079 | cpi->common.cur_frame_force_integer_mv = |
| 6080 | cpi->common.seq_params.force_integer_mv; |
| 6081 | } |
| 6082 | } else { |
| 6083 | cpi->common.cur_frame_force_integer_mv = 0; |
| 6084 | } |
| 6085 | |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 6086 | #if CONFIG_DEBUG |
| 6087 | assert(hash_me_has_at_most_two_refs(cm->buffer_pool->frame_bufs) && |
| 6088 | "Hash-me is leaking memory!"); |
| 6089 | #endif |
| 6090 | |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6091 | if (!is_stat_generation_stage(cpi) && cpi->need_to_clear_prev_hash_table) { |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 6092 | av1_hash_table_clear_all(cpi->previous_hash_table); |
| 6093 | cpi->need_to_clear_prev_hash_table = 0; |
| 6094 | } |
| 6095 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6096 | // Set default state for segment based loop filter update flags. |
| 6097 | cm->lf.mode_ref_delta_update = 0; |
| 6098 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6099 | // Set various flags etc to special state if it is a key frame. |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 6100 | if (frame_is_intra_only(cm) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6101 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6102 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6103 | |
| 6104 | // If segmentation is enabled force a map update for key frames. |
| 6105 | if (seg->enabled) { |
| 6106 | seg->update_map = 1; |
| 6107 | seg->update_data = 1; |
| 6108 | } |
| 6109 | |
| 6110 | // The alternate reference frame cannot be active for a key frame. |
| 6111 | cpi->rc.source_alt_ref_active = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6112 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 6113 | if (cpi->oxcf.mtu == 0) { |
| 6114 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 6115 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 6116 | // Use a default value for the purposes of weighting costs in probability |
| 6117 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 6118 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 6119 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6120 | |
| 6121 | // For 1 pass CBR, check if we are dropping this frame. |
| 6122 | // Never drop on key frame. |
Mufaddal Chakera | 3bcc72c | 2019-12-11 14:38:37 +0530 | [diff] [blame] | 6123 | if (has_no_stats_stage(cpi) && oxcf->rc_mode == AOM_CBR && |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6124 | current_frame->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6125 | if (av1_rc_drop_frame(cpi)) { |
| 6126 | av1_rc_postencode_update_drop_frame(cpi); |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 6127 | release_scaled_references(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6128 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6129 | } |
| 6130 | } |
| 6131 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 6132 | if (oxcf->tuning == AOM_TUNE_SSIM) set_mb_ssim_rdmult_scaling(cpi); |
| 6133 | |
sdeng | 0195916 | 2019-12-20 10:46:24 -0800 | [diff] [blame] | 6134 | #if CONFIG_TUNE_VMAF |
| 6135 | if (oxcf->tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING || |
sdeng | 615dc24 | 2020-02-04 16:06:14 -0800 | [diff] [blame^] | 6136 | oxcf->tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING || |
| 6137 | oxcf->tuning == AOM_TUNE_VMAF_MAX_GAIN) { |
sdeng | 0195916 | 2019-12-20 10:46:24 -0800 | [diff] [blame] | 6138 | av1_set_mb_vmaf_rdmult_scaling(cpi); |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 6139 | } |
sdeng | 0195916 | 2019-12-20 10:46:24 -0800 | [diff] [blame] | 6140 | #endif |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 6141 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6142 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6143 | |
| 6144 | #if CONFIG_INTERNAL_STATS |
| 6145 | memset(cpi->mode_chosen_counts, 0, |
| 6146 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 6147 | #endif |
| 6148 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6149 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6150 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 6151 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6152 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 6153 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6154 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6155 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 6156 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 6157 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 6158 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6159 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 6160 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 6161 | } |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 6162 | cm->current_frame_id = |
| 6163 | ((msb << 8) + lsb) % (1 << seq_params->frame_id_length); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 6164 | |
| 6165 | // S_frame is meant for stitching different streams of different |
| 6166 | // resolutions together, so current_frame_id must be the |
| 6167 | // same across different streams of the same content current_frame_id |
| 6168 | // should be the same and not random. 0x37 is a chosen number as start |
| 6169 | // point |
| 6170 | if (cpi->oxcf.sframe_enabled) cm->current_frame_id = 0x37; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6171 | } else { |
| 6172 | cm->current_frame_id = |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 6173 | (cm->current_frame_id + 1 + (1 << seq_params->frame_id_length)) % |
| 6174 | (1 << seq_params->frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6175 | } |
| 6176 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6177 | |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 6178 | switch (cpi->oxcf.cdf_update_mode) { |
| 6179 | case 0: // No CDF update for any frames(4~6% compression loss). |
| 6180 | cm->disable_cdf_update = 1; |
| 6181 | break; |
| 6182 | case 1: // Enable CDF update for all frames. |
| 6183 | cm->disable_cdf_update = 0; |
| 6184 | break; |
| 6185 | case 2: |
| 6186 | // Strategically determine at which frames to do CDF update. |
| 6187 | // Currently only enable CDF update for all-intra and no-show frames(1.5% |
| 6188 | // compression loss). |
| 6189 | // TODO(huisu@google.com): design schemes for various trade-offs between |
| 6190 | // compression quality and decoding speed. |
Hui Su | b1b76b3 | 2018-02-27 15:24:48 -0800 | [diff] [blame] | 6191 | cm->disable_cdf_update = |
| 6192 | (frame_is_intra_only(cm) || !cm->show_frame) ? 0 : 1; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 6193 | break; |
| 6194 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6195 | cm->timing_info_present &= !seq_params->reduced_still_picture_hdr; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 6196 | |
Hamsalekha S | 37cc1d1 | 2019-12-12 19:27:41 +0530 | [diff] [blame] | 6197 | if (is_stat_consumption_stage_twopass(cpi) && |
| 6198 | cpi->oxcf.enable_tpl_model == 2 && |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 6199 | current_frame->frame_type == INTER_FRAME) { |
| 6200 | if (!cm->show_frame) { |
| 6201 | assert(cpi->tpl_model_pass == 0); |
| 6202 | cpi->tpl_model_pass = 1; |
| 6203 | } |
| 6204 | } |
| 6205 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 6206 | int largest_tile_id = 0; |
| 6207 | #if CONFIG_SUPERRES_IN_RECODE |
| 6208 | if (superres_in_recode_allowed(cpi)) { |
| 6209 | if (encode_with_and_without_superres(cpi, size, dest, &largest_tile_id) != |
| 6210 | AOM_CODEC_OK) { |
| 6211 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6212 | } |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 6213 | } else { |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 6214 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 6215 | if (encode_with_recode_loop_and_filter(cpi, size, dest, NULL, NULL, |
| 6216 | &largest_tile_id) != AOM_CODEC_OK) { |
| 6217 | return AOM_CODEC_ERROR; |
| 6218 | } |
| 6219 | #if CONFIG_SUPERRES_IN_RECODE |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 6220 | } |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 6221 | #endif // CONFIG_SUPERRES_IN_RECODE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6222 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 6223 | cpi->seq_params_locked = 1; |
| 6224 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 6225 | // Update reference frame ids for reference frames this frame will overwrite |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6226 | if (seq_params->frame_id_numbers_present_flag) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 6227 | for (int i = 0; i < REF_FRAMES; i++) { |
| 6228 | if ((current_frame->refresh_frame_flags >> i) & 1) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6229 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 6230 | } |
| 6231 | } |
| 6232 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6233 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6234 | #if DUMP_RECON_FRAMES == 1 |
| 6235 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 6236 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6237 | #endif // DUMP_RECON_FRAMES |
| 6238 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 6239 | if (cm->seg.enabled) { |
| 6240 | if (cm->seg.update_map) { |
| 6241 | update_reference_segmentation_map(cpi); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 6242 | } else if (cm->last_frame_seg_map) { |
David Turner | b757ce0 | 2018-11-12 15:01:28 +0000 | [diff] [blame] | 6243 | memcpy(cm->cur_frame->seg_map, cm->last_frame_seg_map, |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 6244 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 6245 | } |
| 6246 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6247 | |
| 6248 | if (frame_is_intra_only(cm) == 0) { |
| 6249 | release_scaled_references(cpi); |
| 6250 | } |
| 6251 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6252 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 6253 | // for the purpose to verify no mismatch between encoder and decoder. |
| 6254 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
| 6255 | |
| 6256 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6257 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 6258 | #if CONFIG_ENTROPY_STATS |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 6259 | av1_accumulate_frame_counts(&aggregate_fc, &cpi->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 6260 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6261 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 6262 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 6263 | *cm->fc = cpi->tile_data[largest_tile_id].tctx; |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 6264 | av1_reset_cdf_symbol_counters(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6265 | } |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 6266 | if (!cm->large_scale_tile) { |
| 6267 | cm->cur_frame->frame_context = *cm->fc; |
| 6268 | } |
Yunqing Wang | d8fd9e7 | 2019-12-26 15:36:31 -0800 | [diff] [blame] | 6269 | |
| 6270 | if (cpi->oxcf.ext_tile_debug) { |
| 6271 | // (yunqing) This test ensures the correctness of large scale tile coding. |
| 6272 | if (cm->large_scale_tile && is_stat_consumption_stage(cpi)) { |
| 6273 | char fn[20] = "./fc"; |
| 6274 | fn[4] = current_frame->frame_number / 100 + '0'; |
| 6275 | fn[5] = (current_frame->frame_number % 100) / 10 + '0'; |
| 6276 | fn[6] = (current_frame->frame_number % 10) + '0'; |
| 6277 | fn[7] = '\0'; |
| 6278 | av1_print_frame_contexts(cm->fc, fn); |
| 6279 | } |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 6280 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6281 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6282 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 6283 | end_timing(cpi, encode_frame_to_data_rate_time); |
| 6284 | |
| 6285 | // Print out timing information. |
| 6286 | int i; |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 6287 | fprintf(stderr, "\n Frame number: %d, Frame type: %s, Show Frame: %d\n", |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6288 | cm->current_frame.frame_number, |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 6289 | get_frame_type_enum(cm->current_frame.frame_type), cm->show_frame); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6290 | for (i = 0; i < kTimingComponents; i++) { |
| 6291 | cpi->component_time[i] += cpi->frame_component_time[i]; |
| 6292 | fprintf(stderr, " %s: %" PRId64 " us (total: %" PRId64 " us)\n", |
| 6293 | get_component_name(i), cpi->frame_component_time[i], |
| 6294 | cpi->component_time[i]); |
| 6295 | cpi->frame_component_time[i] = 0; |
| 6296 | } |
| 6297 | #endif |
| 6298 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 6299 | cm->last_frame_type = current_frame->frame_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6300 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6301 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6302 | |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 6303 | // Store encoded frame's hash table for in_integer_mv() next time. |
| 6304 | // Beware! If we don't update previous_hash_table here we will leak the |
| 6305 | // items stored in cur_frame's hash_table! |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6306 | if (!is_stat_generation_stage(cpi) && av1_use_hash_me(cpi)) { |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 6307 | cpi->previous_hash_table = &cm->cur_frame->hash_table; |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 6308 | cpi->need_to_clear_prev_hash_table = 1; |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 6309 | } |
| 6310 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6311 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 6312 | // filter deltas. |
| 6313 | cm->seg.update_map = 0; |
| 6314 | cm->seg.update_data = 0; |
| 6315 | cm->lf.mode_ref_delta_update = 0; |
| 6316 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 6317 | // A droppable frame might not be shown but it always |
| 6318 | // takes a space in the gf group. Therefore, even when |
| 6319 | // it is not shown, we still need update the count down. |
| 6320 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6321 | if (cm->show_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6322 | // Don't increment frame counters if this was an altref buffer |
| 6323 | // update not a real frame |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6324 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6325 | } |
| 6326 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6327 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6328 | } |
| 6329 | |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6330 | int av1_encode(AV1_COMP *const cpi, uint8_t *const dest, |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6331 | const EncodeFrameInput *const frame_input, |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6332 | const EncodeFrameParams *const frame_params, |
| 6333 | EncodeFrameResults *const frame_results) { |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6334 | AV1_COMMON *const cm = &cpi->common; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6335 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6336 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6337 | cpi->unscaled_source = frame_input->source; |
| 6338 | cpi->source = frame_input->source; |
| 6339 | cpi->unscaled_last_source = frame_input->last_source; |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6340 | |
David Turner | 6e8b4d9 | 2019-02-18 15:01:33 +0000 | [diff] [blame] | 6341 | current_frame->refresh_frame_flags = frame_params->refresh_frame_flags; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6342 | cm->error_resilient_mode = frame_params->error_resilient_mode; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6343 | cm->primary_ref_frame = frame_params->primary_ref_frame; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 6344 | cm->current_frame.frame_type = frame_params->frame_type; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6345 | cm->show_frame = frame_params->show_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6346 | cpi->ref_frame_flags = frame_params->ref_frame_flags; |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 6347 | cpi->speed = frame_params->speed; |
David Turner | e86ee0d | 2019-02-18 17:16:28 +0000 | [diff] [blame] | 6348 | cm->show_existing_frame = frame_params->show_existing_frame; |
| 6349 | cpi->existing_fb_idx_to_show = frame_params->existing_fb_idx_to_show; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6350 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6351 | memcpy(cm->remapped_ref_idx, frame_params->remapped_ref_idx, |
| 6352 | REF_FRAMES * sizeof(*cm->remapped_ref_idx)); |
| 6353 | |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 6354 | cpi->refresh_last_frame = frame_params->refresh_last_frame; |
| 6355 | cpi->refresh_golden_frame = frame_params->refresh_golden_frame; |
| 6356 | cpi->refresh_bwd_ref_frame = frame_params->refresh_bwd_ref_frame; |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 6357 | cpi->refresh_alt_ref_frame = frame_params->refresh_alt_ref_frame; |
| 6358 | |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6359 | if (current_frame->frame_type == KEY_FRAME && cm->show_frame) |
| 6360 | current_frame->frame_number = 0; |
| 6361 | |
| 6362 | if (cm->show_existing_frame) { |
| 6363 | current_frame->order_hint = cm->cur_frame->order_hint; |
Ravi Chaudhary | 9701cd6 | 2019-07-18 17:32:26 +0530 | [diff] [blame] | 6364 | current_frame->display_order_hint = cm->cur_frame->display_order_hint; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6365 | } else { |
| 6366 | current_frame->order_hint = |
| 6367 | current_frame->frame_number + frame_params->order_offset; |
Ravi Chaudhary | 9701cd6 | 2019-07-18 17:32:26 +0530 | [diff] [blame] | 6368 | current_frame->display_order_hint = current_frame->order_hint; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6369 | current_frame->order_hint %= |
| 6370 | (1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1)); |
| 6371 | } |
| 6372 | |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6373 | if (is_stat_generation_stage(cpi)) { |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 6374 | #if !CONFIG_REALTIME_ONLY |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6375 | av1_first_pass(cpi, frame_input->ts_duration); |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 6376 | #endif |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6377 | } else if (cpi->oxcf.pass == 0 || cpi->oxcf.pass == 2) { |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6378 | if (encode_frame_to_data_rate(cpi, &frame_results->size, dest) != |
| 6379 | AOM_CODEC_OK) { |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6380 | return AOM_CODEC_ERROR; |
| 6381 | } |
| 6382 | } else { |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6383 | return AOM_CODEC_ERROR; |
| 6384 | } |
| 6385 | |
| 6386 | return AOM_CODEC_OK; |
| 6387 | } |
| 6388 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6389 | #if CONFIG_DENOISE |
| 6390 | static int apply_denoise_2d(AV1_COMP *cpi, YV12_BUFFER_CONFIG *sd, |
| 6391 | int block_size, float noise_level, |
| 6392 | int64_t time_stamp, int64_t end_time) { |
| 6393 | AV1_COMMON *const cm = &cpi->common; |
| 6394 | if (!cpi->denoise_and_model) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6395 | cpi->denoise_and_model = aom_denoise_and_model_alloc( |
| 6396 | cm->seq_params.bit_depth, block_size, noise_level); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6397 | if (!cpi->denoise_and_model) { |
| 6398 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6399 | "Error allocating denoise and model"); |
| 6400 | return -1; |
| 6401 | } |
| 6402 | } |
| 6403 | if (!cpi->film_grain_table) { |
| 6404 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 6405 | if (!cpi->film_grain_table) { |
| 6406 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6407 | "Error allocating grain table"); |
| 6408 | return -1; |
| 6409 | } |
| 6410 | memset(cpi->film_grain_table, 0, sizeof(*cpi->film_grain_table)); |
| 6411 | } |
| 6412 | if (aom_denoise_and_model_run(cpi->denoise_and_model, sd, |
| 6413 | &cm->film_grain_params)) { |
| 6414 | if (cm->film_grain_params.apply_grain) { |
| 6415 | aom_film_grain_table_append(cpi->film_grain_table, time_stamp, end_time, |
| 6416 | &cm->film_grain_params); |
| 6417 | } |
| 6418 | } |
| 6419 | return 0; |
| 6420 | } |
| 6421 | #endif |
| 6422 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 6423 | int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6424 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 6425 | int64_t end_time) { |
| 6426 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6427 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6428 | int res = 0; |
| 6429 | const int subsampling_x = sd->subsampling_x; |
| 6430 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6431 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6432 | |
sdeng | e63f9fa | 2019-12-13 09:29:55 -0800 | [diff] [blame] | 6433 | #if CONFIG_TUNE_VMAF |
| 6434 | if (!is_stat_generation_stage(cpi) && |
| 6435 | cpi->oxcf.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING) { |
sdeng | 615dc24 | 2020-02-04 16:06:14 -0800 | [diff] [blame^] | 6436 | av1_vmaf_frame_preprocessing(cpi, sd); |
| 6437 | } |
| 6438 | if (!is_stat_generation_stage(cpi) && |
| 6439 | cpi->oxcf.tuning == AOM_TUNE_VMAF_MAX_GAIN) { |
| 6440 | av1_vmaf_blk_preprocessing(cpi, sd); |
sdeng | e63f9fa | 2019-12-13 09:29:55 -0800 | [diff] [blame] | 6441 | } |
| 6442 | #endif |
| 6443 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6444 | #if CONFIG_INTERNAL_STATS |
| 6445 | struct aom_usec_timer timer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6446 | aom_usec_timer_start(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6447 | #endif |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6448 | #if CONFIG_DENOISE |
| 6449 | if (cpi->oxcf.noise_level > 0) |
| 6450 | if (apply_denoise_2d(cpi, sd, cpi->oxcf.noise_block_size, |
| 6451 | cpi->oxcf.noise_level, time_stamp, end_time) < 0) |
| 6452 | res = -1; |
| 6453 | #endif // CONFIG_DENOISE |
| 6454 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6455 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6456 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6457 | res = -1; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6458 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6459 | aom_usec_timer_mark(&timer); |
| 6460 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6461 | #endif |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6462 | if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6463 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6464 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6465 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6466 | res = -1; |
| 6467 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6468 | if ((seq_params->profile == PROFILE_1) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6469 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6470 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6471 | "Profile 1 requires 4:4:4 color format"); |
| 6472 | res = -1; |
| 6473 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6474 | if ((seq_params->profile == PROFILE_2) && |
| 6475 | (seq_params->bit_depth <= AOM_BITS_10) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6476 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 6477 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 6478 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6479 | res = -1; |
| 6480 | } |
| 6481 | |
| 6482 | return res; |
| 6483 | } |
| 6484 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6485 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6486 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 6487 | const unsigned char *img2, int img2_pitch, |
| 6488 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6489 | |
| 6490 | static void adjust_image_stat(double y, double u, double v, double all, |
| 6491 | ImageStat *s) { |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 6492 | s->stat[STAT_Y] += y; |
| 6493 | s->stat[STAT_U] += u; |
| 6494 | s->stat[STAT_V] += v; |
| 6495 | s->stat[STAT_ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6496 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6497 | } |
| 6498 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6499 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6500 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6501 | double samples = 0.0; |
Yaowu Xu | e75b58a | 2020-01-03 12:56:12 -0800 | [diff] [blame] | 6502 | const uint32_t in_bit_depth = cpi->oxcf.input_bit_depth; |
| 6503 | const uint32_t bit_depth = cpi->td.mb.e_mbd.bd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6504 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6505 | #if CONFIG_INTER_STATS_ONLY |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6506 | if (cm->current_frame.frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6507 | #endif |
| 6508 | cpi->bytes += frame_bytes; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6509 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6510 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 6511 | const YV12_BUFFER_CONFIG *recon = &cpi->common.cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6512 | double y, u, v, frame_all; |
| 6513 | |
| 6514 | cpi->count++; |
| 6515 | if (cpi->b_calculate_psnr) { |
| 6516 | PSNR_STATS psnr; |
| 6517 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6518 | aom_clear_system_state(); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 6519 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | e75b58a | 2020-01-03 12:56:12 -0800 | [diff] [blame] | 6520 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 6521 | #else |
| 6522 | aom_calc_psnr(orig, recon, &psnr); |
| 6523 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6524 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 6525 | &cpi->psnr); |
| 6526 | cpi->total_sq_error += psnr.sse[0]; |
| 6527 | cpi->total_samples += psnr.samples[0]; |
| 6528 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6529 | // TODO(yaowu): unify these two versions into one. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6530 | if (cm->seq_params.use_highbitdepth) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6531 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6532 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6533 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6534 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6535 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6536 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6537 | cpi->summed_quality += frame_ssim2 * weight; |
| 6538 | cpi->summed_weights += weight; |
| 6539 | |
| 6540 | #if 0 |
| 6541 | { |
| 6542 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 6543 | double y2 = psnr.psnr[1]; |
| 6544 | double u2 = psnr.psnr[2]; |
| 6545 | double v2 = psnr.psnr[3]; |
| 6546 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6547 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6548 | cm->current_frame.frame_number, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6549 | frame_psnr2, frame_ssim2); |
| 6550 | fclose(f); |
| 6551 | } |
| 6552 | #endif |
| 6553 | } |
| 6554 | if (cpi->b_calculate_blockiness) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6555 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6556 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6557 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 6558 | recon->y_stride, orig->y_width, orig->y_height); |
| 6559 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6560 | cpi->total_blockiness += frame_blockiness; |
| 6561 | } |
| 6562 | |
| 6563 | if (cpi->b_calculate_consistency) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6564 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6565 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6566 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 6567 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 6568 | |
| 6569 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 6570 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6571 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6572 | if (consistency > 0.0) |
| 6573 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6574 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6575 | cpi->total_inconsistency += this_inconsistency; |
| 6576 | } |
| 6577 | } |
| 6578 | } |
| 6579 | |
| 6580 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6581 | aom_calc_fastssim(orig, recon, &y, &u, &v, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6582 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6583 | frame_all = aom_psnrhvs(orig, recon, &y, &u, &v, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6584 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 6585 | } |
| 6586 | } |
| 6587 | #endif // CONFIG_INTERNAL_STATS |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6588 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 6589 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 6590 | int64_t *time_end, int flush, |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 6591 | const aom_rational64_t *timestamp_ratio) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6592 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 6593 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6594 | |
| 6595 | #if CONFIG_BITSTREAM_DEBUG |
| 6596 | assert(cpi->oxcf.max_threads == 0 && |
| 6597 | "bitstream debug tool does not support multithreading"); |
| 6598 | bitstream_queue_record_write(); |
Yaowu Xu | 63f2ea3 | 2019-04-29 10:47:42 -0700 | [diff] [blame] | 6599 | aom_bitstream_queue_set_frame_write(cm->current_frame.frame_number * 2 + |
| 6600 | cm->show_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6601 | #endif |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 6602 | if (cpi->use_svc && cm->number_spatial_layers > 1) { |
| 6603 | av1_one_pass_cbr_svc_start_layer(cpi); |
| 6604 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6605 | |
Sarah Parker | 740e839 | 2019-01-23 15:47:53 -0800 | [diff] [blame] | 6606 | // Indicates whether or not to use an adaptive quantize b rather than |
| 6607 | // the traditional version |
| 6608 | cm->use_quant_b_adapt = cpi->oxcf.quant_b_adapt; |
| 6609 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6610 | cm->showable_frame = 0; |
David Turner | e43f7fe | 2019-01-15 14:58:00 +0000 | [diff] [blame] | 6611 | *size = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6612 | #if CONFIG_INTERNAL_STATS |
| 6613 | struct aom_usec_timer cmptimer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6614 | aom_usec_timer_start(&cmptimer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6615 | #endif |
chiyotsai | c666b1f | 2019-12-20 10:44:58 -0800 | [diff] [blame] | 6616 | av1_set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6617 | |
Debargha Mukherjee | ba7b8fe | 2018-03-15 23:10:07 -0700 | [diff] [blame] | 6618 | // Normal defaults |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6619 | cm->refresh_frame_context = oxcf->frame_parallel_decoding_mode |
| 6620 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 6621 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 6622 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 6623 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6624 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 6625 | // Initialize fields related to forward keyframes |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 6626 | cpi->no_show_kf = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 6627 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6628 | if (assign_cur_frame_new_fb(cm) == NULL) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6629 | |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 6630 | const int result = |
| 6631 | av1_encode_strategy(cpi, size, dest, frame_flags, time_stamp, time_end, |
| 6632 | timestamp_ratio, flush); |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6633 | if (result != AOM_CODEC_OK && result != -1) { |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 6634 | return AOM_CODEC_ERROR; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6635 | } else if (result == -1) { |
| 6636 | // Returning -1 indicates no frame encoded; more input is required |
| 6637 | return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6638 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6639 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6640 | aom_usec_timer_mark(&cmptimer); |
| 6641 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 6642 | #endif // CONFIG_INTERNAL_STATS |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 6643 | if (cpi->b_calculate_psnr) { |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6644 | if (cm->show_existing_frame || |
| 6645 | (!is_stat_generation_stage(cpi) && cm->show_frame)) { |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 6646 | generate_psnr_packet(cpi); |
| 6647 | } |
| 6648 | } |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 6649 | |
sdeng | 3cd9eec | 2020-01-23 15:49:50 -0800 | [diff] [blame] | 6650 | #if CONFIG_TUNE_VMAF |
| 6651 | if (oxcf->tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING || |
sdeng | 615dc24 | 2020-02-04 16:06:14 -0800 | [diff] [blame^] | 6652 | oxcf->tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING || |
| 6653 | oxcf->tuning == AOM_TUNE_VMAF_MAX_GAIN) { |
sdeng | 3cd9eec | 2020-01-23 15:49:50 -0800 | [diff] [blame] | 6654 | update_vmaf_curve(cpi, cpi->source, &cpi->common.cur_frame->buf); |
| 6655 | } |
| 6656 | #endif |
| 6657 | |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6658 | if (cpi->keep_level_stats && !is_stat_generation_stage(cpi)) { |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 6659 | // Initialize level info. at the beginning of each sequence. |
| 6660 | if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) { |
Hui Su | 58753d6 | 2019-05-29 09:56:19 -0700 | [diff] [blame] | 6661 | av1_init_level_info(cpi); |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 6662 | } |
kyslov | abeeb7c | 2019-03-06 18:35:04 -0800 | [diff] [blame] | 6663 | av1_update_level_info(cpi, *size, *time_stamp, *time_end); |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 6664 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6665 | |
| 6666 | #if CONFIG_INTERNAL_STATS |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6667 | if (!is_stat_generation_stage(cpi)) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6668 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6669 | } |
| 6670 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 6671 | #if CONFIG_SPEED_STATS |
Mufaddal Chakera | e732612 | 2019-12-04 14:49:09 +0530 | [diff] [blame] | 6672 | if (!is_stat_generation_stage(cpi) && !cm->show_existing_frame) { |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 6673 | cpi->tx_search_count += cpi->td.mb.tx_search_count; |
| 6674 | cpi->td.mb.tx_search_count = 0; |
| 6675 | } |
| 6676 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6677 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6678 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6679 | |
Hui Su | 0d0ee66 | 2019-07-29 14:38:36 -0700 | [diff] [blame] | 6680 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6681 | } |
| 6682 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6683 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6684 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6685 | if (!cm->show_frame) { |
| 6686 | return -1; |
| 6687 | } else { |
| 6688 | int ret; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 6689 | if (cm->cur_frame != NULL) { |
| 6690 | *dest = cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6691 | dest->y_width = cm->width; |
| 6692 | dest->y_height = cm->height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6693 | dest->uv_width = cm->width >> cm->seq_params.subsampling_x; |
| 6694 | dest->uv_height = cm->height >> cm->seq_params.subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6695 | ret = 0; |
| 6696 | } else { |
| 6697 | ret = -1; |
| 6698 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6699 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6700 | return ret; |
| 6701 | } |
| 6702 | } |
| 6703 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6704 | int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 6705 | if (cpi->last_show_frame_buf == NULL) return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6706 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 6707 | *frame = cpi->last_show_frame_buf->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6708 | return 0; |
| 6709 | } |
| 6710 | |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6711 | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
| 6712 | const YV12_BUFFER_CONFIG *b) { |
| 6713 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 6714 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
| 6715 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
| 6716 | a->border == b->border && |
| 6717 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
| 6718 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
| 6719 | } |
| 6720 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 6721 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 6722 | YV12_BUFFER_CONFIG *new_frame, |
| 6723 | YV12_BUFFER_CONFIG *sd) { |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6724 | const int num_planes = av1_num_planes(cm); |
| 6725 | if (!equal_dimensions_and_border(new_frame, sd)) |
| 6726 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 6727 | "Incorrect buffer dimensions"); |
| 6728 | else |
| 6729 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
| 6730 | |
| 6731 | return cm->error.error_code; |
| 6732 | } |
| 6733 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6734 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6735 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6736 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6737 | |
| 6738 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6739 | |
| 6740 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6741 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6742 | |
| 6743 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 6744 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6745 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6746 | |
| 6747 | return 0; |
| 6748 | } |
| 6749 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6750 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6751 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6752 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *frame_size) { |
| 6753 | size_t output_size = 0; |
| 6754 | size_t total_bytes_read = 0; |
| 6755 | size_t remaining_size = *frame_size; |
| 6756 | uint8_t *buff_ptr = buffer; |
| 6757 | |
| 6758 | // go through each OBUs |
| 6759 | while (total_bytes_read < *frame_size) { |
| 6760 | uint8_t saved_obu_header[2]; |
| 6761 | uint64_t obu_payload_size; |
| 6762 | size_t length_of_payload_size; |
| 6763 | size_t length_of_obu_size; |
| 6764 | uint32_t obu_header_size = (buff_ptr[0] >> 2) & 0x1 ? 2 : 1; |
| 6765 | size_t obu_bytes_read = obu_header_size; // bytes read for current obu |
| 6766 | |
| 6767 | // save the obu header (1 or 2 bytes) |
| 6768 | memmove(saved_obu_header, buff_ptr, obu_header_size); |
| 6769 | // clear the obu_has_size_field |
| 6770 | saved_obu_header[0] = saved_obu_header[0] & (~0x2); |
| 6771 | |
| 6772 | // get the payload_size and length of payload_size |
| 6773 | if (aom_uleb_decode(buff_ptr + obu_header_size, remaining_size, |
| 6774 | &obu_payload_size, &length_of_payload_size) != 0) { |
| 6775 | return AOM_CODEC_ERROR; |
| 6776 | } |
| 6777 | obu_bytes_read += length_of_payload_size; |
| 6778 | |
| 6779 | // calculate the length of size of the obu header plus payload |
| 6780 | length_of_obu_size = |
| 6781 | aom_uleb_size_in_bytes((uint64_t)(obu_header_size + obu_payload_size)); |
| 6782 | |
| 6783 | // move the rest of data to new location |
| 6784 | memmove(buff_ptr + length_of_obu_size + obu_header_size, |
| 6785 | buff_ptr + obu_bytes_read, remaining_size - obu_bytes_read); |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 6786 | obu_bytes_read += (size_t)obu_payload_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6787 | |
| 6788 | // write the new obu size |
| 6789 | const uint64_t obu_size = obu_header_size + obu_payload_size; |
| 6790 | size_t coded_obu_size; |
| 6791 | if (aom_uleb_encode(obu_size, sizeof(obu_size), buff_ptr, |
| 6792 | &coded_obu_size) != 0) { |
| 6793 | return AOM_CODEC_ERROR; |
| 6794 | } |
| 6795 | |
| 6796 | // write the saved (modified) obu_header following obu size |
| 6797 | memmove(buff_ptr + length_of_obu_size, saved_obu_header, obu_header_size); |
| 6798 | |
| 6799 | total_bytes_read += obu_bytes_read; |
| 6800 | remaining_size -= obu_bytes_read; |
| 6801 | buff_ptr += length_of_obu_size + obu_size; |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 6802 | output_size += length_of_obu_size + (size_t)obu_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6803 | } |
| 6804 | |
| 6805 | *frame_size = output_size; |
| 6806 | return AOM_CODEC_OK; |
| 6807 | } |
| 6808 | |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 6809 | static void svc_set_updates_external_ref_frame_config(AV1_COMP *cpi) { |
| 6810 | cpi->ext_refresh_frame_flags_pending = 1; |
| 6811 | cpi->ext_refresh_last_frame = cpi->svc.refresh[cpi->svc.ref_idx[0]]; |
| 6812 | cpi->ext_refresh_golden_frame = cpi->svc.refresh[cpi->svc.ref_idx[3]]; |
| 6813 | cpi->ext_refresh_bwd_ref_frame = cpi->svc.refresh[cpi->svc.ref_idx[4]]; |
| 6814 | cpi->ext_refresh_alt2_ref_frame = cpi->svc.refresh[cpi->svc.ref_idx[5]]; |
| 6815 | cpi->ext_refresh_alt_ref_frame = cpi->svc.refresh[cpi->svc.ref_idx[6]]; |
| 6816 | cpi->svc.non_reference_frame = 1; |
| 6817 | for (int i = 0; i < REF_FRAMES; i++) { |
| 6818 | if (cpi->svc.refresh[i] == 1) { |
| 6819 | cpi->svc.non_reference_frame = 0; |
| 6820 | break; |
| 6821 | } |
| 6822 | } |
| 6823 | } |
| 6824 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6825 | void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) { |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6826 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 6827 | // should be consistent with internal reference frame selection. Need to |
| 6828 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 6829 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6830 | // GOLDEN, BWDREF, ALTREF2. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6831 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6832 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6833 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 6834 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 6835 | AOM_EFLAG_NO_REF_ARF2)) { |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6836 | int ref = AOM_REFFRAME_ALL; |
| 6837 | |
| 6838 | if (flags & AOM_EFLAG_NO_REF_LAST) ref ^= AOM_LAST_FLAG; |
| 6839 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 6840 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 6841 | |
| 6842 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 6843 | |
| 6844 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 6845 | ref ^= AOM_ALT_FLAG; |
| 6846 | ref ^= AOM_BWD_FLAG; |
| 6847 | ref ^= AOM_ALT2_FLAG; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6848 | } else { |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6849 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 6850 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6851 | } |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6852 | |
| 6853 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6854 | } |
| 6855 | |
| 6856 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6857 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6858 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6859 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6860 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 6861 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6862 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6863 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6864 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6865 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 6866 | upd ^= AOM_ALT_FLAG; |
| 6867 | upd ^= AOM_BWD_FLAG; |
| 6868 | upd ^= AOM_ALT2_FLAG; |
| 6869 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6870 | |
David Turner | ce9b590 | 2019-01-23 17:25:47 +0000 | [diff] [blame] | 6871 | cpi->ext_refresh_last_frame = (upd & AOM_LAST_FLAG) != 0; |
| 6872 | cpi->ext_refresh_golden_frame = (upd & AOM_GOLD_FLAG) != 0; |
| 6873 | cpi->ext_refresh_alt_ref_frame = (upd & AOM_ALT_FLAG) != 0; |
| 6874 | cpi->ext_refresh_bwd_ref_frame = (upd & AOM_BWD_FLAG) != 0; |
| 6875 | cpi->ext_refresh_alt2_ref_frame = (upd & AOM_ALT2_FLAG) != 0; |
| 6876 | cpi->ext_refresh_frame_flags_pending = 1; |
David Turner | 4f1f181 | 2019-01-24 17:00:24 +0000 | [diff] [blame] | 6877 | } else { |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 6878 | if (cpi->svc.external_ref_frame_config) |
| 6879 | svc_set_updates_external_ref_frame_config(cpi); |
| 6880 | else |
| 6881 | cpi->ext_refresh_frame_flags_pending = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6882 | } |
| 6883 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6884 | cpi->ext_use_ref_frame_mvs = cpi->oxcf.allow_ref_frame_mvs & |
| 6885 | ((flags & AOM_EFLAG_NO_REF_FRAME_MVS) == 0); |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6886 | cpi->ext_use_error_resilient = cpi->oxcf.error_resilient_mode | |
| 6887 | ((flags & AOM_EFLAG_ERROR_RESILIENT) != 0); |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6888 | cpi->ext_use_s_frame = |
| 6889 | cpi->oxcf.s_frame_mode | ((flags & AOM_EFLAG_SET_S_FRAME) != 0); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 6890 | cpi->ext_use_primary_ref_none = (flags & AOM_EFLAG_SET_PRIMARY_REF_NONE) != 0; |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6891 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6892 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6893 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6894 | } |
| 6895 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6896 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 6897 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi) { |
| 6898 | if (!cpi) return NULL; |
| 6899 | |
| 6900 | uint8_t header_buf[512] = { 0 }; |
| 6901 | const uint32_t sequence_header_size = |
Yaowu Xu | 797674b | 2019-05-01 17:38:11 -0700 | [diff] [blame] | 6902 | av1_write_sequence_header_obu(cpi, &header_buf[0]); |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 6903 | assert(sequence_header_size <= sizeof(header_buf)); |
| 6904 | if (sequence_header_size == 0) return NULL; |
| 6905 | |
| 6906 | const size_t obu_header_size = 1; |
| 6907 | const size_t size_field_size = aom_uleb_size_in_bytes(sequence_header_size); |
| 6908 | const size_t payload_offset = obu_header_size + size_field_size; |
| 6909 | |
| 6910 | if (payload_offset + sequence_header_size > sizeof(header_buf)) return NULL; |
| 6911 | memmove(&header_buf[payload_offset], &header_buf[0], sequence_header_size); |
| 6912 | |
Hui Su | 4fd1176 | 2019-03-26 16:05:07 -0700 | [diff] [blame] | 6913 | if (av1_write_obu_header(cpi, OBU_SEQUENCE_HEADER, 0, &header_buf[0]) != |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 6914 | obu_header_size) { |
| 6915 | return NULL; |
| 6916 | } |
| 6917 | |
| 6918 | size_t coded_size_field_size = 0; |
| 6919 | if (aom_uleb_encode(sequence_header_size, size_field_size, |
| 6920 | &header_buf[obu_header_size], |
| 6921 | &coded_size_field_size) != 0) { |
| 6922 | return NULL; |
| 6923 | } |
| 6924 | assert(coded_size_field_size == size_field_size); |
| 6925 | |
| 6926 | aom_fixed_buf_t *global_headers = |
| 6927 | (aom_fixed_buf_t *)malloc(sizeof(*global_headers)); |
| 6928 | if (!global_headers) return NULL; |
| 6929 | |
| 6930 | const size_t global_header_buf_size = |
| 6931 | obu_header_size + size_field_size + sequence_header_size; |
| 6932 | |
| 6933 | global_headers->buf = malloc(global_header_buf_size); |
| 6934 | if (!global_headers->buf) { |
| 6935 | free(global_headers); |
| 6936 | return NULL; |
| 6937 | } |
| 6938 | |
| 6939 | memcpy(global_headers->buf, &header_buf[0], global_header_buf_size); |
| 6940 | global_headers->sz = global_header_buf_size; |
| 6941 | return global_headers; |
| 6942 | } |