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" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | #include "av1/encoder/mbgraph.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 | |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 79 | #define DEFAULT_EXPLICIT_ORDER_HINT_BITS 7 |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 80 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 81 | #if CONFIG_ENTROPY_STATS |
| 82 | FRAME_COUNTS aggregate_fc; |
| 83 | #endif // CONFIG_ENTROPY_STATS |
| 84 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 85 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 86 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 87 | |
Debargha Mukherjee | cd14cc1 | 2019-09-06 09:55:52 -0700 | [diff] [blame] | 88 | // Q threshold for high precision mv. |
| 89 | #define HIGH_PRECISION_MV_QTHRESH 128 |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 90 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 91 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | #ifdef OUTPUT_YUV_SKINMAP |
| 93 | FILE *yuv_skinmap_file = NULL; |
| 94 | #endif |
| 95 | #ifdef OUTPUT_YUV_REC |
| 96 | FILE *yuv_rec_file; |
| 97 | #define FILE_NAME_LEN 100 |
| 98 | #endif |
| 99 | |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 100 | const int default_tx_type_probs[FRAME_UPDATE_TYPES][TX_SIZES_ALL][TX_TYPES] = { |
| 101 | { { 221, 189, 214, 292, 0, 0, 0, 0, 0, 2, 38, 68, 0, 0, 0, 0 }, |
| 102 | { 262, 203, 216, 239, 0, 0, 0, 0, 0, 1, 37, 66, 0, 0, 0, 0 }, |
| 103 | { 315, 231, 239, 226, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0 }, |
| 104 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 105 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 106 | { 222, 188, 214, 287, 0, 0, 0, 0, 0, 2, 50, 61, 0, 0, 0, 0 }, |
| 107 | { 256, 182, 205, 282, 0, 0, 0, 0, 0, 2, 21, 76, 0, 0, 0, 0 }, |
| 108 | { 281, 214, 217, 222, 0, 0, 0, 0, 0, 1, 48, 41, 0, 0, 0, 0 }, |
| 109 | { 263, 194, 225, 225, 0, 0, 0, 0, 0, 2, 15, 100, 0, 0, 0, 0 }, |
| 110 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 | { 170, 192, 242, 293, 0, 0, 0, 0, 0, 1, 68, 58, 0, 0, 0, 0 }, |
| 115 | { 199, 210, 213, 291, 0, 0, 0, 0, 0, 1, 14, 96, 0, 0, 0, 0 }, |
| 116 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 | { { 106, 69, 107, 278, 9, 15, 20, 45, 49, 23, 23, 88, 36, 74, 25, 57 }, |
| 121 | { 105, 72, 81, 98, 45, 49, 47, 50, 56, 72, 30, 81, 33, 95, 27, 83 }, |
| 122 | { 211, 105, 109, 120, 57, 62, 43, 49, 52, 58, 42, 116, 0, 0, 0, 0 }, |
| 123 | { 1008, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0 }, |
| 124 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 125 | { 131, 57, 98, 172, 19, 40, 37, 64, 69, 22, 41, 52, 51, 77, 35, 59 }, |
| 126 | { 176, 83, 93, 202, 22, 24, 28, 47, 50, 16, 12, 93, 26, 76, 17, 59 }, |
| 127 | { 136, 72, 89, 95, 46, 59, 47, 56, 61, 68, 35, 51, 32, 82, 26, 69 }, |
| 128 | { 122, 80, 87, 105, 49, 47, 46, 46, 57, 52, 13, 90, 19, 103, 15, 93 }, |
| 129 | { 1009, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0 }, |
| 130 | { 1011, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0 }, |
| 131 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 132 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 133 | { 202, 20, 84, 114, 14, 60, 41, 79, 99, 21, 41, 15, 50, 84, 34, 66 }, |
| 134 | { 196, 44, 23, 72, 30, 22, 28, 57, 67, 13, 4, 165, 15, 148, 9, 131 }, |
| 135 | { 882, 0, 0, 0, 0, 0, 0, 0, 0, 142, 0, 0, 0, 0, 0, 0 }, |
| 136 | { 840, 0, 0, 0, 0, 0, 0, 0, 0, 184, 0, 0, 0, 0, 0, 0 }, |
| 137 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 138 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, |
| 139 | { { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 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 | { { 213, 110, 141, 269, 12, 16, 15, 19, 21, 11, 38, 68, 22, 29, 16, 24 }, |
| 159 | { 216, 119, 128, 143, 38, 41, 26, 30, 31, 30, 42, 70, 23, 36, 19, 32 }, |
| 160 | { 367, 149, 154, 154, 38, 35, 17, 21, 21, 10, 22, 36, 0, 0, 0, 0 }, |
| 161 | { 1022, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, |
| 162 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 163 | { 219, 96, 127, 191, 21, 40, 25, 32, 34, 18, 45, 45, 33, 39, 26, 33 }, |
| 164 | { 296, 99, 122, 198, 23, 21, 19, 24, 25, 13, 20, 64, 23, 32, 18, 27 }, |
| 165 | { 275, 128, 142, 143, 35, 48, 23, 30, 29, 18, 42, 36, 18, 23, 14, 20 }, |
| 166 | { 239, 132, 166, 175, 36, 27, 19, 21, 24, 14, 13, 85, 9, 31, 8, 25 }, |
| 167 | { 1022, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, |
| 168 | { 1022, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, |
| 169 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 170 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 171 | { 309, 25, 79, 59, 25, 80, 34, 53, 61, 25, 49, 23, 43, 64, 36, 59 }, |
| 172 | { 270, 57, 40, 54, 50, 42, 41, 53, 56, 28, 17, 81, 45, 86, 34, 70 }, |
| 173 | { 1005, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0 }, |
| 174 | { 992, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0 }, |
| 175 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 176 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, |
| 177 | { { 133, 63, 55, 83, 57, 87, 58, 72, 68, 16, 24, 35, 29, 105, 25, 114 }, |
| 178 | { 131, 75, 74, 60, 71, 77, 65, 66, 73, 33, 21, 79, 20, 83, 18, 78 }, |
| 179 | { 276, 95, 82, 58, 86, 93, 63, 60, 64, 17, 38, 92, 0, 0, 0, 0 }, |
| 180 | { 1006, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0 }, |
| 181 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 182 | { 147, 49, 75, 78, 50, 97, 60, 67, 76, 17, 42, 35, 31, 93, 27, 80 }, |
| 183 | { 157, 49, 58, 75, 61, 52, 56, 67, 69, 12, 15, 79, 24, 119, 11, 120 }, |
| 184 | { 178, 69, 83, 77, 69, 85, 72, 77, 77, 20, 35, 40, 25, 48, 23, 46 }, |
| 185 | { 174, 55, 64, 57, 73, 68, 62, 61, 75, 15, 12, 90, 17, 99, 16, 86 }, |
| 186 | { 1008, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0 }, |
| 187 | { 1018, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0 }, |
| 188 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 189 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 190 | { 266, 31, 63, 64, 21, 52, 39, 54, 63, 30, 52, 31, 48, 89, 46, 75 }, |
| 191 | { 272, 26, 32, 44, 29, 31, 32, 53, 51, 13, 13, 88, 22, 153, 16, 149 }, |
| 192 | { 923, 0, 0, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 0, 0, 0 }, |
| 193 | { 969, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0 }, |
| 194 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 195 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, |
| 196 | { { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, |
| 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 | { { 158, 92, 125, 298, 12, 15, 20, 29, 31, 12, 29, 67, 34, 44, 23, 35 }, |
| 216 | { 147, 94, 103, 123, 45, 48, 38, 41, 46, 48, 37, 78, 33, 63, 27, 53 }, |
| 217 | { 268, 126, 125, 136, 54, 53, 31, 38, 38, 33, 35, 87, 0, 0, 0, 0 }, |
| 218 | { 1018, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0 }, |
| 219 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 220 | { 159, 72, 103, 194, 20, 35, 37, 50, 56, 21, 39, 40, 51, 61, 38, 48 }, |
| 221 | { 259, 86, 95, 188, 32, 20, 25, 34, 37, 13, 12, 85, 25, 53, 17, 43 }, |
| 222 | { 189, 99, 113, 123, 45, 59, 37, 46, 48, 44, 39, 41, 31, 47, 26, 37 }, |
| 223 | { 175, 110, 113, 128, 58, 38, 33, 33, 43, 29, 13, 100, 14, 68, 12, 57 }, |
| 224 | { 1017, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0 }, |
| 225 | { 1019, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0 }, |
| 226 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 227 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 228 | { 208, 22, 84, 101, 21, 59, 44, 70, 90, 25, 59, 13, 64, 67, 49, 48 }, |
| 229 | { 277, 52, 32, 63, 43, 26, 33, 48, 54, 11, 6, 130, 18, 119, 11, 101 }, |
| 230 | { 963, 0, 0, 0, 0, 0, 0, 0, 0, 61, 0, 0, 0, 0, 0, 0 }, |
| 231 | { 979, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0 }, |
| 232 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 233 | { 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } |
| 234 | }; |
| 235 | |
Yunqing Wang | 5f74dc2 | 2019-10-29 10:35:20 -0700 | [diff] [blame] | 236 | const int default_obmc_probs[FRAME_UPDATE_TYPES][BLOCK_SIZES_ALL] = { |
| 237 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 238 | { 0, 0, 0, 106, 90, 90, 97, 67, 59, 70, 28, |
| 239 | 30, 38, 16, 16, 16, 0, 0, 44, 50, 26, 25 }, |
| 240 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 241 | { 0, 0, 0, 98, 93, 97, 68, 82, 85, 33, 30, |
| 242 | 33, 16, 16, 16, 16, 0, 0, 43, 37, 26, 16 }, |
| 243 | { 0, 0, 0, 91, 80, 76, 78, 55, 49, 24, 16, |
| 244 | 16, 16, 16, 16, 16, 0, 0, 29, 45, 16, 38 }, |
| 245 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 246 | { 0, 0, 0, 103, 89, 89, 89, 62, 63, 76, 34, |
| 247 | 35, 32, 19, 16, 16, 0, 0, 49, 55, 29, 19 } |
| 248 | }; |
| 249 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 250 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | switch (mode) { |
| 252 | case NORMAL: |
| 253 | *hr = 1; |
| 254 | *hs = 1; |
| 255 | break; |
| 256 | case FOURFIVE: |
| 257 | *hr = 4; |
| 258 | *hs = 5; |
| 259 | break; |
| 260 | case THREEFIVE: |
| 261 | *hr = 3; |
| 262 | *hs = 5; |
| 263 | break; |
| 264 | case ONETWO: |
| 265 | *hr = 1; |
| 266 | *hs = 2; |
| 267 | break; |
| 268 | default: |
| 269 | *hr = 1; |
| 270 | *hs = 1; |
| 271 | assert(0); |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 277 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 278 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | unsigned char *const seg_map = cpi->segmentation_map; |
| 280 | int i; |
| 281 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 282 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 283 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 284 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 285 | } |
| 286 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 287 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 288 | struct segmentation *const seg = &cpi->common.seg; |
| 289 | unsigned char *const seg_map = cpi->segmentation_map; |
| 290 | const unsigned char *const active_map = cpi->active_map.map; |
| 291 | int i; |
| 292 | |
| 293 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 294 | |
| 295 | if (frame_is_intra_only(&cpi->common)) { |
| 296 | cpi->active_map.enabled = 0; |
| 297 | cpi->active_map.update = 1; |
| 298 | } |
| 299 | |
| 300 | if (cpi->active_map.update) { |
| 301 | if (cpi->active_map.enabled) { |
| 302 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 303 | 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] | 304 | av1_enable_segmentation(seg); |
| 305 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 306 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 307 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 308 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 309 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 310 | |
| 311 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 312 | -MAX_LOOP_FILTER); |
| 313 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 314 | -MAX_LOOP_FILTER); |
| 315 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 316 | -MAX_LOOP_FILTER); |
| 317 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 318 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 320 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 321 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 322 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 323 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 324 | 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] | 325 | if (seg->enabled) { |
| 326 | seg->update_data = 1; |
| 327 | seg->update_map = 1; |
| 328 | } |
| 329 | } |
| 330 | cpi->active_map.update = 0; |
| 331 | } |
| 332 | } |
| 333 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 334 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 335 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 336 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 337 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 338 | const int mi_rows = cpi->common.mi_rows; |
| 339 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 340 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 341 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 342 | cpi->active_map.update = 1; |
| 343 | if (new_map_16x16) { |
| 344 | int r, c; |
| 345 | for (r = 0; r < mi_rows; ++r) { |
| 346 | for (c = 0; c < mi_cols; ++c) { |
| 347 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 348 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | ? AM_SEGMENT_ID_ACTIVE |
| 350 | : AM_SEGMENT_ID_INACTIVE; |
| 351 | } |
| 352 | } |
| 353 | cpi->active_map.enabled = 1; |
| 354 | } else { |
| 355 | cpi->active_map.enabled = 0; |
| 356 | } |
| 357 | return 0; |
| 358 | } else { |
| 359 | return -1; |
| 360 | } |
| 361 | } |
| 362 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 363 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 364 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 365 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 366 | new_map_16x16) { |
| 367 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 368 | const int mi_rows = cpi->common.mi_rows; |
| 369 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 370 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 371 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 372 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 374 | if (cpi->active_map.enabled) { |
| 375 | int r, c; |
| 376 | for (r = 0; r < mi_rows; ++r) { |
| 377 | for (c = 0; c < mi_cols; ++c) { |
| 378 | // Cyclic refresh segments are considered active despite not having |
| 379 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 380 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 381 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | return 0; |
| 386 | } else { |
| 387 | return -1; |
| 388 | } |
| 389 | } |
| 390 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 391 | // Compute the horizontal frequency components' energy in a frame |
| 392 | // by calculuating the 16x4 Horizontal DCT. This is to be used to |
| 393 | // decide the superresolution parameters. |
Yaowu Xu | bedbf4f | 2019-05-01 17:54:36 -0700 | [diff] [blame] | 394 | static void analyze_hor_freq(const AV1_COMP *cpi, double *energy) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 395 | uint64_t freq_energy[16] = { 0 }; |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 396 | const YV12_BUFFER_CONFIG *buf = cpi->source; |
| 397 | const int bd = cpi->td.mb.e_mbd.bd; |
| 398 | const int width = buf->y_crop_width; |
| 399 | const int height = buf->y_crop_height; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 400 | DECLARE_ALIGNED(16, int32_t, coeff[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 401 | int n = 0; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 402 | memset(freq_energy, 0, sizeof(freq_energy)); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 403 | if (buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 404 | const int16_t *src16 = (const int16_t *)CONVERT_TO_SHORTPTR(buf->y_buffer); |
| 405 | for (int i = 0; i < height - 4; i += 4) { |
| 406 | for (int j = 0; j < width - 16; j += 16) { |
| 407 | av1_fwd_txfm2d_16x4(src16 + i * buf->y_stride + j, coeff, buf->y_stride, |
| 408 | H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 409 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 410 | const uint64_t this_energy = |
| 411 | ((int64_t)coeff[k] * coeff[k]) + |
| 412 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 413 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 414 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 415 | 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] | 416 | } |
| 417 | n++; |
| 418 | } |
| 419 | } |
| 420 | } else { |
Debargha Mukherjee | ac28c72 | 2018-11-14 22:09:46 -0800 | [diff] [blame] | 421 | assert(bd == 8); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 422 | DECLARE_ALIGNED(16, int16_t, src16[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 423 | for (int i = 0; i < height - 4; i += 4) { |
| 424 | for (int j = 0; j < width - 16; j += 16) { |
| 425 | for (int ii = 0; ii < 4; ++ii) |
| 426 | for (int jj = 0; jj < 16; ++jj) |
| 427 | src16[ii * 16 + jj] = |
| 428 | buf->y_buffer[(i + ii) * buf->y_stride + (j + jj)]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 429 | av1_fwd_txfm2d_16x4(src16, coeff, 16, H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 430 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 431 | const uint64_t this_energy = |
| 432 | ((int64_t)coeff[k] * coeff[k]) + |
| 433 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 434 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 435 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 436 | freq_energy[k] += ROUND_POWER_OF_TWO(this_energy, 2); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 437 | } |
| 438 | n++; |
| 439 | } |
| 440 | } |
| 441 | } |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 442 | if (n) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 443 | 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] | 444 | // Convert to cumulative energy |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 445 | for (int k = 14; k > 0; --k) energy[k] += energy[k + 1]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 446 | } else { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 447 | for (int k = 1; k < 16; ++k) energy[k] = 1e+20; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 448 | } |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Yaowu Xu | 45295c3 | 2018-03-29 12:06:10 -0700 | [diff] [blame] | 451 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv, |
| 452 | int cur_frame_force_integer_mv) { |
Debargha Mukherjee | 8d27341 | 2019-09-11 10:36:50 -0700 | [diff] [blame] | 453 | MACROBLOCK *const x = &cpi->td.mb; |
Hui Su | 5036115 | 2018-03-02 11:01:42 -0800 | [diff] [blame] | 454 | cpi->common.allow_high_precision_mv = |
| 455 | allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 456 | const int copy_hp = |
| 457 | cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Debargha Mukherjee | 8d27341 | 2019-09-11 10:36:50 -0700 | [diff] [blame] | 458 | x->nmvcost[0] = &x->nmv_costs[0][MV_MAX]; |
| 459 | x->nmvcost[1] = &x->nmv_costs[1][MV_MAX]; |
| 460 | x->nmvcost_hp[0] = &x->nmv_costs_hp[0][MV_MAX]; |
| 461 | x->nmvcost_hp[1] = &x->nmv_costs_hp[1][MV_MAX]; |
| 462 | int *(*src)[2] = copy_hp ? &x->nmvcost_hp : &x->nmvcost; |
| 463 | x->mv_cost_stack = *src; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 466 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 467 | const AV1_COMMON *const cm = &cpi->common; |
James Zern | bf3ca36 | 2019-10-21 11:33:44 -0700 | [diff] [blame] | 468 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 469 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 470 | return BLOCK_64X64; |
Ryan Lei | c8b6dd6 | 2019-10-23 20:01:26 -0700 | [diff] [blame] | 471 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 472 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 473 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 474 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 475 | |
Ryan Lei | c8b6dd6 | 2019-10-23 20:01:26 -0700 | [diff] [blame] | 476 | // TODO(any): Possibly could improve this with a heuristic. |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 477 | // When superres / resize is on, 'cm->width / height' can change between |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 478 | // calls, so we don't apply this heuristic there. |
| 479 | // Things break if superblock size changes between the first pass and second |
| 480 | // pass encoding, which is why this heuristic is not configured as a |
| 481 | // speed-feature. |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 482 | if (cpi->oxcf.superres_mode == SUPERRES_NONE && |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 483 | cpi->oxcf.resize_mode == RESIZE_NONE && cpi->oxcf.speed >= 1) { |
| 484 | return AOMMIN(cm->width, cm->height) > 480 ? BLOCK_128X128 : BLOCK_64X64; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 487 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 490 | static void setup_frame(AV1_COMP *cpi) { |
| 491 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 492 | // Set up entropy context depending on frame type. The decoder mandates |
| 493 | // the use of the default context, index 0, for keyframes and inter |
| 494 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 495 | // other inter-frames the encoder currently uses only two contexts; |
| 496 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 497 | |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 498 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 499 | cpi->ext_use_primary_ref_none) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 500 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Hui Su | eb4b7de | 2019-04-03 11:00:18 -0700 | [diff] [blame] | 503 | if ((cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) || |
| 504 | frame_is_sframe(cm)) { |
| 505 | if (!cpi->seq_params_locked) { |
| 506 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
| 507 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 508 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 509 | const RefCntBuffer *const primary_ref_buf = get_primary_ref_frame_buf(cm); |
| 510 | if (primary_ref_buf == NULL) { |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 511 | av1_setup_past_independence(cm); |
| 512 | cm->seg.update_map = 1; |
| 513 | cm->seg.update_data = 1; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 514 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 515 | *cm->fc = primary_ref_buf->frame_context; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 516 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 517 | } |
| 518 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 519 | av1_zero(cm->cur_frame->interp_filter_selected); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 520 | cm->prev_frame = get_primary_ref_frame_buf(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 521 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | } |
| 523 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 524 | static void enc_set_mb_mi(AV1_COMMON *cm, int width, int height) { |
| 525 | // Ensure that the decoded width and height are both multiples of |
| 526 | // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if |
| 527 | // subsampling is used). |
| 528 | // This simplifies the implementation of various experiments, |
| 529 | // eg. cdef, which operates on units of 8x8 luma pixels. |
| 530 | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
| 531 | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 532 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 533 | cm->mi_cols = aligned_width >> MI_SIZE_LOG2; |
| 534 | cm->mi_rows = aligned_height >> MI_SIZE_LOG2; |
| 535 | cm->mi_stride = calc_mi_size(cm->mi_cols); |
| 536 | |
| 537 | cm->mb_cols = (cm->mi_cols + 2) >> 2; |
| 538 | cm->mb_rows = (cm->mi_rows + 2) >> 2; |
| 539 | cm->MBs = cm->mb_rows * cm->mb_cols; |
| 540 | |
| 541 | const int is_4k_or_larger = AOMMIN(width, height) >= 2160; |
| 542 | |
| 543 | cm->mi_alloc_bsize = is_4k_or_larger ? BLOCK_8X8 : BLOCK_4X4; |
| 544 | const int mi_alloc_size_1d = mi_size_wide[cm->mi_alloc_bsize]; |
| 545 | cm->mi_alloc_rows = (cm->mi_rows + mi_alloc_size_1d - 1) / mi_alloc_size_1d; |
| 546 | cm->mi_alloc_cols = (cm->mi_cols + mi_alloc_size_1d - 1) / mi_alloc_size_1d; |
| 547 | cm->mi_alloc_stride = |
| 548 | (cm->mi_stride + mi_alloc_size_1d - 1) / mi_alloc_size_1d; |
| 549 | |
| 550 | assert(mi_size_wide[cm->mi_alloc_bsize] == mi_size_high[cm->mi_alloc_bsize]); |
| 551 | |
| 552 | #if CONFIG_LPF_MASK |
chiyotsai | a13c19f | 2019-08-15 10:12:57 -0700 | [diff] [blame] | 553 | av1_alloc_loop_filter_mask(cm); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 554 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 555 | } |
| 556 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 557 | static void enc_setup_mi(AV1_COMMON *cm) { |
| 558 | const int mi_grid_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
| 559 | memset(cm->mi, 0, cm->mi_alloc_size * sizeof(*cm->mi)); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 560 | 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] | 561 | 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] | 562 | } |
| 563 | |
| 564 | static int enc_alloc_mi(AV1_COMMON *cm) { |
| 565 | const int mi_grid_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
| 566 | const int alloc_size_1d = mi_size_wide[cm->mi_alloc_bsize]; |
| 567 | const int alloc_mi_size = |
| 568 | cm->mi_alloc_stride * (calc_mi_size(cm->mi_rows) / alloc_size_1d); |
| 569 | |
| 570 | if (cm->mi_alloc_size < alloc_mi_size || cm->mi_grid_size < mi_grid_size) { |
| 571 | cm->free_mi(cm); |
| 572 | |
| 573 | cm->mi = aom_calloc(alloc_mi_size, sizeof(*cm->mi)); |
| 574 | if (!cm->mi) return 1; |
| 575 | cm->mi_alloc_size = alloc_mi_size; |
| 576 | |
| 577 | cm->mi_grid_base = |
| 578 | (MB_MODE_INFO **)aom_calloc(mi_grid_size, sizeof(MB_MODE_INFO *)); |
| 579 | if (!cm->mi_grid_base) return 1; |
| 580 | cm->mi_grid_size = mi_grid_size; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 581 | |
| 582 | cm->tx_type_map = aom_calloc(calc_mi_size(cm->mi_rows) * cm->mi_stride, |
| 583 | sizeof(*cm->tx_type_map)); |
| 584 | if (!cm->tx_type_map) return 1; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 585 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 590 | static void enc_free_mi(AV1_COMMON *cm) { |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 591 | aom_free(cm->mi); |
| 592 | cm->mi = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 593 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 594 | cm->mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 595 | cm->mi_alloc_size = 0; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 596 | aom_free(cm->tx_type_map); |
| 597 | cm->tx_type_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 600 | void av1_initialize_enc(void) { |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 601 | av1_rtcd(); |
| 602 | aom_dsp_rtcd(); |
| 603 | aom_scale_rtcd(); |
| 604 | av1_init_intra_predictors(); |
| 605 | av1_init_me_luts(); |
| 606 | av1_rc_init_minq_luts(); |
| 607 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 610 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 611 | if (cpi->mbmi_ext_frame_base) { |
| 612 | aom_free(cpi->mbmi_ext_frame_base); |
| 613 | cpi->mbmi_ext_frame_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
| 617 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 618 | AV1_COMMON *cm = &cpi->common; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 619 | 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] | 620 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 621 | if (new_ext_mi_size > cpi->mi_ext_alloc_size) { |
| 622 | dealloc_context_buffers_ext(cpi); |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 623 | CHECK_MEM_ERROR( |
| 624 | cm, cpi->mbmi_ext_frame_base, |
| 625 | aom_calloc(new_ext_mi_size, sizeof(*cpi->mbmi_ext_frame_base))); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 626 | cpi->mi_ext_alloc_size = new_ext_mi_size; |
| 627 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 630 | static void reset_film_grain_chroma_params(aom_film_grain_t *pars) { |
| 631 | pars->num_cr_points = 0; |
| 632 | pars->cr_mult = 0; |
| 633 | pars->cr_luma_mult = 0; |
| 634 | memset(pars->scaling_points_cr, 0, sizeof(pars->scaling_points_cr)); |
| 635 | memset(pars->ar_coeffs_cr, 0, sizeof(pars->ar_coeffs_cr)); |
| 636 | pars->num_cb_points = 0; |
| 637 | pars->cb_mult = 0; |
| 638 | pars->cb_luma_mult = 0; |
Yaowu Xu | fda7dcb | 2019-01-16 13:04:33 -0800 | [diff] [blame] | 639 | pars->chroma_scaling_from_luma = 0; |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 640 | memset(pars->scaling_points_cb, 0, sizeof(pars->scaling_points_cb)); |
| 641 | memset(pars->ar_coeffs_cb, 0, sizeof(pars->ar_coeffs_cb)); |
| 642 | } |
| 643 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 644 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 645 | const AV1EncoderConfig *oxcf) { |
| 646 | AV1_COMMON *const cm = &cpi->common; |
| 647 | cpi->oxcf = *oxcf; |
| 648 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 649 | if (cpi->film_grain_table) { |
| 650 | aom_film_grain_table_free(cpi->film_grain_table); |
| 651 | aom_free(cpi->film_grain_table); |
| 652 | cpi->film_grain_table = NULL; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 653 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 654 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 655 | if (oxcf->film_grain_test_vector) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 656 | cm->seq_params.film_grain_params_present = 1; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 657 | if (cm->current_frame.frame_type == KEY_FRAME) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 658 | memcpy(&cm->film_grain_params, |
| 659 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 660 | sizeof(cm->film_grain_params)); |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 661 | if (oxcf->monochrome) |
| 662 | reset_film_grain_chroma_params(&cm->film_grain_params); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 663 | cm->film_grain_params.bit_depth = cm->seq_params.bit_depth; |
| 664 | if (cm->seq_params.color_range == AOM_CR_FULL_RANGE) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 665 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 666 | } |
| 667 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 668 | } else if (oxcf->film_grain_table_filename) { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 669 | cm->seq_params.film_grain_params_present = 1; |
| 670 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 671 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 672 | memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t)); |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 673 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 674 | aom_film_grain_table_read(cpi->film_grain_table, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 675 | oxcf->film_grain_table_filename, &cm->error); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 676 | } else { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 677 | #if CONFIG_DENOISE |
| 678 | cm->seq_params.film_grain_params_present = (cpi->oxcf.noise_level > 0); |
| 679 | #else |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 680 | cm->seq_params.film_grain_params_present = 0; |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 681 | #endif |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 682 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 683 | } |
| 684 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 685 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 686 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 687 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 688 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 689 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 690 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 691 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 692 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 693 | cpi->tile_data = NULL; |
| 694 | |
| 695 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 696 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 697 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 698 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 699 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 700 | cpi->cyclic_refresh = NULL; |
| 701 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 702 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 703 | cpi->active_map.map = NULL; |
| 704 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 705 | aom_free(cpi->ssim_rdmult_scaling_factors); |
| 706 | cpi->ssim_rdmult_scaling_factors = NULL; |
| 707 | |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 708 | aom_free(cpi->tpl_rdmult_scaling_factors); |
| 709 | cpi->tpl_rdmult_scaling_factors = NULL; |
| 710 | |
| 711 | aom_free(cpi->tpl_sb_rdmult_scaling_factors); |
| 712 | cpi->tpl_sb_rdmult_scaling_factors = NULL; |
| 713 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 714 | aom_free(cpi->td.mb.above_pred_buf); |
| 715 | cpi->td.mb.above_pred_buf = NULL; |
| 716 | |
| 717 | aom_free(cpi->td.mb.left_pred_buf); |
| 718 | cpi->td.mb.left_pred_buf = NULL; |
| 719 | |
| 720 | aom_free(cpi->td.mb.wsrc_buf); |
| 721 | cpi->td.mb.wsrc_buf = NULL; |
| 722 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 723 | aom_free(cpi->td.mb.inter_modes_info); |
| 724 | cpi->td.mb.inter_modes_info = NULL; |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 725 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 726 | for (int i = 0; i < 2; i++) |
| 727 | for (int j = 0; j < 2; j++) { |
| 728 | aom_free(cpi->td.mb.hash_value_buffer[i][j]); |
| 729 | cpi->td.mb.hash_value_buffer[i][j] = NULL; |
| 730 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 731 | aom_free(cpi->td.mb.mask_buf); |
| 732 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 733 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 734 | aom_free(cm->tpl_mvs); |
| 735 | cm->tpl_mvs = NULL; |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 736 | |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 737 | aom_free(cpi->td.mb.mbmi_ext); |
| 738 | cpi->td.mb.mbmi_ext = NULL; |
| 739 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 740 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 741 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 742 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 743 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 744 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 745 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 746 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 747 | aom_free_frame_buffer(&cpi->scaled_source); |
| 748 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 749 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 750 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 751 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 752 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 753 | cpi->tile_tok[0][0] = 0; |
| 754 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 755 | aom_free(cpi->tplist[0][0]); |
| 756 | cpi->tplist[0][0] = NULL; |
| 757 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 758 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 759 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 760 | aom_free(cpi->td.mb.palette_buffer); |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 761 | av1_release_compound_type_rd_buffers(&cpi->td.mb.comp_rd_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 762 | aom_free(cpi->td.mb.tmp_conv_dst); |
| 763 | for (int j = 0; j < 2; ++j) { |
| 764 | aom_free(cpi->td.mb.tmp_obmc_bufs[j]); |
| 765 | } |
| 766 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 767 | #if CONFIG_DENOISE |
| 768 | if (cpi->denoise_and_model) { |
| 769 | aom_denoise_and_model_free(cpi->denoise_and_model); |
| 770 | cpi->denoise_and_model = NULL; |
| 771 | } |
| 772 | #endif |
| 773 | if (cpi->film_grain_table) { |
| 774 | aom_film_grain_table_free(cpi->film_grain_table); |
| 775 | cpi->film_grain_table = NULL; |
| 776 | } |
Hui Su | c3a8d37 | 2019-05-28 15:52:45 -0700 | [diff] [blame] | 777 | |
| 778 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
| 779 | aom_free(cpi->level_info[i]); |
| 780 | } |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 781 | |
| 782 | if (cpi->use_svc) av1_free_svc_cyclic_refresh(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 785 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 786 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 787 | const RATE_CONTROL *const rc = &cpi->rc; |
| 788 | struct segmentation *const seg = &cm->seg; |
| 789 | |
| 790 | int high_q = (int)(rc->avg_q > 48.0); |
| 791 | int qi_delta; |
| 792 | |
| 793 | // Disable and clear down for KF |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 794 | if (cm->current_frame.frame_type == KEY_FRAME) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 795 | // Clear down the global segmentation map |
| 796 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 797 | seg->update_map = 0; |
| 798 | seg->update_data = 0; |
| 799 | cpi->static_mb_pct = 0; |
| 800 | |
| 801 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 802 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 803 | |
| 804 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 805 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 806 | } else if (cpi->refresh_alt_ref_frame) { |
| 807 | // If this is an alt ref frame |
| 808 | // Clear down the global segmentation map |
| 809 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 810 | seg->update_map = 0; |
| 811 | seg->update_data = 0; |
| 812 | cpi->static_mb_pct = 0; |
| 813 | |
| 814 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 815 | av1_disable_segmentation(seg); |
| 816 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 817 | |
Jerome Jiang | 6acbfdc | 2019-05-30 10:05:17 -0700 | [diff] [blame] | 818 | #if !CONFIG_REALTIME_ONLY |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 819 | // Scan frames from current to arf frame. |
| 820 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 821 | av1_update_mbgraph_stats(cpi); |
Jerome Jiang | 6acbfdc | 2019-05-30 10:05:17 -0700 | [diff] [blame] | 822 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 823 | |
| 824 | // If segmentation was enabled set those features needed for the |
| 825 | // arf itself. |
| 826 | if (seg->enabled) { |
| 827 | seg->update_map = 1; |
| 828 | seg->update_data = 1; |
| 829 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 830 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, |
| 831 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 832 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 833 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 834 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 835 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 836 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 837 | |
| 838 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 839 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 840 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 841 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 842 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 843 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 844 | } |
| 845 | } else if (seg->enabled) { |
| 846 | // All other frames if segmentation has been enabled |
| 847 | |
| 848 | // First normal frame in a valid gf or alt ref group |
| 849 | if (rc->frames_since_golden == 0) { |
| 850 | // Set up segment features for normal frames in an arf group |
| 851 | if (rc->source_alt_ref_active) { |
| 852 | seg->update_map = 0; |
| 853 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 854 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 855 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, |
| 856 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 857 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 858 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 859 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 860 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 861 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 862 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 863 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 864 | |
| 865 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 866 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 867 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 868 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 869 | |
| 870 | // Segment coding disabled for compred testing |
| 871 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 872 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 873 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 874 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 875 | } |
| 876 | } else { |
| 877 | // Disable segmentation and clear down features if alt ref |
| 878 | // is not active for this group |
| 879 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 880 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 881 | |
| 882 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 883 | |
| 884 | seg->update_map = 0; |
| 885 | seg->update_data = 0; |
| 886 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 887 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 888 | } |
| 889 | } else if (rc->is_src_frame_alt_ref) { |
| 890 | // Special case where we are coding over the top of a previous |
| 891 | // alt ref frame. |
| 892 | // Segment coding disabled for compred testing |
| 893 | |
| 894 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 895 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 896 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 897 | |
| 898 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 899 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 900 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 901 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 902 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 903 | |
| 904 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 905 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 906 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 907 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 908 | } |
| 909 | // Enable data update |
| 910 | seg->update_data = 1; |
| 911 | } else { |
| 912 | // All other frames. |
| 913 | |
| 914 | // No updates.. leave things as they are. |
| 915 | seg->update_map = 0; |
| 916 | seg->update_data = 0; |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 921 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 922 | AV1_COMMON *const cm = &cpi->common; |
chiyotsai | 2202ba0 | 2019-07-12 16:09:21 -0700 | [diff] [blame] | 923 | MB_MODE_INFO **mi_4x4_ptr = cm->mi_grid_base; |
David Turner | b757ce0 | 2018-11-12 15:01:28 +0000 | [diff] [blame] | 924 | uint8_t *cache_ptr = cm->cur_frame->seg_map; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 925 | int row, col; |
| 926 | |
| 927 | for (row = 0; row < cm->mi_rows; row++) { |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 928 | MB_MODE_INFO **mi_4x4 = mi_4x4_ptr; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 929 | uint8_t *cache = cache_ptr; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 930 | for (col = 0; col < cm->mi_cols; col++, mi_4x4++, cache++) |
| 931 | cache[0] = mi_4x4[0]->segment_id; |
| 932 | mi_4x4_ptr += cm->mi_stride; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 933 | cache_ptr += cm->mi_cols; |
| 934 | } |
| 935 | } |
| 936 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 937 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 938 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 939 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 940 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yunqing Wang | 1d569be | 2019-10-09 13:23:12 -0700 | [diff] [blame] | 941 | int is_scale = (oxcf->resize_mode || oxcf->superres_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | |
Satish Kumar Suman | 7a7239b | 2019-03-13 14:48:14 +0530 | [diff] [blame] | 943 | if (!cpi->lookahead) { |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 944 | cpi->lookahead = av1_lookahead_init( |
| 945 | oxcf->width, oxcf->height, seq_params->subsampling_x, |
| 946 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 7a7239b | 2019-03-13 14:48:14 +0530 | [diff] [blame] | 947 | oxcf->lag_in_frames, oxcf->border_in_pixels, is_scale); |
| 948 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 949 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 950 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | "Failed to allocate lag buffers"); |
| 952 | |
| 953 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yunqing Wang | 1d569be | 2019-10-09 13:23:12 -0700 | [diff] [blame] | 954 | // (yunqing)Here use same border as lookahead buffers. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 955 | if (aom_realloc_frame_buffer( |
| 956 | &cpi->alt_ref_buffer, oxcf->width, oxcf->height, |
| 957 | seq_params->subsampling_x, seq_params->subsampling_y, |
Yunqing Wang | 1d569be | 2019-10-09 13:23:12 -0700 | [diff] [blame] | 958 | seq_params->use_highbitdepth, |
| 959 | is_scale ? oxcf->border_in_pixels : AOM_ENC_LOOKAHEAD_BORDER, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 960 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 961 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 962 | "Failed to allocate altref buffer"); |
| 963 | } |
| 964 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 965 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 966 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 967 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 968 | if (aom_realloc_frame_buffer( |
| 969 | &cpi->last_frame_uf, cm->width, cm->height, seq_params->subsampling_x, |
| 970 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 971 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 972 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 973 | "Failed to allocate last frame buffer"); |
| 974 | |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 975 | if (aom_realloc_frame_buffer( |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 976 | &cpi->trial_frame_rst, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 977 | cm->superres_upscaled_height, seq_params->subsampling_x, |
| 978 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 3b12c00 | 2018-12-19 15:27:20 +0530 | [diff] [blame] | 979 | AOM_RESTORATION_FRAME_BORDER, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 980 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 981 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 982 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 983 | if (aom_realloc_frame_buffer( |
| 984 | &cpi->scaled_source, cm->width, cm->height, seq_params->subsampling_x, |
| 985 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 986 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 987 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 988 | "Failed to allocate scaled source buffer"); |
| 989 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 990 | if (aom_realloc_frame_buffer( |
| 991 | &cpi->scaled_last_source, cm->width, cm->height, |
| 992 | seq_params->subsampling_x, seq_params->subsampling_y, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 993 | seq_params->use_highbitdepth, cpi->oxcf.border_in_pixels, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 994 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 995 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 996 | "Failed to allocate scaled last source buffer"); |
| 997 | } |
| 998 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 999 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1000 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1001 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1002 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1003 | if (av1_alloc_context_buffers(cm, cm->width, cm->height)) { |
| 1004 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 1005 | "Failed to allocate context buffers"); |
| 1006 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1007 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 1008 | int mi_rows_aligned_to_sb = |
| 1009 | ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 1010 | int sb_rows = mi_rows_aligned_to_sb >> cm->seq_params.mib_size_log2; |
| 1011 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 1012 | av1_alloc_txb_buf(cpi); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 1013 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1014 | alloc_context_buffers_ext(cpi); |
| 1015 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1016 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1017 | |
| 1018 | { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1019 | unsigned int tokens = |
| 1020 | 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] | 1021 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1022 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1023 | } |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 1024 | aom_free(cpi->tplist[0][0]); |
| 1025 | |
| 1026 | CHECK_MEM_ERROR(cm, cpi->tplist[0][0], |
| 1027 | aom_calloc(sb_rows * MAX_TILE_ROWS * MAX_TILE_COLS, |
| 1028 | sizeof(*cpi->tplist[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1029 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1030 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1033 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1034 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 1035 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 1038 | double av1_get_compression_ratio(const AV1_COMMON *const cm, |
| 1039 | size_t encoded_frame_size) { |
| 1040 | const int upscaled_width = cm->superres_upscaled_width; |
| 1041 | const int height = cm->height; |
| 1042 | const int luma_pic_size = upscaled_width * height; |
| 1043 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 1044 | const BITSTREAM_PROFILE profile = seq_params->profile; |
| 1045 | const int pic_size_profile_factor = |
| 1046 | profile == PROFILE_0 ? 15 : (profile == PROFILE_1 ? 30 : 36); |
| 1047 | encoded_frame_size = |
| 1048 | (encoded_frame_size > 129 ? encoded_frame_size - 128 : 1); |
| 1049 | const size_t uncompressed_frame_size = |
| 1050 | (luma_pic_size * pic_size_profile_factor) >> 3; |
| 1051 | return uncompressed_frame_size / (double)encoded_frame_size; |
| 1052 | } |
| 1053 | |
Yunqing Wang | 75e20e8 | 2018-06-16 12:10:48 -0700 | [diff] [blame] | 1054 | static void set_tile_info(AV1_COMP *cpi) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1055 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1056 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1057 | |
| 1058 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1059 | |
| 1060 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1061 | 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] | 1062 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1063 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 1064 | 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] | 1065 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1066 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 1067 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1068 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1069 | cm->uniform_tile_spacing_flag = 0; |
| 1070 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 1071 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1072 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 1073 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
David Barker | 6cd5a82 | 2018-03-05 16:19:28 +0000 | [diff] [blame] | 1074 | start_sb += AOMMIN(size_sb, cm->max_tile_width_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1075 | } |
| 1076 | cm->tile_cols = i; |
| 1077 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1078 | } |
| 1079 | av1_calculate_tile_cols(cm); |
| 1080 | |
| 1081 | // configure tile rows |
| 1082 | if (cm->uniform_tile_spacing_flag) { |
| 1083 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 1084 | 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] | 1085 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1086 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 1087 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1088 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1089 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 1090 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1091 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 1092 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 1093 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1094 | } |
| 1095 | cm->tile_rows = i; |
| 1096 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1097 | } |
| 1098 | av1_calculate_tile_rows(cm); |
| 1099 | } |
| 1100 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1101 | static void update_frame_size(AV1_COMP *cpi) { |
| 1102 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1103 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 1104 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1105 | // We need to reallocate the context buffers here in case we need more mis. |
| 1106 | if (av1_alloc_context_buffers(cm, cm->width, cm->height)) { |
| 1107 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 1108 | "Failed to allocate context buffers"); |
| 1109 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1110 | av1_init_context_buffers(cm); |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1111 | |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 1112 | av1_init_macroblockd(cm, xd, NULL); |
chiyotsai | 426c066 | 2019-08-05 16:15:11 -0700 | [diff] [blame] | 1113 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 1114 | const int ext_mi_size = cm->mi_alloc_rows * cm->mi_alloc_cols; |
| 1115 | alloc_context_buffers_ext(cpi); |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 1116 | memset(cpi->mbmi_ext_frame_base, 0, |
| 1117 | ext_mi_size * sizeof(*cpi->mbmi_ext_frame_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1118 | set_tile_info(cpi); |
| 1119 | } |
| 1120 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1121 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1122 | int fb_idx; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 1123 | for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 1124 | cpi->common.remapped_ref_idx[fb_idx] = fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1125 | cpi->rate_index = 0; |
| 1126 | cpi->rate_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1129 | static INLINE int does_level_match(int width, int height, double fps, |
| 1130 | int lvl_width, int lvl_height, |
| 1131 | double lvl_fps, int lvl_dim_mult) { |
| 1132 | const int64_t lvl_luma_pels = lvl_width * lvl_height; |
| 1133 | const double lvl_display_sample_rate = lvl_luma_pels * lvl_fps; |
| 1134 | const int64_t luma_pels = width * height; |
| 1135 | const double display_sample_rate = luma_pels * fps; |
| 1136 | return luma_pels <= lvl_luma_pels && |
| 1137 | display_sample_rate <= lvl_display_sample_rate && |
| 1138 | width <= lvl_width * lvl_dim_mult && |
| 1139 | height <= lvl_height * lvl_dim_mult; |
| 1140 | } |
| 1141 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1142 | static void set_bitstream_level_tier(SequenceHeader *seq, AV1_COMMON *cm, |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 1143 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1144 | // TODO(any): This is a placeholder function that only addresses dimensions |
| 1145 | // and max display sample rates. |
| 1146 | // Need to add checks for max bit rate, max decoded luma sample rate, header |
| 1147 | // rate, etc. that are not covered by this function. |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1148 | AV1_LEVEL level = SEQ_LEVEL_MAX; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1149 | if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, 512, |
| 1150 | 288, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1151 | level = SEQ_LEVEL_2_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1152 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1153 | 704, 396, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1154 | level = SEQ_LEVEL_2_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1155 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1156 | 1088, 612, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1157 | level = SEQ_LEVEL_3_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1158 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1159 | 1376, 774, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1160 | level = SEQ_LEVEL_3_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1161 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1162 | 2048, 1152, 30.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1163 | level = SEQ_LEVEL_4_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1164 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1165 | 2048, 1152, 60.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1166 | level = SEQ_LEVEL_4_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1167 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1168 | 4096, 2176, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1169 | level = SEQ_LEVEL_5_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1170 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1171 | 4096, 2176, 60.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1172 | level = SEQ_LEVEL_5_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1173 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1174 | 4096, 2176, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1175 | level = SEQ_LEVEL_5_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1176 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1177 | 8192, 4352, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1178 | level = SEQ_LEVEL_6_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1179 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1180 | 8192, 4352, 60.0, 2)) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1181 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1182 | 8192, 4352, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1183 | level = SEQ_LEVEL_6_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1184 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1185 | 16384, 8704, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1186 | level = SEQ_LEVEL_7_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1187 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1188 | 16384, 8704, 60.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1189 | level = SEQ_LEVEL_7_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1190 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1191 | 16384, 8704, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1192 | level = SEQ_LEVEL_7_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1193 | } |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1194 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1195 | seq->seq_level_idx[i] = level; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1196 | // Set the maximum parameters for bitrate and buffer size for this profile, |
| 1197 | // level, and tier |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 1198 | cm->op_params[i].bitrate = av1_max_level_bitrate( |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1199 | cm->seq_params.profile, seq->seq_level_idx[i], seq->tier[i]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1200 | // Level with seq_level_idx = 31 returns a high "dummy" bitrate to pass the |
| 1201 | // check |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1202 | if (cm->op_params[i].bitrate == 0) |
| 1203 | aom_internal_error( |
| 1204 | &cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 1205 | "AV1 does not support this combination of profile, level, and tier."); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1206 | // Buffer size in bits/s is bitrate in bits/s * 1 s |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1207 | cm->op_params[i].buffer_size = cm->op_params[i].bitrate; |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1211 | static void init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm, |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1212 | const AV1EncoderConfig *oxcf, int use_svc) { |
Yaowu Xu | 2a9ac43 | 2019-08-06 14:21:17 -0700 | [diff] [blame] | 1213 | seq->still_picture = (oxcf->force_video_mode == 0) && (oxcf->limit == 1); |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1214 | seq->reduced_still_picture_hdr = seq->still_picture; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 1215 | seq->reduced_still_picture_hdr &= !oxcf->full_still_picture_hdr; |
kyslov | 9424338 | 2019-05-02 15:33:32 -0700 | [diff] [blame] | 1216 | seq->force_screen_content_tools = (oxcf->mode == REALTIME) ? 0 : 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1217 | seq->force_integer_mv = 2; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1218 | seq->order_hint_info.enable_order_hint = oxcf->enable_order_hint; |
David Turner | 936235c | 2018-11-28 13:42:01 +0000 | [diff] [blame] | 1219 | seq->frame_id_numbers_present_flag = |
| 1220 | !(seq->still_picture && seq->reduced_still_picture_hdr) && |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1221 | !oxcf->large_scale_tile && oxcf->error_resilient_mode && !use_svc; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1222 | if (seq->still_picture && seq->reduced_still_picture_hdr) { |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1223 | seq->order_hint_info.enable_order_hint = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1224 | seq->force_screen_content_tools = 2; |
| 1225 | seq->force_integer_mv = 2; |
| 1226 | } |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1227 | seq->order_hint_info.order_hint_bits_minus_1 = |
| 1228 | seq->order_hint_info.enable_order_hint |
| 1229 | ? DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1 |
| 1230 | : -1; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1231 | |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 1232 | seq->max_frame_width = |
| 1233 | oxcf->forced_max_frame_width ? oxcf->forced_max_frame_width : oxcf->width; |
| 1234 | seq->max_frame_height = oxcf->forced_max_frame_height |
| 1235 | ? oxcf->forced_max_frame_height |
| 1236 | : oxcf->height; |
| 1237 | seq->num_bits_width = |
| 1238 | (seq->max_frame_width > 1) ? get_msb(seq->max_frame_width - 1) + 1 : 1; |
| 1239 | seq->num_bits_height = |
| 1240 | (seq->max_frame_height > 1) ? get_msb(seq->max_frame_height - 1) + 1 : 1; |
| 1241 | assert(seq->num_bits_width <= 16); |
| 1242 | assert(seq->num_bits_height <= 16); |
| 1243 | |
| 1244 | seq->frame_id_length = FRAME_ID_LENGTH; |
| 1245 | seq->delta_frame_id_length = DELTA_FRAME_ID_LENGTH; |
| 1246 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1247 | seq->enable_dual_filter = oxcf->enable_dual_filter; |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 1248 | seq->order_hint_info.enable_dist_wtd_comp = oxcf->enable_dist_wtd_comp; |
| 1249 | seq->order_hint_info.enable_dist_wtd_comp &= |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1250 | seq->order_hint_info.enable_order_hint; |
| 1251 | seq->order_hint_info.enable_ref_frame_mvs = oxcf->enable_ref_frame_mvs; |
| 1252 | seq->order_hint_info.enable_ref_frame_mvs &= |
| 1253 | seq->order_hint_info.enable_order_hint; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1254 | seq->enable_superres = oxcf->enable_superres; |
| 1255 | seq->enable_cdef = oxcf->enable_cdef; |
| 1256 | seq->enable_restoration = oxcf->enable_restoration; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 1257 | seq->enable_warped_motion = oxcf->enable_warped_motion; |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 1258 | seq->enable_interintra_compound = oxcf->enable_interintra_comp; |
| 1259 | seq->enable_masked_compound = oxcf->enable_masked_comp; |
Debargha Mukherjee | 03c43ba | 2018-12-14 13:08:08 -0800 | [diff] [blame] | 1260 | seq->enable_intra_edge_filter = oxcf->enable_intra_edge_filter; |
Yue Chen | 8f9ca58 | 2018-12-12 15:11:47 -0800 | [diff] [blame] | 1261 | seq->enable_filter_intra = oxcf->enable_filter_intra; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1262 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1263 | set_bitstream_level_tier(seq, cm, oxcf); |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1264 | |
| 1265 | if (seq->operating_points_cnt_minus_1 == 0) { |
| 1266 | seq->operating_point_idc[0] = 0; |
| 1267 | } else { |
Marco Paniconi | 6da983b | 2019-09-16 20:12:43 -0700 | [diff] [blame] | 1268 | // Set operating_point_idc[] such that the i=0 point corresponds to the |
| 1269 | // highest quality operating point (all layers), and subsequent |
| 1270 | // operarting points (i > 0) are lower quality corresponding to |
| 1271 | // skip decoding enhancement layers (temporal first). |
| 1272 | int i = 0; |
| 1273 | assert(seq->operating_points_cnt_minus_1 == |
| 1274 | (int)(cm->number_spatial_layers * cm->number_temporal_layers - 1)); |
| 1275 | for (unsigned int sl = 0; sl < cm->number_spatial_layers; sl++) { |
| 1276 | for (unsigned int tl = 0; tl < cm->number_temporal_layers; tl++) { |
| 1277 | seq->operating_point_idc[i] = |
| 1278 | (~(~0u << (cm->number_spatial_layers - sl)) << 8) | |
| 1279 | ~(~0u << (cm->number_temporal_layers - tl)); |
| 1280 | i++; |
| 1281 | } |
| 1282 | } |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1283 | } |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1286 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1287 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1288 | |
| 1289 | cpi->oxcf = *oxcf; |
| 1290 | cpi->framerate = oxcf->init_framerate; |
| 1291 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1292 | cm->seq_params.profile = oxcf->profile; |
| 1293 | cm->seq_params.bit_depth = oxcf->bit_depth; |
| 1294 | cm->seq_params.use_highbitdepth = oxcf->use_highbitdepth; |
| 1295 | cm->seq_params.color_primaries = oxcf->color_primaries; |
| 1296 | cm->seq_params.transfer_characteristics = oxcf->transfer_characteristics; |
| 1297 | cm->seq_params.matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1298 | cm->seq_params.monochrome = oxcf->monochrome; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1299 | cm->seq_params.chroma_sample_position = oxcf->chroma_sample_position; |
| 1300 | cm->seq_params.color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 1301 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1302 | cm->timing_info.num_units_in_display_tick = |
| 1303 | oxcf->timing_info.num_units_in_display_tick; |
| 1304 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 1305 | cm->timing_info.equal_picture_interval = |
| 1306 | oxcf->timing_info.equal_picture_interval; |
| 1307 | cm->timing_info.num_ticks_per_picture = |
| 1308 | oxcf->timing_info.num_ticks_per_picture; |
| 1309 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1310 | cm->seq_params.display_model_info_present_flag = |
| 1311 | oxcf->display_model_info_present_flag; |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1312 | cm->seq_params.decoder_model_info_present_flag = |
| 1313 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1314 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1315 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1316 | cm->buffer_model.num_units_in_decoding_tick = |
| 1317 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 1318 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1319 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 1320 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1321 | } else if (cm->timing_info_present && |
| 1322 | cm->timing_info.equal_picture_interval && |
| 1323 | !cm->seq_params.decoder_model_info_present_flag) { |
| 1324 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1325 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1326 | } else { |
| 1327 | cm->op_params[0].initial_display_delay = |
| 1328 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1329 | } |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1330 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1331 | if (cm->seq_params.monochrome) { |
| 1332 | cm->seq_params.subsampling_x = 1; |
| 1333 | cm->seq_params.subsampling_y = 1; |
| 1334 | } else if (cm->seq_params.color_primaries == AOM_CICP_CP_BT_709 && |
| 1335 | cm->seq_params.transfer_characteristics == AOM_CICP_TC_SRGB && |
| 1336 | cm->seq_params.matrix_coefficients == AOM_CICP_MC_IDENTITY) { |
| 1337 | cm->seq_params.subsampling_x = 0; |
| 1338 | cm->seq_params.subsampling_y = 0; |
| 1339 | } else { |
| 1340 | if (cm->seq_params.profile == 0) { |
| 1341 | cm->seq_params.subsampling_x = 1; |
| 1342 | cm->seq_params.subsampling_y = 1; |
| 1343 | } else if (cm->seq_params.profile == 1) { |
| 1344 | cm->seq_params.subsampling_x = 0; |
| 1345 | cm->seq_params.subsampling_y = 0; |
| 1346 | } else { |
| 1347 | if (cm->seq_params.bit_depth == AOM_BITS_12) { |
| 1348 | cm->seq_params.subsampling_x = oxcf->chroma_subsampling_x; |
| 1349 | cm->seq_params.subsampling_y = oxcf->chroma_subsampling_y; |
| 1350 | } else { |
| 1351 | cm->seq_params.subsampling_x = 1; |
| 1352 | cm->seq_params.subsampling_y = 0; |
| 1353 | } |
| 1354 | } |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1357 | cm->width = oxcf->width; |
| 1358 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1359 | set_sb_size(&cm->seq_params, |
| 1360 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1361 | alloc_compressor_data(cpi); |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 1362 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 1363 | update_film_grain_parameters(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1364 | |
| 1365 | // Single thread case: use counts in common. |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 1366 | cpi->td.counts = &cpi->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1367 | |
Marco Paniconi | 882c5ad | 2019-09-30 21:32:29 -0700 | [diff] [blame] | 1368 | // Set init SVC parameters. |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1369 | cpi->use_svc = 0; |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 1370 | cpi->svc.external_ref_frame_config = 0; |
| 1371 | cpi->svc.non_reference_frame = 0; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1372 | cm->number_spatial_layers = 1; |
| 1373 | cm->number_temporal_layers = 1; |
Marco Paniconi | 882c5ad | 2019-09-30 21:32:29 -0700 | [diff] [blame] | 1374 | cm->spatial_layer_id = 0; |
| 1375 | cm->temporal_layer_id = 0; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1376 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1377 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1378 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1379 | |
| 1380 | cpi->static_mb_pct = 0; |
| 1381 | cpi->ref_frame_flags = 0; |
| 1382 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1383 | // Reset resize pending flags |
| 1384 | cpi->resize_pending_width = 0; |
| 1385 | cpi->resize_pending_height = 0; |
| 1386 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1387 | init_buffer_indices(cpi); |
| 1388 | } |
| 1389 | |
| 1390 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1391 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1392 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1393 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1394 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1395 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1396 | |
| 1397 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1398 | rc->optimal_buffer_level = |
| 1399 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1400 | rc->maximum_buffer_size = |
| 1401 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1402 | } |
| 1403 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1404 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 1405 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1406 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1407 | cpi->fn_ptr[BT].vf = VF; \ |
| 1408 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1409 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1410 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 1411 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1412 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1413 | |
| 1414 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1415 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1416 | int source_stride, \ |
| 1417 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1418 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1419 | } \ |
| 1420 | static unsigned int fnname##_bits10( \ |
| 1421 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1422 | int ref_stride) { \ |
| 1423 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1424 | } \ |
| 1425 | static unsigned int fnname##_bits12( \ |
| 1426 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1427 | int ref_stride) { \ |
| 1428 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1429 | } |
| 1430 | |
| 1431 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1432 | static unsigned int fnname##_bits8( \ |
| 1433 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1434 | int ref_stride, const uint8_t *second_pred) { \ |
| 1435 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1436 | } \ |
| 1437 | static unsigned int fnname##_bits10( \ |
| 1438 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1439 | int ref_stride, const uint8_t *second_pred) { \ |
| 1440 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1441 | 2; \ |
| 1442 | } \ |
| 1443 | static unsigned int fnname##_bits12( \ |
| 1444 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1445 | int ref_stride, const uint8_t *second_pred) { \ |
| 1446 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1447 | 4; \ |
| 1448 | } |
| 1449 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1450 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1451 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1452 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1453 | unsigned int *sad_array) { \ |
| 1454 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1455 | } \ |
| 1456 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1457 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1458 | unsigned int *sad_array) { \ |
| 1459 | int i; \ |
| 1460 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1461 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1462 | } \ |
| 1463 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1464 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1465 | unsigned int *sad_array) { \ |
| 1466 | int i; \ |
| 1467 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1468 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1469 | } |
| 1470 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1471 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1472 | static unsigned int fnname##_bits8( \ |
| 1473 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1474 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1475 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1476 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1477 | jcp_param); \ |
| 1478 | } \ |
| 1479 | static unsigned int fnname##_bits10( \ |
| 1480 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1481 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1482 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1483 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1484 | jcp_param) >> \ |
| 1485 | 2; \ |
| 1486 | } \ |
| 1487 | static unsigned int fnname##_bits12( \ |
| 1488 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1489 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1490 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1491 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1492 | jcp_param) >> \ |
| 1493 | 4; \ |
| 1494 | } |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1495 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1496 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1497 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1498 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1499 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1500 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1501 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1502 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1503 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1504 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1505 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1506 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1507 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1508 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1509 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1510 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1511 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1512 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1513 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1514 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1515 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1516 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1517 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1518 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1519 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1520 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1521 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1522 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1523 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1524 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1525 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1526 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1527 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1528 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1529 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1530 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1531 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1532 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1533 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1534 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1535 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1536 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1537 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1538 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1539 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1540 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1541 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1542 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1543 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1544 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1545 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1546 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1547 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1548 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1549 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1550 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1551 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1552 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1553 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1554 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1555 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1556 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1557 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1558 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1559 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1560 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1561 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1562 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1563 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1564 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1565 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x128_avg) |
| 1566 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x64_avg) |
| 1567 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x128_avg) |
| 1568 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x16_avg) |
| 1569 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x32_avg) |
| 1570 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x32_avg) |
| 1571 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x64_avg) |
| 1572 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x32_avg) |
| 1573 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x64_avg) |
| 1574 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x16_avg) |
| 1575 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x8_avg) |
| 1576 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x16_avg) |
| 1577 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x8_avg) |
| 1578 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x4_avg) |
| 1579 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x8_avg) |
| 1580 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x4_avg) |
| 1581 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x16_avg) |
| 1582 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x4_avg) |
| 1583 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x32_avg) |
| 1584 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x8_avg) |
| 1585 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x64_avg) |
| 1586 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x16_avg) |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1587 | #endif // CONFIG_AV1_HIGHBITDEPTH |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1588 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1589 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1590 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1591 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1592 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1593 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1594 | static unsigned int fnname##_bits8( \ |
| 1595 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1596 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1597 | int m_stride, int invert_mask) { \ |
| 1598 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1599 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1600 | } \ |
| 1601 | static unsigned int fnname##_bits10( \ |
| 1602 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1603 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1604 | int m_stride, int invert_mask) { \ |
| 1605 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1606 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1607 | 2; \ |
| 1608 | } \ |
| 1609 | static unsigned int fnname##_bits12( \ |
| 1610 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1611 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1612 | int m_stride, int invert_mask) { \ |
| 1613 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1614 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1615 | 4; \ |
| 1616 | } |
| 1617 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1618 | #if CONFIG_AV1_HIGHBITDEPTH |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1619 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1620 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1621 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1622 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1623 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1624 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1625 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1626 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1627 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1628 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1629 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1630 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1631 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1632 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1633 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1634 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1635 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1636 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1637 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1638 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1639 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1640 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1641 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1642 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1643 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1644 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1645 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1646 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1647 | |
| 1648 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1649 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1650 | const int32_t *wsrc, \ |
| 1651 | const int32_t *msk) { \ |
| 1652 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1653 | } \ |
| 1654 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1655 | const int32_t *wsrc, \ |
| 1656 | const int32_t *msk) { \ |
| 1657 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1658 | } \ |
| 1659 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1660 | const int32_t *wsrc, \ |
| 1661 | const int32_t *msk) { \ |
| 1662 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1663 | } |
| 1664 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 1665 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1666 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1667 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1668 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1669 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1670 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1671 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1672 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1673 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1674 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1675 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1676 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1677 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1678 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1679 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1680 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1681 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1682 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1683 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1684 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1685 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1686 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1687 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1688 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1689 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1690 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1691 | if (cm->seq_params.use_highbitdepth) { |
| 1692 | switch (cm->seq_params.bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1693 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1694 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1695 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1696 | aom_highbd_8_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1697 | aom_highbd_8_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1698 | aom_highbd_sad64x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1699 | aom_highbd_dist_wtd_sad64x16_avg_bits8, |
| 1700 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1701 | |
| 1702 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1703 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1704 | aom_highbd_8_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1705 | aom_highbd_8_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1706 | aom_highbd_sad16x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1707 | aom_highbd_dist_wtd_sad16x64_avg_bits8, |
| 1708 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1709 | |
| 1710 | HIGHBD_BFP( |
| 1711 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1712 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1713 | aom_highbd_8_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1714 | aom_highbd_sad32x8x4d_bits8, aom_highbd_dist_wtd_sad32x8_avg_bits8, |
| 1715 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1716 | |
| 1717 | HIGHBD_BFP( |
| 1718 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1719 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1720 | aom_highbd_8_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1721 | aom_highbd_sad8x32x4d_bits8, aom_highbd_dist_wtd_sad8x32_avg_bits8, |
| 1722 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1723 | |
| 1724 | HIGHBD_BFP( |
| 1725 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1726 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1727 | aom_highbd_8_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1728 | aom_highbd_sad16x4x4d_bits8, aom_highbd_dist_wtd_sad16x4_avg_bits8, |
| 1729 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1730 | |
| 1731 | HIGHBD_BFP( |
| 1732 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1733 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1734 | aom_highbd_8_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1735 | aom_highbd_sad4x16x4d_bits8, aom_highbd_dist_wtd_sad4x16_avg_bits8, |
| 1736 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1737 | |
| 1738 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1739 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1740 | aom_highbd_8_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1741 | aom_highbd_8_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1742 | aom_highbd_sad32x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1743 | aom_highbd_dist_wtd_sad32x16_avg_bits8, |
| 1744 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1745 | |
| 1746 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1747 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1748 | aom_highbd_8_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1749 | aom_highbd_8_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1750 | aom_highbd_sad16x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1751 | aom_highbd_dist_wtd_sad16x32_avg_bits8, |
| 1752 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1753 | |
| 1754 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1755 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1756 | aom_highbd_8_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1757 | aom_highbd_8_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1758 | aom_highbd_sad64x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1759 | aom_highbd_dist_wtd_sad64x32_avg_bits8, |
| 1760 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1761 | |
| 1762 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1763 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1764 | aom_highbd_8_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1765 | aom_highbd_8_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1766 | aom_highbd_sad32x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1767 | aom_highbd_dist_wtd_sad32x64_avg_bits8, |
| 1768 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1769 | |
| 1770 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1771 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1772 | aom_highbd_8_sub_pixel_variance32x32, |
| 1773 | aom_highbd_8_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1774 | aom_highbd_sad32x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1775 | aom_highbd_dist_wtd_sad32x32_avg_bits8, |
| 1776 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1777 | |
| 1778 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1779 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1780 | aom_highbd_8_sub_pixel_variance64x64, |
| 1781 | aom_highbd_8_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1782 | aom_highbd_sad64x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1783 | aom_highbd_dist_wtd_sad64x64_avg_bits8, |
| 1784 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1785 | |
| 1786 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1787 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1788 | aom_highbd_8_sub_pixel_variance16x16, |
| 1789 | aom_highbd_8_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1790 | aom_highbd_sad16x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1791 | aom_highbd_dist_wtd_sad16x16_avg_bits8, |
| 1792 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1793 | |
| 1794 | HIGHBD_BFP( |
| 1795 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1796 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1797 | aom_highbd_8_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1798 | aom_highbd_sad16x8x4d_bits8, aom_highbd_dist_wtd_sad16x8_avg_bits8, |
| 1799 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1800 | |
| 1801 | HIGHBD_BFP( |
| 1802 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1803 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1804 | aom_highbd_8_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1805 | aom_highbd_sad8x16x4d_bits8, aom_highbd_dist_wtd_sad8x16_avg_bits8, |
| 1806 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1807 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1808 | HIGHBD_BFP( |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1809 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1810 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1811 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x4d_bits8, |
| 1812 | aom_highbd_dist_wtd_sad8x8_avg_bits8, |
| 1813 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x8) |
| 1814 | |
| 1815 | HIGHBD_BFP( |
| 1816 | BLOCK_8X4, aom_highbd_sad8x4_bits8, aom_highbd_sad8x4_avg_bits8, |
| 1817 | aom_highbd_8_variance8x4, aom_highbd_8_sub_pixel_variance8x4, |
| 1818 | aom_highbd_8_sub_pixel_avg_variance8x4, aom_highbd_sad8x4x4d_bits8, |
| 1819 | aom_highbd_dist_wtd_sad8x4_avg_bits8, |
| 1820 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x4) |
| 1821 | |
| 1822 | HIGHBD_BFP( |
| 1823 | BLOCK_4X8, aom_highbd_sad4x8_bits8, aom_highbd_sad4x8_avg_bits8, |
| 1824 | aom_highbd_8_variance4x8, aom_highbd_8_sub_pixel_variance4x8, |
| 1825 | aom_highbd_8_sub_pixel_avg_variance4x8, aom_highbd_sad4x8x4d_bits8, |
| 1826 | aom_highbd_dist_wtd_sad4x8_avg_bits8, |
| 1827 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x8) |
| 1828 | |
| 1829 | HIGHBD_BFP( |
| 1830 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1831 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1832 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x4d_bits8, |
| 1833 | aom_highbd_dist_wtd_sad4x4_avg_bits8, |
| 1834 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x4) |
| 1835 | |
| 1836 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1837 | aom_highbd_sad128x128_avg_bits8, |
| 1838 | aom_highbd_8_variance128x128, |
| 1839 | aom_highbd_8_sub_pixel_variance128x128, |
| 1840 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1841 | aom_highbd_sad128x128x4d_bits8, |
| 1842 | aom_highbd_dist_wtd_sad128x128_avg_bits8, |
| 1843 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1844 | |
| 1845 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1846 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1847 | aom_highbd_8_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1848 | aom_highbd_8_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1849 | aom_highbd_sad128x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1850 | aom_highbd_dist_wtd_sad128x64_avg_bits8, |
| 1851 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1852 | |
| 1853 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1854 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1855 | aom_highbd_8_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1856 | aom_highbd_8_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1857 | aom_highbd_sad64x128x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1858 | aom_highbd_dist_wtd_sad64x128_avg_bits8, |
| 1859 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1860 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1861 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1862 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1863 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1864 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1865 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1866 | aom_highbd_8_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1867 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1868 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1869 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1870 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1871 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1872 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1873 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1874 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1875 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1876 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1877 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1878 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1879 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1880 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1881 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1882 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1883 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1884 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1885 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1886 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1887 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1888 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1889 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1890 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1891 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1892 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1893 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1894 | aom_highbd_8_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1895 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1896 | aom_highbd_8_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1897 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1898 | aom_highbd_8_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1899 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1900 | aom_highbd_8_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1901 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1902 | aom_highbd_8_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1903 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1904 | aom_highbd_8_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1905 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1906 | aom_highbd_obmc_variance128x128, |
| 1907 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1908 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1909 | aom_highbd_obmc_variance128x64, |
| 1910 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1911 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1912 | aom_highbd_obmc_variance64x128, |
| 1913 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1914 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1915 | aom_highbd_obmc_variance64x64, |
| 1916 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1917 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1918 | aom_highbd_obmc_variance64x32, |
| 1919 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1920 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1921 | aom_highbd_obmc_variance32x64, |
| 1922 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1923 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1924 | aom_highbd_obmc_variance32x32, |
| 1925 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1926 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1927 | aom_highbd_obmc_variance32x16, |
| 1928 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1929 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1930 | aom_highbd_obmc_variance16x32, |
| 1931 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1932 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1933 | aom_highbd_obmc_variance16x16, |
| 1934 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1935 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1936 | aom_highbd_obmc_variance8x16, |
| 1937 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1938 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1939 | aom_highbd_obmc_variance16x8, |
| 1940 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1941 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1942 | aom_highbd_obmc_variance8x8, |
| 1943 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1944 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1945 | aom_highbd_obmc_variance4x8, |
| 1946 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1947 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1948 | aom_highbd_obmc_variance8x4, |
| 1949 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1950 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1951 | aom_highbd_obmc_variance4x4, |
| 1952 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1953 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1954 | aom_highbd_obmc_variance64x16, |
| 1955 | aom_highbd_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1956 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1957 | aom_highbd_obmc_variance16x64, |
| 1958 | aom_highbd_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1959 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1960 | aom_highbd_obmc_variance32x8, |
| 1961 | aom_highbd_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1962 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1963 | aom_highbd_obmc_variance8x32, |
| 1964 | aom_highbd_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1965 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1966 | aom_highbd_obmc_variance16x4, |
| 1967 | aom_highbd_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1968 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1969 | aom_highbd_obmc_variance4x16, |
| 1970 | aom_highbd_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1971 | break; |
| 1972 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1973 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1974 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1975 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1976 | aom_highbd_10_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1977 | aom_highbd_10_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1978 | aom_highbd_sad64x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1979 | aom_highbd_dist_wtd_sad64x16_avg_bits10, |
| 1980 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1981 | |
| 1982 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1983 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1984 | aom_highbd_10_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1985 | aom_highbd_10_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1986 | aom_highbd_sad16x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1987 | aom_highbd_dist_wtd_sad16x64_avg_bits10, |
| 1988 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1989 | |
| 1990 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1991 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1992 | aom_highbd_10_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1993 | aom_highbd_10_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1994 | aom_highbd_sad32x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1995 | aom_highbd_dist_wtd_sad32x8_avg_bits10, |
| 1996 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1997 | |
| 1998 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1999 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 2000 | aom_highbd_10_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2001 | aom_highbd_10_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2002 | aom_highbd_sad8x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2003 | aom_highbd_dist_wtd_sad8x32_avg_bits10, |
| 2004 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2005 | |
| 2006 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 2007 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 2008 | aom_highbd_10_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2009 | aom_highbd_10_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2010 | aom_highbd_sad16x4x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2011 | aom_highbd_dist_wtd_sad16x4_avg_bits10, |
| 2012 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2013 | |
| 2014 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 2015 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 2016 | aom_highbd_10_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2017 | aom_highbd_10_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2018 | aom_highbd_sad4x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2019 | aom_highbd_dist_wtd_sad4x16_avg_bits10, |
| 2020 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2021 | |
| 2022 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 2023 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 2024 | aom_highbd_10_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2025 | aom_highbd_10_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2026 | aom_highbd_sad32x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2027 | aom_highbd_dist_wtd_sad32x16_avg_bits10, |
| 2028 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2029 | |
| 2030 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 2031 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 2032 | aom_highbd_10_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2033 | aom_highbd_10_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2034 | aom_highbd_sad16x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2035 | aom_highbd_dist_wtd_sad16x32_avg_bits10, |
| 2036 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2037 | |
| 2038 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 2039 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 2040 | aom_highbd_10_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2041 | aom_highbd_10_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2042 | aom_highbd_sad64x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2043 | aom_highbd_dist_wtd_sad64x32_avg_bits10, |
| 2044 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2045 | |
| 2046 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 2047 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 2048 | aom_highbd_10_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2049 | aom_highbd_10_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2050 | aom_highbd_sad32x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2051 | aom_highbd_dist_wtd_sad32x64_avg_bits10, |
| 2052 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2053 | |
| 2054 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 2055 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 2056 | aom_highbd_10_sub_pixel_variance32x32, |
| 2057 | aom_highbd_10_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2058 | aom_highbd_sad32x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2059 | aom_highbd_dist_wtd_sad32x32_avg_bits10, |
| 2060 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2061 | |
| 2062 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 2063 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 2064 | aom_highbd_10_sub_pixel_variance64x64, |
| 2065 | aom_highbd_10_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2066 | aom_highbd_sad64x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2067 | aom_highbd_dist_wtd_sad64x64_avg_bits10, |
| 2068 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2069 | |
| 2070 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 2071 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 2072 | aom_highbd_10_sub_pixel_variance16x16, |
| 2073 | aom_highbd_10_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2074 | aom_highbd_sad16x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2075 | aom_highbd_dist_wtd_sad16x16_avg_bits10, |
| 2076 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2077 | |
| 2078 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 2079 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 2080 | aom_highbd_10_sub_pixel_variance16x8, |
| 2081 | aom_highbd_10_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2082 | aom_highbd_sad16x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2083 | aom_highbd_dist_wtd_sad16x8_avg_bits10, |
| 2084 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2085 | |
| 2086 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 2087 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 2088 | aom_highbd_10_sub_pixel_variance8x16, |
| 2089 | aom_highbd_10_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2090 | aom_highbd_sad8x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2091 | aom_highbd_dist_wtd_sad8x16_avg_bits10, |
| 2092 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2093 | |
| 2094 | HIGHBD_BFP( |
| 2095 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 2096 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2097 | aom_highbd_10_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2098 | aom_highbd_sad8x8x4d_bits10, aom_highbd_dist_wtd_sad8x8_avg_bits10, |
| 2099 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2100 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2101 | HIGHBD_BFP( |
| 2102 | BLOCK_8X4, aom_highbd_sad8x4_bits10, aom_highbd_sad8x4_avg_bits10, |
| 2103 | aom_highbd_10_variance8x4, aom_highbd_10_sub_pixel_variance8x4, |
| 2104 | aom_highbd_10_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2105 | aom_highbd_sad8x4x4d_bits10, aom_highbd_dist_wtd_sad8x4_avg_bits10, |
| 2106 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2107 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2108 | HIGHBD_BFP( |
| 2109 | BLOCK_4X8, aom_highbd_sad4x8_bits10, aom_highbd_sad4x8_avg_bits10, |
| 2110 | aom_highbd_10_variance4x8, aom_highbd_10_sub_pixel_variance4x8, |
| 2111 | aom_highbd_10_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2112 | aom_highbd_sad4x8x4d_bits10, aom_highbd_dist_wtd_sad4x8_avg_bits10, |
| 2113 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2114 | |
| 2115 | HIGHBD_BFP( |
| 2116 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 2117 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2118 | aom_highbd_10_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2119 | aom_highbd_sad4x4x4d_bits10, aom_highbd_dist_wtd_sad4x4_avg_bits10, |
| 2120 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2121 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2122 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 2123 | aom_highbd_sad128x128_avg_bits10, |
| 2124 | aom_highbd_10_variance128x128, |
| 2125 | aom_highbd_10_sub_pixel_variance128x128, |
| 2126 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 2127 | aom_highbd_sad128x128x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2128 | aom_highbd_dist_wtd_sad128x128_avg_bits10, |
| 2129 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2130 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2131 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 2132 | aom_highbd_sad128x64_avg_bits10, |
| 2133 | aom_highbd_10_variance128x64, |
| 2134 | aom_highbd_10_sub_pixel_variance128x64, |
| 2135 | aom_highbd_10_sub_pixel_avg_variance128x64, |
| 2136 | aom_highbd_sad128x64x4d_bits10, |
| 2137 | aom_highbd_dist_wtd_sad128x64_avg_bits10, |
| 2138 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2139 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2140 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 2141 | aom_highbd_sad64x128_avg_bits10, |
| 2142 | aom_highbd_10_variance64x128, |
| 2143 | aom_highbd_10_sub_pixel_variance64x128, |
| 2144 | aom_highbd_10_sub_pixel_avg_variance64x128, |
| 2145 | aom_highbd_sad64x128x4d_bits10, |
| 2146 | aom_highbd_dist_wtd_sad64x128_avg_bits10, |
| 2147 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2148 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2149 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 2150 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 2151 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 2152 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 2153 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 2154 | aom_highbd_10_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2155 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 2156 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 2157 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 2158 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 2159 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 2160 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 2161 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 2162 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 2163 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 2164 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 2165 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 2166 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 2167 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 2168 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 2169 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 2170 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 2171 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 2172 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 2173 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 2174 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 2175 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 2176 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 2177 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 2178 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 2179 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 2180 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2181 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 2182 | aom_highbd_10_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2183 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 2184 | aom_highbd_10_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2185 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 2186 | aom_highbd_10_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2187 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 2188 | aom_highbd_10_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2189 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 2190 | aom_highbd_10_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2191 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 2192 | aom_highbd_10_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2193 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 2194 | aom_highbd_10_obmc_variance128x128, |
| 2195 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 2196 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 2197 | aom_highbd_10_obmc_variance128x64, |
| 2198 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 2199 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 2200 | aom_highbd_10_obmc_variance64x128, |
| 2201 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2202 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 2203 | aom_highbd_10_obmc_variance64x64, |
| 2204 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2205 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2206 | aom_highbd_10_obmc_variance64x32, |
| 2207 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2208 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2209 | aom_highbd_10_obmc_variance32x64, |
| 2210 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2211 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2212 | aom_highbd_10_obmc_variance32x32, |
| 2213 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2214 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2215 | aom_highbd_10_obmc_variance32x16, |
| 2216 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2217 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2218 | aom_highbd_10_obmc_variance16x32, |
| 2219 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2220 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2221 | aom_highbd_10_obmc_variance16x16, |
| 2222 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2223 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2224 | aom_highbd_10_obmc_variance8x16, |
| 2225 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2226 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2227 | aom_highbd_10_obmc_variance16x8, |
| 2228 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2229 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2230 | aom_highbd_10_obmc_variance8x8, |
| 2231 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2232 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2233 | aom_highbd_10_obmc_variance4x8, |
| 2234 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2235 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2236 | aom_highbd_10_obmc_variance8x4, |
| 2237 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2238 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2239 | aom_highbd_10_obmc_variance4x4, |
| 2240 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2241 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2242 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2243 | aom_highbd_10_obmc_variance64x16, |
| 2244 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2245 | |
| 2246 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2247 | aom_highbd_10_obmc_variance16x64, |
| 2248 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2249 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2250 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2251 | aom_highbd_10_obmc_variance32x8, |
| 2252 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2253 | |
| 2254 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2255 | aom_highbd_10_obmc_variance8x32, |
| 2256 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2257 | |
| 2258 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2259 | aom_highbd_10_obmc_variance16x4, |
| 2260 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2261 | |
| 2262 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2263 | aom_highbd_10_obmc_variance4x16, |
| 2264 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2265 | break; |
| 2266 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2267 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2268 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2269 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2270 | aom_highbd_12_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2271 | aom_highbd_12_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2272 | aom_highbd_sad64x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2273 | aom_highbd_dist_wtd_sad64x16_avg_bits12, |
| 2274 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2275 | |
| 2276 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2277 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2278 | aom_highbd_12_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2279 | aom_highbd_12_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2280 | aom_highbd_sad16x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2281 | aom_highbd_dist_wtd_sad16x64_avg_bits12, |
| 2282 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2283 | |
| 2284 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2285 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2286 | aom_highbd_12_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2287 | aom_highbd_12_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2288 | aom_highbd_sad32x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2289 | aom_highbd_dist_wtd_sad32x8_avg_bits12, |
| 2290 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2291 | |
| 2292 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2293 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2294 | aom_highbd_12_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2295 | aom_highbd_12_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2296 | aom_highbd_sad8x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2297 | aom_highbd_dist_wtd_sad8x32_avg_bits12, |
| 2298 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2299 | |
| 2300 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2301 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2302 | aom_highbd_12_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2303 | aom_highbd_12_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2304 | aom_highbd_sad16x4x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2305 | aom_highbd_dist_wtd_sad16x4_avg_bits12, |
| 2306 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2307 | |
| 2308 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2309 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2310 | aom_highbd_12_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2311 | aom_highbd_12_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2312 | aom_highbd_sad4x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2313 | aom_highbd_dist_wtd_sad4x16_avg_bits12, |
| 2314 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2315 | |
| 2316 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2317 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2318 | aom_highbd_12_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2319 | aom_highbd_12_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2320 | aom_highbd_sad32x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2321 | aom_highbd_dist_wtd_sad32x16_avg_bits12, |
| 2322 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2323 | |
| 2324 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2325 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2326 | aom_highbd_12_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2327 | aom_highbd_12_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2328 | aom_highbd_sad16x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2329 | aom_highbd_dist_wtd_sad16x32_avg_bits12, |
| 2330 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2331 | |
| 2332 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2333 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2334 | aom_highbd_12_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2335 | aom_highbd_12_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2336 | aom_highbd_sad64x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2337 | aom_highbd_dist_wtd_sad64x32_avg_bits12, |
| 2338 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2339 | |
| 2340 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2341 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2342 | aom_highbd_12_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2343 | aom_highbd_12_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2344 | aom_highbd_sad32x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2345 | aom_highbd_dist_wtd_sad32x64_avg_bits12, |
| 2346 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2347 | |
| 2348 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2349 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2350 | aom_highbd_12_sub_pixel_variance32x32, |
| 2351 | aom_highbd_12_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2352 | aom_highbd_sad32x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2353 | aom_highbd_dist_wtd_sad32x32_avg_bits12, |
| 2354 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2355 | |
| 2356 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2357 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2358 | aom_highbd_12_sub_pixel_variance64x64, |
| 2359 | aom_highbd_12_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2360 | aom_highbd_sad64x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2361 | aom_highbd_dist_wtd_sad64x64_avg_bits12, |
| 2362 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2363 | |
| 2364 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2365 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2366 | aom_highbd_12_sub_pixel_variance16x16, |
| 2367 | aom_highbd_12_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2368 | aom_highbd_sad16x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2369 | aom_highbd_dist_wtd_sad16x16_avg_bits12, |
| 2370 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2371 | |
| 2372 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2373 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2374 | aom_highbd_12_sub_pixel_variance16x8, |
| 2375 | aom_highbd_12_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2376 | aom_highbd_sad16x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2377 | aom_highbd_dist_wtd_sad16x8_avg_bits12, |
| 2378 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2379 | |
| 2380 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2381 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2382 | aom_highbd_12_sub_pixel_variance8x16, |
| 2383 | aom_highbd_12_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2384 | aom_highbd_sad8x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2385 | aom_highbd_dist_wtd_sad8x16_avg_bits12, |
| 2386 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2387 | |
| 2388 | HIGHBD_BFP( |
| 2389 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2390 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2391 | aom_highbd_12_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2392 | aom_highbd_sad8x8x4d_bits12, aom_highbd_dist_wtd_sad8x8_avg_bits12, |
| 2393 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2394 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2395 | HIGHBD_BFP( |
| 2396 | BLOCK_8X4, aom_highbd_sad8x4_bits12, aom_highbd_sad8x4_avg_bits12, |
| 2397 | aom_highbd_12_variance8x4, aom_highbd_12_sub_pixel_variance8x4, |
| 2398 | aom_highbd_12_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2399 | aom_highbd_sad8x4x4d_bits12, aom_highbd_dist_wtd_sad8x4_avg_bits12, |
| 2400 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2401 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2402 | HIGHBD_BFP( |
| 2403 | BLOCK_4X8, aom_highbd_sad4x8_bits12, aom_highbd_sad4x8_avg_bits12, |
| 2404 | aom_highbd_12_variance4x8, aom_highbd_12_sub_pixel_variance4x8, |
| 2405 | aom_highbd_12_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2406 | aom_highbd_sad4x8x4d_bits12, aom_highbd_dist_wtd_sad4x8_avg_bits12, |
| 2407 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2408 | |
| 2409 | HIGHBD_BFP( |
| 2410 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2411 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2412 | aom_highbd_12_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2413 | aom_highbd_sad4x4x4d_bits12, aom_highbd_dist_wtd_sad4x4_avg_bits12, |
| 2414 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2415 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2416 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2417 | aom_highbd_sad128x128_avg_bits12, |
| 2418 | aom_highbd_12_variance128x128, |
| 2419 | aom_highbd_12_sub_pixel_variance128x128, |
| 2420 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2421 | aom_highbd_sad128x128x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2422 | aom_highbd_dist_wtd_sad128x128_avg_bits12, |
| 2423 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2424 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2425 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2426 | aom_highbd_sad128x64_avg_bits12, |
| 2427 | aom_highbd_12_variance128x64, |
| 2428 | aom_highbd_12_sub_pixel_variance128x64, |
| 2429 | aom_highbd_12_sub_pixel_avg_variance128x64, |
| 2430 | aom_highbd_sad128x64x4d_bits12, |
| 2431 | aom_highbd_dist_wtd_sad128x64_avg_bits12, |
| 2432 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2433 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2434 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2435 | aom_highbd_sad64x128_avg_bits12, |
| 2436 | aom_highbd_12_variance64x128, |
| 2437 | aom_highbd_12_sub_pixel_variance64x128, |
| 2438 | aom_highbd_12_sub_pixel_avg_variance64x128, |
| 2439 | aom_highbd_sad64x128x4d_bits12, |
| 2440 | aom_highbd_dist_wtd_sad64x128_avg_bits12, |
| 2441 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2442 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2443 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2444 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2445 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2446 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2447 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2448 | aom_highbd_12_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2449 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2450 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2451 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2452 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2453 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2454 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2455 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2456 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2457 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2458 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2459 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2460 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2461 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2462 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2463 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2464 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2465 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2466 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2467 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2468 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2469 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2470 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2471 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2472 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2473 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2474 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2475 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2476 | aom_highbd_12_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2477 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2478 | aom_highbd_12_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2479 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2480 | aom_highbd_12_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2481 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2482 | aom_highbd_12_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2483 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2484 | aom_highbd_12_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2485 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2486 | aom_highbd_12_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2487 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2488 | aom_highbd_12_obmc_variance128x128, |
| 2489 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2490 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2491 | aom_highbd_12_obmc_variance128x64, |
| 2492 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2493 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2494 | aom_highbd_12_obmc_variance64x128, |
| 2495 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2496 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2497 | aom_highbd_12_obmc_variance64x64, |
| 2498 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2499 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2500 | aom_highbd_12_obmc_variance64x32, |
| 2501 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2502 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2503 | aom_highbd_12_obmc_variance32x64, |
| 2504 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2505 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2506 | aom_highbd_12_obmc_variance32x32, |
| 2507 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2508 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2509 | aom_highbd_12_obmc_variance32x16, |
| 2510 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2511 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2512 | aom_highbd_12_obmc_variance16x32, |
| 2513 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2514 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2515 | aom_highbd_12_obmc_variance16x16, |
| 2516 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2517 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2518 | aom_highbd_12_obmc_variance8x16, |
| 2519 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2520 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2521 | aom_highbd_12_obmc_variance16x8, |
| 2522 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2523 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2524 | aom_highbd_12_obmc_variance8x8, |
| 2525 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2526 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2527 | aom_highbd_12_obmc_variance4x8, |
| 2528 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2529 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2530 | aom_highbd_12_obmc_variance8x4, |
| 2531 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2532 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2533 | aom_highbd_12_obmc_variance4x4, |
| 2534 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2535 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2536 | aom_highbd_12_obmc_variance64x16, |
| 2537 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2538 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2539 | aom_highbd_12_obmc_variance16x64, |
| 2540 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2541 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2542 | aom_highbd_12_obmc_variance32x8, |
| 2543 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2544 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2545 | aom_highbd_12_obmc_variance8x32, |
| 2546 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2547 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2548 | aom_highbd_12_obmc_variance16x4, |
| 2549 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2550 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2551 | aom_highbd_12_obmc_variance4x16, |
| 2552 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2553 | break; |
| 2554 | |
| 2555 | default: |
| 2556 | assert(0 && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2557 | "cm->seq_params.bit_depth should be AOM_BITS_8, " |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2558 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2559 | } |
| 2560 | } |
| 2561 | } |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 2562 | #endif // CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2563 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2564 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2565 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2566 | |
| 2567 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2568 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2569 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2570 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2571 | |
| 2572 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2573 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2574 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2575 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2576 | |
| 2577 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2578 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2579 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2580 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 2583 | static void set_tpl_stats_block_size(AV1_COMP *cpi) { |
| 2584 | AV1_COMMON *const cm = &cpi->common; |
| 2585 | const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720; |
| 2586 | |
| 2587 | // 0: 4x4, 1: 8x8, 2: 16x16 |
| 2588 | cpi->tpl_stats_block_mis_log2 = is_720p_or_larger ? 2 : 1; |
| 2589 | } |
| 2590 | |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 2591 | void av1_alloc_compound_type_rd_buffers(AV1_COMMON *const cm, |
| 2592 | CompoundTypeRdBuffers *const bufs) { |
| 2593 | CHECK_MEM_ERROR( |
| 2594 | cm, bufs->pred0, |
| 2595 | (uint8_t *)aom_memalign(16, 2 * MAX_SB_SQUARE * sizeof(*bufs->pred0))); |
| 2596 | CHECK_MEM_ERROR( |
| 2597 | cm, bufs->pred1, |
| 2598 | (uint8_t *)aom_memalign(16, 2 * MAX_SB_SQUARE * sizeof(*bufs->pred1))); |
| 2599 | CHECK_MEM_ERROR( |
| 2600 | cm, bufs->residual1, |
| 2601 | (int16_t *)aom_memalign(32, MAX_SB_SQUARE * sizeof(*bufs->residual1))); |
| 2602 | CHECK_MEM_ERROR( |
| 2603 | cm, bufs->diff10, |
| 2604 | (int16_t *)aom_memalign(32, MAX_SB_SQUARE * sizeof(*bufs->diff10))); |
| 2605 | CHECK_MEM_ERROR(cm, bufs->tmp_best_mask_buf, |
| 2606 | (uint8_t *)aom_malloc(2 * MAX_SB_SQUARE * |
| 2607 | sizeof(*bufs->tmp_best_mask_buf))); |
| 2608 | } |
| 2609 | |
| 2610 | void av1_release_compound_type_rd_buffers(CompoundTypeRdBuffers *const bufs) { |
| 2611 | aom_free(bufs->pred0); |
| 2612 | aom_free(bufs->pred1); |
| 2613 | aom_free(bufs->residual1); |
| 2614 | aom_free(bufs->diff10); |
| 2615 | aom_free(bufs->tmp_best_mask_buf); |
| 2616 | av1_zero(*bufs); // Set all pointers to NULL for safety. |
| 2617 | } |
| 2618 | |
Wan-Teh Chang | bcacb32 | 2019-09-11 14:50:20 -0700 | [diff] [blame] | 2619 | static void config_target_level(AV1_COMP *const cpi, AV1_LEVEL target_level, |
| 2620 | int tier) { |
| 2621 | aom_clear_system_state(); |
| 2622 | |
| 2623 | AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 2624 | SequenceHeader *const seq_params = &cpi->common.seq_params; |
| 2625 | |
| 2626 | // Adjust target bitrate to be no larger than 70% of level limit. |
| 2627 | const BITSTREAM_PROFILE profile = seq_params->profile; |
| 2628 | const double level_bitrate_limit = |
| 2629 | av1_get_max_bitrate_for_level(target_level, tier, profile); |
| 2630 | const int64_t max_bitrate = (int64_t)(level_bitrate_limit * 0.70); |
| 2631 | oxcf->target_bandwidth = AOMMIN(oxcf->target_bandwidth, max_bitrate); |
| 2632 | // Also need to update cpi->twopass.bits_left. |
| 2633 | TWO_PASS *const twopass = &cpi->twopass; |
| 2634 | FIRSTPASS_STATS *stats = &twopass->total_stats; |
| 2635 | cpi->twopass.bits_left = |
| 2636 | (int64_t)(stats->duration * cpi->oxcf.target_bandwidth / 10000000.0); |
| 2637 | |
| 2638 | // Adjust max over-shoot percentage. |
| 2639 | oxcf->over_shoot_pct = 0; |
| 2640 | |
| 2641 | // Adjust max quantizer. |
| 2642 | oxcf->worst_allowed_q = 255; |
| 2643 | |
| 2644 | // Adjust number of tiles and tile columns to be under level limit. |
| 2645 | int max_tiles, max_tile_cols; |
| 2646 | av1_get_max_tiles_for_level(target_level, &max_tiles, &max_tile_cols); |
| 2647 | while (oxcf->tile_columns > 0 && (1 << oxcf->tile_columns) > max_tile_cols) { |
| 2648 | --oxcf->tile_columns; |
| 2649 | } |
| 2650 | const int tile_cols = (1 << oxcf->tile_columns); |
| 2651 | while (oxcf->tile_rows > 0 && |
| 2652 | tile_cols * (1 << oxcf->tile_rows) > max_tiles) { |
| 2653 | --oxcf->tile_rows; |
| 2654 | } |
| 2655 | |
| 2656 | // Adjust min compression ratio. |
| 2657 | const int still_picture = seq_params->still_picture; |
| 2658 | const double min_cr = |
| 2659 | av1_get_min_cr_for_level(target_level, tier, still_picture); |
| 2660 | oxcf->min_cr = AOMMAX(oxcf->min_cr, (unsigned int)(min_cr * 100)); |
| 2661 | } |
| 2662 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2663 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2664 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2665 | SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2666 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2667 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2668 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2669 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2670 | if (seq_params->profile != oxcf->profile) seq_params->profile = oxcf->profile; |
| 2671 | seq_params->bit_depth = oxcf->bit_depth; |
| 2672 | seq_params->color_primaries = oxcf->color_primaries; |
| 2673 | seq_params->transfer_characteristics = oxcf->transfer_characteristics; |
| 2674 | seq_params->matrix_coefficients = oxcf->matrix_coefficients; |
| 2675 | seq_params->monochrome = oxcf->monochrome; |
| 2676 | seq_params->chroma_sample_position = oxcf->chroma_sample_position; |
| 2677 | seq_params->color_range = oxcf->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2678 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2679 | assert(IMPLIES(seq_params->profile <= PROFILE_1, |
| 2680 | seq_params->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2681 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2682 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2683 | cm->timing_info.num_units_in_display_tick = |
| 2684 | oxcf->timing_info.num_units_in_display_tick; |
| 2685 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 2686 | cm->timing_info.equal_picture_interval = |
| 2687 | oxcf->timing_info.equal_picture_interval; |
| 2688 | cm->timing_info.num_ticks_per_picture = |
| 2689 | oxcf->timing_info.num_ticks_per_picture; |
| 2690 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2691 | seq_params->display_model_info_present_flag = |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2692 | oxcf->display_model_info_present_flag; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2693 | seq_params->decoder_model_info_present_flag = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2694 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2695 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2696 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2697 | cm->buffer_model.num_units_in_decoding_tick = |
| 2698 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 2699 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2700 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 2701 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2702 | } else if (cm->timing_info_present && |
| 2703 | cm->timing_info.equal_picture_interval && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2704 | !seq_params->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2705 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2706 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 2707 | } else { |
| 2708 | cm->op_params[0].initial_display_delay = |
| 2709 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2710 | } |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2711 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2712 | update_film_grain_parameters(cpi, oxcf); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2713 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2714 | cpi->oxcf = *oxcf; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2715 | x->e_mbd.bd = (int)seq_params->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2716 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2717 | |
Wan-Teh Chang | bcacb32 | 2019-09-11 14:50:20 -0700 | [diff] [blame] | 2718 | memcpy(cpi->target_seq_level_idx, cpi->oxcf.target_seq_level_idx, |
| 2719 | sizeof(cpi->target_seq_level_idx)); |
| 2720 | cpi->keep_level_stats = 0; |
| 2721 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
| 2722 | if (cpi->target_seq_level_idx[i] <= SEQ_LEVELS) { |
| 2723 | cpi->keep_level_stats |= 1u << i; |
| 2724 | if (!cpi->level_info[i]) { |
| 2725 | CHECK_MEM_ERROR(cm, cpi->level_info[i], |
| 2726 | aom_calloc(1, sizeof(*cpi->level_info[i]))); |
| 2727 | } |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | // TODO(huisu@): level targeting currently only works for the 0th operating |
| 2732 | // point, so scalable coding is not supported yet. |
| 2733 | if (cpi->target_seq_level_idx[0] < SEQ_LEVELS) { |
| 2734 | // Adjust encoder config in order to meet target level. |
| 2735 | config_target_level(cpi, cpi->target_seq_level_idx[0], seq_params->tier[0]); |
| 2736 | } |
| 2737 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2738 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2739 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2740 | } else { |
| 2741 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2742 | } |
| 2743 | |
| 2744 | cpi->refresh_last_frame = 1; |
| 2745 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2746 | cpi->refresh_bwd_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2747 | |
Debargha Mukherjee | 229fdc8 | 2018-03-10 07:45:33 -0800 | [diff] [blame] | 2748 | cm->refresh_frame_context = (oxcf->frame_parallel_decoding_mode) |
| 2749 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 2750 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2751 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 2752 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2753 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2754 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2755 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2756 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2757 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2758 | |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 2759 | if (x->comp_rd_buffer.pred0 == NULL) { |
| 2760 | av1_alloc_compound_type_rd_buffers(cm, &x->comp_rd_buffer); |
| 2761 | } |
| 2762 | |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2763 | if (x->tmp_conv_dst == NULL) { |
| 2764 | CHECK_MEM_ERROR( |
| 2765 | cm, x->tmp_conv_dst, |
| 2766 | 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] | 2767 | x->e_mbd.tmp_conv_dst = x->tmp_conv_dst; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2768 | } |
| 2769 | for (int i = 0; i < 2; ++i) { |
| 2770 | if (x->tmp_obmc_bufs[i] == NULL) { |
| 2771 | CHECK_MEM_ERROR(cm, x->tmp_obmc_bufs[i], |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 2772 | aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE * |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2773 | sizeof(*x->tmp_obmc_bufs[i]))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2774 | x->e_mbd.tmp_obmc_bufs[i] = x->tmp_obmc_bufs[i]; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2778 | av1_reset_segment_features(cm); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2779 | set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2780 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2781 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2782 | |
| 2783 | // Under a configuration change, where maximum_buffer_size may change, |
| 2784 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2785 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2786 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2787 | |
| 2788 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2789 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2790 | |
| 2791 | // Set absolute upper and lower quality limits |
| 2792 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2793 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2794 | |
Urvang Joshi | b55cb5e | 2018-09-12 14:50:21 -0700 | [diff] [blame] | 2795 | cm->interp_filter = oxcf->large_scale_tile ? EIGHTTAP_REGULAR : SWITCHABLE; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 2796 | cm->switchable_motion_mode = 1; |
| 2797 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2798 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2799 | cm->render_width = cpi->oxcf.render_width; |
| 2800 | cm->render_height = cpi->oxcf.render_height; |
| 2801 | } else { |
| 2802 | cm->render_width = cpi->oxcf.width; |
| 2803 | cm->render_height = cpi->oxcf.height; |
| 2804 | } |
| 2805 | cm->width = cpi->oxcf.width; |
| 2806 | cm->height = cpi->oxcf.height; |
| 2807 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2808 | int sb_size = seq_params->sb_size; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2809 | // Superblock size should not be updated after the first key frame. |
| 2810 | if (!cpi->seq_params_locked) { |
| 2811 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Hui Su | d909c2c | 2019-03-08 11:51:14 -0800 | [diff] [blame] | 2812 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) |
| 2813 | seq_params->tier[i] = (oxcf->tier_mask >> i) & 1; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2814 | } |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2815 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2816 | if (cpi->initial_width || sb_size != seq_params->sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2817 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2818 | seq_params->sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2819 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2820 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2821 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2822 | realloc_segmentation_maps(cpi); |
| 2823 | cpi->initial_width = cpi->initial_height = 0; |
| 2824 | } |
| 2825 | } |
| 2826 | update_frame_size(cpi); |
| 2827 | |
| 2828 | cpi->alt_ref_source = NULL; |
| 2829 | rc->is_src_frame_alt_ref = 0; |
| 2830 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2831 | set_tile_info(cpi); |
| 2832 | |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 2833 | if (!cpi->svc.external_ref_frame_config) |
| 2834 | cpi->ext_refresh_frame_flags_pending = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2835 | cpi->ext_refresh_frame_context_pending = 0; |
| 2836 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 2837 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2838 | highbd_set_var_fns(cpi); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 2839 | #endif |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 2840 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 2841 | // Init sequence level coding tools |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2842 | // This should not be called after the first key frame. |
| 2843 | if (!cpi->seq_params_locked) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2844 | seq_params->operating_points_cnt_minus_1 = |
Marco Paniconi | 6da983b | 2019-09-16 20:12:43 -0700 | [diff] [blame] | 2845 | (cm->number_spatial_layers > 1 || cm->number_temporal_layers > 1) |
| 2846 | ? cm->number_spatial_layers * cm->number_temporal_layers - 1 |
| 2847 | : 0; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 2848 | init_seq_coding_tools(&cm->seq_params, cm, oxcf, cpi->use_svc); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2849 | } |
Marco Paniconi | 5b1e473 | 2019-08-08 18:57:53 -0700 | [diff] [blame] | 2850 | |
| 2851 | if (cpi->use_svc) |
| 2852 | av1_update_layer_context_change_config(cpi, oxcf->target_bandwidth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2855 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2856 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2857 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2858 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2859 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2860 | |
| 2861 | if (!cm) return NULL; |
| 2862 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2863 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2864 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 2865 | // The jmp_buf is valid only for the duration of the function that calls |
| 2866 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 2867 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2868 | if (setjmp(cm->error.jmp)) { |
| 2869 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2870 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2871 | return 0; |
| 2872 | } |
| 2873 | |
| 2874 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2875 | cm->alloc_mi = enc_alloc_mi; |
| 2876 | cm->free_mi = enc_free_mi; |
| 2877 | cm->setup_mi = enc_setup_mi; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame] | 2878 | cm->set_mb_mi = enc_set_mb_mi; |
| 2879 | |
| 2880 | cm->mi_alloc_bsize = BLOCK_4X4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2881 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2882 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2883 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2884 | CHECK_MEM_ERROR( |
| 2885 | cm, cm->default_frame_context, |
| 2886 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2887 | memset(cm->fc, 0, sizeof(*cm->fc)); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2888 | memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2889 | |
| 2890 | cpi->resize_state = 0; |
| 2891 | cpi->resize_avg_qp = 0; |
| 2892 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2893 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2894 | cpi->common.buffer_pool = pool; |
| 2895 | |
| 2896 | init_config(cpi, oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2897 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2898 | |
Jingning Han | 17af774 | 2019-09-17 16:58:03 -0700 | [diff] [blame] | 2899 | init_frame_info(&cpi->frame_info, cm); |
| 2900 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 2901 | cm->current_frame.frame_number = 0; |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 2902 | cm->current_frame_id = -1; |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2903 | cpi->seq_params_locked = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2904 | cpi->partition_search_skippable_frame = 0; |
| 2905 | cpi->tile_data = NULL; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 2906 | cpi->last_show_frame_buf = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2907 | realloc_segmentation_maps(cpi); |
| 2908 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2909 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2910 | i++) { |
| 2911 | CHECK_MEM_ERROR( |
| 2912 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2913 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2916 | cpi->refresh_alt_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2917 | |
| 2918 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2919 | #if CONFIG_INTERNAL_STATS |
| 2920 | cpi->b_calculate_blockiness = 1; |
| 2921 | cpi->b_calculate_consistency = 1; |
| 2922 | cpi->total_inconsistency = 0; |
| 2923 | cpi->psnr.worst = 100.0; |
| 2924 | cpi->worst_ssim = 100.0; |
| 2925 | |
| 2926 | cpi->count = 0; |
| 2927 | cpi->bytes = 0; |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 2928 | #if CONFIG_SPEED_STATS |
| 2929 | cpi->tx_search_count = 0; |
| 2930 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2931 | |
| 2932 | if (cpi->b_calculate_psnr) { |
| 2933 | cpi->total_sq_error = 0; |
| 2934 | cpi->total_samples = 0; |
| 2935 | cpi->tot_recode_hits = 0; |
| 2936 | cpi->summed_quality = 0; |
| 2937 | cpi->summed_weights = 0; |
| 2938 | } |
| 2939 | |
| 2940 | cpi->fastssim.worst = 100.0; |
| 2941 | cpi->psnrhvs.worst = 100.0; |
| 2942 | |
| 2943 | if (cpi->b_calculate_blockiness) { |
| 2944 | cpi->total_blockiness = 0; |
| 2945 | cpi->worst_blockiness = 0.0; |
| 2946 | } |
| 2947 | |
| 2948 | if (cpi->b_calculate_consistency) { |
| 2949 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2950 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2951 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2952 | cpi->worst_consistency = 100.0; |
| 2953 | } |
| 2954 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2955 | #if CONFIG_ENTROPY_STATS |
| 2956 | av1_zero(aggregate_fc); |
| 2957 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2958 | |
| 2959 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2960 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2961 | #ifdef OUTPUT_YUV_SKINMAP |
| 2962 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2963 | #endif |
| 2964 | #ifdef OUTPUT_YUV_REC |
| 2965 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2966 | #endif |
| 2967 | |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 2968 | #if !CONFIG_REALTIME_ONLY |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2969 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2970 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2971 | } else if (oxcf->pass == 2) { |
| 2972 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2973 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2974 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2975 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2976 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2977 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2978 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2979 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2980 | } |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 2981 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2982 | |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 2983 | int sb_mi_size = av1_get_sb_mi_size(cm); |
| 2984 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2985 | CHECK_MEM_ERROR( |
| 2986 | cm, cpi->td.mb.above_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2987 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2988 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2989 | CHECK_MEM_ERROR( |
| 2990 | cm, cpi->td.mb.left_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2991 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2992 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2993 | |
| 2994 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2995 | (int32_t *)aom_memalign( |
| 2996 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2997 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 2998 | CHECK_MEM_ERROR( |
| 2999 | cm, cpi->td.mb.inter_modes_info, |
| 3000 | (InterModesInfo *)aom_malloc(sizeof(*cpi->td.mb.inter_modes_info))); |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3001 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3002 | for (int x = 0; x < 2; x++) |
| 3003 | for (int y = 0; y < 2; y++) |
| 3004 | CHECK_MEM_ERROR( |
| 3005 | cm, cpi->td.mb.hash_value_buffer[x][y], |
| 3006 | (uint32_t *)aom_malloc(AOM_BUFFER_SIZE_FOR_BLOCK_HASH * |
| 3007 | sizeof(*cpi->td.mb.hash_value_buffer[0][0]))); |
| 3008 | |
| 3009 | cpi->td.mb.g_crc_initialized = 0; |
| 3010 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3011 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 3012 | (int32_t *)aom_memalign( |
| 3013 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 3014 | |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 3015 | CHECK_MEM_ERROR(cm, cpi->td.mb.mbmi_ext, |
| 3016 | aom_calloc(sb_mi_size, sizeof(*cpi->td.mb.mbmi_ext))); |
| 3017 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 3018 | av1_set_speed_features_framesize_independent(cpi, oxcf->speed); |
| 3019 | av1_set_speed_features_framesize_dependent(cpi, oxcf->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3020 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 3021 | { |
| 3022 | const int bsize = BLOCK_16X16; |
| 3023 | const int w = mi_size_wide[bsize]; |
| 3024 | const int h = mi_size_high[bsize]; |
| 3025 | const int num_cols = (cm->mi_cols + w - 1) / w; |
| 3026 | const int num_rows = (cm->mi_rows + h - 1) / h; |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 3027 | CHECK_MEM_ERROR(cm, cpi->tpl_rdmult_scaling_factors, |
| 3028 | aom_calloc(num_rows * num_cols, |
| 3029 | sizeof(*cpi->tpl_rdmult_scaling_factors))); |
| 3030 | CHECK_MEM_ERROR(cm, cpi->tpl_sb_rdmult_scaling_factors, |
| 3031 | aom_calloc(num_rows * num_cols, |
| 3032 | sizeof(*cpi->tpl_sb_rdmult_scaling_factors))); |
| 3033 | } |
| 3034 | |
| 3035 | { |
| 3036 | const int bsize = BLOCK_16X16; |
| 3037 | const int w = mi_size_wide[bsize]; |
| 3038 | const int h = mi_size_high[bsize]; |
| 3039 | const int num_cols = (cm->mi_cols + w - 1) / w; |
| 3040 | const int num_rows = (cm->mi_rows + h - 1) / h; |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 3041 | CHECK_MEM_ERROR(cm, cpi->ssim_rdmult_scaling_factors, |
| 3042 | aom_calloc(num_rows * num_cols, |
| 3043 | sizeof(*cpi->ssim_rdmult_scaling_factors))); |
| 3044 | } |
| 3045 | |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 3046 | set_tpl_stats_block_size(cpi); |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 3047 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 3048 | const int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 3049 | const int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 3050 | |
| 3051 | cpi->tpl_stats_buffer[frame].is_valid = 0; |
| 3052 | cpi->tpl_stats_buffer[frame].width = |
| 3053 | mi_cols >> cpi->tpl_stats_block_mis_log2; |
| 3054 | cpi->tpl_stats_buffer[frame].height = |
| 3055 | mi_rows >> cpi->tpl_stats_block_mis_log2; |
| 3056 | cpi->tpl_stats_buffer[frame].stride = cpi->tpl_stats_buffer[frame].width; |
| 3057 | cpi->tpl_stats_buffer[frame].mi_rows = cm->mi_rows; |
| 3058 | cpi->tpl_stats_buffer[frame].mi_cols = cm->mi_cols; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3059 | |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 3060 | CHECK_MEM_ERROR( |
| 3061 | cm, cpi->tpl_stats_buffer[frame].tpl_stats_ptr, |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 3062 | aom_calloc(cpi->tpl_stats_buffer[frame].width * |
| 3063 | cpi->tpl_stats_buffer[frame].height, |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 3064 | sizeof(*cpi->tpl_stats_buffer[frame].tpl_stats_ptr))); |
Jingning Han | 5e98d3b | 2019-09-23 21:59:36 -0700 | [diff] [blame] | 3065 | |
| 3066 | if (aom_alloc_frame_buffer( |
| 3067 | &cpi->tpl_stats_buffer[frame].rec_picture_buf, cm->width, |
| 3068 | cm->height, cm->seq_params.subsampling_x, |
| 3069 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
| 3070 | cpi->oxcf.border_in_pixels, cm->byte_alignment)) |
| 3071 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3072 | "Failed to allocate frame buffer"); |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3073 | } |
Jingning Han | 31a0ee9 | 2019-07-15 13:56:55 -0700 | [diff] [blame] | 3074 | cpi->tpl_frame = &cpi->tpl_stats_buffer[REF_FRAMES + 1]; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3075 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 3076 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3077 | av1_zero(cpi->partition_stats); |
| 3078 | #endif |
| 3079 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3080 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 3081 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 3082 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 3083 | cpi->fn_ptr[BT].vf = VF; \ |
| 3084 | cpi->fn_ptr[BT].svf = SVF; \ |
| 3085 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 3086 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 3087 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3088 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3089 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3090 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3091 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3092 | aom_sad4x16x4d, aom_dist_wtd_sad4x16_avg, |
| 3093 | aom_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3094 | |
| 3095 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3096 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3097 | aom_sad16x4x4d, aom_dist_wtd_sad16x4_avg, |
| 3098 | aom_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3099 | |
| 3100 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3101 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3102 | aom_sad8x32x4d, aom_dist_wtd_sad8x32_avg, |
| 3103 | aom_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3104 | |
| 3105 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3106 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3107 | aom_sad32x8x4d, aom_dist_wtd_sad32x8_avg, |
| 3108 | aom_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3109 | |
| 3110 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3111 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3112 | aom_sad16x64x4d, aom_dist_wtd_sad16x64_avg, |
| 3113 | aom_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3114 | |
| 3115 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3116 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3117 | aom_sad64x16x4d, aom_dist_wtd_sad64x16_avg, |
| 3118 | aom_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3119 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3120 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 3121 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3122 | aom_sad128x128x4d, aom_dist_wtd_sad128x128_avg, |
| 3123 | aom_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3124 | |
| 3125 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3126 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3127 | aom_sad128x64x4d, aom_dist_wtd_sad128x64_avg, |
| 3128 | aom_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3129 | |
| 3130 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3131 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3132 | aom_sad64x128x4d, aom_dist_wtd_sad64x128_avg, |
| 3133 | aom_dist_wtd_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3134 | |
| 3135 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3136 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3137 | aom_sad32x16x4d, aom_dist_wtd_sad32x16_avg, |
| 3138 | aom_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3139 | |
| 3140 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3141 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3142 | aom_sad16x32x4d, aom_dist_wtd_sad16x32_avg, |
| 3143 | aom_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3144 | |
| 3145 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3146 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3147 | aom_sad64x32x4d, aom_dist_wtd_sad64x32_avg, |
| 3148 | aom_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3149 | |
| 3150 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3151 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3152 | aom_sad32x64x4d, aom_dist_wtd_sad32x64_avg, |
| 3153 | aom_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3154 | |
| 3155 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 3156 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3157 | aom_sad32x32x4d, aom_dist_wtd_sad32x32_avg, |
| 3158 | aom_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3159 | |
| 3160 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 3161 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3162 | aom_sad64x64x4d, aom_dist_wtd_sad64x64_avg, |
| 3163 | aom_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3164 | |
| 3165 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 3166 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3167 | aom_sad16x16x4d, aom_dist_wtd_sad16x16_avg, |
| 3168 | aom_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3169 | |
| 3170 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3171 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3172 | aom_sad16x8x4d, aom_dist_wtd_sad16x8_avg, |
| 3173 | aom_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3174 | |
| 3175 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3176 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3177 | aom_sad8x16x4d, aom_dist_wtd_sad8x16_avg, |
| 3178 | aom_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3179 | |
| 3180 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3181 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3182 | aom_dist_wtd_sad8x8_avg, aom_dist_wtd_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3183 | |
| 3184 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3185 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, aom_sad8x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3186 | aom_dist_wtd_sad8x4_avg, aom_dist_wtd_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3187 | |
| 3188 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3189 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, aom_sad4x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3190 | aom_dist_wtd_sad4x8_avg, aom_dist_wtd_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3191 | |
| 3192 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 3193 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 3194 | aom_dist_wtd_sad4x4_avg, aom_dist_wtd_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3195 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3196 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 3197 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 3198 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 3199 | cpi->fn_ptr[BT].osvf = OSVF; |
| 3200 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3201 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 3202 | aom_obmc_sub_pixel_variance128x128) |
| 3203 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 3204 | aom_obmc_sub_pixel_variance128x64) |
| 3205 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 3206 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3207 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 3208 | aom_obmc_sub_pixel_variance64x64) |
| 3209 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 3210 | aom_obmc_sub_pixel_variance64x32) |
| 3211 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 3212 | aom_obmc_sub_pixel_variance32x64) |
| 3213 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 3214 | aom_obmc_sub_pixel_variance32x32) |
| 3215 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 3216 | aom_obmc_sub_pixel_variance32x16) |
| 3217 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 3218 | aom_obmc_sub_pixel_variance16x32) |
| 3219 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 3220 | aom_obmc_sub_pixel_variance16x16) |
| 3221 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 3222 | aom_obmc_sub_pixel_variance16x8) |
| 3223 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 3224 | aom_obmc_sub_pixel_variance8x16) |
| 3225 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 3226 | aom_obmc_sub_pixel_variance8x8) |
| 3227 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 3228 | aom_obmc_sub_pixel_variance4x8) |
| 3229 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 3230 | aom_obmc_sub_pixel_variance8x4) |
| 3231 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 3232 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3233 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 3234 | aom_obmc_sub_pixel_variance4x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3235 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 3236 | aom_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3237 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 3238 | aom_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3239 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 3240 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3241 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 3242 | aom_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3243 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 3244 | aom_obmc_sub_pixel_variance64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3245 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3246 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 3247 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 3248 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3249 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3250 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 3251 | aom_masked_sub_pixel_variance128x128) |
| 3252 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 3253 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3254 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 3255 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 3256 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 3257 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 3258 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 3259 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 3260 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 3261 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 3262 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 3263 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 3264 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 3265 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 3266 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3267 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3268 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 3269 | |
| 3270 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 3271 | |
| 3272 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 3273 | |
| 3274 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3275 | |
| 3276 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 3277 | |
| 3278 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3279 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 3280 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3281 | highbd_set_var_fns(cpi); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 3282 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3283 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3284 | /* av1_init_quantizer() is first called here. Add check in |
| 3285 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3286 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3287 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3288 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3289 | av1_init_quantizer(cpi); |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 3290 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3291 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3292 | av1_loop_filter_init(cm); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3293 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3294 | cm->superres_upscaled_width = oxcf->width; |
| 3295 | cm->superres_upscaled_height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3296 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3297 | |
| 3298 | cm->error.setjmp = 0; |
| 3299 | |
| 3300 | return cpi; |
| 3301 | } |
| 3302 | |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3303 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3304 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 3305 | |
| 3306 | #define SNPRINT2(H, T, V) \ |
| 3307 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3308 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3309 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3310 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 3311 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3312 | unsigned int i; |
| 3313 | int t; |
| 3314 | |
| 3315 | if (!cpi) return; |
| 3316 | |
| 3317 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3318 | const int num_planes = av1_num_planes(cm); |
| 3319 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 3320 | if (cm->current_frame.frame_number > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3321 | #if CONFIG_ENTROPY_STATS |
| 3322 | if (cpi->oxcf.pass != 1) { |
| 3323 | fprintf(stderr, "Writing counts.stt\n"); |
| 3324 | FILE *f = fopen("counts.stt", "wb"); |
| 3325 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 3326 | fclose(f); |
| 3327 | } |
| 3328 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3329 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3330 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3331 | |
| 3332 | if (cpi->oxcf.pass != 1) { |
| 3333 | char headings[512] = { 0 }; |
| 3334 | char results[512] = { 0 }; |
| 3335 | FILE *f = fopen("opsnr.stt", "a"); |
| 3336 | double time_encoded = |
| 3337 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3338 | 10000000.000; |
| 3339 | double total_encode_time = |
| 3340 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3341 | const double dr = |
| 3342 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3343 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3344 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3345 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3346 | |
| 3347 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3348 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3349 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3350 | const double total_ssim = |
| 3351 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3352 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3353 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3354 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3355 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3356 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3357 | snprintf(results, sizeof(results), |
| 3358 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3359 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3360 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3361 | "%7.3f\t%7.3f\t%7.3f", |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3362 | dr, cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, |
| 3363 | cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, total_ssim, |
| 3364 | total_ssim, cpi->fastssim.stat[STAT_ALL] / cpi->count, |
| 3365 | cpi->psnrhvs.stat[STAT_ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3366 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3367 | cpi->psnr.stat[STAT_Y] / cpi->count, |
| 3368 | cpi->psnr.stat[STAT_U] / cpi->count, |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3369 | cpi->psnr.stat[STAT_V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3370 | |
| 3371 | if (cpi->b_calculate_blockiness) { |
| 3372 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3373 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3374 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3375 | } |
| 3376 | |
| 3377 | if (cpi->b_calculate_consistency) { |
| 3378 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3379 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3380 | (double)cpi->total_inconsistency); |
| 3381 | |
| 3382 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3383 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3384 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3385 | } |
Yue Chen | f0652ed | 2019-08-13 16:09:25 -0700 | [diff] [blame] | 3386 | |
| 3387 | SNPRINT(headings, "\t Time\tRcErr\tAbsErr"); |
| 3388 | SNPRINT2(results, "\t%8.0f", total_encode_time); |
| 3389 | SNPRINT2(results, "\t%7.2f", rate_err); |
| 3390 | SNPRINT2(results, "\t%7.2f", fabs(rate_err)); |
| 3391 | |
| 3392 | fprintf(f, "%s\tAPsnr611\n", headings); |
| 3393 | fprintf(f, "%s\t%7.3f\n", results, |
| 3394 | (6 * cpi->psnr.stat[STAT_Y] + cpi->psnr.stat[STAT_U] + |
| 3395 | cpi->psnr.stat[STAT_V]) / |
| 3396 | (cpi->count * 8)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | fclose(f); |
| 3400 | } |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3401 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 3402 | #if CONFIG_SPEED_STATS |
| 3403 | if (cpi->oxcf.pass != 1) { |
| 3404 | fprintf(stdout, "tx_search_count = %d\n", cpi->tx_search_count); |
| 3405 | } |
| 3406 | #endif // CONFIG_SPEED_STATS |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3407 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 3408 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3409 | if (cpi->oxcf.pass != 1) { |
| 3410 | av1_print_partition_stats(&cpi->partition_stats); |
| 3411 | } |
| 3412 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 3415 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 3416 | aom_free(cpi->tpl_stats_buffer[frame].tpl_stats_ptr); |
| 3417 | cpi->tpl_stats_buffer[frame].is_valid = 0; |
Jingning Han | 5e98d3b | 2019-09-23 21:59:36 -0700 | [diff] [blame] | 3418 | |
| 3419 | aom_free_frame_buffer(&cpi->tpl_stats_buffer[frame].rec_picture_buf); |
| 3420 | cpi->tpl_stats_buffer[frame].rec_picture = NULL; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3423 | for (t = cpi->num_workers - 1; t >= 0; --t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3424 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3425 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3426 | |
| 3427 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3428 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3429 | |
| 3430 | // Deallocate allocated thread data. |
Ravi Chaudhary | 4cd458b | 2019-06-04 17:42:35 +0530 | [diff] [blame] | 3431 | aom_free(thread_data->td->tctx); |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3432 | if (t > 0) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3433 | aom_free(thread_data->td->palette_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3434 | aom_free(thread_data->td->tmp_conv_dst); |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 3435 | av1_release_compound_type_rd_buffers(&thread_data->td->comp_rd_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3436 | for (int j = 0; j < 2; ++j) { |
| 3437 | aom_free(thread_data->td->tmp_obmc_bufs[j]); |
| 3438 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3439 | aom_free(thread_data->td->above_pred_buf); |
| 3440 | aom_free(thread_data->td->left_pred_buf); |
| 3441 | aom_free(thread_data->td->wsrc_buf); |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 3442 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3443 | aom_free(thread_data->td->inter_modes_info); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3444 | for (int x = 0; x < 2; x++) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3445 | for (int y = 0; y < 2; y++) { |
| 3446 | aom_free(thread_data->td->hash_value_buffer[x][y]); |
| 3447 | thread_data->td->hash_value_buffer[x][y] = NULL; |
| 3448 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3449 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3450 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3451 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3452 | av1_free_pc_tree(thread_data->td, num_planes); |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 3453 | aom_free(thread_data->td->mbmi_ext); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3454 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3455 | } |
| 3456 | } |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 3457 | #if CONFIG_MULTITHREAD |
Ravi Chaudhary | 4cd458b | 2019-06-04 17:42:35 +0530 | [diff] [blame] | 3458 | if (cpi->row_mt_mutex_ != NULL) { |
| 3459 | pthread_mutex_destroy(cpi->row_mt_mutex_); |
| 3460 | aom_free(cpi->row_mt_mutex_); |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 3461 | } |
| 3462 | #endif |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 3463 | av1_row_mt_mem_dealloc(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3464 | aom_free(cpi->tile_thr_data); |
| 3465 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3466 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3467 | if (cpi->num_workers > 1) { |
| 3468 | av1_loop_filter_dealloc(&cpi->lf_row_sync); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 3469 | av1_loop_restoration_dealloc(&cpi->lr_row_sync, cpi->num_workers); |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3470 | } |
| 3471 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3472 | dealloc_compressor_data(cpi); |
| 3473 | |
| 3474 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3475 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3476 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3479 | #if CONFIG_INTERNAL_STATS |
| 3480 | aom_free(cpi->ssim_vars); |
| 3481 | cpi->ssim_vars = NULL; |
| 3482 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3483 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3484 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3485 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3486 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 3487 | } |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3488 | #if CONFIG_HTB_TRELLIS |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 3489 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3490 | #endif // CONFIG_HTB_TRELLIS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3491 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3492 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3493 | |
| 3494 | #ifdef OUTPUT_YUV_SKINMAP |
| 3495 | fclose(yuv_skinmap_file); |
| 3496 | #endif |
| 3497 | #ifdef OUTPUT_YUV_REC |
| 3498 | fclose(yuv_rec_file); |
| 3499 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3502 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3503 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3504 | int i; |
| 3505 | PSNR_STATS psnr; |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 3506 | #if CONFIG_AV1_HIGHBITDEPTH |
| 3507 | // TODO(yaowu): unify these two versions into one. |
| 3508 | if (cpi->common.seq_params.use_highbitdepth) |
| 3509 | aom_calc_highbd_psnr(cpi->source, &cpi->common.cur_frame->buf, &psnr, |
| 3510 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
| 3511 | else |
| 3512 | aom_calc_psnr(cpi->source, &cpi->common.cur_frame->buf, &psnr); |
| 3513 | #else |
| 3514 | aom_calc_psnr(cpi->source, &cpi->common.cur_frame->buf, &psnr); |
| 3515 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3516 | |
| 3517 | for (i = 0; i < 4; ++i) { |
| 3518 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3519 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3520 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3521 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3522 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3523 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3526 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3527 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3528 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 3529 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3530 | return 0; |
| 3531 | } |
| 3532 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3533 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3534 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3535 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3536 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3537 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3538 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3539 | return 0; |
| 3540 | } else { |
| 3541 | return -1; |
| 3542 | } |
| 3543 | } |
| 3544 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3545 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3546 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3547 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3548 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3549 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3550 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3551 | return 0; |
| 3552 | } else { |
| 3553 | return -1; |
| 3554 | } |
| 3555 | } |
| 3556 | |
| 3557 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3558 | cpi->ext_refresh_frame_context = update; |
| 3559 | cpi->ext_refresh_frame_context_pending = 1; |
| 3560 | return 0; |
| 3561 | } |
| 3562 | |
| 3563 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3564 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3565 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3566 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3567 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3568 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3569 | uint8_t *src = s->y_buffer; |
| 3570 | int h = s->y_height; |
| 3571 | |
| 3572 | do { |
| 3573 | fwrite(src, s->y_width, 1, f); |
| 3574 | src += s->y_stride; |
| 3575 | } while (--h); |
| 3576 | |
| 3577 | src = s->u_buffer; |
| 3578 | h = s->uv_height; |
| 3579 | |
| 3580 | do { |
| 3581 | fwrite(src, s->uv_width, 1, f); |
| 3582 | src += s->uv_stride; |
| 3583 | } while (--h); |
| 3584 | |
| 3585 | src = s->v_buffer; |
| 3586 | h = s->uv_height; |
| 3587 | |
| 3588 | do { |
| 3589 | fwrite(src, s->uv_width, 1, f); |
| 3590 | src += s->uv_stride; |
| 3591 | } while (--h); |
| 3592 | } |
| 3593 | #endif |
| 3594 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3595 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3596 | 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] | 3597 | uint8_t *src = s->y_buffer; |
| 3598 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3599 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3600 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3601 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3602 | |
| 3603 | do { |
| 3604 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3605 | src16 += s->y_stride; |
| 3606 | } while (--h); |
| 3607 | |
| 3608 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3609 | h = s->uv_height; |
| 3610 | |
| 3611 | do { |
| 3612 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3613 | src16 += s->uv_stride; |
| 3614 | } while (--h); |
| 3615 | |
| 3616 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3617 | h = s->uv_height; |
| 3618 | |
| 3619 | do { |
| 3620 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3621 | src16 += s->uv_stride; |
| 3622 | } while (--h); |
| 3623 | |
| 3624 | fflush(yuv_rec_file); |
| 3625 | return; |
| 3626 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3627 | |
| 3628 | do { |
| 3629 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3630 | src += s->y_stride; |
| 3631 | } while (--h); |
| 3632 | |
| 3633 | src = s->u_buffer; |
| 3634 | h = s->uv_height; |
| 3635 | |
| 3636 | do { |
| 3637 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3638 | src += s->uv_stride; |
| 3639 | } while (--h); |
| 3640 | |
| 3641 | src = s->v_buffer; |
| 3642 | h = s->uv_height; |
| 3643 | |
| 3644 | do { |
| 3645 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3646 | src += s->uv_stride; |
| 3647 | } while (--h); |
| 3648 | |
| 3649 | fflush(yuv_rec_file); |
| 3650 | } |
| 3651 | #endif // OUTPUT_YUV_REC |
| 3652 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3653 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3654 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3655 | int i; |
| 3656 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3657 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3658 | AV1_COMMON *const cm = &cpi->common; |
| 3659 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3660 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3661 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3662 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3663 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3664 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3665 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3666 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 3667 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 3668 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 3669 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3670 | } |
| 3671 | } |
| 3672 | return recode; |
| 3673 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3674 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3675 | // Function to test for conditions that indicate we should loop |
| 3676 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3677 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3678 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3679 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3680 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3681 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3682 | int force_recode = 0; |
| 3683 | |
| 3684 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3685 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3686 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3687 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3688 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3689 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3690 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3691 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3692 | // Deal with frame undershoot and whether or not we are |
| 3693 | // below the automatically set cq level. |
| 3694 | if (q > oxcf->cq_level && |
| 3695 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3696 | force_recode = 1; |
| 3697 | } |
| 3698 | } |
| 3699 | } |
| 3700 | return force_recode; |
| 3701 | } |
| 3702 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3703 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3704 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3705 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3706 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3707 | |
| 3708 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3709 | // 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] | 3710 | if (cpi->ref_frame_flags & av1_ref_frame_flag_list[ref_frame]) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3711 | BufferPool *const pool = cm->buffer_pool; |
| 3712 | const YV12_BUFFER_CONFIG *const ref = |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3713 | get_ref_frame_yv12_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3714 | |
| 3715 | if (ref == NULL) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3716 | cpi->scaled_ref_buf[ref_frame - 1] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3717 | continue; |
| 3718 | } |
| 3719 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3720 | 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] | 3721 | // Replace the reference buffer with a copy having a thicker border, |
| 3722 | // if the reference buffer is higher resolution than the current |
| 3723 | // frame, and the border is thin. |
| 3724 | if ((ref->y_crop_width > cm->width || |
| 3725 | ref->y_crop_height > cm->height) && |
| 3726 | ref->border < AOM_BORDER_IN_PIXELS) { |
| 3727 | RefCntBuffer *ref_fb = get_ref_frame_buf(cm, ref_frame); |
| 3728 | if (aom_yv12_realloc_with_new_border( |
| 3729 | &ref_fb->buf, AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3730 | num_planes) != 0) { |
| 3731 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3732 | "Failed to allocate frame buffer"); |
| 3733 | } |
| 3734 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3735 | int force_scaling = 0; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3736 | RefCntBuffer *new_fb = cpi->scaled_ref_buf[ref_frame - 1]; |
| 3737 | if (new_fb == NULL) { |
| 3738 | const int new_fb_idx = get_free_fb(cm); |
| 3739 | if (new_fb_idx == INVALID_IDX) { |
Wan-Teh Chang | 4a8c004 | 2018-10-05 09:41:52 -0700 | [diff] [blame] | 3740 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3741 | "Unable to find free frame buffer"); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3742 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3743 | force_scaling = 1; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3744 | new_fb = &pool->frame_bufs[new_fb_idx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3745 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3746 | |
| 3747 | if (force_scaling || new_fb->buf.y_crop_width != cm->width || |
| 3748 | new_fb->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3749 | if (aom_realloc_frame_buffer( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3750 | &new_fb->buf, cm->width, cm->height, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3751 | cm->seq_params.subsampling_x, cm->seq_params.subsampling_y, |
Debargha Mukherjee | fa946af | 2019-03-26 16:58:55 -0700 | [diff] [blame] | 3752 | cm->seq_params.use_highbitdepth, AOM_BORDER_IN_PIXELS, |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3753 | cm->byte_alignment, NULL, NULL, NULL)) { |
| 3754 | if (force_scaling) { |
| 3755 | // Release the reference acquired in the get_free_fb() call above. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3756 | --new_fb->ref_count; |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3757 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3758 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3759 | "Failed to allocate frame buffer"); |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3760 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3761 | av1_resize_and_extend_frame( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3762 | ref, &new_fb->buf, (int)cm->seq_params.bit_depth, num_planes); |
| 3763 | cpi->scaled_ref_buf[ref_frame - 1] = new_fb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3764 | alloc_frame_mvs(cm, new_fb); |
| 3765 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3766 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3767 | RefCntBuffer *buf = get_ref_frame_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3768 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3769 | buf->buf.y_crop_height = ref->y_crop_height; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3770 | cpi->scaled_ref_buf[ref_frame - 1] = buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3771 | ++buf->ref_count; |
| 3772 | } |
| 3773 | } else { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3774 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_buf[ref_frame - 1] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3775 | } |
| 3776 | } |
| 3777 | } |
| 3778 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3779 | static void release_scaled_references(AV1_COMP *cpi) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3780 | // TODO(isbs): only refresh the necessary frames, rather than all of them |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3781 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 3782 | RefCntBuffer *const buf = cpi->scaled_ref_buf[i]; |
| 3783 | if (buf != NULL) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3784 | --buf->ref_count; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3785 | cpi->scaled_ref_buf[i] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3786 | } |
| 3787 | } |
| 3788 | } |
| 3789 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3790 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3791 | const AV1_COMMON *const cm = &cpi->common; |
| 3792 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3793 | |
| 3794 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3795 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3796 | |
| 3797 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3798 | if (frame_is_intra_only(cm)) { |
| 3799 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3800 | // after a key/intra-only frame. |
| 3801 | cpi->max_mv_magnitude = max_mv_def; |
| 3802 | } else { |
| 3803 | if (cm->show_frame) { |
| 3804 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3805 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3806 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3807 | cpi->mv_step_param = av1_init_search_range( |
| 3808 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3809 | } |
| 3810 | cpi->max_mv_magnitude = 0; |
| 3811 | } |
| 3812 | } |
| 3813 | } |
| 3814 | |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3815 | static void set_screen_content_options(AV1_COMP *cpi) { |
| 3816 | AV1_COMMON *cm = &cpi->common; |
| 3817 | |
| 3818 | if (cm->seq_params.force_screen_content_tools != 2) { |
| 3819 | cm->allow_screen_content_tools = cm->allow_intrabc = |
| 3820 | cm->seq_params.force_screen_content_tools; |
| 3821 | return; |
| 3822 | } |
| 3823 | |
| 3824 | if (cpi->oxcf.content == AOM_CONTENT_SCREEN) { |
| 3825 | cm->allow_screen_content_tools = cm->allow_intrabc = 1; |
| 3826 | return; |
| 3827 | } |
| 3828 | |
| 3829 | // Estimate if the source frame is screen content, based on the portion of |
| 3830 | // blocks that have few luma colors. |
| 3831 | const uint8_t *src = cpi->source->y_buffer; |
| 3832 | assert(src != NULL); |
| 3833 | const int use_hbd = cpi->source->flags & YV12_FLAG_HIGHBITDEPTH; |
| 3834 | const int stride = cpi->source->y_stride; |
| 3835 | const int width = cpi->source->y_width; |
| 3836 | const int height = cpi->source->y_height; |
| 3837 | const int bd = cm->seq_params.bit_depth; |
| 3838 | const int blk_w = 16; |
| 3839 | const int blk_h = 16; |
| 3840 | // These threshold values are selected experimentally. |
| 3841 | const int color_thresh = 4; |
| 3842 | const unsigned int var_thresh = 0; |
| 3843 | // Counts of blocks with no more than color_thresh colors. |
| 3844 | int counts_1 = 0; |
| 3845 | // Counts of blocks with no more than color_thresh colors and variance larger |
| 3846 | // than var_thresh. |
| 3847 | int counts_2 = 0; |
| 3848 | |
| 3849 | for (int r = 0; r + blk_h <= height; r += blk_h) { |
| 3850 | for (int c = 0; c + blk_w <= width; c += blk_w) { |
| 3851 | int count_buf[1 << 12]; // Maximum (1 << 12) color levels. |
| 3852 | const uint8_t *const this_src = src + r * stride + c; |
| 3853 | const int n_colors = |
| 3854 | use_hbd ? av1_count_colors_highbd(this_src, stride, blk_w, blk_h, bd, |
| 3855 | count_buf) |
| 3856 | : av1_count_colors(this_src, stride, blk_w, blk_h, count_buf); |
| 3857 | if (n_colors > 1 && n_colors <= color_thresh) { |
| 3858 | ++counts_1; |
| 3859 | struct buf_2d buf; |
| 3860 | buf.stride = stride; |
| 3861 | buf.buf = (uint8_t *)this_src; |
| 3862 | const unsigned int var = |
| 3863 | use_hbd |
| 3864 | ? av1_high_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16, bd) |
| 3865 | : av1_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16); |
| 3866 | if (var > var_thresh) ++counts_2; |
| 3867 | } |
| 3868 | } |
| 3869 | } |
| 3870 | |
| 3871 | // The threshold values are selected experimentally. |
| 3872 | cm->allow_screen_content_tools = |
| 3873 | counts_1 * blk_h * blk_w * 10 > width * height; |
| 3874 | // IntraBC would force loop filters off, so we use more strict rules that also |
| 3875 | // requires that the block has high variance. |
| 3876 | cm->allow_intrabc = cm->allow_screen_content_tools && |
Hui Su | 64a2ffb | 2019-04-11 16:47:13 -0700 | [diff] [blame] | 3877 | counts_2 * blk_h * blk_w * 12 > width * height; |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3878 | } |
| 3879 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3880 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3881 | int i; |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3882 | AV1_COMMON *cm = &cpi->common; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3883 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3884 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3885 | } |
| 3886 | cpi->global_motion_search_done = 0; |
Yunqing Wang | 9411e43 | 2019-03-14 15:53:23 -0700 | [diff] [blame] | 3887 | |
| 3888 | if (frame_is_intra_only(cm)) set_screen_content_options(cpi); |
| 3889 | cpi->is_screen_content_type = (cm->allow_screen_content_tools != 0); |
| 3890 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 3891 | av1_set_speed_features_framesize_independent(cpi, cpi->speed); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3892 | av1_set_rd_speed_thresholds(cpi); |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3893 | cm->interp_filter = SWITCHABLE; |
| 3894 | cm->switchable_motion_mode = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 3897 | #if !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 3898 | static int get_gfu_boost_from_r0(double r0, int frames_to_key) { |
| 3899 | double factor = sqrt((double)frames_to_key); |
| 3900 | factor = AOMMIN(factor, 10.0); |
| 3901 | factor = AOMMAX(factor, 4.0); |
| 3902 | const int boost = (int)rint((200.0 + 10.0 * factor) / r0); |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3903 | return boost; |
| 3904 | } |
| 3905 | |
Debargha Mukherjee | afd3cc2 | 2019-06-10 11:35:17 -0700 | [diff] [blame] | 3906 | static int get_kf_boost_from_r0(double r0, int frames_to_key) { |
| 3907 | double factor = sqrt((double)frames_to_key); |
| 3908 | factor = AOMMIN(factor, 10.0); |
| 3909 | factor = AOMMAX(factor, 4.0); |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 3910 | const int boost = (int)rint((75.0 + 14.0 * factor) / r0); |
| 3911 | return boost; |
| 3912 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 3913 | #endif |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 3914 | |
| 3915 | int combine_prior_with_tpl_boost(int prior_boost, int tpl_boost, |
| 3916 | int frames_to_key) { |
| 3917 | double factor = sqrt((double)frames_to_key); |
| 3918 | factor = AOMMIN(factor, 12.0); |
| 3919 | factor = AOMMAX(factor, 4.0); |
| 3920 | factor -= 4.0; |
| 3921 | 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] | 3922 | return boost; |
| 3923 | } |
| 3924 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 3925 | #if !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3926 | static void process_tpl_stats_frame(AV1_COMP *cpi) { |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 3927 | const GF_GROUP *const gf_group = &cpi->gf_group; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3928 | AV1_COMMON *const cm = &cpi->common; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3929 | |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 3930 | assert(IMPLIES(gf_group->size > 0, gf_group->index < gf_group->size)); |
Jingning Han | 31a0ee9 | 2019-07-15 13:56:55 -0700 | [diff] [blame] | 3931 | |
| 3932 | const int tpl_idx = gf_group->index; |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 3933 | TplDepFrame *tpl_frame = &cpi->tpl_frame[tpl_idx]; |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3934 | TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3935 | |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3936 | if (tpl_frame->is_valid) { |
| 3937 | int tpl_stride = tpl_frame->stride; |
| 3938 | int64_t intra_cost_base = 0; |
| 3939 | int64_t mc_dep_cost_base = 0; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 3940 | #if !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3941 | int64_t mc_saved_base = 0; |
| 3942 | int64_t mc_count_base = 0; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 3943 | #endif // !USE_TPL_CLASSIC_MODEL |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 3944 | const int step = 1 << cpi->tpl_stats_block_mis_log2; |
Debargha Mukherjee | edfa4fe | 2019-07-08 14:23:39 -0700 | [diff] [blame] | 3945 | 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] | 3946 | |
| 3947 | for (int row = 0; row < cm->mi_rows; row += step) { |
| 3948 | for (int col = 0; col < mi_cols_sr; col += step) { |
| 3949 | TplDepStats *this_stats = |
| 3950 | &tpl_stats[av1_tpl_ptr_pos(cpi, row, col, tpl_stride)]; |
Jingning Han | 40e870f | 2019-10-02 16:05:39 -0700 | [diff] [blame] | 3951 | int64_t mc_dep_delta = |
| 3952 | RDCOST(tpl_frame->base_rdmult, this_stats->mc_dep_rate, |
| 3953 | this_stats->mc_dep_dist); |
| 3954 | intra_cost_base += (this_stats->recrf_dist << RDDIV_BITS); |
| 3955 | mc_dep_cost_base += |
| 3956 | (this_stats->recrf_dist << RDDIV_BITS) + mc_dep_delta; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 3957 | #if !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3958 | mc_count_base += this_stats->mc_count; |
| 3959 | mc_saved_base += this_stats->mc_saved; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 3960 | #endif // !USE_TPL_CLASSIC_MODEL |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3961 | } |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3962 | } |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3963 | |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3964 | if (mc_dep_cost_base == 0) { |
| 3965 | tpl_frame->is_valid = 0; |
| 3966 | } else { |
| 3967 | aom_clear_system_state(); |
| 3968 | cpi->rd.r0 = (double)intra_cost_base / mc_dep_cost_base; |
Jingning Han | 44a573b | 2019-09-04 14:01:22 -0700 | [diff] [blame] | 3969 | if (is_frame_arf_and_tpl_eligible(gf_group)) { |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3970 | cpi->rd.arf_r0 = cpi->rd.r0; |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 3971 | const int gfu_boost = |
| 3972 | 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] | 3973 | // printf("old boost %d new boost %d\n", cpi->rc.gfu_boost, |
Debargha Mukherjee | afd3cc2 | 2019-06-10 11:35:17 -0700 | [diff] [blame] | 3974 | // gfu_boost); |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 3975 | cpi->rc.gfu_boost = combine_prior_with_tpl_boost( |
| 3976 | cpi->rc.gfu_boost, gfu_boost, cpi->rc.frames_to_key); |
Debargha Mukherjee | afd3cc2 | 2019-06-10 11:35:17 -0700 | [diff] [blame] | 3977 | } else if (frame_is_intra_only(cm)) { |
Debargha Mukherjee | 0a121a9 | 2019-06-19 13:12:46 -0700 | [diff] [blame] | 3978 | // TODO(debargha): Turn off q adjustment for kf temporarily to |
| 3979 | // reduce impact on speed of encoding. Need to investigate how |
| 3980 | // to mitigate the issue. |
| 3981 | if (cpi->oxcf.rc_mode == AOM_Q) { |
| 3982 | const int kf_boost = |
| 3983 | get_kf_boost_from_r0(cpi->rd.r0, cpi->rc.frames_to_key); |
| 3984 | // printf("old kf boost %d new kf boost %d [%d]\n", cpi->rc.kf_boost, |
| 3985 | // kf_boost, cpi->rc.frames_to_key); |
Debargha Mukherjee | 2e2b09c | 2019-06-14 13:50:42 -0700 | [diff] [blame] | 3986 | cpi->rc.kf_boost = combine_prior_with_tpl_boost( |
| 3987 | cpi->rc.kf_boost, kf_boost, cpi->rc.frames_to_key); |
Debargha Mukherjee | 0a121a9 | 2019-06-19 13:12:46 -0700 | [diff] [blame] | 3988 | } |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3989 | } |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 3990 | #if !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3991 | cpi->rd.mc_count_base = |
| 3992 | (double)mc_count_base / (cm->mi_rows * cm->mi_cols); |
| 3993 | cpi->rd.mc_saved_base = |
| 3994 | (double)mc_saved_base / (cm->mi_rows * cm->mi_cols); |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 3995 | #endif // !USE_TPL_CLASSIC_MODEL |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 3996 | aom_clear_system_state(); |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 3997 | } |
| 3998 | } |
| 3999 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4000 | #endif // !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4001 | |
Debargha Mukherjee | cd14cc1 | 2019-09-06 09:55:52 -0700 | [diff] [blame] | 4002 | static int determine_frame_high_precision_mv(const AV1_COMP *cpi, int qindex) { |
| 4003 | (void)cpi; |
| 4004 | if (cpi->sf.reduce_high_precision_mv_usage == 2) |
| 4005 | return 0; |
| 4006 | else if (cpi->sf.reduce_high_precision_mv_usage == 1) |
| 4007 | return qindex < HIGH_PRECISION_MV_QTHRESH / 2; |
| 4008 | else |
| 4009 | return qindex < HIGH_PRECISION_MV_QTHRESH; |
| 4010 | } |
| 4011 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4012 | 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] | 4013 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4014 | AV1_COMMON *const cm = &cpi->common; |
| 4015 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4016 | |
| 4017 | // Setup variables that depend on the dimensions of the frame. |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 4018 | av1_set_speed_features_framesize_dependent(cpi, cpi->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4019 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4020 | #if !CONFIG_REALTIME_ONLY |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4021 | if (cpi->oxcf.enable_tpl_model && cpi->tpl_model_pass == 0 && |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 4022 | is_frame_tpl_eligible(cpi)) { |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 4023 | process_tpl_stats_frame(cpi); |
sdeng | f46a106 | 2019-08-04 18:43:50 -0700 | [diff] [blame] | 4024 | av1_tpl_rdmult_setup(cpi); |
| 4025 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 4026 | #endif |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 4027 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 4028 | // Decide q and q bounds. |
Angie Chiang | 958904c | 2019-09-19 16:03:35 -0700 | [diff] [blame] | 4029 | *q = av1_rc_pick_q_and_bounds(cpi, &cpi->rc, cm->width, cm->height, |
| 4030 | cpi->gf_group.index, bottom_index, top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4031 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4032 | if (!frame_is_intra_only(cm)) { |
Debargha Mukherjee | cd14cc1 | 2019-09-06 09:55:52 -0700 | [diff] [blame] | 4033 | const int use_hp = cpi->common.cur_frame_force_integer_mv |
| 4034 | ? 0 |
| 4035 | : determine_frame_high_precision_mv(cpi, *q); |
| 4036 | set_high_precision_mv(cpi, use_hp, cpi->common.cur_frame_force_integer_mv); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4037 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4038 | |
| 4039 | // Configure experimental use of segmentation for enhanced coding of |
| 4040 | // static regions if indicated. |
| 4041 | // Only allowed in the second pass of a two pass encode, as it requires |
| 4042 | // lagged coding, and if the relevant speed feature flag is set. |
| 4043 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 4044 | configure_static_seg_features(cpi); |
| 4045 | } |
| 4046 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4047 | static void init_motion_estimation(AV1_COMP *cpi) { |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4048 | AV1_COMMON *const cm = &cpi->common; |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4049 | const int y_stride = cpi->scaled_source.y_stride; |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4050 | const int y_stride_src = |
| 4051 | ((cpi->oxcf.width != cm->width || cpi->oxcf.height != cm->height) || |
| 4052 | av1_superres_scaled(cm)) |
| 4053 | ? y_stride |
| 4054 | : cpi->lookahead->buf->img.y_stride; |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4055 | // Update if ss_cfg is uninitialized or the current frame has a new stride |
| 4056 | const int should_update = !cpi->ss_cfg[SS_CFG_SRC].stride || |
| 4057 | !cpi->ss_cfg[SS_CFG_LOOKAHEAD].stride || |
| 4058 | (y_stride != cpi->ss_cfg[SS_CFG_SRC].stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4059 | |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4060 | if (!should_update) { |
| 4061 | return; |
| 4062 | } |
| 4063 | |
| 4064 | if (cpi->sf.mv.search_method == DIAMOND) { |
Satish Kumar Suman | e6d0be5 | 2019-02-14 14:33:28 +0530 | [diff] [blame] | 4065 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 4066 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], |
| 4067 | y_stride_src); |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 4068 | } else { |
| 4069 | // Update the offsets in search_sites as y_stride can change due to scaled |
| 4070 | // references. This update allows NSTEP to be used on scaled references as |
| 4071 | // long as sf.mv.search_method is not DIAMOND. Currently in the codebae, |
| 4072 | // sf.mv.search_method is never set to DIAMOND. |
| 4073 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 4074 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], y_stride_src); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4075 | } |
| 4076 | } |
| 4077 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4078 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4079 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 4080 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4081 | (void)width; |
| 4082 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4083 | (void)sx; |
| 4084 | (void)sy; |
| 4085 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4086 | int s = AOMMIN(sx, sy); |
| 4087 | #else |
| 4088 | int s = 0; |
| 4089 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4090 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 4091 | if (width * height > 352 * 288) |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 4092 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 4093 | else |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 4094 | rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4095 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 4096 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4097 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4098 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 4099 | static void init_ref_frame_bufs(AV1_COMP *cpi) { |
| 4100 | AV1_COMMON *const cm = &cpi->common; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4101 | int i; |
| 4102 | BufferPool *const pool = cm->buffer_pool; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4103 | cm->cur_frame = NULL; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4104 | for (i = 0; i < REF_FRAMES; ++i) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4105 | cm->ref_frame_map[i] = NULL; |
Wan-Teh Chang | d05e033 | 2018-10-03 12:00:43 -0700 | [diff] [blame] | 4106 | } |
| 4107 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4108 | pool->frame_bufs[i].ref_count = 0; |
| 4109 | } |
RogerZhou | 86902d0 | 2018-02-28 15:29:16 -0800 | [diff] [blame] | 4110 | if (cm->seq_params.force_screen_content_tools) { |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 4111 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 4112 | 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] | 4113 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4114 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4115 | } |
| 4116 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4117 | static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4118 | int subsampling_x, int subsampling_y) { |
| 4119 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4120 | SequenceHeader *const seq_params = &cm->seq_params; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4121 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4122 | if (!cpi->initial_width || seq_params->use_highbitdepth != use_highbitdepth || |
| 4123 | seq_params->subsampling_x != subsampling_x || |
| 4124 | seq_params->subsampling_y != subsampling_y) { |
| 4125 | seq_params->subsampling_x = subsampling_x; |
| 4126 | seq_params->subsampling_y = subsampling_y; |
| 4127 | seq_params->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4128 | |
| 4129 | alloc_raw_frame_buffers(cpi); |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 4130 | init_ref_frame_bufs(cpi); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4131 | alloc_util_frame_buffers(cpi); |
| 4132 | |
| 4133 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 4134 | |
| 4135 | cpi->initial_width = cm->width; |
| 4136 | cpi->initial_height = cm->height; |
| 4137 | cpi->initial_mbs = cm->MBs; |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | // Returns 1 if the assigned width or height was <= 0. |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 4142 | int av1_set_size_literal(AV1_COMP *cpi, int width, int height) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4143 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4144 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4145 | check_initial_width(cpi, cm->seq_params.use_highbitdepth, |
| 4146 | cm->seq_params.subsampling_x, |
| 4147 | cm->seq_params.subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4148 | |
| 4149 | if (width <= 0 || height <= 0) return 1; |
| 4150 | |
| 4151 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4152 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4153 | |
| 4154 | if (cpi->initial_width && cpi->initial_height && |
| 4155 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 4156 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4157 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4158 | alloc_compressor_data(cpi); |
| 4159 | realloc_segmentation_maps(cpi); |
| 4160 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4161 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4162 | update_frame_size(cpi); |
| 4163 | |
| 4164 | return 0; |
| 4165 | } |
| 4166 | |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4167 | void av1_set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4168 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4169 | const SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4170 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4171 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4172 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4173 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4174 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 4175 | // There has been a change in the encoded frame size |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 4176 | av1_set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4177 | set_mv_search_params(cpi); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4178 | // Recalculate 'all_lossless' in case super-resolution was (un)selected. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4179 | cm->all_lossless = cm->coded_lossless && !av1_superres_scaled(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4180 | } |
| 4181 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4182 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4183 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4186 | alloc_frame_mvs(cm, cm->cur_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4187 | |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 4188 | // Allocate above context buffers |
Cherma Rajan A | f147908 | 2018-05-09 14:26:34 +0530 | [diff] [blame] | 4189 | if (cm->num_allocated_above_context_planes < av1_num_planes(cm) || |
| 4190 | cm->num_allocated_above_context_mi_col < cm->mi_cols || |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 4191 | cm->num_allocated_above_contexts < cm->tile_rows) { |
| 4192 | av1_free_above_context_buffers(cm, cm->num_allocated_above_contexts); |
| 4193 | if (av1_alloc_above_context_buffers(cm, cm->tile_rows)) |
| 4194 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 4195 | "Failed to allocate context buffers"); |
| 4196 | } |
| 4197 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4198 | // Reset the frame pointers to the current frame size. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4199 | if (aom_realloc_frame_buffer( |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4200 | &cm->cur_frame->buf, cm->width, cm->height, seq_params->subsampling_x, |
| 4201 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 4202 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4203 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4204 | "Failed to allocate frame buffer"); |
| 4205 | |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4206 | const int frame_width = cm->superres_upscaled_width; |
| 4207 | const int frame_height = cm->superres_upscaled_height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4208 | set_restoration_unit_size(frame_width, frame_height, |
| 4209 | seq_params->subsampling_x, |
| 4210 | seq_params->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4211 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 4212 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4213 | |
| 4214 | av1_alloc_restoration_buffers(cm); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4215 | alloc_util_frame_buffers(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4216 | init_motion_estimation(cpi); |
| 4217 | |
| 4218 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4219 | RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4220 | if (buf != NULL) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4221 | struct scale_factors *sf = get_ref_scale_factors(cm, ref_frame); |
| 4222 | av1_setup_scale_factors_for_frame(sf, buf->buf.y_crop_width, |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 4223 | buf->buf.y_crop_height, cm->width, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 4224 | cm->height); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4225 | 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] | 4226 | } |
| 4227 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4228 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 4229 | 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] | 4230 | cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4231 | |
| 4232 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4233 | } |
| 4234 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4235 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 4236 | // Choose an arbitrary random number |
| 4237 | static unsigned int seed = 56789; |
| 4238 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4239 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4240 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4241 | |
Debargha Mukherjee | 2b7c2b3 | 2018-04-10 07:35:28 -0700 | [diff] [blame] | 4242 | if (cpi->common.seq_params.reduced_still_picture_hdr) return SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4243 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4244 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4245 | case RESIZE_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4246 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4247 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4248 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4249 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4250 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4251 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4252 | default: assert(0); |
| 4253 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4254 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 4257 | #if CONFIG_SUPERRES_IN_RECODE |
| 4258 | static int superres_in_recode_allowed(const AV1_COMP *const cpi) { |
| 4259 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 4260 | // Empirically found to not be beneficial for AOM_Q mode and images coding. |
| 4261 | return oxcf->superres_mode == SUPERRES_AUTO && |
| 4262 | (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) && |
| 4263 | cpi->rc.frames_to_key > 1; |
| 4264 | } |
| 4265 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 4266 | |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4267 | #define SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME_SOLO 0.012 |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4268 | #define SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME 0.008 |
| 4269 | #define SUPERRES_ENERGY_BY_Q2_THRESH_ARFFRAME 0.008 |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4270 | #define SUPERRES_ENERGY_BY_AC_THRESH 0.2 |
| 4271 | |
| 4272 | static double get_energy_by_q2_thresh(const GF_GROUP *gf_group, |
| 4273 | const RATE_CONTROL *rc) { |
| 4274 | // TODO(now): Return keyframe thresh * factor based on frame type / pyramid |
| 4275 | // level. |
| 4276 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 4277 | return SUPERRES_ENERGY_BY_Q2_THRESH_ARFFRAME; |
| 4278 | } else if (gf_group->update_type[gf_group->index] == KF_UPDATE) { |
| 4279 | if (rc->frames_to_key <= 1) |
| 4280 | return SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME_SOLO; |
| 4281 | else |
| 4282 | return SUPERRES_ENERGY_BY_Q2_THRESH_KEYFRAME; |
| 4283 | } else { |
| 4284 | assert(0); |
| 4285 | } |
| 4286 | return 0; |
| 4287 | } |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4288 | |
| 4289 | 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] | 4290 | double threshq, |
| 4291 | double threshp) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4292 | const double q = av1_convert_qindex_to_q(qindex, AOM_BITS_8); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4293 | const double tq = threshq * q * q; |
| 4294 | const double tp = threshp * energy[1]; |
| 4295 | const double thresh = AOMMIN(tq, tp); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4296 | int k; |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4297 | for (k = SCALE_NUMERATOR * 2; k > SCALE_NUMERATOR; --k) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4298 | if (energy[k - 1] > thresh) break; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4299 | } |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4300 | return 3 * SCALE_NUMERATOR - k; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4301 | } |
| 4302 | |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4303 | static uint8_t get_superres_denom_for_qindex(const AV1_COMP *cpi, int qindex, |
| 4304 | int sr_kf, int sr_arf) { |
| 4305 | // Use superres for Key-frames and Alt-ref frames only. |
| 4306 | const GF_GROUP *gf_group = &cpi->gf_group; |
| 4307 | if (gf_group->update_type[gf_group->index] != KF_UPDATE && |
| 4308 | gf_group->update_type[gf_group->index] != ARF_UPDATE) { |
| 4309 | return SCALE_NUMERATOR; |
| 4310 | } |
| 4311 | if (gf_group->update_type[gf_group->index] == KF_UPDATE && !sr_kf) { |
| 4312 | return SCALE_NUMERATOR; |
| 4313 | } |
| 4314 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE && !sr_arf) { |
| 4315 | return SCALE_NUMERATOR; |
| 4316 | } |
| 4317 | |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4318 | double energy[16]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4319 | analyze_hor_freq(cpi, energy); |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4320 | |
| 4321 | const double energy_by_q2_thresh = |
| 4322 | get_energy_by_q2_thresh(gf_group, &cpi->rc); |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 4323 | int denom = get_superres_denom_from_qindex_energy( |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4324 | qindex, energy, energy_by_q2_thresh, SUPERRES_ENERGY_BY_AC_THRESH); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4325 | /* |
| 4326 | printf("\nenergy = ["); |
| 4327 | for (int k = 1; k < 16; ++k) printf("%f, ", energy[k]); |
| 4328 | printf("]\n"); |
Debargha Mukherjee | c94082f | 2019-07-09 13:42:57 -0700 | [diff] [blame] | 4329 | printf("boost = %d\n", |
| 4330 | (gf_group->update_type[gf_group->index] == KF_UPDATE) |
| 4331 | ? cpi->rc.kf_boost |
| 4332 | : cpi->rc.gfu_boost); |
| 4333 | printf("denom = %d\n", denom); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 4334 | */ |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 4335 | #if CONFIG_SUPERRES_IN_RECODE |
| 4336 | if (superres_in_recode_allowed(cpi)) { |
| 4337 | // Force superres to be tried in the recode loop, as full-res is also going |
| 4338 | // to be tried anyway. |
| 4339 | denom = AOMMAX(denom, SCALE_NUMERATOR + 1); |
| 4340 | } |
| 4341 | #endif // CONFIG_SUPERRES_IN_RECODE |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4342 | return denom; |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 4343 | } |
| 4344 | |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 4345 | // If true, SUPERRES_AUTO mode will exhaustively search over all superres |
| 4346 | // denominators for all frames (except overlay and internal overlay frames). |
| 4347 | #define SUPERRES_RECODE_ALL_RATIOS 0 |
| 4348 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4349 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 4350 | // Choose an arbitrary random number |
| 4351 | static unsigned int seed = 34567; |
| 4352 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4353 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4354 | uint8_t new_denom = SCALE_NUMERATOR; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4355 | |
| 4356 | // Make sure that superres mode of the frame is consistent with the |
| 4357 | // sequence-level flag. |
| 4358 | assert(IMPLIES(oxcf->superres_mode != SUPERRES_NONE, |
| 4359 | cpi->common.seq_params.enable_superres)); |
| 4360 | assert(IMPLIES(!cpi->common.seq_params.enable_superres, |
| 4361 | oxcf->superres_mode == SUPERRES_NONE)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4362 | |
| 4363 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4364 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4365 | case SUPERRES_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4366 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4367 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4368 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4369 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4370 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4371 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4372 | case SUPERRES_QTHRESH: { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 4373 | // Do not use superres when screen content tools are used. |
| 4374 | if (cpi->common.allow_screen_content_tools) break; |
Debargha Mukherjee | 2b2c5fd | 2018-11-14 13:21:24 -0800 | [diff] [blame] | 4375 | if (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) |
| 4376 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4377 | |
| 4378 | // Now decide the use of superres based on 'q'. |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4379 | int bottom_index, top_index; |
| 4380 | const int q = av1_rc_pick_q_and_bounds( |
Angie Chiang | 958904c | 2019-09-19 16:03:35 -0700 | [diff] [blame] | 4381 | 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] | 4382 | &bottom_index, &top_index); |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 4383 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 4384 | const int qthresh = (frame_is_intra_only(&cpi->common)) |
| 4385 | ? oxcf->superres_kf_qthresh |
| 4386 | : oxcf->superres_qthresh; |
Urvang Joshi | b17e0a6 | 2019-01-11 16:11:54 -0800 | [diff] [blame] | 4387 | if (q <= qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4388 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4389 | } else { |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4390 | new_denom = get_superres_denom_for_qindex(cpi, q, 1, 1); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4391 | } |
| 4392 | break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4393 | } |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4394 | case SUPERRES_AUTO: { |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4395 | // Do not use superres when screen content tools are used. |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4396 | if (cpi->common.allow_screen_content_tools) break; |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4397 | if (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) |
| 4398 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4399 | |
| 4400 | // Now decide the use of superres based on 'q'. |
| 4401 | int bottom_index, top_index; |
| 4402 | const int q = av1_rc_pick_q_and_bounds( |
Angie Chiang | 958904c | 2019-09-19 16:03:35 -0700 | [diff] [blame] | 4403 | 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] | 4404 | &bottom_index, &top_index); |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4405 | |
| 4406 | const int qthresh = 128; |
| 4407 | if (q <= qthresh) { |
| 4408 | new_denom = SCALE_NUMERATOR; |
| 4409 | } else { |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 4410 | #if SUPERRES_RECODE_ALL_RATIOS |
| 4411 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
| 4412 | new_denom = oxcf->superres_kf_scale_denominator; |
| 4413 | else |
| 4414 | new_denom = oxcf->superres_scale_denominator; |
| 4415 | #else |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4416 | new_denom = get_superres_denom_for_qindex(cpi, q, 1, 1); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 4417 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 4418 | } |
| 4419 | break; |
| 4420 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4421 | default: assert(0); |
| 4422 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4423 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4424 | } |
| 4425 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4426 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4427 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4428 | } |
| 4429 | |
| 4430 | 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] | 4431 | // Only need to check the width, as scaling is horizontal only. |
| 4432 | (void)oheight; |
| 4433 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4434 | } |
| 4435 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4436 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4437 | SUPERRES_MODE superres_mode, int owidth, |
| 4438 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4439 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4440 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4441 | } |
| 4442 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4443 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4444 | int resize_denom = |
| 4445 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 4446 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 4447 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4448 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4449 | // Alter superres scale as needed to enforce conformity. |
| 4450 | rsz->superres_denom = |
| 4451 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 4452 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4453 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4454 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4455 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4456 | // Alter resize scale as needed to enforce conformity. |
| 4457 | resize_denom = |
| 4458 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4459 | rsz->resize_width = owidth; |
| 4460 | rsz->resize_height = oheight; |
| 4461 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4462 | resize_denom); |
| 4463 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4464 | if (resize_denom > SCALE_NUMERATOR) { |
| 4465 | --resize_denom; |
| 4466 | rsz->resize_width = owidth; |
| 4467 | rsz->resize_height = oheight; |
| 4468 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 4469 | resize_denom); |
| 4470 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4471 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4472 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4473 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4474 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4475 | if (resize_denom > rsz->superres_denom) |
| 4476 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4477 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4478 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4479 | rsz->resize_width = owidth; |
| 4480 | rsz->resize_height = oheight; |
| 4481 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4482 | resize_denom); |
| 4483 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 4484 | (resize_denom > SCALE_NUMERATOR || |
| 4485 | rsz->superres_denom > SCALE_NUMERATOR)); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4486 | } else { // We are allowed to alter neither resize scale nor superres |
| 4487 | // scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4488 | return 0; |
| 4489 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4490 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4491 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4492 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4493 | // Calculates resize and superres params for next frame |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4494 | static size_params_type calculate_next_size_params(AV1_COMP *cpi) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4495 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 4496 | size_params_type rsz = { oxcf->width, oxcf->height, SCALE_NUMERATOR }; |
Urvang Joshi | 510d8f6 | 2019-01-10 12:11:50 -0800 | [diff] [blame] | 4497 | int resize_denom = SCALE_NUMERATOR; |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 4498 | if (oxcf->pass == 0 && cpi->use_svc && |
| 4499 | cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1) { |
| 4500 | rsz.resize_width = cpi->common.width; |
| 4501 | rsz.resize_height = cpi->common.height; |
| 4502 | return rsz; |
| 4503 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4504 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4505 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 4506 | rsz.resize_width = cpi->resize_pending_width; |
| 4507 | rsz.resize_height = cpi->resize_pending_height; |
| 4508 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 4509 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4510 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4511 | rsz.resize_width = cpi->oxcf.width; |
| 4512 | rsz.resize_height = cpi->oxcf.height; |
| 4513 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4514 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4515 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4516 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4517 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 4518 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4519 | assert(0 && "Invalid scale parameters"); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4520 | return rsz; |
| 4521 | } |
| 4522 | |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 4523 | static void setup_frame_size_from_params(AV1_COMP *cpi, |
| 4524 | const size_params_type *rsz) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4525 | int encode_width = rsz->resize_width; |
| 4526 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4527 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4528 | AV1_COMMON *cm = &cpi->common; |
| 4529 | cm->superres_upscaled_width = encode_width; |
| 4530 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4531 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4532 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 4533 | rsz->superres_denom); |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4534 | av1_set_frame_size(cpi, encode_width, encode_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 4537 | void av1_setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 4538 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 4539 | // Reset superres params from previous frame. |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 4540 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4541 | const size_params_type rsz = calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4542 | setup_frame_size_from_params(cpi, &rsz); |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 4543 | |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 4544 | assert(av1_is_min_tile_width_satisfied(cm)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4545 | } |
| 4546 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4547 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4548 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4549 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4550 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4551 | if (!av1_superres_scaled(cm)) return; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4552 | |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4553 | assert(cpi->oxcf.enable_superres); |
| 4554 | assert(!is_lossless_requested(&cpi->oxcf)); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4555 | assert(!cm->all_lossless); |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4556 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4557 | av1_superres_upscale(cm, NULL); |
| 4558 | |
| 4559 | // If regular resizing is occurring the source will need to be downscaled to |
| 4560 | // match the upscaled superres resolution. Otherwise the original source is |
| 4561 | // used. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4562 | if (!av1_resize_scaled(cm)) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4563 | cpi->source = cpi->unscaled_source; |
| 4564 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4565 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4566 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4567 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4568 | // Do downscale. cm->(width|height) has been updated by |
| 4569 | // av1_superres_upscale |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4570 | if (aom_realloc_frame_buffer( |
| 4571 | &cpi->scaled_source, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4572 | cm->superres_upscaled_height, cm->seq_params.subsampling_x, |
| 4573 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
| 4574 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4575 | aom_internal_error( |
| 4576 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4577 | "Failed to reallocate scaled source buffer for superres"); |
| 4578 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4579 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4580 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4581 | (int)cm->seq_params.bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4582 | cpi->source = &cpi->scaled_source; |
| 4583 | } |
| 4584 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4585 | |
Yue Chen | 92271e1 | 2019-07-09 16:28:02 -0700 | [diff] [blame] | 4586 | static void cdef_restoration_frame(AV1_COMP *cpi, AV1_COMMON *cm, |
| 4587 | MACROBLOCKD *xd, int use_restoration, |
| 4588 | int use_cdef) { |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4589 | if (use_restoration) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4590 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4591 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4592 | if (use_cdef) { |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4593 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4594 | start_timing(cpi, cdef_time); |
| 4595 | #endif |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4596 | // Find CDEF parameters |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4597 | av1_cdef_search(&cm->cur_frame->buf, cpi->source, cm, xd, |
Hui Su | b93880a | 2019-06-27 18:29:30 -0700 | [diff] [blame] | 4598 | cpi->sf.cdef_pick_method, cpi->td.mb.rdmult); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4599 | |
| 4600 | // Apply the filter |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4601 | av1_cdef_frame(&cm->cur_frame->buf, cm, xd); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4602 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4603 | end_timing(cpi, cdef_time); |
| 4604 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4605 | } else { |
| 4606 | cm->cdef_info.cdef_bits = 0; |
| 4607 | cm->cdef_info.cdef_strengths[0] = 0; |
| 4608 | cm->cdef_info.nb_cdef_strengths = 1; |
| 4609 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4610 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4611 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4612 | superres_post_encode(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4613 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4614 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4615 | start_timing(cpi, loop_restoration_time); |
| 4616 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4617 | if (use_restoration) { |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4618 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 1); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4619 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4620 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4621 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4622 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4623 | if (cpi->num_workers > 1) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4624 | av1_loop_restoration_filter_frame_mt(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4625 | cpi->workers, cpi->num_workers, |
| 4626 | &cpi->lr_row_sync, &cpi->lr_ctxt); |
| 4627 | else |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4628 | av1_loop_restoration_filter_frame(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4629 | &cpi->lr_ctxt); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4630 | } |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4631 | } else { |
| 4632 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4633 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4634 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4635 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4636 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4637 | end_timing(cpi, loop_restoration_time); |
| 4638 | #endif |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4639 | } |
| 4640 | |
Yue Chen | 92271e1 | 2019-07-09 16:28:02 -0700 | [diff] [blame] | 4641 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 4642 | const int num_planes = av1_num_planes(cm); |
| 4643 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 4644 | |
| 4645 | assert(IMPLIES(is_lossless_requested(&cpi->oxcf), |
| 4646 | cm->coded_lossless && cm->all_lossless)); |
| 4647 | |
| 4648 | const int use_loopfilter = !cm->coded_lossless && !cm->large_scale_tile; |
| 4649 | const int use_cdef = cm->seq_params.enable_cdef && !cm->coded_lossless && |
| 4650 | !cm->large_scale_tile; |
| 4651 | const int use_restoration = cm->seq_params.enable_restoration && |
| 4652 | !cm->all_lossless && !cm->large_scale_tile; |
| 4653 | |
| 4654 | struct loopfilter *lf = &cm->lf; |
| 4655 | |
| 4656 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4657 | start_timing(cpi, loop_filter_time); |
| 4658 | #endif |
| 4659 | if (use_loopfilter) { |
| 4660 | aom_clear_system_state(); |
| 4661 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4662 | } else { |
| 4663 | lf->filter_level[0] = 0; |
| 4664 | lf->filter_level[1] = 0; |
| 4665 | } |
| 4666 | |
| 4667 | if (lf->filter_level[0] || lf->filter_level[1]) { |
| 4668 | if (cpi->num_workers > 1) |
| 4669 | av1_loop_filter_frame_mt(&cm->cur_frame->buf, cm, xd, 0, num_planes, 0, |
| 4670 | #if CONFIG_LPF_MASK |
| 4671 | 0, |
| 4672 | #endif |
| 4673 | cpi->workers, cpi->num_workers, |
| 4674 | &cpi->lf_row_sync); |
| 4675 | else |
| 4676 | av1_loop_filter_frame(&cm->cur_frame->buf, cm, xd, |
| 4677 | #if CONFIG_LPF_MASK |
| 4678 | 0, |
| 4679 | #endif |
| 4680 | 0, num_planes, 0); |
| 4681 | } |
| 4682 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4683 | end_timing(cpi, loop_filter_time); |
| 4684 | #endif |
| 4685 | |
| 4686 | cdef_restoration_frame(cpi, cm, xd, use_restoration, use_cdef); |
| 4687 | } |
| 4688 | |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4689 | static void fix_interp_filter(InterpFilter *const interp_filter, |
| 4690 | const FRAME_COUNTS *const counts) { |
| 4691 | if (*interp_filter == SWITCHABLE) { |
| 4692 | // Check to see if only one of the filters is actually used |
| 4693 | int count[SWITCHABLE_FILTERS] = { 0 }; |
| 4694 | int num_filters_used = 0; |
| 4695 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4696 | for (int j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) |
| 4697 | count[i] += counts->switchable_interp[j][i]; |
| 4698 | num_filters_used += (count[i] > 0); |
| 4699 | } |
| 4700 | if (num_filters_used == 1) { |
| 4701 | // Only one filter is used. So set the filter at frame level |
| 4702 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4703 | if (count[i]) { |
| 4704 | if (i == EIGHTTAP_REGULAR) *interp_filter = i; |
| 4705 | break; |
| 4706 | } |
| 4707 | } |
| 4708 | } |
| 4709 | } |
| 4710 | } |
| 4711 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4712 | static void finalize_encoded_frame(AV1_COMP *const cpi) { |
| 4713 | AV1_COMMON *const cm = &cpi->common; |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4714 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4715 | |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4716 | if (!cm->seq_params.reduced_still_picture_hdr && |
| 4717 | encode_show_existing_frame(cm)) { |
| 4718 | RefCntBuffer *const frame_to_show = |
| 4719 | cm->ref_frame_map[cpi->existing_fb_idx_to_show]; |
| 4720 | |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4721 | if (frame_to_show == NULL) { |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4722 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 4723 | "Buffer does not contain a reconstructed frame"); |
| 4724 | } |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4725 | assert(frame_to_show->ref_count > 0); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4726 | assign_frame_buffer_p(&cm->cur_frame, frame_to_show); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4727 | } |
David Turner | 08f909c | 2018-12-18 13:29:14 +0000 | [diff] [blame] | 4728 | |
| 4729 | if (!encode_show_existing_frame(cm) && |
| 4730 | cm->seq_params.film_grain_params_present && |
| 4731 | (cm->show_frame || cm->showable_frame)) { |
| 4732 | // Copy the current frame's film grain params to the its corresponding |
| 4733 | // RefCntBuffer slot. |
| 4734 | cm->cur_frame->film_grain_params = cm->film_grain_params; |
| 4735 | |
| 4736 | // We must update the parameters if this is not an INTER_FRAME |
| 4737 | if (current_frame->frame_type != INTER_FRAME) |
| 4738 | cm->cur_frame->film_grain_params.update_parameters = 1; |
| 4739 | |
| 4740 | // Iterate the random seed for the next frame. |
| 4741 | cm->film_grain_params.random_seed += 3381; |
| 4742 | if (cm->film_grain_params.random_seed == 0) |
| 4743 | cm->film_grain_params.random_seed = 7391; |
| 4744 | } |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4745 | |
| 4746 | // Initialise all tiles' contexts from the global frame context |
| 4747 | for (int tile_col = 0; tile_col < cm->tile_cols; tile_col++) { |
| 4748 | for (int tile_row = 0; tile_row < cm->tile_rows; tile_row++) { |
| 4749 | const int tile_idx = tile_row * cm->tile_cols + tile_col; |
| 4750 | cpi->tile_data[tile_idx].tctx = *cm->fc; |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | fix_interp_filter(&cm->interp_filter, cpi->td.counts); |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4755 | } |
| 4756 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4757 | static int get_regulated_q_overshoot(AV1_COMP *const cpi, int q_low, int q_high, |
| 4758 | int top_index, int bottom_index) { |
| 4759 | const AV1_COMMON *const cm = &cpi->common; |
| 4760 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4761 | |
| 4762 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4763 | |
| 4764 | int q_regulated = |
| 4765 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4766 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4767 | |
| 4768 | int retries = 0; |
| 4769 | while (q_regulated < q_low && retries < 10) { |
| 4770 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4771 | q_regulated = |
| 4772 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4773 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4774 | retries++; |
| 4775 | } |
| 4776 | return q_regulated; |
| 4777 | } |
| 4778 | |
| 4779 | static int get_regulated_q_undershoot(AV1_COMP *const cpi, int q_high, |
| 4780 | int top_index, int bottom_index) { |
| 4781 | const AV1_COMMON *const cm = &cpi->common; |
| 4782 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4783 | |
| 4784 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4785 | int q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4786 | top_index, cm->width, cm->height); |
| 4787 | |
| 4788 | int retries = 0; |
| 4789 | while (q_regulated > q_high && retries < 10) { |
| 4790 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4791 | q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4792 | top_index, cm->width, cm->height); |
| 4793 | retries++; |
| 4794 | } |
| 4795 | return q_regulated; |
| 4796 | } |
| 4797 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4798 | // Called after encode_with_recode_loop() has just encoded a frame and packed |
| 4799 | // its bitstream. This function works out whether we under- or over-shot |
| 4800 | // our bitrate target and adjusts q as appropriate. Also decides whether |
| 4801 | // or not we should do another recode loop, indicated by *loop |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4802 | static void recode_loop_update_q( |
| 4803 | AV1_COMP *const cpi, int *const loop, int *const q, int *const q_low, |
| 4804 | int *const q_high, const int top_index, const int bottom_index, |
| 4805 | int *const undershoot_seen, int *const overshoot_seen, |
| 4806 | int *const low_cr_seen, const int loop_at_this_size) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4807 | AV1_COMMON *const cm = &cpi->common; |
| 4808 | RATE_CONTROL *const rc = &cpi->rc; |
| 4809 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4810 | const int min_cr = cpi->oxcf.min_cr; |
| 4811 | if (min_cr > 0) { |
| 4812 | aom_clear_system_state(); |
| 4813 | const double compression_ratio = |
| 4814 | av1_get_compression_ratio(cm, rc->projected_frame_size >> 3); |
| 4815 | const double target_cr = min_cr / 100.0; |
| 4816 | if (compression_ratio < target_cr) { |
| 4817 | *low_cr_seen = 1; |
| 4818 | if (*q < rc->worst_quality) { |
| 4819 | const double cr_ratio = target_cr / compression_ratio; |
| 4820 | const int projected_q = AOMMAX(*q + 1, (int)(*q * cr_ratio * cr_ratio)); |
| 4821 | *q = AOMMIN(AOMMIN(projected_q, *q + 32), rc->worst_quality); |
| 4822 | *q_low = AOMMAX(*q, *q_low); |
| 4823 | *q_high = AOMMAX(*q, *q_high); |
| 4824 | *loop = 1; |
| 4825 | } |
| 4826 | } |
| 4827 | if (*low_cr_seen) return; |
| 4828 | } |
| 4829 | |
| 4830 | if (cpi->oxcf.rc_mode == AOM_Q) return; |
| 4831 | |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4832 | const int last_q = *q; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4833 | int frame_over_shoot_limit = 0, frame_under_shoot_limit = 0; |
| 4834 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4835 | &frame_under_shoot_limit, |
| 4836 | &frame_over_shoot_limit); |
| 4837 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4838 | |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4839 | if (cm->current_frame.frame_type == KEY_FRAME && rc->this_key_frame_forced && |
| 4840 | rc->projected_frame_size < rc->max_frame_bandwidth) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4841 | int64_t kf_err; |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4842 | const int64_t high_err_target = cpi->ambient_err; |
| 4843 | const int64_t low_err_target = cpi->ambient_err >> 1; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4844 | |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 4845 | #if CONFIG_AV1_HIGHBITDEPTH |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4846 | if (cm->seq_params.use_highbitdepth) { |
| 4847 | kf_err = aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4848 | } else { |
| 4849 | kf_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4850 | } |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 4851 | #else |
| 4852 | kf_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4853 | #endif |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4854 | // Prevent possible divide by zero error below for perfect KF |
| 4855 | kf_err += !kf_err; |
| 4856 | |
| 4857 | // The key frame is not good enough or we can afford |
| 4858 | // to make it better without undue risk of popping. |
| 4859 | if ((kf_err > high_err_target && |
| 4860 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4861 | (kf_err > low_err_target && |
| 4862 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4863 | // Lower q_high |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4864 | *q_high = AOMMAX(*q - 1, *q_low); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4865 | |
| 4866 | // Adjust Q |
| 4867 | *q = (int)((*q * high_err_target) / kf_err); |
| 4868 | *q = AOMMIN(*q, (*q_high + *q_low) >> 1); |
| 4869 | } else if (kf_err < low_err_target && |
| 4870 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4871 | // The key frame is much better than the previous frame |
| 4872 | // Raise q_low |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4873 | *q_low = AOMMIN(*q + 1, *q_high); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4874 | |
| 4875 | // Adjust Q |
| 4876 | *q = (int)((*q * low_err_target) / kf_err); |
| 4877 | *q = AOMMIN(*q, (*q_high + *q_low + 1) >> 1); |
| 4878 | } |
| 4879 | |
| 4880 | // Clamp Q to upper and lower limits: |
| 4881 | *q = clamp(*q, *q_low, *q_high); |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4882 | *loop = (*q != last_q); |
| 4883 | return; |
| 4884 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4885 | |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4886 | if (recode_loop_test(cpi, frame_over_shoot_limit, frame_under_shoot_limit, *q, |
| 4887 | AOMMAX(*q_high, top_index), bottom_index)) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4888 | // Is the projected frame size out of range and are we allowed |
| 4889 | // to attempt to recode. |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4890 | |
| 4891 | // Frame size out of permitted range: |
| 4892 | // Update correction factor & compute new Q to try... |
| 4893 | // Frame is too large |
| 4894 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4895 | // Special case if the projected size is > the max allowed. |
Urvang Joshi | 7344d3e | 2019-07-25 17:24:57 -0700 | [diff] [blame] | 4896 | if (*q == *q_high && |
| 4897 | rc->projected_frame_size >= rc->max_frame_bandwidth) { |
| 4898 | const double q_val_high_current = |
| 4899 | av1_convert_qindex_to_q(*q_high, cm->seq_params.bit_depth); |
| 4900 | const double q_val_high_new = |
| 4901 | q_val_high_current * |
| 4902 | ((double)rc->projected_frame_size / rc->max_frame_bandwidth); |
| 4903 | *q_high = av1_find_qindex(q_val_high_new, cm->seq_params.bit_depth, |
| 4904 | rc->best_quality, rc->worst_quality); |
| 4905 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4906 | |
| 4907 | // Raise Qlow as to at least the current value |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4908 | *q_low = AOMMIN(*q + 1, *q_high); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4909 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4910 | if (*undershoot_seen || loop_at_this_size > 2 || |
| 4911 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4912 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4913 | |
| 4914 | *q = (*q_high + *q_low + 1) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4915 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 4916 | const int q_mid = (*q_high + *q_low + 1) / 2; |
| 4917 | const int q_regulated = get_regulated_q_overshoot( |
| 4918 | cpi, *q_low, *q_high, top_index, bottom_index); |
| 4919 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 4920 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 4921 | *q = (q_mid + q_regulated + 1) / 2; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4922 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4923 | *q = get_regulated_q_overshoot(cpi, *q_low, *q_high, top_index, |
| 4924 | bottom_index); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | *overshoot_seen = 1; |
| 4928 | } else { |
| 4929 | // Frame is too small |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4930 | *q_high = AOMMAX(*q - 1, *q_low); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4931 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4932 | if (*overshoot_seen || loop_at_this_size > 2 || |
| 4933 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4934 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4935 | *q = (*q_high + *q_low) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4936 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 4937 | const int q_mid = (*q_high + *q_low) / 2; |
| 4938 | const int q_regulated = |
| 4939 | get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 4940 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 4941 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 4942 | *q = (q_mid + q_regulated) / 2; |
| 4943 | |
| 4944 | // Special case reset for qlow for constrained quality. |
| 4945 | // This should only trigger where there is very substantial |
| 4946 | // undershoot on a frame and the auto cq level is above |
| 4947 | // the user passsed in value. |
| 4948 | if (cpi->oxcf.rc_mode == AOM_CQ && q_regulated < *q_low) { |
| 4949 | *q_low = *q; |
| 4950 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4951 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4952 | *q = get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 4953 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4954 | // Special case reset for qlow for constrained quality. |
| 4955 | // This should only trigger where there is very substantial |
| 4956 | // undershoot on a frame and the auto cq level is above |
| 4957 | // the user passsed in value. |
| 4958 | if (cpi->oxcf.rc_mode == AOM_CQ && *q < *q_low) { |
| 4959 | *q_low = *q; |
| 4960 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | *undershoot_seen = 1; |
| 4964 | } |
| 4965 | |
| 4966 | // Clamp Q to upper and lower limits: |
| 4967 | *q = clamp(*q, *q_low, *q_high); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4968 | } |
Hui Su | 01dfe03 | 2019-09-11 14:10:42 -0700 | [diff] [blame] | 4969 | |
| 4970 | *loop = (*q != last_q); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4971 | } |
| 4972 | |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 4973 | static int get_interp_filter_selected(const AV1_COMMON *const cm, |
| 4974 | MV_REFERENCE_FRAME ref, |
| 4975 | InterpFilter ifilter) { |
| 4976 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref); |
| 4977 | if (buf == NULL) return 0; |
| 4978 | return buf->interp_filter_selected[ifilter]; |
| 4979 | } |
| 4980 | |
Satish Kumar Suman | 0389a49 | 2019-07-31 13:35:58 +0530 | [diff] [blame] | 4981 | static uint16_t setup_interp_filter_search_mask(AV1_COMP *cpi) { |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 4982 | const AV1_COMMON *const cm = &cpi->common; |
| 4983 | int ref_total[REF_FRAMES] = { 0 }; |
Satish Kumar Suman | 0389a49 | 2019-07-31 13:35:58 +0530 | [diff] [blame] | 4984 | uint16_t mask = ALLOW_ALL_INTERP_FILT_MASK; |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 4985 | |
| 4986 | 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] | 4987 | return mask; |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 4988 | |
| 4989 | for (MV_REFERENCE_FRAME ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) { |
| 4990 | for (InterpFilter ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 4991 | ++ifilter) { |
| 4992 | ref_total[ref] += get_interp_filter_selected(cm, ref, ifilter); |
| 4993 | } |
| 4994 | } |
| 4995 | int ref_total_total = (ref_total[LAST2_FRAME] + ref_total[LAST3_FRAME] + |
| 4996 | ref_total[GOLDEN_FRAME] + ref_total[BWDREF_FRAME] + |
| 4997 | ref_total[ALTREF2_FRAME] + ref_total[ALTREF_FRAME]); |
| 4998 | |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 4999 | for (InterpFilter ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 5000 | ++ifilter) { |
| 5001 | int last_score = get_interp_filter_selected(cm, LAST_FRAME, ifilter) * 30; |
| 5002 | if (ref_total[LAST_FRAME] && last_score <= ref_total[LAST_FRAME]) { |
| 5003 | int filter_score = |
| 5004 | get_interp_filter_selected(cm, LAST2_FRAME, ifilter) * 20 + |
| 5005 | get_interp_filter_selected(cm, LAST3_FRAME, ifilter) * 20 + |
| 5006 | get_interp_filter_selected(cm, GOLDEN_FRAME, ifilter) * 20 + |
| 5007 | get_interp_filter_selected(cm, BWDREF_FRAME, ifilter) * 10 + |
| 5008 | get_interp_filter_selected(cm, ALTREF2_FRAME, ifilter) * 10 + |
| 5009 | get_interp_filter_selected(cm, ALTREF_FRAME, ifilter) * 10; |
Satish Kumar Suman | 0389a49 | 2019-07-31 13:35:58 +0530 | [diff] [blame] | 5010 | if (filter_score < ref_total_total) { |
| 5011 | DUAL_FILTER_TYPE filt_type = ifilter + SWITCHABLE_FILTERS * ifilter; |
| 5012 | reset_interp_filter_allowed_mask(&mask, filt_type); |
| 5013 | } |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5014 | } |
| 5015 | } |
| 5016 | return mask; |
| 5017 | } |
| 5018 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5019 | 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] | 5020 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5021 | RATE_CONTROL *const rc = &cpi->rc; |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5022 | const int allow_recode = (cpi->sf.recode_loop != DISALLOW_RECODE); |
Hui Su | a1d7184 | 2019-07-31 12:02:24 -0700 | [diff] [blame] | 5023 | // Must allow recode if minimum compression ratio is set. |
| 5024 | assert(IMPLIES(cpi->oxcf.min_cr > 0, allow_recode)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5025 | |
| 5026 | set_size_independent_vars(cpi); |
Satish Kumar Suman | 829c168 | 2019-07-31 11:30:07 +0530 | [diff] [blame] | 5027 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
Yunqing Wang | c3ab927 | 2019-11-01 17:43:58 -0700 | [diff] [blame] | 5028 | cpi->interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5029 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5030 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5031 | av1_setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5032 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5033 | #if CONFIG_SUPERRES_IN_RECODE |
| 5034 | if (superres_in_recode_allowed(cpi) && |
| 5035 | cm->superres_scale_denominator == SCALE_NUMERATOR) { |
| 5036 | // Superres won't be picked, so no need to try, as we will go through |
| 5037 | // another recode loop for full-resolution after this anyway. |
| 5038 | return -1; |
| 5039 | } |
| 5040 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 5041 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5042 | int top_index = 0, bottom_index = 0; |
| 5043 | int q = 0, q_low = 0, q_high = 0; |
| 5044 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 5045 | q_low = bottom_index; |
| 5046 | q_high = top_index; |
| 5047 | |
Yunqing Wang | 80a7af6 | 2019-08-22 16:07:44 -0700 | [diff] [blame] | 5048 | if (cpi->sf.tx_type_search.prune_tx_type_using_stats && |
| 5049 | cm->current_frame.frame_type == KEY_FRAME) { |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 5050 | av1_copy(cpi->tx_type_probs, default_tx_type_probs); |
| 5051 | |
Yunqing Wang | eb7c218 | 2019-08-22 18:15:48 -0700 | [diff] [blame] | 5052 | int thr[2][2] = { { 15, 10 }, { 17, 10 } }; |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 5053 | for (int f = 0; f < FRAME_UPDATE_TYPES; f++) { |
Yunqing Wang | eb7c218 | 2019-08-22 18:15:48 -0700 | [diff] [blame] | 5054 | int kf_arf_update = (f == KF_UPDATE || f == ARF_UPDATE); |
| 5055 | cpi->tx_type_probs_thresh[f] = |
| 5056 | thr[cpi->sf.tx_type_search.prune_tx_type_using_stats - 1] |
| 5057 | [kf_arf_update]; |
Yunqing Wang | db70bf4 | 2019-08-19 09:28:11 -0700 | [diff] [blame] | 5058 | } |
| 5059 | } |
| 5060 | |
Yunqing Wang | 3ea314b | 2019-11-18 16:01:14 -0800 | [diff] [blame] | 5061 | if (!cpi->sf.disable_obmc && cpi->sf.prune_obmc_prob_thresh > 0 && |
Yunqing Wang | 5f74dc2 | 2019-10-29 10:35:20 -0700 | [diff] [blame] | 5062 | cm->current_frame.frame_type == KEY_FRAME) { |
| 5063 | av1_copy(cpi->obmc_probs, default_obmc_probs); |
Yunqing Wang | 5f74dc2 | 2019-10-29 10:35:20 -0700 | [diff] [blame] | 5064 | } |
| 5065 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5066 | // Loop variables |
| 5067 | int loop_count = 0; |
| 5068 | int loop_at_this_size = 0; |
| 5069 | int loop = 0; |
| 5070 | int overshoot_seen = 0; |
| 5071 | int undershoot_seen = 0; |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 5072 | int low_cr_seen = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5073 | |
| 5074 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5075 | printf("\n Encoding a frame:"); |
| 5076 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5077 | do { |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5078 | loop = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5079 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5080 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5081 | // if frame was scaled calculate global_motion_search again if already |
| 5082 | // done |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5083 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5084 | if (cpi->source->y_crop_width != cm->width || |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5085 | cpi->source->y_crop_height != cm->height) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5086 | cpi->global_motion_search_done = 0; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5087 | } |
| 5088 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5089 | cpi->source = |
| 5090 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5091 | if (cpi->unscaled_last_source != NULL) { |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 5092 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 5093 | &cpi->scaled_last_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5094 | } |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 5095 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5096 | if (!frame_is_intra_only(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5097 | if (loop_count > 0) { |
| 5098 | release_scaled_references(cpi); |
| 5099 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5100 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5101 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5102 | av1_set_quantizer(cm, q); |
Fyodor Kyslov | 25daf5d | 2019-10-23 10:33:26 -0700 | [diff] [blame] | 5103 | if (cpi->oxcf.deltaq_mode != NO_DELTA_Q) av1_init_quantizer(cpi); |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 5104 | |
| 5105 | av1_set_variance_partition_thresholds(cpi, q, 0); |
| 5106 | |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 5107 | // printf("Frame %d/%d: q = %d, frame_type = %d superres_denom = %d\n", |
| 5108 | // cm->current_frame.frame_number, cm->show_frame, q, |
| 5109 | // cm->current_frame.frame_type, cm->superres_scale_denominator); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5110 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5111 | if (loop_count == 0) { |
| 5112 | setup_frame(cpi); |
| 5113 | } else if (get_primary_ref_frame_buf(cm) == NULL) { |
| 5114 | // Base q-index may have changed, so we need to assign proper default coef |
| 5115 | // probs before every iteration. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5116 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 5117 | av1_setup_frame_contexts(cm); |
David Barker | fc91b39 | 2018-03-09 15:32:03 +0000 | [diff] [blame] | 5118 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5119 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5120 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5121 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5122 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5123 | av1_setup_in_frame_q_adj(cpi); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5124 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && !allow_recode) { |
| 5125 | suppress_active_map(cpi); |
| 5126 | av1_cyclic_refresh_setup(cpi); |
| 5127 | apply_active_map(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5128 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5129 | |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 5130 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 5131 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 5132 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
Jerome Jiang | b23571d | 2019-10-23 14:15:55 -0700 | [diff] [blame] | 5133 | cm->seg.enabled = cm->prev_frame->seg.enabled; |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 5134 | } else { |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 5135 | av1_calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 5136 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 5137 | } else { |
| 5138 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 5139 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 5140 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Jerome Jiang | b23571d | 2019-10-23 14:15:55 -0700 | [diff] [blame] | 5141 | cm->cur_frame->seg.enabled = cm->seg.enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5142 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5143 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5144 | start_timing(cpi, av1_encode_frame_time); |
| 5145 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5146 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5147 | av1_encode_frame(cpi); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5148 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5149 | end_timing(cpi, av1_encode_frame_time); |
| 5150 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5151 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5152 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5153 | |
| 5154 | // Dummy pack of the bitstream using up to date stats to get an |
| 5155 | // accurate estimate of output frame size to determine if we need |
| 5156 | // to recode. |
Hui Su | 7e3eeaa | 2019-09-11 15:50:41 -0700 | [diff] [blame] | 5157 | const int do_dummy_pack = (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF && |
| 5158 | cpi->oxcf.rc_mode != AOM_Q) || |
| 5159 | cpi->oxcf.min_cr > 0; |
Hui Su | a1d7184 | 2019-07-31 12:02:24 -0700 | [diff] [blame] | 5160 | if (do_dummy_pack) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5161 | finalize_encoded_frame(cpi); |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5162 | int largest_tile_id = 0; // Output from bitstream: unused here |
| 5163 | 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] | 5164 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5165 | |
| 5166 | rc->projected_frame_size = (int)(*size) << 3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 5169 | if (allow_recode) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5170 | // Update q and decide whether to do a recode loop |
| 5171 | recode_loop_update_q(cpi, &loop, &q, &q_low, &q_high, top_index, |
| 5172 | bottom_index, &undershoot_seen, &overshoot_seen, |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 5173 | &low_cr_seen, loop_at_this_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | // Special case for overlay frame. |
Hui Su | 7e3eeaa | 2019-09-11 15:50:41 -0700 | [diff] [blame] | 5177 | if (loop && rc->is_src_frame_alt_ref && |
| 5178 | rc->projected_frame_size < rc->max_frame_bandwidth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5179 | loop = 0; |
Hui Su | 7e3eeaa | 2019-09-11 15:50:41 -0700 | [diff] [blame] | 5180 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5181 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5182 | if (allow_recode && !cpi->sf.gm_disable_recode && |
| 5183 | recode_loop_test_global_motion(cpi)) { |
| 5184 | loop = 1; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5185 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5186 | |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 5187 | #if !CONFIG_REALTIME_ONLY |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5188 | if (cpi->tpl_model_pass == 1) { |
| 5189 | assert(cpi->oxcf.enable_tpl_model == 2); |
Debargha Mukherjee | 347c64d | 2019-05-08 13:53:46 -0700 | [diff] [blame] | 5190 | av1_tpl_setup_forward_stats(cpi); |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5191 | cpi->tpl_model_pass = 0; |
| 5192 | loop = 1; |
| 5193 | } |
Jerome Jiang | d413f4a | 2019-09-23 14:53:03 -0700 | [diff] [blame] | 5194 | #endif |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5195 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5196 | if (loop) { |
| 5197 | ++loop_count; |
| 5198 | ++loop_at_this_size; |
| 5199 | |
| 5200 | #if CONFIG_INTERNAL_STATS |
| 5201 | ++cpi->tot_recode_hits; |
| 5202 | #endif |
| 5203 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5204 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5205 | if (loop) printf("\n Recoding:"); |
| 5206 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5207 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5208 | |
Marco Paniconi | 574e59e | 2019-10-23 15:47:28 -0700 | [diff] [blame] | 5209 | // Update some stats from cyclic refresh. |
| 5210 | if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled && |
| 5211 | !frame_is_intra_only(cm)) |
| 5212 | av1_cyclic_refresh_postencode(cpi); |
| 5213 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5214 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5217 | static int encode_with_recode_loop_and_filter(AV1_COMP *cpi, size_t *size, |
| 5218 | uint8_t *dest, int64_t *sse, |
| 5219 | int64_t *rate, |
| 5220 | int *largest_tile_id) { |
| 5221 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5222 | start_timing(cpi, encode_with_recode_loop_time); |
| 5223 | #endif |
| 5224 | int err = encode_with_recode_loop(cpi, size, dest); |
| 5225 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5226 | end_timing(cpi, encode_with_recode_loop_time); |
| 5227 | #endif |
| 5228 | if (err != AOM_CODEC_OK) { |
| 5229 | if (err == -1) { |
| 5230 | // special case as described in encode_with_recode_loop(). |
| 5231 | // Encoding was skipped. |
| 5232 | err = AOM_CODEC_OK; |
| 5233 | if (sse != NULL) *sse = INT64_MAX; |
| 5234 | if (rate != NULL) *rate = INT64_MAX; |
| 5235 | *largest_tile_id = 0; |
| 5236 | } |
| 5237 | return err; |
| 5238 | } |
| 5239 | |
| 5240 | #ifdef OUTPUT_YUV_SKINMAP |
| 5241 | if (cpi->common.current_frame.frame_number > 1) { |
| 5242 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
| 5243 | } |
| 5244 | #endif // OUTPUT_YUV_SKINMAP |
| 5245 | |
| 5246 | AV1_COMMON *const cm = &cpi->common; |
| 5247 | SequenceHeader *const seq_params = &cm->seq_params; |
| 5248 | |
| 5249 | // Special case code to reduce pulsing when key frames are forced at a |
| 5250 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5251 | // the force key frame |
| 5252 | 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] | 5253 | #if CONFIG_AV1_HIGHBITDEPTH |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5254 | if (seq_params->use_highbitdepth) { |
| 5255 | cpi->ambient_err = aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5256 | } else { |
| 5257 | cpi->ambient_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5258 | } |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 5259 | #else |
| 5260 | cpi->ambient_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5261 | #endif |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | cm->cur_frame->buf.color_primaries = seq_params->color_primaries; |
| 5265 | cm->cur_frame->buf.transfer_characteristics = |
| 5266 | seq_params->transfer_characteristics; |
| 5267 | cm->cur_frame->buf.matrix_coefficients = seq_params->matrix_coefficients; |
| 5268 | cm->cur_frame->buf.monochrome = seq_params->monochrome; |
| 5269 | cm->cur_frame->buf.chroma_sample_position = |
| 5270 | seq_params->chroma_sample_position; |
| 5271 | cm->cur_frame->buf.color_range = seq_params->color_range; |
| 5272 | cm->cur_frame->buf.render_width = cm->render_width; |
| 5273 | cm->cur_frame->buf.render_height = cm->render_height; |
| 5274 | |
| 5275 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5276 | // off. |
| 5277 | |
| 5278 | // Pick the loop filter level for the frame. |
| 5279 | if (!cm->allow_intrabc) { |
| 5280 | loopfilter_frame(cpi, cm); |
| 5281 | } else { |
| 5282 | cm->lf.filter_level[0] = 0; |
| 5283 | cm->lf.filter_level[1] = 0; |
| 5284 | cm->cdef_info.cdef_bits = 0; |
| 5285 | cm->cdef_info.cdef_strengths[0] = 0; |
| 5286 | cm->cdef_info.nb_cdef_strengths = 1; |
| 5287 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
| 5288 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5289 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5290 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
| 5291 | } |
| 5292 | |
| 5293 | // TODO(debargha): Fix mv search range on encoder side |
| 5294 | // aom_extend_frame_inner_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
| 5295 | aom_extend_frame_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
| 5296 | |
| 5297 | #ifdef OUTPUT_YUV_REC |
| 5298 | aom_write_one_yuv_frame(cm, &cm->cur_frame->buf); |
| 5299 | #endif |
| 5300 | |
| 5301 | finalize_encoded_frame(cpi); |
| 5302 | // Build the bitstream |
| 5303 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5304 | start_timing(cpi, av1_pack_bitstream_final_time); |
| 5305 | #endif |
| 5306 | if (av1_pack_bitstream(cpi, dest, size, largest_tile_id) != AOM_CODEC_OK) |
| 5307 | return AOM_CODEC_ERROR; |
| 5308 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5309 | end_timing(cpi, av1_pack_bitstream_final_time); |
| 5310 | #endif |
| 5311 | |
| 5312 | // Compute sse and rate. |
| 5313 | if (sse != NULL) { |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 5314 | #if CONFIG_AV1_HIGHBITDEPTH |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5315 | *sse = (seq_params->use_highbitdepth) |
| 5316 | ? aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf) |
| 5317 | : aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 5318 | #else |
| 5319 | *sse = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 5320 | #endif |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5321 | } |
| 5322 | if (rate != NULL) { |
| 5323 | const int64_t bits = (*size << 3); |
| 5324 | *rate = (bits << 5); // To match scale. |
| 5325 | } |
| 5326 | return AOM_CODEC_OK; |
| 5327 | } |
| 5328 | |
| 5329 | #if CONFIG_SUPERRES_IN_RECODE |
| 5330 | |
| 5331 | static void save_cur_buf(AV1_COMP *cpi) { |
| 5332 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5333 | AV1_COMMON *cm = &cpi->common; |
| 5334 | const YV12_BUFFER_CONFIG *ybf = &cm->cur_frame->buf; |
| 5335 | memset(&cc->copy_buffer, 0, sizeof(cc->copy_buffer)); |
| 5336 | if (aom_alloc_frame_buffer(&cc->copy_buffer, ybf->y_crop_width, |
| 5337 | ybf->y_crop_height, ybf->subsampling_x, |
| 5338 | ybf->subsampling_y, |
| 5339 | ybf->flags & YV12_FLAG_HIGHBITDEPTH, ybf->border, |
| 5340 | cm->byte_alignment) != AOM_CODEC_OK) { |
| 5341 | aom_internal_error( |
| 5342 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 5343 | "Failed to allocate copy buffer for saving coding context"); |
| 5344 | } |
| 5345 | aom_yv12_copy_frame(ybf, &cc->copy_buffer, av1_num_planes(cm)); |
| 5346 | } |
| 5347 | |
| 5348 | // Coding context that only needs to be saved when recode loop includes |
| 5349 | // filtering (deblocking, CDEF, superres post-encode upscale and/or loop |
| 5350 | // restoraton). |
| 5351 | static void save_extra_coding_context(AV1_COMP *cpi) { |
| 5352 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5353 | AV1_COMMON *cm = &cpi->common; |
| 5354 | |
| 5355 | cc->lf = cm->lf; |
| 5356 | cc->cdef_info = cm->cdef_info; |
| 5357 | cc->rc = cpi->rc; |
| 5358 | } |
| 5359 | |
| 5360 | static void save_all_coding_context(AV1_COMP *cpi) { |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5361 | save_cur_buf(cpi); |
| 5362 | save_extra_coding_context(cpi); |
| 5363 | if (!frame_is_intra_only(&cpi->common)) release_scaled_references(cpi); |
| 5364 | } |
| 5365 | |
| 5366 | static void restore_cur_buf(AV1_COMP *cpi) { |
| 5367 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5368 | AV1_COMMON *cm = &cpi->common; |
| 5369 | aom_yv12_copy_frame(&cc->copy_buffer, &cm->cur_frame->buf, |
| 5370 | av1_num_planes(cm)); |
| 5371 | } |
| 5372 | |
| 5373 | // Coding context that only needs to be restored when recode loop includes |
| 5374 | // filtering (deblocking, CDEF, superres post-encode upscale and/or loop |
| 5375 | // restoraton). |
| 5376 | static void restore_extra_coding_context(AV1_COMP *cpi) { |
| 5377 | CODING_CONTEXT *const cc = &cpi->coding_context; |
| 5378 | AV1_COMMON *cm = &cpi->common; |
| 5379 | cm->lf = cc->lf; |
| 5380 | cm->cdef_info = cc->cdef_info; |
| 5381 | cpi->rc = cc->rc; |
| 5382 | } |
| 5383 | |
| 5384 | static void restore_all_coding_context(AV1_COMP *cpi) { |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5385 | restore_cur_buf(cpi); |
| 5386 | restore_extra_coding_context(cpi); |
| 5387 | if (!frame_is_intra_only(&cpi->common)) release_scaled_references(cpi); |
| 5388 | } |
| 5389 | |
| 5390 | static int encode_with_and_without_superres(AV1_COMP *cpi, size_t *size, |
| 5391 | uint8_t *dest, |
| 5392 | int *largest_tile_id) { |
| 5393 | const AV1_COMMON *const cm = &cpi->common; |
| 5394 | AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5395 | assert(cm->seq_params.enable_superres); |
| 5396 | assert(superres_in_recode_allowed(cpi)); |
| 5397 | aom_codec_err_t err = AOM_CODEC_OK; |
| 5398 | save_all_coding_context(cpi); |
| 5399 | |
| 5400 | // Encode with superres. |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5401 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5402 | int64_t superres_sses[SCALE_NUMERATOR]; |
| 5403 | int64_t superres_rates[SCALE_NUMERATOR]; |
| 5404 | int superres_largest_tile_ids[SCALE_NUMERATOR]; |
| 5405 | // Use superres for Key-frames and Alt-ref frames only. |
| 5406 | const GF_GROUP *const gf_group = &cpi->gf_group; |
| 5407 | if (gf_group->update_type[gf_group->index] != OVERLAY_UPDATE && |
| 5408 | gf_group->update_type[gf_group->index] != INTNL_OVERLAY_UPDATE) { |
| 5409 | for (int denom = SCALE_NUMERATOR + 1; denom <= 2 * SCALE_NUMERATOR; |
| 5410 | ++denom) { |
| 5411 | oxcf->superres_scale_denominator = denom; |
| 5412 | oxcf->superres_kf_scale_denominator = denom; |
| 5413 | const int this_index = denom - (SCALE_NUMERATOR + 1); |
| 5414 | err = encode_with_recode_loop_and_filter( |
| 5415 | cpi, size, dest, &superres_sses[this_index], |
| 5416 | &superres_rates[this_index], &superres_largest_tile_ids[this_index]); |
| 5417 | if (err != AOM_CODEC_OK) return err; |
| 5418 | restore_all_coding_context(cpi); |
| 5419 | } |
| 5420 | // Reset. |
| 5421 | oxcf->superres_scale_denominator = SCALE_NUMERATOR; |
| 5422 | oxcf->superres_kf_scale_denominator = SCALE_NUMERATOR; |
| 5423 | } else { |
| 5424 | for (int denom = SCALE_NUMERATOR + 1; denom <= 2 * SCALE_NUMERATOR; |
| 5425 | ++denom) { |
| 5426 | const int this_index = denom - (SCALE_NUMERATOR + 1); |
| 5427 | superres_sses[this_index] = INT64_MAX; |
| 5428 | superres_rates[this_index] = INT64_MAX; |
| 5429 | } |
| 5430 | } |
| 5431 | #else |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5432 | int64_t sse1 = INT64_MAX; |
| 5433 | int64_t rate1 = INT64_MAX; |
| 5434 | int largest_tile_id1; |
| 5435 | err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse1, &rate1, |
| 5436 | &largest_tile_id1); |
| 5437 | if (err != AOM_CODEC_OK) return err; |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5438 | restore_all_coding_context(cpi); |
| 5439 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5440 | |
| 5441 | // Encode without superres. |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5442 | int64_t sse2 = INT64_MAX; |
| 5443 | int64_t rate2 = INT64_MAX; |
| 5444 | int largest_tile_id2; |
| 5445 | oxcf->superres_mode = SUPERRES_NONE; // To force full-res. |
| 5446 | err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse2, &rate2, |
| 5447 | &largest_tile_id2); |
| 5448 | oxcf->superres_mode = SUPERRES_AUTO; // Reset. |
| 5449 | if (err != AOM_CODEC_OK) return err; |
| 5450 | |
| 5451 | // Note: Both use common rdmult based on base qindex of fullres. |
| 5452 | const int64_t rdmult = |
| 5453 | av1_compute_rd_mult_based_on_qindex(cpi, cm->base_qindex); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5454 | |
| 5455 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5456 | // Find the best rdcost among all superres denoms. |
| 5457 | double proj_rdcost1 = DBL_MAX; |
| 5458 | int64_t sse1 = INT64_MAX; |
| 5459 | int64_t rate1 = INT64_MAX; |
| 5460 | int largest_tile_id1 = 0; |
| 5461 | (void)sse1; |
| 5462 | (void)rate1; |
| 5463 | (void)largest_tile_id1; |
| 5464 | int best_denom = -1; |
| 5465 | for (int denom = SCALE_NUMERATOR + 1; denom <= 2 * SCALE_NUMERATOR; ++denom) { |
| 5466 | const int this_index = denom - (SCALE_NUMERATOR + 1); |
| 5467 | const int64_t this_sse = superres_sses[this_index]; |
| 5468 | const int64_t this_rate = superres_rates[this_index]; |
| 5469 | const int this_largest_tile_id = superres_largest_tile_ids[this_index]; |
| 5470 | const double this_rdcost = RDCOST_DBL(rdmult, this_rate, this_sse); |
| 5471 | if (this_rdcost < proj_rdcost1) { |
| 5472 | sse1 = this_sse; |
| 5473 | rate1 = this_rate; |
| 5474 | largest_tile_id1 = this_largest_tile_id; |
| 5475 | proj_rdcost1 = this_rdcost; |
| 5476 | best_denom = denom; |
| 5477 | } |
| 5478 | } |
| 5479 | #else |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5480 | const double proj_rdcost1 = RDCOST_DBL(rdmult, rate1, sse1); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5481 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5482 | const double proj_rdcost2 = RDCOST_DBL(rdmult, rate2, sse2); |
| 5483 | |
| 5484 | // Re-encode with superres if it's better. |
| 5485 | if (proj_rdcost1 < proj_rdcost2) { |
| 5486 | restore_all_coding_context(cpi); |
| 5487 | // TODO(urvang): We should avoid rerunning the recode loop by saving |
| 5488 | // previous output+state, or running encode only for the selected 'q' in |
| 5489 | // previous step. |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5490 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5491 | // Again, temporarily force the best denom. |
| 5492 | oxcf->superres_scale_denominator = best_denom; |
| 5493 | oxcf->superres_kf_scale_denominator = best_denom; |
| 5494 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5495 | int64_t sse3 = INT64_MAX; |
| 5496 | int64_t rate3 = INT64_MAX; |
| 5497 | err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse3, &rate3, |
| 5498 | largest_tile_id); |
| 5499 | assert(sse1 == sse3); |
| 5500 | assert(rate1 == rate3); |
| 5501 | assert(largest_tile_id1 == *largest_tile_id); |
Urvang Joshi | bc82d38 | 2019-11-01 17:59:20 -0700 | [diff] [blame] | 5502 | #if SUPERRES_RECODE_ALL_RATIOS |
| 5503 | // Reset. |
| 5504 | oxcf->superres_scale_denominator = SCALE_NUMERATOR; |
| 5505 | oxcf->superres_kf_scale_denominator = SCALE_NUMERATOR; |
| 5506 | #endif // SUPERRES_RECODE_ALL_RATIOS |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 5507 | } else { |
| 5508 | *largest_tile_id = largest_tile_id2; |
| 5509 | } |
| 5510 | |
| 5511 | return err; |
| 5512 | } |
| 5513 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 5514 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5515 | #define DUMP_RECON_FRAMES 0 |
| 5516 | |
| 5517 | #if DUMP_RECON_FRAMES == 1 |
| 5518 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5519 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 5520 | AV1_COMMON *const cm = &cpi->common; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5521 | const CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5522 | const YV12_BUFFER_CONFIG *recon_buf = &cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5523 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5524 | if (recon_buf == NULL) { |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5525 | printf("Frame %d is not ready.\n", current_frame->frame_number); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5526 | return; |
| 5527 | } |
| 5528 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 5529 | static const int flag_list[REF_FRAMES] = { 0, |
| 5530 | AOM_LAST_FLAG, |
| 5531 | AOM_LAST2_FLAG, |
| 5532 | AOM_LAST3_FLAG, |
| 5533 | AOM_GOLD_FLAG, |
| 5534 | AOM_BWD_FLAG, |
| 5535 | AOM_ALT2_FLAG, |
| 5536 | AOM_ALT_FLAG }; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5537 | printf( |
| 5538 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 5539 | "show_existing_frame=%d) " |
| 5540 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5541 | current_frame->frame_number, current_frame->order_hint, cm->show_frame, |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5542 | cm->show_existing_frame); |
| 5543 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 5544 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
| 5545 | const int ref_offset = buf != NULL ? (int)buf->order_hint : -1; |
Urvang Joshi | b6f1767 | 2019-03-05 11:51:02 -0800 | [diff] [blame] | 5546 | printf(" %d(%c)", ref_offset, |
| 5547 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N'); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5548 | } |
| 5549 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5550 | |
| 5551 | if (!cm->show_frame) { |
| 5552 | 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] | 5553 | current_frame->frame_number); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5554 | return; |
| 5555 | } |
| 5556 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5557 | int h; |
| 5558 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 5559 | FILE *f_recon = NULL; |
| 5560 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5561 | if (current_frame->frame_number == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5562 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 5563 | printf("Unable to open file %s to write.\n", file_name); |
| 5564 | return; |
| 5565 | } |
| 5566 | } else { |
| 5567 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 5568 | printf("Unable to open file %s to append.\n", file_name); |
| 5569 | return; |
| 5570 | } |
| 5571 | } |
| 5572 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 5573 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 5574 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
Urvang Joshi | 7a89023 | 2019-03-22 17:00:31 -0700 | [diff] [blame] | 5575 | "refresh_alt_ref_frame=%d, " |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 5576 | "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] | 5577 | current_frame->frame_number, cpi->gf_group.index, |
| 5578 | cpi->gf_group.update_type[cpi->gf_group.index], current_frame->order_hint, |
| 5579 | cm->show_frame, cm->show_existing_frame, cpi->rc.source_alt_ref_active, |
| 5580 | cpi->refresh_alt_ref_frame, recon_buf->y_stride, recon_buf->uv_stride, |
| 5581 | cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5582 | #if 0 |
| 5583 | int ref_frame; |
| 5584 | printf("get_ref_frame_map_idx: ["); |
| 5585 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 5586 | printf(" %d", get_ref_frame_map_idx(cm, ref_frame)); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5587 | printf(" ]\n"); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5588 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5589 | |
| 5590 | // --- Y --- |
| 5591 | for (h = 0; h < cm->height; ++h) { |
| 5592 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 5593 | f_recon); |
| 5594 | } |
| 5595 | // --- U --- |
| 5596 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5597 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5598 | f_recon); |
| 5599 | } |
| 5600 | // --- V --- |
| 5601 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5602 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5603 | f_recon); |
| 5604 | } |
| 5605 | |
| 5606 | fclose(f_recon); |
| 5607 | } |
| 5608 | #endif // DUMP_RECON_FRAMES |
| 5609 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5610 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 5611 | const YV12_BUFFER_CONFIG *last_picture, |
| 5612 | hash_table *last_hash_table) { |
| 5613 | aom_clear_system_state(); |
| 5614 | // check use hash ME |
| 5615 | int k; |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5616 | |
Ranjit Kumar Tulabandu | 9f26c99 | 2019-10-24 12:24:52 +0530 | [diff] [blame] | 5617 | const int block_size = FORCE_INT_MV_DECISION_BLOCK_SIZE; |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5618 | const double threshold_current = 0.8; |
| 5619 | const double threshold_average = 0.95; |
| 5620 | const int max_history_size = 32; |
| 5621 | int T = 0; // total block |
| 5622 | int C = 0; // match with collocated block |
| 5623 | int S = 0; // smooth region but not match with collocated block |
| 5624 | int M = 0; // match with other block |
| 5625 | |
| 5626 | const int pic_width = cur_picture->y_width; |
| 5627 | const int pic_height = cur_picture->y_height; |
| 5628 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 5629 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 5630 | const int x_pos = j; |
| 5631 | const int y_pos = i; |
| 5632 | int match = 1; |
| 5633 | T++; |
| 5634 | |
| 5635 | // check whether collocated block match with current |
| 5636 | uint8_t *p_cur = cur_picture->y_buffer; |
| 5637 | uint8_t *p_ref = last_picture->y_buffer; |
| 5638 | int stride_cur = cur_picture->y_stride; |
| 5639 | int stride_ref = last_picture->y_stride; |
| 5640 | p_cur += (y_pos * stride_cur + x_pos); |
| 5641 | p_ref += (y_pos * stride_ref + x_pos); |
| 5642 | |
| 5643 | if (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5644 | uint16_t *p16_cur = CONVERT_TO_SHORTPTR(p_cur); |
| 5645 | uint16_t *p16_ref = CONVERT_TO_SHORTPTR(p_ref); |
| 5646 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5647 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5648 | if (p16_cur[tmpX] != p16_ref[tmpX]) { |
| 5649 | match = 0; |
| 5650 | } |
| 5651 | } |
| 5652 | p16_cur += stride_cur; |
| 5653 | p16_ref += stride_ref; |
| 5654 | } |
| 5655 | } else { |
| 5656 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 5657 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 5658 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 5659 | match = 0; |
| 5660 | } |
| 5661 | } |
| 5662 | p_cur += stride_cur; |
| 5663 | p_ref += stride_ref; |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | if (match) { |
| 5668 | C++; |
| 5669 | continue; |
| 5670 | } |
| 5671 | |
| 5672 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 5673 | y_pos) || |
| 5674 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 5675 | S++; |
| 5676 | continue; |
| 5677 | } |
Remya | a14a458 | 2019-11-05 13:17:36 +0530 | [diff] [blame] | 5678 | if (av1_use_hash_me(cpi)) { |
| 5679 | uint32_t hash_value_1; |
| 5680 | uint32_t hash_value_2; |
| 5681 | av1_get_block_hash_value( |
| 5682 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 5683 | block_size, &hash_value_1, &hash_value_2, |
| 5684 | (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb); |
| 5685 | // Hashing does not work for highbitdepth currently. |
| 5686 | // TODO(Roger): Make it work for highbitdepth. |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5687 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 5688 | M++; |
| 5689 | } |
| 5690 | } |
| 5691 | } |
| 5692 | } |
| 5693 | |
| 5694 | assert(T > 0); |
| 5695 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 5696 | double m_rate = ((double)(M)) / ((double)(T)); |
| 5697 | |
| 5698 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 5699 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 5700 | |
| 5701 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 5702 | cpi->rate_size++; |
| 5703 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 5704 | |
| 5705 | if (csm_rate < threshold_current) { |
| 5706 | return 0; |
| 5707 | } |
| 5708 | |
| 5709 | if (C == T) { |
| 5710 | return 1; |
| 5711 | } |
| 5712 | |
| 5713 | double csm_average = 0.0; |
| 5714 | double m_average = 0.0; |
| 5715 | |
| 5716 | for (k = 0; k < cpi->rate_size; k++) { |
| 5717 | csm_average += cpi->csm_rate_array[k]; |
| 5718 | m_average += cpi->m_rate_array[k]; |
| 5719 | } |
| 5720 | csm_average /= cpi->rate_size; |
| 5721 | m_average /= cpi->rate_size; |
| 5722 | |
| 5723 | if (csm_average < threshold_average) { |
| 5724 | return 0; |
| 5725 | } |
| 5726 | |
| 5727 | if (M > (T - C - S) / 3) { |
| 5728 | return 1; |
| 5729 | } |
| 5730 | |
| 5731 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 5732 | return 1; |
| 5733 | } |
| 5734 | |
| 5735 | if (csm_average + m_average > 1.01) { |
| 5736 | return 1; |
| 5737 | } |
| 5738 | |
| 5739 | return 0; |
| 5740 | } |
| 5741 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5742 | // Refresh reference frame buffers according to refresh_frame_flags. |
| 5743 | static void refresh_reference_frames(AV1_COMP *cpi) { |
| 5744 | AV1_COMMON *const cm = &cpi->common; |
| 5745 | // All buffers are refreshed for shown keyframes and S-frames. |
| 5746 | |
| 5747 | for (int ref_frame = 0; ref_frame < REF_FRAMES; ref_frame++) { |
| 5748 | if (((cm->current_frame.refresh_frame_flags >> ref_frame) & 1) == 1) { |
| 5749 | assign_frame_buffer_p(&cm->ref_frame_map[ref_frame], cm->cur_frame); |
| 5750 | } |
| 5751 | } |
| 5752 | } |
| 5753 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 5754 | static void set_mb_ssim_rdmult_scaling(AV1_COMP *cpi) { |
| 5755 | AV1_COMMON *cm = &cpi->common; |
| 5756 | ThreadData *td = &cpi->td; |
| 5757 | MACROBLOCK *x = &td->mb; |
| 5758 | MACROBLOCKD *xd = &x->e_mbd; |
| 5759 | uint8_t *y_buffer = cpi->source->y_buffer; |
| 5760 | const int y_stride = cpi->source->y_stride; |
| 5761 | const int block_size = BLOCK_16X16; |
| 5762 | |
| 5763 | const int num_mi_w = mi_size_wide[block_size]; |
| 5764 | const int num_mi_h = mi_size_high[block_size]; |
| 5765 | const int num_cols = (cm->mi_cols + num_mi_w - 1) / num_mi_w; |
| 5766 | const int num_rows = (cm->mi_rows + num_mi_h - 1) / num_mi_h; |
| 5767 | double log_sum = 0.0; |
| 5768 | int row, col; |
| 5769 | const int use_hbd = cpi->source->flags & YV12_FLAG_HIGHBITDEPTH; |
| 5770 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 5771 | // Loop through each 16x16 block. |
| 5772 | for (row = 0; row < num_rows; ++row) { |
| 5773 | for (col = 0; col < num_cols; ++col) { |
| 5774 | int mi_row, mi_col; |
| 5775 | double var = 0.0, num_of_var = 0.0; |
| 5776 | const int index = row * num_cols + col; |
| 5777 | |
| 5778 | // Loop through each 8x8 block. |
| 5779 | for (mi_row = row * num_mi_h; |
| 5780 | mi_row < cm->mi_rows && mi_row < (row + 1) * num_mi_h; mi_row += 2) { |
| 5781 | for (mi_col = col * num_mi_w; |
| 5782 | mi_col < cm->mi_cols && mi_col < (col + 1) * num_mi_w; |
| 5783 | mi_col += 2) { |
| 5784 | struct buf_2d buf; |
| 5785 | const int row_offset_y = mi_row << 2; |
| 5786 | const int col_offset_y = mi_col << 2; |
| 5787 | |
| 5788 | buf.buf = y_buffer + row_offset_y * y_stride + col_offset_y; |
| 5789 | buf.stride = y_stride; |
| 5790 | |
| 5791 | if (use_hbd) { |
| 5792 | var += av1_high_get_sby_perpixel_variance(cpi, &buf, BLOCK_8X8, |
| 5793 | xd->bd); |
| 5794 | } else { |
| 5795 | var += av1_get_sby_perpixel_variance(cpi, &buf, BLOCK_8X8); |
| 5796 | } |
| 5797 | |
| 5798 | num_of_var += 1.0; |
| 5799 | } |
| 5800 | } |
sdeng | 32185d1 | 2019-06-19 14:47:09 -0700 | [diff] [blame] | 5801 | var = var / num_of_var; |
sdeng | bdc0cd2 | 2019-11-11 15:09:34 -0800 | [diff] [blame^] | 5802 | |
| 5803 | // Curve fitting with an exponential model on all 16x16 blocks from the |
| 5804 | // midres dataset. |
| 5805 | var = 67.035434 * (1 - exp(-0.0021489 * var)) + 17.492222; |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 5806 | cpi->ssim_rdmult_scaling_factors[index] = var; |
| 5807 | log_sum += log(var); |
| 5808 | } |
| 5809 | } |
| 5810 | log_sum = exp(log_sum / (double)(num_rows * num_cols)); |
| 5811 | |
| 5812 | for (row = 0; row < num_rows; ++row) { |
| 5813 | for (col = 0; col < num_cols; ++col) { |
| 5814 | const int index = row * num_cols + col; |
| 5815 | cpi->ssim_rdmult_scaling_factors[index] /= log_sum; |
| 5816 | } |
| 5817 | } |
| 5818 | |
| 5819 | (void)xd; |
| 5820 | } |
| 5821 | |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 5822 | #if CONFIG_DEBUG |
| 5823 | static int hash_me_has_at_most_two_refs(RefCntBuffer *frame_bufs) { |
| 5824 | int total_count = 0; |
| 5825 | for (int frame_idx = 0; frame_idx < FRAME_BUFFERS; ++frame_idx) { |
| 5826 | if (frame_bufs[frame_idx].hash_table.has_content > 1) { |
| 5827 | return 0; |
| 5828 | } |
| 5829 | total_count += frame_bufs[frame_idx].hash_table.has_content; |
| 5830 | } |
| 5831 | |
| 5832 | return total_count <= 2; |
| 5833 | } |
| 5834 | #endif |
| 5835 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5836 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, |
| 5837 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5838 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5839 | SequenceHeader *const seq_params = &cm->seq_params; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5840 | CurrentFrame *const current_frame = &cm->current_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5841 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5842 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5843 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5844 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5845 | start_timing(cpi, encode_frame_to_data_rate_time); |
| 5846 | #endif |
| 5847 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5848 | // frame type has been decided outside of this function call |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5849 | cm->cur_frame->frame_type = current_frame->frame_type; |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 5850 | |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 5851 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 5852 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 5853 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5854 | cm->allow_ref_frame_mvs &= frame_might_allow_ref_frame_mvs(cm); |
Yunqing Wang | d48fb16 | 2018-06-15 10:55:28 -0700 | [diff] [blame] | 5855 | // cm->allow_ref_frame_mvs needs to be written into the frame header while |
| 5856 | // cm->large_scale_tile is 1, therefore, "cm->large_scale_tile=1" case is |
| 5857 | // separated from frame_might_allow_ref_frame_mvs(). |
| 5858 | cm->allow_ref_frame_mvs &= !cm->large_scale_tile; |
| 5859 | |
Debargha Mukherjee | 1d7217e | 2018-03-26 13:32:13 -0700 | [diff] [blame] | 5860 | cm->allow_warped_motion = |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 5861 | cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5862 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 5863 | cm->last_frame_type = current_frame->frame_type; |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 5864 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 5865 | if (encode_show_existing_frame(cm)) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5866 | finalize_encoded_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5867 | // Build the bitstream |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5868 | int largest_tile_id = 0; // Output from bitstream: unused here |
| 5869 | 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] | 5870 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5871 | |
David Turner | 9031186 | 2018-11-29 13:34:36 +0000 | [diff] [blame] | 5872 | if (seq_params->frame_id_numbers_present_flag && |
| 5873 | current_frame->frame_type == KEY_FRAME) { |
| 5874 | // Displaying a forward key-frame, so reset the ref buffer IDs |
| 5875 | int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show]; |
| 5876 | for (int i = 0; i < REF_FRAMES; i++) |
| 5877 | cm->ref_frame_id[i] = display_frame_id; |
| 5878 | } |
| 5879 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5880 | cpi->seq_params_locked = 1; |
| 5881 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5882 | #if DUMP_RECON_FRAMES == 1 |
| 5883 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5884 | dump_filtered_recon_frames(cpi); |
| 5885 | #endif // DUMP_RECON_FRAMES |
| 5886 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5887 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 5888 | // for the purpose to verify no mismatch between encoder and decoder. |
| 5889 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5890 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5891 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5892 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5893 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 5894 | // to do post-encoding update accordingly. |
| 5895 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5896 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5897 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5898 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5899 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5900 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5901 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5902 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5903 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5904 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5905 | // Work out whether to force_integer_mv this frame |
| 5906 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools && |
| 5907 | !frame_is_intra_only(cm)) { |
| 5908 | if (cpi->common.seq_params.force_integer_mv == 2) { |
| 5909 | // Adaptive mode: see what previous frame encoded did |
| 5910 | if (cpi->unscaled_last_source != NULL) { |
| 5911 | cm->cur_frame_force_integer_mv = |
| 5912 | is_integer_mv(cpi, cpi->source, cpi->unscaled_last_source, |
| 5913 | cpi->previous_hash_table); |
| 5914 | } else { |
| 5915 | cpi->common.cur_frame_force_integer_mv = 0; |
| 5916 | } |
| 5917 | } else { |
| 5918 | cpi->common.cur_frame_force_integer_mv = |
| 5919 | cpi->common.seq_params.force_integer_mv; |
| 5920 | } |
| 5921 | } else { |
| 5922 | cpi->common.cur_frame_force_integer_mv = 0; |
| 5923 | } |
| 5924 | |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 5925 | #if CONFIG_DEBUG |
| 5926 | assert(hash_me_has_at_most_two_refs(cm->buffer_pool->frame_bufs) && |
| 5927 | "Hash-me is leaking memory!"); |
| 5928 | #endif |
| 5929 | |
| 5930 | if (cpi->oxcf.pass != 1 && cpi->need_to_clear_prev_hash_table) { |
| 5931 | av1_hash_table_clear_all(cpi->previous_hash_table); |
| 5932 | cpi->need_to_clear_prev_hash_table = 0; |
| 5933 | } |
| 5934 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5935 | // Set default state for segment based loop filter update flags. |
| 5936 | cm->lf.mode_ref_delta_update = 0; |
| 5937 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5938 | // 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] | 5939 | if (frame_is_intra_only(cm) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5940 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5941 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5942 | |
| 5943 | // If segmentation is enabled force a map update for key frames. |
| 5944 | if (seg->enabled) { |
| 5945 | seg->update_map = 1; |
| 5946 | seg->update_data = 1; |
| 5947 | } |
| 5948 | |
| 5949 | // The alternate reference frame cannot be active for a key frame. |
| 5950 | cpi->rc.source_alt_ref_active = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5951 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5952 | if (cpi->oxcf.mtu == 0) { |
| 5953 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 5954 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 5955 | // Use a default value for the purposes of weighting costs in probability |
| 5956 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5957 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 5958 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5959 | |
| 5960 | // For 1 pass CBR, check if we are dropping this frame. |
| 5961 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5962 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5963 | current_frame->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5964 | if (av1_rc_drop_frame(cpi)) { |
| 5965 | av1_rc_postencode_update_drop_frame(cpi); |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 5966 | release_scaled_references(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5967 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5968 | } |
| 5969 | } |
| 5970 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 5971 | if (oxcf->tuning == AOM_TUNE_SSIM) set_mb_ssim_rdmult_scaling(cpi); |
| 5972 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5973 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5974 | |
| 5975 | #if CONFIG_INTERNAL_STATS |
| 5976 | memset(cpi->mode_chosen_counts, 0, |
| 5977 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 5978 | #endif |
| 5979 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5980 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5981 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 5982 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5983 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5984 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5985 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5986 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5987 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 5988 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5989 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5990 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5991 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5992 | } |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 5993 | cm->current_frame_id = |
| 5994 | ((msb << 8) + lsb) % (1 << seq_params->frame_id_length); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 5995 | |
| 5996 | // S_frame is meant for stitching different streams of different |
| 5997 | // resolutions together, so current_frame_id must be the |
| 5998 | // same across different streams of the same content current_frame_id |
| 5999 | // should be the same and not random. 0x37 is a chosen number as start |
| 6000 | // point |
| 6001 | if (cpi->oxcf.sframe_enabled) cm->current_frame_id = 0x37; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6002 | } else { |
| 6003 | cm->current_frame_id = |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 6004 | (cm->current_frame_id + 1 + (1 << seq_params->frame_id_length)) % |
| 6005 | (1 << seq_params->frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6006 | } |
| 6007 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6008 | |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 6009 | switch (cpi->oxcf.cdf_update_mode) { |
| 6010 | case 0: // No CDF update for any frames(4~6% compression loss). |
| 6011 | cm->disable_cdf_update = 1; |
| 6012 | break; |
| 6013 | case 1: // Enable CDF update for all frames. |
| 6014 | cm->disable_cdf_update = 0; |
| 6015 | break; |
| 6016 | case 2: |
| 6017 | // Strategically determine at which frames to do CDF update. |
| 6018 | // Currently only enable CDF update for all-intra and no-show frames(1.5% |
| 6019 | // compression loss). |
| 6020 | // TODO(huisu@google.com): design schemes for various trade-offs between |
| 6021 | // compression quality and decoding speed. |
Hui Su | b1b76b3 | 2018-02-27 15:24:48 -0800 | [diff] [blame] | 6022 | cm->disable_cdf_update = |
| 6023 | (frame_is_intra_only(cm) || !cm->show_frame) ? 0 : 1; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 6024 | break; |
| 6025 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6026 | cm->timing_info_present &= !seq_params->reduced_still_picture_hdr; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 6027 | |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 6028 | if (cpi->oxcf.pass == 2 && cpi->oxcf.enable_tpl_model == 2 && |
| 6029 | current_frame->frame_type == INTER_FRAME) { |
| 6030 | if (!cm->show_frame) { |
| 6031 | assert(cpi->tpl_model_pass == 0); |
| 6032 | cpi->tpl_model_pass = 1; |
| 6033 | } |
| 6034 | } |
| 6035 | |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 6036 | int largest_tile_id = 0; |
| 6037 | #if CONFIG_SUPERRES_IN_RECODE |
| 6038 | if (superres_in_recode_allowed(cpi)) { |
| 6039 | if (encode_with_and_without_superres(cpi, size, dest, &largest_tile_id) != |
| 6040 | AOM_CODEC_OK) { |
| 6041 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6042 | } |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 6043 | } else { |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 6044 | #endif // CONFIG_SUPERRES_IN_RECODE |
| 6045 | if (encode_with_recode_loop_and_filter(cpi, size, dest, NULL, NULL, |
| 6046 | &largest_tile_id) != AOM_CODEC_OK) { |
| 6047 | return AOM_CODEC_ERROR; |
| 6048 | } |
| 6049 | #if CONFIG_SUPERRES_IN_RECODE |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 6050 | } |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 6051 | #endif // CONFIG_SUPERRES_IN_RECODE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6052 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 6053 | cpi->seq_params_locked = 1; |
| 6054 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 6055 | // Update reference frame ids for reference frames this frame will overwrite |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6056 | if (seq_params->frame_id_numbers_present_flag) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 6057 | for (int i = 0; i < REF_FRAMES; i++) { |
| 6058 | if ((current_frame->refresh_frame_flags >> i) & 1) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6059 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 6060 | } |
| 6061 | } |
| 6062 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6063 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6064 | #if DUMP_RECON_FRAMES == 1 |
| 6065 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 6066 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6067 | #endif // DUMP_RECON_FRAMES |
| 6068 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 6069 | if (cm->seg.enabled) { |
| 6070 | if (cm->seg.update_map) { |
| 6071 | update_reference_segmentation_map(cpi); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 6072 | } else if (cm->last_frame_seg_map) { |
David Turner | b757ce0 | 2018-11-12 15:01:28 +0000 | [diff] [blame] | 6073 | memcpy(cm->cur_frame->seg_map, cm->last_frame_seg_map, |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 6074 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 6075 | } |
| 6076 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6077 | |
| 6078 | if (frame_is_intra_only(cm) == 0) { |
| 6079 | release_scaled_references(cpi); |
| 6080 | } |
| 6081 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6082 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 6083 | // for the purpose to verify no mismatch between encoder and decoder. |
| 6084 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
| 6085 | |
| 6086 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6087 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 6088 | #if CONFIG_ENTROPY_STATS |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 6089 | av1_accumulate_frame_counts(&aggregate_fc, &cpi->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 6090 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6091 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 6092 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 6093 | *cm->fc = cpi->tile_data[largest_tile_id].tctx; |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 6094 | av1_reset_cdf_symbol_counters(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6095 | } |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 6096 | if (!cm->large_scale_tile) { |
| 6097 | cm->cur_frame->frame_context = *cm->fc; |
| 6098 | } |
| 6099 | #define EXT_TILE_DEBUG 0 |
| 6100 | #if EXT_TILE_DEBUG |
| 6101 | if (cm->large_scale_tile && oxcf->pass == 2) { |
| 6102 | char fn[20] = "./fc"; |
| 6103 | fn[4] = current_frame->frame_number / 100 + '0'; |
| 6104 | fn[5] = (current_frame->frame_number % 100) / 10 + '0'; |
| 6105 | fn[6] = (current_frame->frame_number % 10) + '0'; |
| 6106 | fn[7] = '\0'; |
| 6107 | av1_print_frame_contexts(cm->fc, fn); |
| 6108 | } |
| 6109 | #endif // EXT_TILE_DEBUG |
| 6110 | #undef EXT_TILE_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6111 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6112 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 6113 | end_timing(cpi, encode_frame_to_data_rate_time); |
| 6114 | |
| 6115 | // Print out timing information. |
| 6116 | int i; |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 6117 | 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] | 6118 | cm->current_frame.frame_number, |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 6119 | get_frame_type_enum(cm->current_frame.frame_type), cm->show_frame); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6120 | for (i = 0; i < kTimingComponents; i++) { |
| 6121 | cpi->component_time[i] += cpi->frame_component_time[i]; |
| 6122 | fprintf(stderr, " %s: %" PRId64 " us (total: %" PRId64 " us)\n", |
| 6123 | get_component_name(i), cpi->frame_component_time[i], |
| 6124 | cpi->component_time[i]); |
| 6125 | cpi->frame_component_time[i] = 0; |
| 6126 | } |
| 6127 | #endif |
| 6128 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 6129 | cm->last_frame_type = current_frame->frame_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6130 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6131 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6132 | |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 6133 | // Store encoded frame's hash table for in_integer_mv() next time. |
| 6134 | // Beware! If we don't update previous_hash_table here we will leak the |
| 6135 | // items stored in cur_frame's hash_table! |
Remya | a14a458 | 2019-11-05 13:17:36 +0530 | [diff] [blame] | 6136 | if (oxcf->pass != 1 && av1_use_hash_me(cpi)) { |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 6137 | cpi->previous_hash_table = &cm->cur_frame->hash_table; |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 6138 | cpi->need_to_clear_prev_hash_table = 1; |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 6139 | } |
| 6140 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6141 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 6142 | // filter deltas. |
| 6143 | cm->seg.update_map = 0; |
| 6144 | cm->seg.update_data = 0; |
| 6145 | cm->lf.mode_ref_delta_update = 0; |
| 6146 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 6147 | // A droppable frame might not be shown but it always |
| 6148 | // takes a space in the gf group. Therefore, even when |
| 6149 | // it is not shown, we still need update the count down. |
| 6150 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6151 | if (cm->show_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6152 | // Don't increment frame counters if this was an altref buffer |
| 6153 | // update not a real frame |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6154 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6155 | } |
| 6156 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6157 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6158 | } |
| 6159 | |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6160 | int av1_encode(AV1_COMP *const cpi, uint8_t *const dest, |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6161 | const EncodeFrameInput *const frame_input, |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6162 | const EncodeFrameParams *const frame_params, |
| 6163 | EncodeFrameResults *const frame_results) { |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6164 | AV1_COMMON *const cm = &cpi->common; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6165 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6166 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6167 | cpi->unscaled_source = frame_input->source; |
| 6168 | cpi->source = frame_input->source; |
| 6169 | cpi->unscaled_last_source = frame_input->last_source; |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6170 | |
David Turner | 6e8b4d9 | 2019-02-18 15:01:33 +0000 | [diff] [blame] | 6171 | current_frame->refresh_frame_flags = frame_params->refresh_frame_flags; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6172 | cm->error_resilient_mode = frame_params->error_resilient_mode; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6173 | cm->primary_ref_frame = frame_params->primary_ref_frame; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 6174 | cm->current_frame.frame_type = frame_params->frame_type; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6175 | cm->show_frame = frame_params->show_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 6176 | cpi->ref_frame_flags = frame_params->ref_frame_flags; |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 6177 | cpi->speed = frame_params->speed; |
David Turner | e86ee0d | 2019-02-18 17:16:28 +0000 | [diff] [blame] | 6178 | cm->show_existing_frame = frame_params->show_existing_frame; |
| 6179 | 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] | 6180 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6181 | memcpy(cm->remapped_ref_idx, frame_params->remapped_ref_idx, |
| 6182 | REF_FRAMES * sizeof(*cm->remapped_ref_idx)); |
| 6183 | |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 6184 | cpi->refresh_last_frame = frame_params->refresh_last_frame; |
| 6185 | cpi->refresh_golden_frame = frame_params->refresh_golden_frame; |
| 6186 | cpi->refresh_bwd_ref_frame = frame_params->refresh_bwd_ref_frame; |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 6187 | cpi->refresh_alt_ref_frame = frame_params->refresh_alt_ref_frame; |
| 6188 | |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6189 | if (current_frame->frame_type == KEY_FRAME && cm->show_frame) |
| 6190 | current_frame->frame_number = 0; |
| 6191 | |
| 6192 | if (cm->show_existing_frame) { |
| 6193 | current_frame->order_hint = cm->cur_frame->order_hint; |
Ravi Chaudhary | 9701cd6 | 2019-07-18 17:32:26 +0530 | [diff] [blame] | 6194 | current_frame->display_order_hint = cm->cur_frame->display_order_hint; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6195 | } else { |
| 6196 | current_frame->order_hint = |
| 6197 | current_frame->frame_number + frame_params->order_offset; |
Ravi Chaudhary | 9701cd6 | 2019-07-18 17:32:26 +0530 | [diff] [blame] | 6198 | current_frame->display_order_hint = current_frame->order_hint; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 6199 | current_frame->order_hint %= |
| 6200 | (1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1)); |
| 6201 | } |
| 6202 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6203 | if (cpi->oxcf.pass == 1) { |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 6204 | #if !CONFIG_REALTIME_ONLY |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6205 | av1_first_pass(cpi, frame_input->ts_duration); |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame] | 6206 | #endif |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6207 | } else if (cpi->oxcf.pass == 0 || cpi->oxcf.pass == 2) { |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 6208 | if (encode_frame_to_data_rate(cpi, &frame_results->size, dest) != |
| 6209 | AOM_CODEC_OK) { |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 6210 | return AOM_CODEC_ERROR; |
| 6211 | } |
| 6212 | } else { |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 6213 | return AOM_CODEC_ERROR; |
| 6214 | } |
| 6215 | |
| 6216 | return AOM_CODEC_OK; |
| 6217 | } |
| 6218 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6219 | #if CONFIG_DENOISE |
| 6220 | static int apply_denoise_2d(AV1_COMP *cpi, YV12_BUFFER_CONFIG *sd, |
| 6221 | int block_size, float noise_level, |
| 6222 | int64_t time_stamp, int64_t end_time) { |
| 6223 | AV1_COMMON *const cm = &cpi->common; |
| 6224 | if (!cpi->denoise_and_model) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6225 | cpi->denoise_and_model = aom_denoise_and_model_alloc( |
| 6226 | cm->seq_params.bit_depth, block_size, noise_level); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6227 | if (!cpi->denoise_and_model) { |
| 6228 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6229 | "Error allocating denoise and model"); |
| 6230 | return -1; |
| 6231 | } |
| 6232 | } |
| 6233 | if (!cpi->film_grain_table) { |
| 6234 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 6235 | if (!cpi->film_grain_table) { |
| 6236 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6237 | "Error allocating grain table"); |
| 6238 | return -1; |
| 6239 | } |
| 6240 | memset(cpi->film_grain_table, 0, sizeof(*cpi->film_grain_table)); |
| 6241 | } |
| 6242 | if (aom_denoise_and_model_run(cpi->denoise_and_model, sd, |
| 6243 | &cm->film_grain_params)) { |
| 6244 | if (cm->film_grain_params.apply_grain) { |
| 6245 | aom_film_grain_table_append(cpi->film_grain_table, time_stamp, end_time, |
| 6246 | &cm->film_grain_params); |
| 6247 | } |
| 6248 | } |
| 6249 | return 0; |
| 6250 | } |
| 6251 | #endif |
| 6252 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 6253 | 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] | 6254 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 6255 | int64_t end_time) { |
| 6256 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6257 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6258 | int res = 0; |
| 6259 | const int subsampling_x = sd->subsampling_x; |
| 6260 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6261 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6262 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6263 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6264 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6265 | #if CONFIG_INTERNAL_STATS |
| 6266 | struct aom_usec_timer timer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6267 | aom_usec_timer_start(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6268 | #endif |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 6269 | #if CONFIG_DENOISE |
| 6270 | if (cpi->oxcf.noise_level > 0) |
| 6271 | if (apply_denoise_2d(cpi, sd, cpi->oxcf.noise_block_size, |
| 6272 | cpi->oxcf.noise_level, time_stamp, end_time) < 0) |
| 6273 | res = -1; |
| 6274 | #endif // CONFIG_DENOISE |
| 6275 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6276 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6277 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6278 | res = -1; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6279 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6280 | aom_usec_timer_mark(&timer); |
| 6281 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6282 | #endif |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6283 | if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6284 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6285 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6286 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6287 | res = -1; |
| 6288 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6289 | if ((seq_params->profile == PROFILE_1) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6290 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6291 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6292 | "Profile 1 requires 4:4:4 color format"); |
| 6293 | res = -1; |
| 6294 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6295 | if ((seq_params->profile == PROFILE_2) && |
| 6296 | (seq_params->bit_depth <= AOM_BITS_10) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6297 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 6298 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 6299 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6300 | res = -1; |
| 6301 | } |
| 6302 | |
| 6303 | return res; |
| 6304 | } |
| 6305 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6306 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6307 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 6308 | const unsigned char *img2, int img2_pitch, |
| 6309 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6310 | |
| 6311 | static void adjust_image_stat(double y, double u, double v, double all, |
| 6312 | ImageStat *s) { |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 6313 | s->stat[STAT_Y] += y; |
| 6314 | s->stat[STAT_U] += u; |
| 6315 | s->stat[STAT_V] += v; |
| 6316 | s->stat[STAT_ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6317 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6318 | } |
| 6319 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6320 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6321 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6322 | double samples = 0.0; |
| 6323 | uint32_t in_bit_depth = 8; |
| 6324 | uint32_t bit_depth = 8; |
| 6325 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6326 | #if CONFIG_INTER_STATS_ONLY |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 6327 | if (cm->current_frame.frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6328 | #endif |
| 6329 | cpi->bytes += frame_bytes; |
| 6330 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6331 | if (cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6332 | in_bit_depth = cpi->oxcf.input_bit_depth; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6333 | bit_depth = cm->seq_params.bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6334 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6335 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6336 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 6337 | const YV12_BUFFER_CONFIG *recon = &cpi->common.cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6338 | double y, u, v, frame_all; |
| 6339 | |
| 6340 | cpi->count++; |
| 6341 | if (cpi->b_calculate_psnr) { |
| 6342 | PSNR_STATS psnr; |
| 6343 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6344 | aom_clear_system_state(); |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 6345 | #if CONFIG_AV1_HIGHBITDEPTH |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6346 | // TODO(yaowu): unify these two versions into one. |
Jerome Jiang | fa1d173 | 2019-08-06 10:31:20 -0700 | [diff] [blame] | 6347 | if (cm->seq_params.use_highbitdepth) |
| 6348 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
| 6349 | else |
| 6350 | aom_calc_psnr(orig, recon, &psnr); |
| 6351 | #else |
| 6352 | aom_calc_psnr(orig, recon, &psnr); |
| 6353 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6354 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 6355 | &cpi->psnr); |
| 6356 | cpi->total_sq_error += psnr.sse[0]; |
| 6357 | cpi->total_samples += psnr.samples[0]; |
| 6358 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6359 | // TODO(yaowu): unify these two versions into one. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6360 | if (cm->seq_params.use_highbitdepth) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6361 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6362 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6363 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6364 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6365 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6366 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6367 | cpi->summed_quality += frame_ssim2 * weight; |
| 6368 | cpi->summed_weights += weight; |
| 6369 | |
| 6370 | #if 0 |
| 6371 | { |
| 6372 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 6373 | double y2 = psnr.psnr[1]; |
| 6374 | double u2 = psnr.psnr[2]; |
| 6375 | double v2 = psnr.psnr[3]; |
| 6376 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6377 | 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] | 6378 | cm->current_frame.frame_number, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6379 | frame_psnr2, frame_ssim2); |
| 6380 | fclose(f); |
| 6381 | } |
| 6382 | #endif |
| 6383 | } |
| 6384 | if (cpi->b_calculate_blockiness) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6385 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6386 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6387 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 6388 | recon->y_stride, orig->y_width, orig->y_height); |
| 6389 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6390 | cpi->total_blockiness += frame_blockiness; |
| 6391 | } |
| 6392 | |
| 6393 | if (cpi->b_calculate_consistency) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6394 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6395 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6396 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 6397 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 6398 | |
| 6399 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 6400 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6401 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6402 | if (consistency > 0.0) |
| 6403 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6404 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6405 | cpi->total_inconsistency += this_inconsistency; |
| 6406 | } |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6411 | 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] | 6412 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6413 | 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] | 6414 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 6415 | } |
| 6416 | } |
| 6417 | #endif // CONFIG_INTERNAL_STATS |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6418 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 6419 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 6420 | int64_t *time_end, int flush, |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 6421 | const aom_rational64_t *timestamp_ratio) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6422 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 6423 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6424 | |
| 6425 | #if CONFIG_BITSTREAM_DEBUG |
| 6426 | assert(cpi->oxcf.max_threads == 0 && |
| 6427 | "bitstream debug tool does not support multithreading"); |
| 6428 | bitstream_queue_record_write(); |
Yaowu Xu | 63f2ea3 | 2019-04-29 10:47:42 -0700 | [diff] [blame] | 6429 | aom_bitstream_queue_set_frame_write(cm->current_frame.frame_number * 2 + |
| 6430 | cm->show_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6431 | #endif |
Marco Paniconi | 6397132 | 2019-08-15 21:32:05 -0700 | [diff] [blame] | 6432 | if (cpi->use_svc && cm->number_spatial_layers > 1) { |
| 6433 | av1_one_pass_cbr_svc_start_layer(cpi); |
| 6434 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6435 | |
Sarah Parker | 740e839 | 2019-01-23 15:47:53 -0800 | [diff] [blame] | 6436 | // Indicates whether or not to use an adaptive quantize b rather than |
| 6437 | // the traditional version |
| 6438 | cm->use_quant_b_adapt = cpi->oxcf.quant_b_adapt; |
| 6439 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 6440 | cm->showable_frame = 0; |
David Turner | e43f7fe | 2019-01-15 14:58:00 +0000 | [diff] [blame] | 6441 | *size = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6442 | #if CONFIG_INTERNAL_STATS |
| 6443 | struct aom_usec_timer cmptimer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6444 | aom_usec_timer_start(&cmptimer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6445 | #endif |
Debargha Mukherjee | cd14cc1 | 2019-09-06 09:55:52 -0700 | [diff] [blame] | 6446 | set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6447 | |
Debargha Mukherjee | ba7b8fe | 2018-03-15 23:10:07 -0700 | [diff] [blame] | 6448 | // Normal defaults |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6449 | cm->refresh_frame_context = oxcf->frame_parallel_decoding_mode |
| 6450 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 6451 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 6452 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 6453 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6454 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 6455 | // Initialize fields related to forward keyframes |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 6456 | cpi->no_show_kf = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 6457 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6458 | if (assign_cur_frame_new_fb(cm) == NULL) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6459 | |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 6460 | const int result = |
| 6461 | av1_encode_strategy(cpi, size, dest, frame_flags, time_stamp, time_end, |
| 6462 | timestamp_ratio, flush); |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6463 | if (result != AOM_CODEC_OK && result != -1) { |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 6464 | return AOM_CODEC_ERROR; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 6465 | } else if (result == -1) { |
| 6466 | // Returning -1 indicates no frame encoded; more input is required |
| 6467 | return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6468 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 6469 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6470 | aom_usec_timer_mark(&cmptimer); |
| 6471 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 6472 | #endif // CONFIG_INTERNAL_STATS |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 6473 | if (cpi->b_calculate_psnr) { |
| 6474 | if (cm->show_existing_frame || (oxcf->pass != 1 && cm->show_frame)) { |
| 6475 | generate_psnr_packet(cpi); |
| 6476 | } |
| 6477 | } |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 6478 | |
| 6479 | if (cpi->keep_level_stats && oxcf->pass != 1) { |
| 6480 | // Initialize level info. at the beginning of each sequence. |
| 6481 | if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) { |
Hui Su | 58753d6 | 2019-05-29 09:56:19 -0700 | [diff] [blame] | 6482 | av1_init_level_info(cpi); |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 6483 | } |
kyslov | abeeb7c | 2019-03-06 18:35:04 -0800 | [diff] [blame] | 6484 | av1_update_level_info(cpi, *size, *time_stamp, *time_end); |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 6485 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6486 | |
| 6487 | #if CONFIG_INTERNAL_STATS |
| 6488 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6489 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6490 | } |
| 6491 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 6492 | #if CONFIG_SPEED_STATS |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 6493 | if (cpi->oxcf.pass != 1 && !cm->show_existing_frame) { |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 6494 | cpi->tx_search_count += cpi->td.mb.tx_search_count; |
| 6495 | cpi->td.mb.tx_search_count = 0; |
| 6496 | } |
| 6497 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6498 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6499 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6500 | |
Hui Su | 0d0ee66 | 2019-07-29 14:38:36 -0700 | [diff] [blame] | 6501 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6502 | } |
| 6503 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6504 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6505 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6506 | if (!cm->show_frame) { |
| 6507 | return -1; |
| 6508 | } else { |
| 6509 | int ret; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 6510 | if (cm->cur_frame != NULL) { |
| 6511 | *dest = cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6512 | dest->y_width = cm->width; |
| 6513 | dest->y_height = cm->height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 6514 | dest->uv_width = cm->width >> cm->seq_params.subsampling_x; |
| 6515 | dest->uv_height = cm->height >> cm->seq_params.subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6516 | ret = 0; |
| 6517 | } else { |
| 6518 | ret = -1; |
| 6519 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6520 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6521 | return ret; |
| 6522 | } |
| 6523 | } |
| 6524 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6525 | 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] | 6526 | if (cpi->last_show_frame_buf == NULL) return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6527 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 6528 | *frame = cpi->last_show_frame_buf->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6529 | return 0; |
| 6530 | } |
| 6531 | |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6532 | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
| 6533 | const YV12_BUFFER_CONFIG *b) { |
| 6534 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 6535 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
| 6536 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
| 6537 | a->border == b->border && |
| 6538 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
| 6539 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
| 6540 | } |
| 6541 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 6542 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 6543 | YV12_BUFFER_CONFIG *new_frame, |
| 6544 | YV12_BUFFER_CONFIG *sd) { |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 6545 | const int num_planes = av1_num_planes(cm); |
| 6546 | if (!equal_dimensions_and_border(new_frame, sd)) |
| 6547 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 6548 | "Incorrect buffer dimensions"); |
| 6549 | else |
| 6550 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
| 6551 | |
| 6552 | return cm->error.error_code; |
| 6553 | } |
| 6554 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6555 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6556 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6557 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6558 | |
| 6559 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6560 | |
| 6561 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6562 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6563 | |
| 6564 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 6565 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6566 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6567 | |
| 6568 | return 0; |
| 6569 | } |
| 6570 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6571 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6572 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6573 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *frame_size) { |
| 6574 | size_t output_size = 0; |
| 6575 | size_t total_bytes_read = 0; |
| 6576 | size_t remaining_size = *frame_size; |
| 6577 | uint8_t *buff_ptr = buffer; |
| 6578 | |
| 6579 | // go through each OBUs |
| 6580 | while (total_bytes_read < *frame_size) { |
| 6581 | uint8_t saved_obu_header[2]; |
| 6582 | uint64_t obu_payload_size; |
| 6583 | size_t length_of_payload_size; |
| 6584 | size_t length_of_obu_size; |
| 6585 | uint32_t obu_header_size = (buff_ptr[0] >> 2) & 0x1 ? 2 : 1; |
| 6586 | size_t obu_bytes_read = obu_header_size; // bytes read for current obu |
| 6587 | |
| 6588 | // save the obu header (1 or 2 bytes) |
| 6589 | memmove(saved_obu_header, buff_ptr, obu_header_size); |
| 6590 | // clear the obu_has_size_field |
| 6591 | saved_obu_header[0] = saved_obu_header[0] & (~0x2); |
| 6592 | |
| 6593 | // get the payload_size and length of payload_size |
| 6594 | if (aom_uleb_decode(buff_ptr + obu_header_size, remaining_size, |
| 6595 | &obu_payload_size, &length_of_payload_size) != 0) { |
| 6596 | return AOM_CODEC_ERROR; |
| 6597 | } |
| 6598 | obu_bytes_read += length_of_payload_size; |
| 6599 | |
| 6600 | // calculate the length of size of the obu header plus payload |
| 6601 | length_of_obu_size = |
| 6602 | aom_uleb_size_in_bytes((uint64_t)(obu_header_size + obu_payload_size)); |
| 6603 | |
| 6604 | // move the rest of data to new location |
| 6605 | memmove(buff_ptr + length_of_obu_size + obu_header_size, |
| 6606 | buff_ptr + obu_bytes_read, remaining_size - obu_bytes_read); |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 6607 | obu_bytes_read += (size_t)obu_payload_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6608 | |
| 6609 | // write the new obu size |
| 6610 | const uint64_t obu_size = obu_header_size + obu_payload_size; |
| 6611 | size_t coded_obu_size; |
| 6612 | if (aom_uleb_encode(obu_size, sizeof(obu_size), buff_ptr, |
| 6613 | &coded_obu_size) != 0) { |
| 6614 | return AOM_CODEC_ERROR; |
| 6615 | } |
| 6616 | |
| 6617 | // write the saved (modified) obu_header following obu size |
| 6618 | memmove(buff_ptr + length_of_obu_size, saved_obu_header, obu_header_size); |
| 6619 | |
| 6620 | total_bytes_read += obu_bytes_read; |
| 6621 | remaining_size -= obu_bytes_read; |
| 6622 | buff_ptr += length_of_obu_size + obu_size; |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 6623 | output_size += length_of_obu_size + (size_t)obu_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 6624 | } |
| 6625 | |
| 6626 | *frame_size = output_size; |
| 6627 | return AOM_CODEC_OK; |
| 6628 | } |
| 6629 | |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 6630 | static void svc_set_updates_external_ref_frame_config(AV1_COMP *cpi) { |
| 6631 | cpi->ext_refresh_frame_flags_pending = 1; |
| 6632 | cpi->ext_refresh_last_frame = cpi->svc.refresh[cpi->svc.ref_idx[0]]; |
| 6633 | cpi->ext_refresh_golden_frame = cpi->svc.refresh[cpi->svc.ref_idx[3]]; |
| 6634 | cpi->ext_refresh_bwd_ref_frame = cpi->svc.refresh[cpi->svc.ref_idx[4]]; |
| 6635 | cpi->ext_refresh_alt2_ref_frame = cpi->svc.refresh[cpi->svc.ref_idx[5]]; |
| 6636 | cpi->ext_refresh_alt_ref_frame = cpi->svc.refresh[cpi->svc.ref_idx[6]]; |
| 6637 | cpi->svc.non_reference_frame = 1; |
| 6638 | for (int i = 0; i < REF_FRAMES; i++) { |
| 6639 | if (cpi->svc.refresh[i] == 1) { |
| 6640 | cpi->svc.non_reference_frame = 0; |
| 6641 | break; |
| 6642 | } |
| 6643 | } |
| 6644 | } |
| 6645 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6646 | 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] | 6647 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 6648 | // should be consistent with internal reference frame selection. Need to |
| 6649 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 6650 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6651 | // GOLDEN, BWDREF, ALTREF2. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6652 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6653 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6654 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 6655 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 6656 | AOM_EFLAG_NO_REF_ARF2)) { |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6657 | int ref = AOM_REFFRAME_ALL; |
| 6658 | |
| 6659 | if (flags & AOM_EFLAG_NO_REF_LAST) ref ^= AOM_LAST_FLAG; |
| 6660 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 6661 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 6662 | |
| 6663 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 6664 | |
| 6665 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 6666 | ref ^= AOM_ALT_FLAG; |
| 6667 | ref ^= AOM_BWD_FLAG; |
| 6668 | ref ^= AOM_ALT2_FLAG; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6669 | } else { |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6670 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 6671 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6672 | } |
Marco Paniconi | 60a4d7f | 2019-08-02 14:43:27 -0700 | [diff] [blame] | 6673 | |
| 6674 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6675 | } |
| 6676 | |
| 6677 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6678 | (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] | 6679 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6680 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6681 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 6682 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6683 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6684 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6685 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6686 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 6687 | upd ^= AOM_ALT_FLAG; |
| 6688 | upd ^= AOM_BWD_FLAG; |
| 6689 | upd ^= AOM_ALT2_FLAG; |
| 6690 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6691 | |
David Turner | ce9b590 | 2019-01-23 17:25:47 +0000 | [diff] [blame] | 6692 | cpi->ext_refresh_last_frame = (upd & AOM_LAST_FLAG) != 0; |
| 6693 | cpi->ext_refresh_golden_frame = (upd & AOM_GOLD_FLAG) != 0; |
| 6694 | cpi->ext_refresh_alt_ref_frame = (upd & AOM_ALT_FLAG) != 0; |
| 6695 | cpi->ext_refresh_bwd_ref_frame = (upd & AOM_BWD_FLAG) != 0; |
| 6696 | cpi->ext_refresh_alt2_ref_frame = (upd & AOM_ALT2_FLAG) != 0; |
| 6697 | cpi->ext_refresh_frame_flags_pending = 1; |
David Turner | 4f1f181 | 2019-01-24 17:00:24 +0000 | [diff] [blame] | 6698 | } else { |
Marco Paniconi | d8574e3 | 2019-08-04 21:30:12 -0700 | [diff] [blame] | 6699 | if (cpi->svc.external_ref_frame_config) |
| 6700 | svc_set_updates_external_ref_frame_config(cpi); |
| 6701 | else |
| 6702 | cpi->ext_refresh_frame_flags_pending = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6703 | } |
| 6704 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6705 | cpi->ext_use_ref_frame_mvs = cpi->oxcf.allow_ref_frame_mvs & |
| 6706 | ((flags & AOM_EFLAG_NO_REF_FRAME_MVS) == 0); |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6707 | cpi->ext_use_error_resilient = cpi->oxcf.error_resilient_mode | |
| 6708 | ((flags & AOM_EFLAG_ERROR_RESILIENT) != 0); |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 6709 | cpi->ext_use_s_frame = |
| 6710 | cpi->oxcf.s_frame_mode | ((flags & AOM_EFLAG_SET_S_FRAME) != 0); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 6711 | 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] | 6712 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6713 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6714 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6715 | } |
| 6716 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 6717 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 6718 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi) { |
| 6719 | if (!cpi) return NULL; |
| 6720 | |
| 6721 | uint8_t header_buf[512] = { 0 }; |
| 6722 | const uint32_t sequence_header_size = |
Yaowu Xu | 797674b | 2019-05-01 17:38:11 -0700 | [diff] [blame] | 6723 | av1_write_sequence_header_obu(cpi, &header_buf[0]); |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 6724 | assert(sequence_header_size <= sizeof(header_buf)); |
| 6725 | if (sequence_header_size == 0) return NULL; |
| 6726 | |
| 6727 | const size_t obu_header_size = 1; |
| 6728 | const size_t size_field_size = aom_uleb_size_in_bytes(sequence_header_size); |
| 6729 | const size_t payload_offset = obu_header_size + size_field_size; |
| 6730 | |
| 6731 | if (payload_offset + sequence_header_size > sizeof(header_buf)) return NULL; |
| 6732 | memmove(&header_buf[payload_offset], &header_buf[0], sequence_header_size); |
| 6733 | |
Hui Su | 4fd1176 | 2019-03-26 16:05:07 -0700 | [diff] [blame] | 6734 | 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] | 6735 | obu_header_size) { |
| 6736 | return NULL; |
| 6737 | } |
| 6738 | |
| 6739 | size_t coded_size_field_size = 0; |
| 6740 | if (aom_uleb_encode(sequence_header_size, size_field_size, |
| 6741 | &header_buf[obu_header_size], |
| 6742 | &coded_size_field_size) != 0) { |
| 6743 | return NULL; |
| 6744 | } |
| 6745 | assert(coded_size_field_size == size_field_size); |
| 6746 | |
| 6747 | aom_fixed_buf_t *global_headers = |
| 6748 | (aom_fixed_buf_t *)malloc(sizeof(*global_headers)); |
| 6749 | if (!global_headers) return NULL; |
| 6750 | |
| 6751 | const size_t global_header_buf_size = |
| 6752 | obu_header_size + size_field_size + sequence_header_size; |
| 6753 | |
| 6754 | global_headers->buf = malloc(global_header_buf_size); |
| 6755 | if (!global_headers->buf) { |
| 6756 | free(global_headers); |
| 6757 | return NULL; |
| 6758 | } |
| 6759 | |
| 6760 | memcpy(global_headers->buf, &header_buf[0], global_header_buf_size); |
| 6761 | global_headers->sz = global_header_buf_size; |
| 6762 | return global_headers; |
| 6763 | } |