1 /*
2 * Copyright (c) 2018, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 
23 //!
24 //! \file     encode_hevc_vdenc_const_settings.cpp
25 //! \brief    Defines the common interface for hevc vdenc const settings
26 //! \details  The encode feature manager is further sub-divided by platform type
27 //!           this file is for the base interface which is shared by all components.
28 //!
29 
30 #include "encode_hevc_vdenc_const_settings.h"
31 #include "codec_def_common.h"
32 #include "codec_def_encode.h"
33 #include "encode_utils.h"
34 #include "mhw_vdbox_vdenc_cmdpar.h"
35 #include "mos_os.h"
36 #include "mos_solo_generic.h"
37 #include "mos_utilities.h"
38 #include "mos_utilities_common.h"
39 #include <math.h>
40 #include <stddef.h>
41 #include <algorithm>
42 #include <cstdint>
43 #include <functional>
44 #include <vector>
45 #if _ENCODE_RESERVED
46 #include "mhw_vdbox_vdenc_cmdpar_ext.h"
47 #endif // _ENCODE_RESERVED
48 
49 namespace encode
50 {
51 // BRC Init/Rest related params
52 const uint16_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_0[] = {
53     0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0003, 0x0004, 0x0005,
54     0x0006, 0x0008, 0x000A, 0x000C, 0x000F, 0x0013, 0x0018, 0x001E, 0x0026, 0x0030, 0x003D, 0x004D, 0x0061, 0x007A, 0x009A, 0x00C2,
55     0x00F4, 0x0133, 0x0183, 0x01E8, 0x0266, 0x0306, 0x03CF, 0x04CD, 0x060C, 0x079F, 0x099A, 0x0C18, 0x0F3D, 0x1333, 0x1831, 0x1E7A,
56     0x2666, 0x3062, 0x3CF5, 0x4CCD
57 };
58 
59 const uint16_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_1[] = {
60     0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0004, 0x0005,
61     0x0007, 0x0008, 0x000A, 0x000D, 0x0011, 0x0015, 0x001A, 0x0021, 0x002A, 0x0034, 0x0042, 0x0053, 0x0069, 0x0084, 0x00A6, 0x00D2,
62     0x0108, 0x014D, 0x01A3, 0x0210, 0x029A, 0x0347, 0x0421, 0x0533, 0x068D, 0x0841, 0x0A66, 0x0D1A, 0x1082, 0x14CD, 0x1A35, 0x2105,
63     0x299A, 0x346A, 0x4209, 0x5333
64 };
65 
66 const uint8_t HevcVdencBrcConstSettings::m_estRateThreshP0[7] =
67 {
68     4, 8, 12, 16, 20, 24, 28
69 };
70 
71 const uint8_t HevcVdencBrcConstSettings::m_estRateThreshB0[7] =
72 {
73     4, 8, 12, 16, 20, 24, 28
74 };
75 
76 const uint8_t HevcVdencBrcConstSettings::m_estRateThreshI0[7] =
77 {
78     4, 8, 12, 16, 20, 24, 28
79 };
80 
81 const int8_t HevcVdencBrcConstSettings::m_instRateThreshP0[4] =
82 {
83     40, 60, 80, 120
84 };
85 
86 const int8_t HevcVdencBrcConstSettings::m_instRateThreshB0[4] =
87 {
88     35, 60, 80, 120
89 };
90 
91 const int8_t HevcVdencBrcConstSettings::m_instRateThreshI0[4] =
92 {
93     40, 60, 90, 115
94 };
95 
96 const int8_t HevcVdencBrcConstSettings::m_lowdelayDevThreshPB[] = {
97     -45, -33, -23, -15, -8, 0, 15, 25,
98 };
99 
100 const int8_t HevcVdencBrcConstSettings::m_lowdelayDevThreshVBR[] = {
101     -45, -35, -25, -15, -8, 0, 20, 40,
102 };
103 const int8_t HevcVdencBrcConstSettings::m_lowdelayDevThreshI[] = {
104     -40, -30, -17, -10, -5, 0, 10, 20,
105 };
106 
107 const double HevcVdencBrcConstSettings::m_devThreshIFPNEG[] = {
108     0.80, 0.60, 0.34, 0.2,
109 };
110 
111 const double HevcVdencBrcConstSettings::m_devThreshIFPPOS[] = {
112     0.2, 0.4 , 0.66, 0.9,
113 };
114 
115 const double HevcVdencBrcConstSettings::m_devThreshPBFPNEG[] = {
116     0.90, 0.66, 0.46, 0.3,
117 };
118 
119 const double HevcVdencBrcConstSettings::m_devThreshPBFPPOS[] = {
120     0.3, 0.46, 0.70, 0.90,
121 };
122 
123 const double HevcVdencBrcConstSettings::m_devThreshVBRNEG[] = {
124     0.90, 0.70, 0.50, 0.3,
125 };
126 
127 const double HevcVdencBrcConstSettings::m_devThreshVBRPOS[] = {
128     0.4, 0.5, 0.75, 0.90,
129 };
130 
131 const uint16_t HevcVdencBrcConstSettings::m_startGAdjFrame[4] =
132 {
133     10, 50, 100, 150
134 };
135 
136 const uint32_t HevcVdencBrcConstSettings::m_hucConstantData[]  = {
137     0x01900190, 0x01900190, 0x01900190, 0x01900190, 0x01900190, 0x012c012c, 0x012c012c, 0x012c012c,
138     0x012c012c, 0x012c012c, 0x00c800c8, 0x00c800c8, 0x00c800c8, 0x00c800c8, 0x00c800c8, 0x00640064,
139     0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x00640064,
140     0x00640064, 0x00640064, 0x01900190, 0x01900190, 0x01900190, 0x01900190, 0x01900190, 0x012c012c,
141     0x012c012c, 0x012c012c, 0x012c012c, 0x012c012c, 0x00c800c8, 0x00c800c8, 0x00c800c8, 0x00c800c8,
142     0x00c800c8, 0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x00640064,
143     0x00640064, 0x00640064, 0x00640064, 0x00640064, 0x503c1e04, 0xffc88c78, 0x3c1e0400, 0xc88c7850,
144     0x140200ff, 0xa0824628, 0x0000ffc8, 0x00000000, 0x04030302, 0x00000000, 0x03030200, 0x0000ff04,
145     0x02020000, 0xffff0303, 0x01000000, 0xff020202, 0x0000ffff, 0x02020100, 0x00fffffe, 0x01010000,
146     0xfffffe02, 0x010000ff, 0xfefe0201, 0x0000ffff, 0xfe010100, 0x00fffffe, 0x01010000, 0x00000000,
147     0x03030200, 0x00000004, 0x03020000, 0x00ff0403, 0x02000000, 0xff030302, 0x000000ff, 0x02020201,
148     0x00ffffff, 0x02010000, 0xfffffe02, 0x01000000, 0xfffe0201, 0x0000ffff, 0xfe020101, 0x00fffffe,
149     0x01010000, 0xfffffefe, 0x01000000, 0x00000001, 0x03020000, 0x00000403, 0x02000000, 0xff040303,
150     0x00000000, 0x03030202, 0x0000ffff, 0x02020100, 0xffffff02, 0x01000000, 0xfffe0202, 0x000000ff,
151     0xfe020101, 0x00ffffff, 0x02010100, 0xfffffefe, 0x01000000, 0xfffefe01, 0x000000ff, 0xe0e00101,
152     0xc0d0d0d0, 0xe0e0b0c0, 0xd0d0d0e0, 0xf0f0c0d0, 0xd0e0e0e0, 0x0408d0d0, 0xe8f0f800, 0x1820dce0,
153     0xf8fc0210, 0x2024ecf0, 0x0008101c, 0x2428f8fc, 0x08101418, 0x2830f800, 0x0c14181c, 0x3040fc00,
154     0x0c10141c, 0xe8f80408, 0xc8d0d4e0, 0xf0f8b0c0, 0xccd4d8e0, 0x0000c0c8, 0xd8dce4f0, 0x0408d0d4,
155     0xf0f80000, 0x0808dce8, 0xf0f80004, 0x0810dce8, 0x00080808, 0x0810f8fc, 0x08080808, 0x1010f800,
156     0x08080808, 0x1020fc00, 0x08080810, 0xfc000408, 0xe0e8f0f8, 0x0001d0d8, 0xe8f0f8fc, 0x0204d8e0,
157     0xf8fdff00, 0x0408e8f0, 0xfcff0002, 0x1014f0f8, 0xfcff0004, 0x1418f0f8, 0x00040810, 0x181cf8fc,
158     0x04081014, 0x1820f800, 0x04081014, 0x3040fc00, 0x0c10141c, 0x40300408, 0x80706050, 0x30a0a090,
159     0x70605040, 0xa0a09080, 0x60504030, 0xa0908070, 0x040201a0, 0x18141008, 0x02012420, 0x0a080604,
160     0x01101010, 0x0c080402, 0x10101010, 0x05030201, 0x02010106, 0x00000503, 0xff030201, 0x02010000,
161     0x000000ff, 0xfffefe01, 0xfdfd0100, 0xfb00ffff, 0xfffffefd, 0xfefdfbfa, 0x030201ff, 0x01010605,
162     0x00050302, 0x03020101, 0x010000ff, 0x0000ff02, 0xffff0100, 0xfe0100ff, 0x00ffffff, 0xfffffefc,
163     0xfefcfb00, 0x0101ffff, 0x01050402, 0x04020101, 0x01010000, 0x0000ff02, 0x00ff0101, 0xff000000,
164     0x0100ffff, 0xfffffffe, 0xfffefd00, 0xfcfb00ff, 0x1efffffe, 0x070d0e10, 0x00003207, 0x00000000,
165     0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000,
166     0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000,
167     0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
168     0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000,
169     0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10,
170     0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207,
171     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000,
172     0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000,
173     0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000,
174     0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
175     0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000,
176     0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10,
177     0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207,
178     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000,
179     0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000,
180     0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000,
181     0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
182     0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000,
183     0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10,
184     0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207,
185     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000,
186     0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000,
187     0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000,
188     0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
189     0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000,
190     0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10,
191     0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207,
192     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000,
193     0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000,
194     0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000,
195     0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
196     0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000,
197     0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10,
198     0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207,
199     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000,
200     0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000,
201     0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000,
202     0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
203     0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000,
204     0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10,
205     0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207,
206     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000,
207     0x00000000, 0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000,
208     0x00000000, 0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000,
209     0x00000000, 0x1e000000, 0x070d0e10, 0x00003207, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
210     0x00000000, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff,
211     0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff,
212     0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff,
213     0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000,
214     0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff,
215     0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff,
216     0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000,
217     0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff,
218     0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff,
219     0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff,
220     0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff,
221     0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff,
222     0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000,
223     0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff,
224     0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff,
225     0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000,
226     0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff,
227     0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff,
228     0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff,
229     0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff,
230     0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff,
231     0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000,
232     0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff,
233     0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff,
234     0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000,
235     0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff,
236     0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff,
237     0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff,
238     0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff,
239     0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff,
240     0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000,
241     0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff,
242     0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff,
243     0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000,
244     0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff,
245     0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff, 0x0000ffff,
246     0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff, 0xffffffff,
247     0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff, 0xffffffff,
248     0xffffffff, 0x0000ffff, 0xffffffff, 0xffff0000, 0xffffffff, 0xffffffff, 0xffff0000, 0x0000ffff,
249     0xffffffff, 0xffffffff, 0x0000ffff, 0xffffffff
250 };
251 
252 const uint16_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_2[] = {
253     0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0004, 0x0004,
254     0x0005, 0x0006, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000E, 0x0010, 0x0012, 0x0014, 0x0016, 0x0019, 0x001C,
255     0x001F, 0x0023, 0x0027, 0x002C, 0x0032, 0x0038, 0x003E, 0x0046, 0x004F, 0x0058, 0x0063, 0x006F, 0x007D, 0x008C, 0x009D, 0x00B1,
256     0x00C6, 0x00DF, 0x00FA, 0x0118
257 };
258 
259 const uint16_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_3[] = {
260     0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0004, 0x0004, 0x0005,
261     0x0005, 0x0006, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000D, 0x000E, 0x0010, 0x0012, 0x0014, 0x0017, 0x001A, 0x001D,
262     0x0021, 0x0024, 0x0029, 0x002E, 0x0034, 0x003A, 0x0041, 0x0049, 0x0052, 0x005C, 0x0067, 0x0074, 0x0082, 0x0092, 0x00A4, 0x00B8,
263     0x00CE, 0x00E8, 0x0104, 0x0124
264 };
265 
266 const uint32_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_7[] = {
267     0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e,
268     0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707,
269     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000,
270     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000,
271     0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000,
272     0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
273     0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
274     0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e,
275     0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707,
276     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000,
277     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000,
278     0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000,
279     0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
280     0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
281     0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e,
282     0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707,
283     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000,
284     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000,
285     0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000,
286     0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
287     0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
288     0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e,
289     0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707,
290     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000,
291     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000,
292     0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000,
293     0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
294     0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
295     0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e,
296     0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707,
297     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000,
298     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000,
299     0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000,
300     0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
301     0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
302     0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e,
303     0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707,
304     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000,
305     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000,
306     0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000,
307     0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
308     0x00000000, 0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
309     0x0d0e101e, 0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e,
310     0x00320707, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707,
311     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0d0e101e, 0x00320707, 0x00000000,
312     0x00000000, 0x00000000, 0x00000000, 0x00000000
313 };
314 
315 const uint32_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_8[] = {
316     0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e,
317     0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707,
318     0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314,
319     0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15,
320     0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d,
321     0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333,
322     0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b,
323     0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e,
324     0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707,
325     0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314,
326     0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15,
327     0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d,
328     0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333,
329     0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b,
330     0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e,
331     0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707,
332     0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314,
333     0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15,
334     0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d,
335     0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333,
336     0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b,
337     0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e,
338     0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707,
339     0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314,
340     0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15,
341     0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d,
342     0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333,
343     0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b,
344     0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e,
345     0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707,
346     0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314,
347     0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15,
348     0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d,
349     0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333,
350     0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b,
351     0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e,
352     0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707,
353     0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314,
354     0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15,
355     0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d,
356     0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333,
357     0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b,
358     0x0d0e101e, 0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e,
359     0x44320707, 0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707,
360     0x15232314, 0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b, 0x0d0e101e, 0x44320707, 0x15232314,
361     0x6e4d3f15, 0x04476e4d, 0x1f232333, 0x0f13131b
362 };
363 
364 const int8_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_4[9][8] = {
365     { 0,  0, -8, -12, -16, -20, -28, -36 },
366 { 0,  0, -4, -8, -12,  -16, -24, -32 },
367 { 4,  2,  0, -1, -3,  -8, -16, -24 },
368 { 8,  4,  2,  0, -1,  -4,  -8, -16 },
369 { 20, 16,  4,  0, -1,  -4,  -8, -16 },
370 { 24, 20, 16,  8,  4,   0,  -4, -8 },
371 { 28, 24, 20, 16,  8,   4,  0, -8 },
372 { 32, 24, 20, 16, 8,   4,   0, -4 },
373 { 64, 48, 28, 20, 16,  12,  8,  4 },
374 };
375 
376 const int8_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_5[9][8] = {
377     { -8,  -24, -32, -40, -44, -48, -52, -80 },
378 { -8,  -16, -32, -40, -40,  -44, -44, -56 },
379 { 0,    0,  -12, -20, -24,  -28, -32, -36 },
380 { 8,   4,  0,   0,    -8,   -16,  -24, -32 },
381 { 32,  16,  8, 4,    -4,   -8,  -16,  -20 },
382 { 36,  24,  16, 8,    4,    -2,  -4, -8 },
383 { 40, 36, 24,   20, 16,  8,  0, -8 },
384 { 48, 40, 28,  24, 20,  12,  0, -4 },
385 { 64, 48, 28, 20, 16,  12,  8,  4 },
386 };
387 
388 const int8_t HevcVdencBrcConstSettings::HevcVdencBrcConstSettings_6[9][8] = {
389     { 0, -4, -8, -16, -24, -32, -40, -48 },
390 { 1,  0, -4, -8, -16,  -24, -32, -40 },
391 { 4,  2,  0, -1, -3,  -8, -16, -24 },
392 { 8,  4,  2,  0, -1,  -4,  -8, -16 },
393 { 20, 16,  4,  0, -1,  -4,  -8, -16 },
394 { 24, 20, 16,  8,  4,   0,  -4, -8 },
395 { 28, 24, 20, 16,  8,   4,  0, -8 },
396 { 32, 24, 20, 16, 8,   4,   0, -4 },
397 { 64, 48, 28, 20, 16,  12,  8,  4 },
398 };
399 
400 const uint8_t HevcVdencBrcConstSettings::m_rateRatioThreshold[7] =
401 {
402     40, 75, 97, 103, 125, 160, 0
403 };
404 const uint8_t HevcVdencBrcConstSettings::m_startGAdjMult[5] =
405 {
406     1, 1, 3, 2, 1
407 };
408 
409 const uint8_t HevcVdencBrcConstSettings::m_startGAdjDiv[5] =
410 {
411     40, 5, 5, 3, 1
412 };
413 
414 const uint8_t HevcVdencBrcConstSettings::m_rateRatioThresholdQP[8] =
415 {
416     253, 254, 255, 0, 1, 2, 3, 0
417 };
418 
EncodeHevcVdencConstSettings()419 EncodeHevcVdencConstSettings::EncodeHevcVdencConstSettings()
420 {
421     m_featureSetting = MOS_New(HevcVdencFeatureSettings);
422 }
423 
~EncodeHevcVdencConstSettings()424 EncodeHevcVdencConstSettings::~EncodeHevcVdencConstSettings()
425 {
426     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
427     MOS_Delete(setting);
428     m_featureSetting = nullptr;
429 }
430 
PrepareConstSettings()431 MOS_STATUS EncodeHevcVdencConstSettings::PrepareConstSettings()
432 {
433     ENCODE_FUNC_CALL();
434 
435     ENCODE_CHK_STATUS_RETURN(SetTUSettings());
436     ENCODE_CHK_STATUS_RETURN(SetCommonSettings());
437     ENCODE_CHK_STATUS_RETURN(SetVdencStreaminStateSettings());
438     ENCODE_CHK_STATUS_RETURN(SetVdencCmd1Settings());
439     ENCODE_CHK_STATUS_RETURN(SetVdencCmd2Settings());
440     ENCODE_CHK_STATUS_RETURN(SetBrcSettings());
441     ENCODE_CHK_STATUS_RETURN(SetLaTUSettings());
442     ENCODE_CHK_STATUS_RETURN(SetVdencLaCmd1Settings());
443     ENCODE_CHK_STATUS_RETURN(SetVdencLaCmd2Settings());
444 
445     if (m_osItf != nullptr)
446     {
447         // To enable rounding precision here
448         MediaUserSetting::Value outValue;
449         ReadUserSetting(
450             m_userSettingPtr,
451             outValue,
452             "HEVC VDEnc Rounding Enable",
453             MediaUserSetting::Group::Sequence);
454         m_hevcVdencRoundingPrecisionEnabled = outValue.Get<bool>();
455 
456 #if (_DEBUG || _RELEASE_INTERNAL)
457         ReportUserSettingForDebug(
458             m_userSettingPtr,
459             "HEVC VDEnc Rounding Enable",
460             m_hevcVdencRoundingPrecisionEnabled,
461             MediaUserSetting::Group::Sequence);
462 #endif
463 /*
464         MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
465         MOS_UserFeature_ReadValue_ID(
466             nullptr,
467             __MEDIA_USER_FEATURE_VALUE_HEVC_RDO_ENABLE_ID,
468             &userFeatureData,
469             m_osItf->pOsContext);
470         m_hevcRdoqEnabled = (userFeatureData.i32Data) ? true : false;
471 #if (_DEBUG || _RELEASE_INTERNAL)
472         WriteUserFeature(__MEDIA_USER_FEATURE_VALUE_HEVC_RDO_ENABLE_ID, m_hevcRdoqEnabled, m_osItf->pOsContext);
473 #endif
474 */
475     }
476 
477     return MOS_STATUS_SUCCESS;
478 }
479 
Update(void * params)480 MOS_STATUS EncodeHevcVdencConstSettings::Update(void *params)
481 {
482     ENCODE_FUNC_CALL();
483     ENCODE_CHK_NULL_RETURN(m_featureSetting);
484 
485     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
486     ENCODE_CHK_NULL_RETURN(setting);
487 
488     EncoderParams *encodeParams = (EncoderParams *)params;
489 
490     PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams =
491         static_cast<PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS>(encodeParams->pSeqParams);
492     ENCODE_CHK_NULL_RETURN(hevcSeqParams);
493     m_hevcSeqParams = hevcSeqParams;
494 
495     PCODEC_HEVC_ENCODE_PICTURE_PARAMS hevcPicParams =
496         static_cast<PCODEC_HEVC_ENCODE_PICTURE_PARAMS>(encodeParams->pPicParams);
497     ENCODE_CHK_NULL_RETURN(hevcPicParams);
498     m_hevcPicParams = hevcPicParams;
499 
500     PCODEC_HEVC_ENCODE_SLICE_PARAMS hevcSliceParams =
501         static_cast<PCODEC_HEVC_ENCODE_SLICE_PARAMS>(encodeParams->pSliceParams);
502     ENCODE_CHK_NULL_RETURN(hevcSliceParams);
503     m_hevcSliceParams = hevcSliceParams;
504 
505     bool isLaAnalysisPass = (m_hevcSeqParams->LookaheadDepth > 0) && m_hevcSeqParams->bLookAheadPhase;
506     if (isLaAnalysisPass == true && m_isLaSetting == false)
507     {
508         setting->rdoqEnable.swap(setting->rdoqLaEnable);
509         setting->acqpEnable.swap(setting->acqpLaEnable);
510         setting->vdencCmd1Settings.swap(setting->vdencLaCmd1Settings);
511         setting->vdencCmd2Settings.swap(setting->vdencLaCmd2Settings);
512         m_isLaSetting = true;
513     }
514 
515     return MOS_STATUS_SUCCESS;
516 }
517 
518 #define CLIP3(MIN_, MAX_, X) (((X) < (MIN_)) ? (MIN_) : (((X) > (MAX_)) ? (MAX_) : (X)))
519 
SetTUSettings()520 MOS_STATUS EncodeHevcVdencConstSettings::SetTUSettings()
521 {
522     ENCODE_FUNC_CALL();
523     ENCODE_CHK_NULL_RETURN(m_featureSetting);
524     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
525 
526     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
527     ENCODE_CHK_NULL_RETURN(setting);
528 
529     setting->rdoqEnable         = {true, true, true, true, true, true, true, false};
530     setting->acqpEnable         = {true, true, true, true, true, true, true, false};
531 
532     return eStatus;
533 }
534 
SetCommonSettings()535 MOS_STATUS EncodeHevcVdencConstSettings::SetCommonSettings()
536 {
537     ENCODE_FUNC_CALL();
538     ENCODE_CHK_NULL_RETURN(m_featureSetting);
539 
540     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
541     ENCODE_CHK_NULL_RETURN(setting);
542 
543     setting->transformSkipCoeffsTable = {{
544         {{
545             {{
546                 {{
547                     {42, 37}, {32, 40}
548                 }},
549                 {{
550                     {40, 40}, {32, 45}
551                 }}
552             }},
553             {{
554                 {{
555                     {29, 48}, {26, 53}
556                 }},
557                 {{
558                     {26, 56}, {24, 62}
559                 }}
560             }}
561         }},
562         {{
563             {{
564                 {{
565                     {42, 40}, {32, 45}
566                 }},
567                 {{
568                     {40, 46}, {32, 48}
569                 }}
570             }},
571             {{
572                 {{
573                     {26, 53}, {24, 58}
574                 }},
575                 {{
576                     {32, 53}, {26, 64}
577                 }}
578             }}
579         }},
580         {{
581             {{
582                 {{
583                     {38, 42}, {32, 51}
584                 }},
585                 {{
586                     {43, 43}, {35, 46}
587                 }}
588             }},
589             {{
590                 {{
591                     {26, 56}, {24, 64}
592                 }},
593                 {{
594                     {35, 50}, {32, 57}
595                 }}
596             }}
597         }},
598         {{
599             {{
600                 {{
601                     {35, 46}, {32, 52}
602                 }},
603                 {{
604                     {51, 42}, {38, 53}
605                 }}
606             }},
607             {{
608                 {{
609                     {29, 56}, {29, 70}
610                 }},
611                 {{
612                     {38, 47}, {37, 64}
613                 }}
614             }}
615         }},
616     }};
617 
618     setting->transformSkipLambdaTable = {
619     149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
620     149, 149, 149, 149, 149, 149, 149, 149, 149, 162, 174, 186, 199, 211, 224, 236,
621     249, 261, 273, 286, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298,
622     298, 298, 298, 298
623     };
624 
625     setting->rdoqLamdas8bits = {{
626     {{
627         {{
628             {   //Intra Luma
629                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001,
630                 0x0001, 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0005,
631                 0x0007, 0x0008, 0x000a, 0x000d, 0x0011, 0x0015, 0x001a, 0x0021,
632                 0x002a, 0x0034, 0x0042, 0x0053, 0x0069, 0x0084, 0x00a6, 0x00d2,
633                 0x0108, 0x014d, 0x01a3, 0x0210, 0x029a, 0x0347, 0x0421, 0x0533,
634                 0x068d, 0x0841, 0x0a66, 0x0d1a, 0x1082, 0x14cd, 0x1a35, 0x2105,
635                 0x299a, 0x346a, 0x4209, 0x5333
636             },
637             {   //Intra Chroma
638                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001,
639                 0x0001, 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0005,
640                 0x0007, 0x0008, 0x000a, 0x000d, 0x0011, 0x0015, 0x001a, 0x0021,
641                 0x002a, 0x0034, 0x0042, 0x0053, 0x0069, 0x0084, 0x00a6, 0x00d2,
642                 0x0108, 0x014d, 0x01a3, 0x0210, 0x029a, 0x0347, 0x0421, 0x0533,
643                 0x068d, 0x0841, 0x0a66, 0x0d1a, 0x1082, 0x14cd, 0x1a35, 0x2105,
644                 0x299a, 0x346a, 0x4209, 0x5333
645             },
646         }},
647         {{
648             {   //Inter Luma
649                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
650                 0x0003, 0x0004, 0x0006, 0x0007, 0x0009, 0x000b, 0x000e, 0x0012,
651                 0x0016, 0x001c, 0x0023, 0x002c, 0x0038, 0x0046, 0x0059, 0x0075,
652                 0x009b, 0x00cc, 0x010c, 0x0160, 0x01cd, 0x025b, 0x0314, 0x0405,
653                 0x053d, 0x06d2, 0x08df, 0x0b2d, 0x0e14, 0x11bd, 0x165a, 0x1c29,
654                 0x237b, 0x2cb4, 0x3852, 0x46f5, 0x5967, 0x70a4, 0x8deb, 0xb2ce,
655                 0xe148, 0xffff, 0xffff, 0xffff
656             },
657             {   //Inter Chroma
658                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
659                 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000b, 0x000d, 0x0011,
660                 0x0015, 0x001b, 0x0021, 0x002a, 0x0035, 0x0043, 0x0054, 0x006c,
661                 0x008c, 0x00b4, 0x00e7, 0x0129, 0x017d, 0x01ea, 0x0275, 0x0327,
662                 0x040c, 0x0530, 0x06a7, 0x0862, 0x0a8f, 0x0d4e, 0x10c3, 0x151f,
663                 0x1a9c, 0x2187, 0x2a3d, 0x3538, 0x430d, 0x547b, 0x6a70, 0x861b,
664                 0xa8f6, 0xd4e0, 0xffff, 0xffff
665             },
666         }},
667     }},
668     {{
669         {{
670             {   //Intra Luma
671                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
672                 0x0003, 0x0004, 0x0006, 0x0007, 0x0009, 0x000b, 0x000e, 0x0012,
673                 0x0016, 0x001c, 0x0023, 0x002c, 0x0038, 0x0046, 0x0059, 0x0075,
674                 0x009b, 0x00cc, 0x010c, 0x0160, 0x01cd, 0x025b, 0x0314, 0x0405,
675                 0x053d, 0x06d2, 0x08df, 0x0b2d, 0x0e14, 0x11bd, 0x165a, 0x1c29,
676                 0x237b, 0x2cb4, 0x3852, 0x46f5, 0x5967, 0x70a4, 0x8deb, 0xb2ce,
677                 0xe148, 0xffff, 0xffff, 0xffff
678             },
679             {   //Intra Chroma
680                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
681                 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000b, 0x000d, 0x0011,
682                 0x0015, 0x001b, 0x0021, 0x002a, 0x0035, 0x0043, 0x0054, 0x006c,
683                 0x008c, 0x00b4, 0x00e7, 0x0129, 0x017d, 0x01ea, 0x0275, 0x0327,
684                 0x040c, 0x0530, 0x06a7, 0x0862, 0x0a8f, 0x0d4e, 0x10c3, 0x151f,
685                 0x1a9c, 0x2187, 0x2a3d, 0x3538, 0x430d, 0x547b, 0x6a70, 0x861b,
686                 0xa8f6, 0xd4e0, 0xffff, 0xffff
687             },
688         }},
689         {{
690             {   //Inter Luma
691                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
692                 0x0003, 0x0004, 0x0006, 0x0007, 0x0009, 0x000b, 0x000e, 0x0012,
693                 0x0016, 0x001c, 0x0023, 0x002c, 0x0038, 0x0046, 0x0059, 0x0075,
694                 0x009b, 0x00cc, 0x010c, 0x0160, 0x01cd, 0x025b, 0x0314, 0x0405,
695                 0x053d, 0x06d2, 0x08df, 0x0b2d, 0x0e14, 0x11bd, 0x165a, 0x1c29,
696                 0x237b, 0x2cb4, 0x3852, 0x46f5, 0x5967, 0x70a4, 0x8deb, 0xb2ce,
697                 0xe148, 0xffff, 0xffff, 0xffff
698             },
699             {   //Inter Chroma
700                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
701                 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000b, 0x000d, 0x0011,
702                 0x0015, 0x001b, 0x0021, 0x002a, 0x0035, 0x0043, 0x0054, 0x006c,
703                 0x008c, 0x00b4, 0x00e7, 0x0129, 0x017d, 0x01ea, 0x0275, 0x0327,
704                 0x040c, 0x0530, 0x06a7, 0x0862, 0x0a8f, 0x0d4e, 0x10c3, 0x151f,
705                 0x1a9c, 0x2187, 0x2a3d, 0x3538, 0x430d, 0x547b, 0x6a70, 0x861b,
706                 0xa8f6, 0xd4e0, 0xffff, 0xffff
707             },
708         }},
709     }}
710 }};
711 
712     setting->rdoqLamdas10bits = {{
713     {{
714         {{
715             {   //Intra Luma
716                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
717                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
718                 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002,
719                 0x0003, 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000a, 0x000d,
720                 0x0011, 0x0015, 0x001a, 0x0021, 0x002a, 0x0034, 0x0042, 0x0053,
721                 0x0069, 0x0084, 0x00a6, 0x00d2, 0x0108, 0x014d, 0x01a3, 0x0210,
722                 0x029a, 0x0347, 0x0421, 0x0533, 0x068d, 0x0841, 0x0a66, 0x0d1a,
723                 0x1082, 0x14cd, 0x1a35, 0x2105, 0x299a, 0x346a, 0x4209, 0x5333
724             },
725             {   //Intra Chroma
726                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
727                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
728                 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002,
729                 0x0003, 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000a, 0x000d,
730                 0x0011, 0x0015, 0x001a, 0x0021, 0x002a, 0x0034, 0x0042, 0x0053,
731                 0x0069, 0x0084, 0x00a6, 0x00d2, 0x0108, 0x014d, 0x01a3, 0x0210,
732                 0x029a, 0x0347, 0x0421, 0x0533, 0x068d, 0x0841, 0x0a66, 0x0d1a,
733                 0x1082, 0x14cd, 0x1a35, 0x2105, 0x299a, 0x346a, 0x4209, 0x5333
734             },
735         }},
736         {{
737             {   //Inter Luma
738                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
739                 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001,
740                 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0006, 0x0007,
741                 0x0009, 0x000b, 0x000e, 0x0012, 0x0016, 0x001c, 0x0023, 0x002c,
742                 0x0038, 0x0046, 0x0059, 0x0075, 0x009b, 0x00cc, 0x010c, 0x0160,
743                 0x01cd, 0x025b, 0x0314, 0x0405, 0x053d, 0x06d2, 0x08df, 0x0b2d,
744                 0x0e14, 0x11bd, 0x165a, 0x1c29, 0x237b, 0x2cb4, 0x3852, 0x46f5,
745                 0x5967, 0x70a4, 0x8deb, 0xb2ce, 0xe148, 0xffff, 0xffff, 0xffff
746             },
747             {   //Inter Chroma
748                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
749                 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001,
750                 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0005, 0x0007,
751                 0x0008, 0x000b, 0x000d, 0x0011, 0x0015, 0x001b, 0x0021, 0x002a,
752                 0x0035, 0x0043, 0x0054, 0x006c, 0x008c, 0x00b4, 0x00e7, 0x0129,
753                 0x017d, 0x01ea, 0x0275, 0x0327, 0x040c, 0x0530, 0x06a7, 0x0862,
754                 0x0a8f, 0x0d4e, 0x10c3, 0x151f, 0x1a9c, 0x2187, 0x2a3d, 0x3538,
755                 0x430d, 0x547b, 0x6a70, 0x861b, 0xa8f6, 0xd4e0, 0xffff, 0xffff
756             },
757         }},
758     }},
759     {{
760         {{
761             {   //Intra Luma
762                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
763                 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001,
764                 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0006, 0x0007,
765                 0x0009, 0x000b, 0x000e, 0x0012, 0x0016, 0x001c, 0x0023, 0x002c,
766                 0x0038, 0x0046, 0x0059, 0x0075, 0x009b, 0x00cc, 0x010c, 0x0160,
767                 0x01cd, 0x025b, 0x0314, 0x0405, 0x053d, 0x06d2, 0x08df, 0x0b2d,
768                 0x0e14, 0x11bd, 0x165a, 0x1c29, 0x237b, 0x2cb4, 0x3852, 0x46f5,
769                 0x5967, 0x70a4, 0x8deb, 0xb2ce, 0xe148, 0xffff, 0xffff, 0xffff
770             },
771             {   //Intra Chroma
772                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
773                 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001,
774                 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0005, 0x0007,
775                 0x0008, 0x000b, 0x000d, 0x0011, 0x0015, 0x001b, 0x0021, 0x002a,
776                 0x0035, 0x0043, 0x0054, 0x006c, 0x008c, 0x00b4, 0x00e7, 0x0129,
777                 0x017d, 0x01ea, 0x0275, 0x0327, 0x040c, 0x0530, 0x06a7, 0x0862,
778                 0x0a8f, 0x0d4e, 0x10c3, 0x151f, 0x1a9c, 0x2187, 0x2a3d, 0x3538,
779                 0x430d, 0x547b, 0x6a70, 0x861b, 0xa8f6, 0xd4e0, 0xffff, 0xffff
780             },
781         }},
782         {{
783             {   //Inter Luma
784                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
785                 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001,
786                 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0006, 0x0007,
787                 0x0009, 0x000b, 0x000e, 0x0012, 0x0016, 0x001c, 0x0023, 0x002c,
788                 0x0038, 0x0046, 0x0059, 0x0075, 0x009b, 0x00cc, 0x010c, 0x0160,
789                 0x01cd, 0x025b, 0x0314, 0x0405, 0x053d, 0x06d2, 0x08df, 0x0b2d,
790                 0x0e14, 0x11bd, 0x165a, 0x1c29, 0x237b, 0x2cb4, 0x3852, 0x46f5,
791                 0x5967, 0x70a4, 0x8deb, 0xb2ce, 0xe148, 0xffff, 0xffff, 0xffff
792             },
793             {   //Inter Chroma
794                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
795                 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001,
796                 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0005, 0x0007,
797                 0x0008, 0x000b, 0x000d, 0x0011, 0x0015, 0x001b, 0x0021, 0x002a,
798                 0x0035, 0x0043, 0x0054, 0x006c, 0x008c, 0x00b4, 0x00e7, 0x0129,
799                 0x017d, 0x01ea, 0x0275, 0x0327, 0x040c, 0x0530, 0x06a7, 0x0862,
800                 0x0a8f, 0x0d4e, 0x10c3, 0x151f, 0x1a9c, 0x2187, 0x2a3d, 0x3538,
801                 0x430d, 0x547b, 0x6a70, 0x861b, 0xa8f6, 0xd4e0, 0xffff, 0xffff
802             },
803         }},
804     }}
805 }};
806 
807     setting->rdoqLamdas12bits = {{
808     {{
809         {{
810             {   //Intra Luma
811                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
812                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
813                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
814                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001,
815                 0x0001, 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0005,
816                 0x0007, 0x0008, 0x000a, 0x000d, 0x0011, 0x0015, 0x001a, 0x0021,
817                 0x002a, 0x0034, 0x0042, 0x0053, 0x0069, 0x0084, 0x00a6, 0x00d2,
818                 0x0108, 0x014d, 0x01a3, 0x0210, 0x029a, 0x0347, 0x0421, 0x0533,
819                 0x068d, 0x0841, 0x0a66, 0x0d1a, 0x1082, 0x14cd, 0x1a35, 0x2105,
820                 0x299a, 0x346a, 0x4209, 0x5333
821             },
822             {   //Intra Chroma
823                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
824                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
825                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
826                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001,
827                 0x0001, 0x0001, 0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0005,
828                 0x0007, 0x0008, 0x000a, 0x000d, 0x0011, 0x0015, 0x001a, 0x0021,
829                 0x002a, 0x0034, 0x0042, 0x0053, 0x0069, 0x0084, 0x00a6, 0x00d2,
830                 0x0108, 0x014d, 0x01a3, 0x0210, 0x029a, 0x0347, 0x0421, 0x0533,
831                 0x068d, 0x0841, 0x0a66, 0x0d1a, 0x1082, 0x14cd, 0x1a35, 0x2105,
832                 0x299a, 0x346a, 0x4209, 0x5333
833             },
834         }},
835         {{
836             {   //Inter Luma
837                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
838                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
839                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
840                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
841                 0x0003, 0x0004, 0x0006, 0x0007, 0x0009, 0x000b, 0x000e, 0x0012,
842                 0x0016, 0x001c, 0x0023, 0x002c, 0x0038, 0x0046, 0x0059, 0x0075,
843                 0x009b, 0x00cc, 0x010c, 0x0160, 0x01cd, 0x025b, 0x0314, 0x0405,
844                 0x053d, 0x06d2, 0x08df, 0x0b2d, 0x0e14, 0x11bd, 0x165a, 0x1c29,
845                 0x237b, 0x2cb4, 0x3852, 0x46f5, 0x5967, 0x70a4, 0x8deb, 0xb2ce,
846                 0xe148, 0xffff, 0xffff, 0xffff
847             },
848             {   //Inter Chroma
849                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
850                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
851                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
852                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
853                 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000b, 0x000d, 0x0011,
854                 0x0015, 0x001b, 0x0021, 0x002a, 0x0035, 0x0043, 0x0054, 0x006c,
855                 0x008c, 0x00b4, 0x00e7, 0x0129, 0x017d, 0x01ea, 0x0275, 0x0327,
856                 0x040c, 0x0530, 0x06a7, 0x0862, 0x0a8f, 0x0d4e, 0x10c3, 0x151f,
857                 0x1a9c, 0x2187, 0x2a3d, 0x3538, 0x430d, 0x547b, 0x6a70, 0x861b,
858                 0xa8f6, 0xd4e0, 0xffff, 0xffff
859             },
860         }},
861     }},
862     {{
863         {{
864             {   //Intra Luma
865                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
866                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
867                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
868                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
869                 0x0003, 0x0004, 0x0006, 0x0007, 0x0009, 0x000b, 0x000e, 0x0012,
870                 0x0016, 0x001c, 0x0023, 0x002c, 0x0038, 0x0046, 0x0059, 0x0075,
871                 0x009b, 0x00cc, 0x010c, 0x0160, 0x01cd, 0x025b, 0x0314, 0x0405,
872                 0x053d, 0x06d2, 0x08df, 0x0b2d, 0x0e14, 0x11bd, 0x165a, 0x1c29,
873                 0x237b, 0x2cb4, 0x3852, 0x46f5, 0x5967, 0x70a4, 0x8deb, 0xb2ce,
874                 0xe148, 0xffff, 0xffff, 0xffff
875             },
876             {   //Intra Chroma
877                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
878                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
879                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
880                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
881                 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000b, 0x000d, 0x0011,
882                 0x0015, 0x001b, 0x0021, 0x002a, 0x0035, 0x0043, 0x0054, 0x006c,
883                 0x008c, 0x00b4, 0x00e7, 0x0129, 0x017d, 0x01ea, 0x0275, 0x0327,
884                 0x040c, 0x0530, 0x06a7, 0x0862, 0x0a8f, 0x0d4e, 0x10c3, 0x151f,
885                 0x1a9c, 0x2187, 0x2a3d, 0x3538, 0x430d, 0x547b, 0x6a70, 0x861b,
886                 0xa8f6, 0xd4e0, 0xffff, 0xffff
887             },
888         }},
889         {{
890             {   //Inter Luma
891                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
892                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
893                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
894                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
895                 0x0003, 0x0004, 0x0006, 0x0007, 0x0009, 0x000b, 0x000e, 0x0012,
896                 0x0016, 0x001c, 0x0023, 0x002c, 0x0038, 0x0046, 0x0059, 0x0075,
897                 0x009b, 0x00cc, 0x010c, 0x0160, 0x01cd, 0x025b, 0x0314, 0x0405,
898                 0x053d, 0x06d2, 0x08df, 0x0b2d, 0x0e14, 0x11bd, 0x165a, 0x1c29,
899                 0x237b, 0x2cb4, 0x3852, 0x46f5, 0x5967, 0x70a4, 0x8deb, 0xb2ce,
900                 0xe148, 0xffff, 0xffff, 0xffff
901             },
902             {   //Inter Chroma
903                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
904                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
905                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
906                 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003,
907                 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000b, 0x000d, 0x0011,
908                 0x0015, 0x001b, 0x0021, 0x002a, 0x0035, 0x0043, 0x0054, 0x006c,
909                 0x008c, 0x00b4, 0x00e7, 0x0129, 0x017d, 0x01ea, 0x0275, 0x0327,
910                 0x040c, 0x0530, 0x06a7, 0x0862, 0x0a8f, 0x0d4e, 0x10c3, 0x151f,
911                 0x1a9c, 0x2187, 0x2a3d, 0x3538, 0x430d, 0x547b, 0x6a70, 0x861b,
912                 0xa8f6, 0xd4e0, 0xffff, 0xffff
913             },
914         }},
915     }}
916 }};
917 
918     return MOS_STATUS_SUCCESS;
919 }
920 
SetVdencStreaminStateSettings()921 MOS_STATUS EncodeHevcVdencConstSettings::SetVdencStreaminStateSettings()
922 {
923     ENCODE_FUNC_CALL();
924 
925     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
926     ENCODE_CHK_NULL_RETURN(setting);
927 
928     setting->vdencStreaminStateSettings.emplace_back(
929         VDENC_STREAMIN_STATE_LAMBDA() {
930             static const std::array<
931                 std::array<
932                     uint8_t,
933                     NUM_TARGET_USAGE_MODES + 1>,
934                 4>
935                 numMergeCandidates = {{
936                     {0, 1, 1, 1, 1, 1, 2, 2},
937                     {0, 2, 2, 2, 2, 2, 2, 2},
938                     {0, 3, 3, 3, 3, 3, 2, 2},
939                     {0, 4, 4, 4, 4, 4, 2, 2},
940                 }};
941 
942             static const std::array<
943                 uint8_t,
944                 NUM_TARGET_USAGE_MODES + 1>
945                 numImePredictors = {0, 8, 8, 8, 8, 8, 4, 4};
946 
947             par.maxTuSize                = 3;  //Maximum TU Size allowed, restriction to be set to 3
948             par.maxCuSize                = (cu64Align) ? 3 : 2;
949             par.numMergeCandidateCu64x64 = numMergeCandidates[3][m_hevcSeqParams->TargetUsage];
950             par.numMergeCandidateCu32x32 = numMergeCandidates[2][m_hevcSeqParams->TargetUsage];
951             par.numMergeCandidateCu16x16 = numMergeCandidates[1][m_hevcSeqParams->TargetUsage];
952             par.numMergeCandidateCu8x8   = numMergeCandidates[0][m_hevcSeqParams->TargetUsage];
953             par.numImePredictors         = numImePredictors[m_hevcSeqParams->TargetUsage];
954 
955             auto waTable = m_osItf == nullptr ? nullptr : m_osItf->pfnGetWaTable(m_osItf);
956             if (waTable)
957             {
958                 if (MEDIA_IS_WA(waTable, WaHEVCVDEncROINumMergeCandidateSetting) && m_hevcSeqParams->TargetUsage == 4)
959                 {
960                     par.numMergeCandidateCu64x64 = 3;
961                     par.numMergeCandidateCu32x32 = 3;
962                     par.numMergeCandidateCu16x16 = 2;
963                     par.numMergeCandidateCu8x8   = 1;
964                 }
965 
966                 ENCODE_CHK_NULL_RETURN(m_osItf);
967                 if (MEDIA_IS_WA(waTable, Wa_22011549751) && m_hevcPicParams->CodingType == I_TYPE && !m_osItf->bSimIsActive && !Mos_Solo_Extension((MOS_CONTEXT_HANDLE)m_osItf->pOsContext) && !m_hevcPicParams->pps_curr_pic_ref_enabled_flag)
968                 {
969                     par.numMergeCandidateCu64x64 = 0;
970                     par.numMergeCandidateCu32x32 = 0;
971                     par.numMergeCandidateCu16x16 = 0;
972                     par.numMergeCandidateCu8x8   = 2;
973                     par.numImePredictors         = 0;
974                 }
975             }
976 
977             return MOS_STATUS_SUCCESS;
978         });
979 
980     return MOS_STATUS_SUCCESS;
981 }
982 
SetVdencCmd1Settings()983 MOS_STATUS EncodeHevcVdencConstSettings::SetVdencCmd1Settings()
984 {
985     ENCODE_FUNC_CALL();
986     ENCODE_CHK_NULL_RETURN(m_featureSetting);
987 
988     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
989     ENCODE_CHK_NULL_RETURN(setting);
990 
991     setting->vdencCmd1Settings = {
992         VDENC_CMD1_LAMBDA()
993         {
994             static constexpr std::array<std::array<double, 4>, 2> ConstTable1 =
995             {{
996                 {0.68445, 1.03428, 1.17, 1.17},
997                 {0.7605, 0.9464, 0.9464, 1.04}
998             }};
999 
1000             static constexpr std::array<double, 13> LowDelayTable =
1001             {
1002                 0.7048, 0.763533, 0.822267, 0.881, 0.939733, 0.998467,
1003                 1.0572, 1.11593, 1.17467, 1.2334, 1.29213, 1.35087, 1.4096
1004             };
1005 
1006             static constexpr std::array<double, 52> ConstTable2 =
1007             {
1008                 1.000000,  1.000000,  1.000000,  1.000000,  1.000000,
1009                 1.000000,  1.000000,  1.000000,  1.000000,  1.000000,
1010                 1.000000,  1.000000,  1.259921,  1.587401,  2.000000,
1011                 2.519842,  3.174802,  4.000000,  5.039684,  6.349604,
1012                 8.000000,  10.079368, 12.699208, 16.000000, 20.158737,
1013                 25.398417, 32.000000, 40.317474, 50.796834, 64.000000,
1014                 80.634947, 101.593667, 128.0000, 161.269894, 203.187335,
1015                 256.00000, 322.539789, 406.374669, 512.0000, 645.079578,
1016                 812.749339, 1024.0000, 1290.159155, 1625.498677, 2048.0,
1017                 2580.31831, 3250.997354, 4096.0000, 5160.636620, 6501.994709, 8192
1018             };
1019 
1020             double doubleNum0;
1021 
1022             uint32_t bGopSize = m_hevcSeqParams->GopRefDist;
1023             int32_t  depth    = m_hevcPicParams->HierarchLevelPlus1 ? m_hevcPicParams->HierarchLevelPlus1 - 1 : 0;
1024             uint8_t  qp       = m_hevcPicParams->QpY + m_hevcSliceParams->slice_qp_delta;
1025 
1026             if (m_hevcSeqParams->LowDelayMode)
1027             {
1028                 if (m_hevcPicParams->CodingType == I_TYPE)
1029                 {
1030                     doubleNum0 = 0.4845;
1031                 }
1032                 else
1033                 {
1034                     if (depth == 0)
1035                     {
1036                         doubleNum0 = 0.578;
1037                     }
1038                     else
1039                     {
1040                         int tmp = CLIP3(24, 36, qp);
1041                         doubleNum0 = LowDelayTable[tmp - 24];
1042                     }
1043                 }
1044             }
1045             else
1046             {
1047                 if (m_hevcPicParams->CodingType == I_TYPE)
1048                 {
1049                     doubleNum0 = 0.60;
1050                 }
1051                 else if (m_hevcPicParams->CodingType == B_TYPE && bGopSize == 4)
1052                 {
1053                     doubleNum0 = ConstTable1[0][depth];
1054                 }
1055                 else if (m_hevcPicParams->CodingType == B_TYPE && bGopSize == 8)
1056                 {
1057                     doubleNum0 = ConstTable1[1][depth];
1058                 }
1059                 else
1060                 {
1061                     doubleNum0 = 0.65;
1062                 }
1063             }
1064 
1065             double doubleNum1 = doubleNum0 * ConstTable2[qp - 1];
1066             par.vdencCmd1Par0 = (uint16_t)(MOS_MIN(65535, doubleNum1 * 4 + 0.5));
1067 
1068             doubleNum1 = sqrt(doubleNum1);
1069             par.vdencCmd1Par1 = (uint16_t)(MOS_MIN(65535, doubleNum1 * 4 + 0.5));
1070 
1071             par.vdencCmd1Par2[0] = 0;
1072             par.vdencCmd1Par2[1] = 2;
1073             par.vdencCmd1Par2[2] = 3;
1074             par.vdencCmd1Par2[3] = 5;
1075             par.vdencCmd1Par2[4] = 6;
1076             par.vdencCmd1Par2[5] = 8;
1077             par.vdencCmd1Par2[6] = 9;
1078             par.vdencCmd1Par2[7] = 11;
1079 
1080             return MOS_STATUS_SUCCESS;
1081         },
1082         VDENC_CMD1_LAMBDA()
1083         {
1084             static const std::array<uint8_t, 12> data = {
1085                 4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92
1086             };
1087 
1088             for (size_t i = 0; i < data.size(); i++)
1089             {
1090                 par.vdencCmd1Par3[i] = data[i];
1091                 par.vdencCmd1Par4[i] = data[i];
1092             }
1093 
1094             return MOS_STATUS_SUCCESS;
1095         },
1096         VDENC_CMD1_LAMBDA()
1097         {
1098             par.vdencCmd1Par22 = 4;
1099 
1100             return MOS_STATUS_SUCCESS;
1101         },
1102         VDENC_CMD1_LAMBDA()
1103         {
1104             par.vdencCmd1Par24 = 0;
1105             par.vdencCmd1Par25 = 0;
1106             par.vdencCmd1Par26 = 0;
1107             par.vdencCmd1Par27 = 0;
1108             par.vdencCmd1Par28 = 0;
1109             par.vdencCmd1Par29 = 0;
1110             par.vdencCmd1Par30 = 0;
1111             par.vdencCmd1Par31 = 0;
1112 
1113             return MOS_STATUS_SUCCESS;
1114         },
1115         VDENC_CMD1_LAMBDA()
1116         {
1117             par.vdencCmd1Par32 = 0;
1118             par.vdencCmd1Par33 = 0;
1119 
1120             if (m_hevcPicParams->CodingType == I_TYPE)
1121             {
1122                 par.vdencCmd1Par34 = 21;
1123                 par.vdencCmd1Par35 = 0;
1124             }
1125             else
1126             {
1127                 par.vdencCmd1Par34 = 7;
1128                 par.vdencCmd1Par35 = 4;
1129             }
1130 
1131             return MOS_STATUS_SUCCESS;
1132         },
1133         VDENC_CMD1_LAMBDA()
1134         {
1135             par.vdencCmd1Par44 = 0;
1136             par.vdencCmd1Par45 = 20;
1137             par.vdencCmd1Par46 = 0;
1138 
1139             return MOS_STATUS_SUCCESS;
1140         },
1141         VDENC_CMD1_LAMBDA()
1142         {
1143             par.vdencCmd1Par47 = 12;
1144             par.vdencCmd1Par48 = 12;
1145             par.vdencCmd1Par49 = 12;
1146             par.vdencCmd1Par50 = 12;
1147             par.vdencCmd1Par51 = 12;
1148             par.vdencCmd1Par52 = 12;
1149             par.vdencCmd1Par53 = 12;
1150             par.vdencCmd1Par54 = 12;
1151 
1152             return MOS_STATUS_SUCCESS;
1153         },
1154         VDENC_CMD1_LAMBDA()
1155         {
1156             par.vdencCmd1Par55 = 0x10;
1157             par.vdencCmd1Par56 = 0x10;
1158             par.vdencCmd1Par57 = 0x10;
1159             par.vdencCmd1Par58 = 0x10;
1160             par.vdencCmd1Par59 = 0x10;
1161             par.vdencCmd1Par60 = 0x10;
1162             par.vdencCmd1Par61 = 0x10;
1163             par.vdencCmd1Par62 = 0x10;
1164             par.vdencCmd1Par63 = 0x10;
1165             par.vdencCmd1Par64 = 0x10;
1166             par.vdencCmd1Par65 = 0x10;
1167             par.vdencCmd1Par66 = 0x10;
1168             par.vdencCmd1Par67 = 0x10;
1169             par.vdencCmd1Par68 = 0x10;
1170             par.vdencCmd1Par69 = 0x10;
1171             par.vdencCmd1Par70 = 0x10;
1172             par.vdencCmd1Par71 = 0x10;
1173             par.vdencCmd1Par72 = 0x10;
1174             par.vdencCmd1Par73 = 0x10;
1175             par.vdencCmd1Par74 = 0x10;
1176             par.vdencCmd1Par75 = 0x10;
1177             par.vdencCmd1Par76 = 0x10;
1178             par.vdencCmd1Par77 = 0x10;
1179             par.vdencCmd1Par78 = 0x10;
1180             par.vdencCmd1Par79 = 0x10;
1181             par.vdencCmd1Par80 = 0x10;
1182             par.vdencCmd1Par81 = 0x10;
1183             par.vdencCmd1Par82 = 0x10;
1184             par.vdencCmd1Par83 = 0x10;
1185             par.vdencCmd1Par84 = 0x10;
1186             par.vdencCmd1Par85 = 0x10;
1187             par.vdencCmd1Par86 = 0x10;
1188 
1189             return MOS_STATUS_SUCCESS;
1190         },
1191         VDENC_CMD1_LAMBDA()
1192         {
1193             if (m_hevcPicParams->CodingType == I_TYPE)
1194             {
1195                 par.vdencCmd1Par87 = 16;
1196                 par.vdencCmd1Par88 = 16;
1197                 par.vdencCmd1Par89 = 47;
1198             }
1199             else if (m_hevcPicParams->CodingType == B_TYPE)
1200             {
1201                 par.vdencCmd1Par87 = 20;
1202                 par.vdencCmd1Par88 = 20;
1203                 par.vdencCmd1Par89 = 20;
1204             }
1205 
1206             return MOS_STATUS_SUCCESS;
1207         }
1208     };
1209 
1210     return MOS_STATUS_SUCCESS;
1211 }
1212 
SetBrcSettings()1213 MOS_STATUS EncodeHevcVdencConstSettings::SetBrcSettings()
1214 {
1215     ENCODE_FUNC_CALL();
1216     ENCODE_CHK_NULL_RETURN(m_featureSetting);
1217 
1218     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
1219     ENCODE_CHK_NULL_RETURN(setting);
1220 
1221     setting->brcSettings.HevcVdencBrcSettings_0.data = (void *)m_brcSettings.HevcVdencBrcConstSettings_0;
1222     setting->brcSettings.HevcVdencBrcSettings_0.size = sizeof(m_brcSettings.HevcVdencBrcConstSettings_0);
1223     setting->brcSettings.HevcVdencBrcSettings_1.data = (void *)m_brcSettings.HevcVdencBrcConstSettings_1;
1224     setting->brcSettings.HevcVdencBrcSettings_1.size = sizeof(m_brcSettings.HevcVdencBrcConstSettings_1);
1225 
1226     setting->brcSettings.estRateThreshP0.data = (void *)m_brcSettings.m_estRateThreshP0;
1227     setting->brcSettings.estRateThreshP0.size = sizeof(m_brcSettings.m_estRateThreshP0);
1228 
1229     setting->brcSettings.estRateThreshB0.data = (void *)m_brcSettings.m_estRateThreshB0;
1230     setting->brcSettings.estRateThreshB0.size = sizeof(m_brcSettings.m_estRateThreshB0);
1231 
1232     setting->brcSettings.estRateThreshI0.data = (void *)m_brcSettings.m_estRateThreshI0;
1233     setting->brcSettings.estRateThreshI0.size = sizeof(m_brcSettings.m_estRateThreshI0);
1234 
1235     setting->brcSettings.instRateThreshP0.data = (void *)m_brcSettings.m_instRateThreshP0;
1236     setting->brcSettings.instRateThreshP0.size = sizeof(m_brcSettings.m_instRateThreshP0);
1237 
1238     setting->brcSettings.instRateThreshB0.data = (void *)m_brcSettings.m_instRateThreshB0;
1239     setting->brcSettings.instRateThreshB0.size = sizeof(m_brcSettings.m_instRateThreshB0);
1240 
1241     setting->brcSettings.instRateThreshI0.data = (void *)m_brcSettings.m_instRateThreshI0;
1242     setting->brcSettings.instRateThreshI0.size = sizeof(m_brcSettings.m_instRateThreshI0);
1243 
1244     setting->brcSettings.devThreshIFPNEG.data = (void *)m_brcSettings.m_devThreshIFPNEG;
1245     setting->brcSettings.devThreshIFPNEG.size = sizeof(m_brcSettings.m_devThreshIFPNEG);
1246 
1247     setting->brcSettings.devThreshIFPPOS.data = (void *)m_brcSettings.m_devThreshIFPPOS;
1248     setting->brcSettings.devThreshIFPPOS.size = sizeof(m_brcSettings.m_devThreshIFPPOS);
1249 
1250     setting->brcSettings.devThreshPBFPNEG.data = (void *)m_brcSettings.m_devThreshPBFPNEG;
1251     setting->brcSettings.devThreshPBFPNEG.size = sizeof(m_brcSettings.m_devThreshPBFPNEG);
1252 
1253     setting->brcSettings.devThreshPBFPPOS.data = (void *)m_brcSettings.m_devThreshPBFPPOS;
1254     setting->brcSettings.devThreshPBFPPOS.size = sizeof(m_brcSettings.m_devThreshPBFPPOS);
1255 
1256     setting->brcSettings.devThreshVBRNEG.data = (void *)m_brcSettings.m_devThreshVBRNEG;
1257     setting->brcSettings.devThreshVBRNEG.size = sizeof(m_brcSettings.m_devThreshVBRNEG);
1258 
1259     setting->brcSettings.devThreshVBRPOS.data = (void *)m_brcSettings.m_devThreshVBRPOS;
1260     setting->brcSettings.devThreshVBRPOS.size = sizeof(m_brcSettings.m_devThreshVBRPOS);
1261 
1262     setting->brcSettings.lowdelayDevThreshPB.data = (void *)m_brcSettings.m_lowdelayDevThreshPB;
1263     setting->brcSettings.lowdelayDevThreshPB.size = sizeof(m_brcSettings.m_lowdelayDevThreshPB);
1264 
1265     setting->brcSettings.lowdelayDevThreshVBR.data = (void *)m_brcSettings.m_lowdelayDevThreshVBR;
1266     setting->brcSettings.lowdelayDevThreshVBR.size = sizeof(m_brcSettings.m_lowdelayDevThreshVBR);
1267 
1268     setting->brcSettings.lowdelayDevThreshI.data = (void *)m_brcSettings.m_lowdelayDevThreshI;
1269     setting->brcSettings.lowdelayDevThreshI.size = sizeof(m_brcSettings.m_lowdelayDevThreshI);
1270 
1271     setting->brcSettings.startGAdjFrame.data = (void *)m_brcSettings.m_startGAdjFrame;
1272     setting->brcSettings.startGAdjFrame.size = sizeof(m_brcSettings.m_startGAdjFrame);
1273 
1274     setting->brcSettings.numDevThreshlds = m_brcSettings.m_numDevThreshlds;
1275     setting->brcSettings.devStdFPS = m_brcSettings.m_devStdFPS;
1276     setting->brcSettings.bpsRatioLow = m_brcSettings.m_bpsRatioLow;
1277     setting->brcSettings.bpsRatioHigh = m_brcSettings.m_bpsRatioHigh;
1278     setting->brcSettings.postMultPB = m_brcSettings.m_postMultPB;
1279     setting->brcSettings.negMultPB = m_brcSettings.m_negMultPB;
1280     setting->brcSettings.posMultVBR = m_brcSettings.m_posMultVBR;
1281     setting->brcSettings.negMultVBR = m_brcSettings.m_negMultVBR;
1282 
1283     setting->brcSettings.hucConstantData.data = (void *)m_brcSettings.m_hucConstantData;
1284     setting->brcSettings.hucConstantData.size = sizeof(m_brcSettings.m_hucConstantData);
1285 
1286     setting->brcSettings.HevcVdencBrcSettings_2.data = (void *)m_brcSettings.HevcVdencBrcConstSettings_2;
1287     setting->brcSettings.HevcVdencBrcSettings_2.size = sizeof(m_brcSettings.HevcVdencBrcConstSettings_2);
1288 
1289     setting->brcSettings.HevcVdencBrcSettings_3.data = (void *)m_brcSettings.HevcVdencBrcConstSettings_3;
1290     setting->brcSettings.HevcVdencBrcSettings_3.size = sizeof(m_brcSettings.HevcVdencBrcConstSettings_3);
1291 
1292     setting->brcSettings.HevcVdencBrcSettings_7.data = (void *)m_brcSettings.HevcVdencBrcConstSettings_7;
1293     setting->brcSettings.HevcVdencBrcSettings_7.size = sizeof(m_brcSettings.HevcVdencBrcConstSettings_7);
1294 
1295     setting->brcSettings.HevcVdencBrcSettings_8.data = (void *)m_brcSettings.HevcVdencBrcConstSettings_8;
1296     setting->brcSettings.HevcVdencBrcSettings_8.size = sizeof(m_brcSettings.HevcVdencBrcConstSettings_8);
1297 
1298     setting->brcSettings.HevcVdencBrcSettings_4 = (int8_t(*)[9][8])m_brcSettings.HevcVdencBrcConstSettings_4;
1299 
1300     setting->brcSettings.HevcVdencBrcSettings_5 = (int8_t(*)[9][8])m_brcSettings.HevcVdencBrcConstSettings_5;
1301 
1302     setting->brcSettings.HevcVdencBrcSettings_6 = (int8_t(*)[9][8])m_brcSettings.HevcVdencBrcConstSettings_6;
1303 
1304     setting->brcSettings.rateRatioThreshold.data = (void *)m_brcSettings.m_rateRatioThreshold;
1305     setting->brcSettings.rateRatioThreshold.size = sizeof(m_brcSettings.m_rateRatioThreshold);
1306 
1307     setting->brcSettings.startGAdjMult.data = (void *)m_brcSettings.m_startGAdjMult;
1308     setting->brcSettings.startGAdjMult.size = sizeof(m_brcSettings.m_startGAdjMult);
1309 
1310     setting->brcSettings.startGAdjDiv.data = (void *)m_brcSettings.m_startGAdjDiv;
1311     setting->brcSettings.startGAdjDiv.size = sizeof(m_brcSettings.m_startGAdjDiv);
1312 
1313     setting->brcSettings.rateRatioThresholdQP.data = (void *)m_brcSettings.m_rateRatioThresholdQP;
1314     setting->brcSettings.rateRatioThresholdQP.size = sizeof(m_brcSettings.m_rateRatioThresholdQP);
1315 
1316     setting->brcSettings.topFrmSzThrForAdapt2Pass_U8 = m_brcSettings.m_topFrmSzThrForAdapt2Pass_U8;
1317     setting->brcSettings.botFrmSzThrForAdapt2Pass_U8 = m_brcSettings.m_botFrmSzThrForAdapt2Pass_U8;
1318 
1319     setting->brcSettings.topQPDeltaThrForAdapt2Pass_U8 = m_brcSettings.m_topQPDeltaThrForAdapt2Pass_U8;
1320     setting->brcSettings.botQPDeltaThrForAdapt2Pass_U8 = m_brcSettings.m_botQPDeltaThrForAdapt2Pass_U8;
1321 
1322     setting->brcSettings.deltaQPForSadZone0_S8 = m_brcSettings.m_deltaQPForSadZone0_S8;
1323     setting->brcSettings.deltaQPForSadZone1_S8 = m_brcSettings.m_deltaQPForSadZone1_S8;
1324     setting->brcSettings.deltaQPForSadZone2_S8 = m_brcSettings.m_deltaQPForSadZone2_S8;
1325     setting->brcSettings.deltaQPForSadZone3_S8 = m_brcSettings.m_deltaQPForSadZone3_S8;
1326     setting->brcSettings.deltaQPForMvZero_S8 = m_brcSettings.m_deltaQPForMvZero_S8;
1327     setting->brcSettings.deltaQPForMvZone0_S8 = m_brcSettings.m_deltaQPForMvZone0_S8;
1328     setting->brcSettings.deltaQPForMvZone1_S8 = m_brcSettings.m_deltaQPForMvZone1_S8;
1329     setting->brcSettings.deltaQPForMvZone2_S8 = m_brcSettings.m_deltaQPForMvZone2_S8;
1330 
1331     setting->brcSettings.reEncodePositiveQPDeltaThr_S8 = m_brcSettings.m_reEncodePositiveQPDeltaThr_S8;
1332     setting->brcSettings.reEncodeNegativeQPDeltaThr_S8 = m_brcSettings.m_reEncodeNegativeQPDeltaThr_S8;
1333     setting->brcSettings.sceneChgPrevIntraPctThreshold_U8 = m_brcSettings.m_sceneChgPrevIntraPctThreshold_U8;
1334     setting->brcSettings.sceneChgCurIntraPctThreshold_U8 = m_brcSettings.m_sceneChgCurIntraPctThreshold_U8;
1335 
1336     return MOS_STATUS_SUCCESS;
1337 }
1338 
SetLaTUSettings()1339 MOS_STATUS EncodeHevcVdencConstSettings::SetLaTUSettings()
1340 {
1341     ENCODE_FUNC_CALL();
1342     ENCODE_CHK_NULL_RETURN(m_featureSetting);
1343     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
1344 
1345     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
1346     ENCODE_CHK_NULL_RETURN(setting);
1347 
1348     setting->rdoqLaEnable = {true, true, true, true, true, true, true, true};
1349     setting->acqpLaEnable = {true, true, true, true, true, true, true, false};
1350 
1351     return eStatus;
1352 }
1353 
SetVdencLaCmd1Settings()1354 MOS_STATUS EncodeHevcVdencConstSettings::SetVdencLaCmd1Settings()
1355 {
1356     ENCODE_FUNC_CALL();
1357     ENCODE_CHK_NULL_RETURN(m_featureSetting);
1358 
1359     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
1360     ENCODE_CHK_NULL_RETURN(setting);
1361 
1362     setting->vdencLaCmd1Settings = {
1363         VDENC_CMD1_LAMBDA()
1364         {
1365             static constexpr std::array<std::array<double, 4>, 2> ConstTable1 =
1366             {{
1367                 {0.68445, 1.03428, 1.17, 1.17},
1368                 {0.7605, 0.9464, 0.9464, 1.04}
1369             }};
1370 
1371             static constexpr std::array<double, 13> LowDelayTable =
1372             {
1373                 0.7048, 0.763533, 0.822267, 0.881, 0.939733, 0.998467,
1374                 1.0572, 1.11593, 1.17467, 1.2334, 1.29213, 1.35087, 1.4096
1375             };
1376 
1377             static constexpr std::array<double, 52> ConstTable2 =
1378             {
1379                 1.000000,  1.000000,  1.000000,  1.000000,  1.000000,
1380                 1.000000,  1.000000,  1.000000,  1.000000,  1.000000,
1381                 1.000000,  1.000000,  1.259921,  1.587401,  2.000000,
1382                 2.519842,  3.174802,  4.000000,  5.039684,  6.349604,
1383                 8.000000,  10.079368, 12.699208, 16.000000, 20.158737,
1384                 25.398417, 32.000000, 40.317474, 50.796834, 64.000000,
1385                 80.634947, 101.593667, 128.0000, 161.269894, 203.187335,
1386                 256.00000, 322.539789, 406.374669, 512.0000, 645.079578,
1387                 812.749339, 1024.0000, 1290.159155, 1625.498677, 2048.0,
1388                 2580.31831, 3250.997354, 4096.0000, 5160.636620, 6501.994709, 8192
1389             };
1390 
1391             double doubleNum0;
1392 
1393             uint32_t bGopSize = m_hevcSeqParams->GopRefDist;
1394             int32_t  depth    = m_hevcPicParams->HierarchLevelPlus1 ? m_hevcPicParams->HierarchLevelPlus1 - 1 : 0;
1395             uint8_t  qp       = m_hevcPicParams->QpY + m_hevcSliceParams->slice_qp_delta;
1396 
1397             if (m_hevcSeqParams->LowDelayMode)
1398             {
1399                 if (m_hevcPicParams->CodingType == I_TYPE)
1400                 {
1401                     doubleNum0 = 0.4845;
1402                 }
1403                 else
1404                 {
1405                     if (depth == 0)
1406                     {
1407                         doubleNum0 = 0.578;
1408                     }
1409                     else
1410                     {
1411                         int tmp = CLIP3(24, 36, qp);
1412                         doubleNum0 = LowDelayTable[tmp - 24];
1413                     }
1414                 }
1415             }
1416             else
1417             {
1418                 if (m_hevcPicParams->CodingType == I_TYPE)
1419                 {
1420                     doubleNum0 = 0.60;
1421                 }
1422                 else if (m_hevcPicParams->CodingType == B_TYPE && bGopSize == 4)
1423                 {
1424                     doubleNum0 = ConstTable1[0][depth];
1425                 }
1426                 else if (m_hevcPicParams->CodingType == B_TYPE && bGopSize == 8)
1427                 {
1428                     doubleNum0 = ConstTable1[1][depth];
1429                 }
1430                 else
1431                 {
1432                     doubleNum0 = 0.65;
1433                 }
1434             }
1435 
1436             double doubleNum1 = doubleNum0 * ConstTable2[qp - 1];
1437             par.vdencCmd1Par0 = (uint16_t)(MOS_MIN(65535, doubleNum1 * 4 + 0.5));
1438 
1439             doubleNum1 = sqrt(doubleNum1);
1440             par.vdencCmd1Par1 = (uint16_t)(MOS_MIN(65535, doubleNum1 * 4 + 0.5));
1441 
1442             par.vdencCmd1Par2[0] = 0;
1443             par.vdencCmd1Par2[1] = 2;
1444             par.vdencCmd1Par2[2] = 3;
1445             par.vdencCmd1Par2[3] = 5;
1446             par.vdencCmd1Par2[4] = 6;
1447             par.vdencCmd1Par2[5] = 8;
1448             par.vdencCmd1Par2[6] = 9;
1449             par.vdencCmd1Par2[7] = 11;
1450 
1451             return MOS_STATUS_SUCCESS;
1452         },
1453         VDENC_CMD1_LAMBDA()
1454         {
1455             static const std::array<uint8_t, 12> data = {
1456                 4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92
1457             };
1458 
1459             for (size_t i = 0; i < data.size(); i++)
1460             {
1461                 par.vdencCmd1Par3[i] = data[i];
1462             }
1463 
1464             return MOS_STATUS_SUCCESS;
1465         },
1466         VDENC_CMD1_LAMBDA()
1467         {
1468             static const std::array<uint8_t, 12> data = {
1469                 3, 10, 16, 22, 29, 35, 42, 48, 54, 61, 67, 74};
1470 
1471             for (size_t i = 0; i < data.size(); i++)
1472             {
1473                 par.vdencCmd1Par4[i] = data[i];
1474             }
1475 
1476             return MOS_STATUS_SUCCESS;
1477         },
1478         VDENC_CMD1_LAMBDA()
1479         {
1480             par.vdencCmd1Par22 = 4;
1481 
1482             return MOS_STATUS_SUCCESS;
1483         },
1484         VDENC_CMD1_LAMBDA()
1485         {
1486             par.vdencCmd1Par24 = 0;
1487             par.vdencCmd1Par25 = 0;
1488             par.vdencCmd1Par26 = 0;
1489             par.vdencCmd1Par27 = 0;
1490             par.vdencCmd1Par28 = 0;
1491             par.vdencCmd1Par29 = 0;
1492             par.vdencCmd1Par30 = 0;
1493             par.vdencCmd1Par31 = 0;
1494 
1495             return MOS_STATUS_SUCCESS;
1496         },
1497         VDENC_CMD1_LAMBDA()
1498         {
1499             par.vdencCmd1Par32 = 0;
1500             par.vdencCmd1Par33 = 0;
1501 
1502             if (m_hevcPicParams->CodingType == I_TYPE)
1503             {
1504                 par.vdencCmd1Par34 = 21;
1505                 par.vdencCmd1Par35 = 0;
1506             }
1507             else
1508             {
1509                 par.vdencCmd1Par34 = 7;
1510                 par.vdencCmd1Par35 = 4;
1511             }
1512 
1513             return MOS_STATUS_SUCCESS;
1514         },
1515         VDENC_CMD1_LAMBDA()
1516         {
1517             par.vdencCmd1Par44 = 0;
1518             par.vdencCmd1Par45 = 20;
1519             par.vdencCmd1Par46 = 0;
1520 
1521             return MOS_STATUS_SUCCESS;
1522         },
1523         VDENC_CMD1_LAMBDA()
1524         {
1525             par.vdencCmd1Par47 = 12;
1526             par.vdencCmd1Par48 = 12;
1527             par.vdencCmd1Par49 = 12;
1528             par.vdencCmd1Par50 = 12;
1529             par.vdencCmd1Par51 = 12;
1530             par.vdencCmd1Par52 = 12;
1531             par.vdencCmd1Par53 = 12;
1532             par.vdencCmd1Par54 = 12;
1533 
1534             return MOS_STATUS_SUCCESS;
1535         },
1536         VDENC_CMD1_LAMBDA()
1537         {
1538             par.vdencCmd1Par55 = 0x0E;
1539             par.vdencCmd1Par56 = 0x0E;
1540             par.vdencCmd1Par57 = 0x0C;
1541             par.vdencCmd1Par58 = 0x0B;
1542             par.vdencCmd1Par59 = 0x10;
1543             par.vdencCmd1Par60 = 0x10;
1544             par.vdencCmd1Par61 = 0x0F;
1545             par.vdencCmd1Par62 = 0x0F;
1546             par.vdencCmd1Par63 = 0x10;
1547             par.vdencCmd1Par64 = 0x10;
1548             par.vdencCmd1Par65 = 0x10;
1549             par.vdencCmd1Par66 = 0x10;
1550             par.vdencCmd1Par67 = 0x14;
1551             par.vdencCmd1Par68 = 0x10;
1552             par.vdencCmd1Par69 = 0x10;
1553             par.vdencCmd1Par70 = 0x10;
1554             par.vdencCmd1Par71 = 0x0C;
1555             par.vdencCmd1Par72 = 0x0C;
1556             par.vdencCmd1Par73 = 0x0A;
1557             par.vdencCmd1Par74 = 0x0A;
1558             par.vdencCmd1Par75 = 0x10;
1559             par.vdencCmd1Par76 = 0x10;
1560             par.vdencCmd1Par77 = 0x10;
1561             par.vdencCmd1Par78 = 0x10;
1562             par.vdencCmd1Par79 = 0x10;
1563             par.vdencCmd1Par80 = 0x10;
1564             par.vdencCmd1Par81 = 0x10;
1565             par.vdencCmd1Par82 = 0x10;
1566             par.vdencCmd1Par83 = 0x10;
1567             par.vdencCmd1Par84 = 0x10;
1568             par.vdencCmd1Par85 = 0x0E;
1569             par.vdencCmd1Par86 = 0x0F;
1570 
1571             return MOS_STATUS_SUCCESS;
1572         },
1573     };
1574 
1575     setting->vdencLaCmd1Settings.emplace_back(
1576         VDENC_CMD1_LAMBDA() {
1577             static const std::array<uint8_t, 16> data = {
1578                 11, 0, 0, 0, 14, 0, 0, 0,
1579                 11, 0, 0, 0, 0, 0, 0, 0
1580             };
1581 
1582             if (m_hevcPicParams->CodingType == I_TYPE)
1583             {
1584                 return MOS_STATUS_SUCCESS;
1585             }
1586 
1587             for (size_t i = 0; i < 4; i++)
1588             {
1589                 par.vdencCmd1Par8[i]  = data[i];
1590                 par.vdencCmd1Par9[i]  = data[i + 4];
1591                 par.vdencCmd1Par10[i] = data[i + 8];
1592                 par.vdencCmd1Par11[i] = data[i + 12];
1593             }
1594 
1595             return MOS_STATUS_SUCCESS;
1596         });
1597 
1598     setting->vdencLaCmd1Settings.emplace_back(
1599         VDENC_CMD1_LAMBDA() {
1600             static const std::array<uint8_t, 16> data = {
1601                 23, 0, 0, 0, 26, 0, 0, 0,
1602                 21, 0, 0, 0, 0, 0, 0, 0
1603             };
1604 
1605             if (m_hevcPicParams->CodingType == I_TYPE)
1606             {
1607                 return MOS_STATUS_SUCCESS;
1608             }
1609 
1610             for (size_t i = 0; i < 4; i++)
1611             {
1612                 par.vdencCmd1Par12[i] = data[i];
1613                 par.vdencCmd1Par13[i] = data[i + 4];
1614                 par.vdencCmd1Par14[i] = data[i + 8];
1615                 par.vdencCmd1Par15[i] = data[i + 12];
1616             }
1617 
1618             return MOS_STATUS_SUCCESS;
1619         });
1620 
1621     setting->vdencLaCmd1Settings.emplace_back(
1622         VDENC_CMD1_LAMBDA() {
1623             if (m_hevcPicParams->CodingType == P_TYPE)
1624             {
1625                 par.vdencCmd1Par16 = 82;
1626                 par.vdencCmd1Par17 = 20;
1627                 par.vdencCmd1Par18 = 83;
1628                 par.vdencCmd1Par19 = 17;
1629                 par.vdencCmd1Par20 = 15;
1630                 par.vdencCmd1Par21 = 0;
1631             }
1632             else if (m_hevcPicParams->CodingType == B_TYPE)
1633             {
1634                 par.vdencCmd1Par16 = 99;
1635                 par.vdencCmd1Par17 = 23;
1636                 par.vdencCmd1Par18 = 99;
1637                 par.vdencCmd1Par19 = 19;
1638                 par.vdencCmd1Par20 = 17;
1639                 par.vdencCmd1Par21 = 0;
1640             }
1641 
1642             return MOS_STATUS_SUCCESS;
1643         });
1644 
1645     setting->vdencLaCmd1Settings.emplace_back(
1646         VDENC_CMD1_LAMBDA() {
1647             if (m_hevcPicParams->CodingType == I_TYPE)
1648             {
1649                 par.vdencCmd1Par23 = 63;
1650             }
1651             else
1652             {
1653                 par.vdencCmd1Par23 = 54;
1654             }
1655 
1656             return MOS_STATUS_SUCCESS;
1657         });
1658 
1659     setting->vdencLaCmd1Settings.emplace_back(
1660         VDENC_CMD1_LAMBDA() {
1661             if (m_hevcPicParams->CodingType == I_TYPE)
1662             {
1663                 par.vdencCmd1Par30 = 12;
1664             }
1665 
1666             return MOS_STATUS_SUCCESS;
1667         });
1668 
1669     setting->vdencLaCmd1Settings.emplace_back(
1670         VDENC_CMD1_LAMBDA() {
1671             if (m_hevcPicParams->CodingType == I_TYPE)
1672             {
1673                 par.vdencCmd1Par36 = 17;
1674                 par.vdencCmd1Par37 = 47;
1675                 par.vdencCmd1Par38 = 20;
1676                 par.vdencCmd1Par39 = 9;
1677                 par.vdencCmd1Par40 = 17;
1678                 par.vdencCmd1Par41 = m_hevcPicParams->NumROI ? 0 : 30;
1679             }
1680             else
1681             {
1682                 par.vdencCmd1Par36 = 7;
1683                 par.vdencCmd1Par37 = 18;
1684                 par.vdencCmd1Par38 = 18;
1685                 par.vdencCmd1Par39 = 18;
1686                 par.vdencCmd1Par40 = 27;
1687                 par.vdencCmd1Par41 = m_hevcPicParams->NumROI ? 0 : 68;
1688             }
1689 
1690             return MOS_STATUS_SUCCESS;
1691         });
1692 
1693     setting->vdencLaCmd1Settings.emplace_back(
1694         VDENC_CMD1_LAMBDA() {
1695             if (m_hevcPicParams->CodingType == P_TYPE)
1696             {
1697                 par.vdencCmd1Par48 = 0;
1698                 par.vdencCmd1Par49 = 32;
1699                 par.vdencCmd1Par50 = 68;
1700             }
1701 
1702             return MOS_STATUS_SUCCESS;
1703         });
1704 
1705     setting->vdencLaCmd1Settings.emplace_back(
1706         VDENC_CMD1_LAMBDA() {
1707             static constexpr std::array<
1708                 std::array<uint8_t,
1709                     3>,
1710                 3>
1711                 data = {{
1712                     {20, 35, 35},
1713                     {20, 35, 35},
1714                     {47, 16, 16}
1715                     }};
1716 
1717             if (m_hevcPicParams->CodingType == I_TYPE)
1718             {
1719                 par.vdencCmd1Par87 = data[2][2];
1720                 par.vdencCmd1Par88 = data[2][1];
1721                 par.vdencCmd1Par89 = data[2][0];
1722             }
1723             else if (m_hevcPicParams->CodingType == P_TYPE)
1724             {
1725                 par.vdencCmd1Par87 = data[1][2];
1726                 par.vdencCmd1Par88 = data[1][1];
1727                 par.vdencCmd1Par89 = data[1][0];
1728             }
1729             else if (m_hevcPicParams->CodingType == B_TYPE)
1730             {
1731                 par.vdencCmd1Par87 = data[0][2];
1732                 par.vdencCmd1Par88 = data[0][1];
1733                 par.vdencCmd1Par89 = data[0][0];
1734             }
1735 
1736             return MOS_STATUS_SUCCESS;
1737         });
1738 
1739     return MOS_STATUS_SUCCESS;
1740 }
1741 
SetVdencLaCmd2Settings()1742 MOS_STATUS EncodeHevcVdencConstSettings::SetVdencLaCmd2Settings()
1743 {
1744 
1745     ENCODE_FUNC_CALL();
1746     ENCODE_CHK_NULL_RETURN(m_featureSetting);
1747 
1748     auto setting = static_cast<HevcVdencFeatureSettings *>(m_featureSetting);
1749     ENCODE_CHK_NULL_RETURN(setting);
1750 
1751 #if !(_MEDIA_RESERVED)
1752     setting->vdencLaCmd2Settings.emplace_back(
1753         VDENC_CMD2_LAMBDA()
1754         {
1755             par.extSettings.emplace_back(
1756                 [this, isLowDelay, &par](uint32_t *data) {
1757                     auto waTable = m_osItf->pfnGetWaTable(m_osItf);
1758                     ENCODE_CHK_NULL_RETURN(waTable);
1759 
1760                     uint32_t CodingTypeMinus1              = m_hevcPicParams->CodingType - 1;
1761                     uint32_t numL0Minus1Is0                = m_hevcSliceParams->num_ref_idx_l0_active_minus1 == 0;
1762                     uint32_t lowDelay                      = isLowDelay;
1763                     uint32_t currPicRef                    = m_hevcPicParams->pps_curr_pic_ref_enabled_flag;
1764                     uint32_t paletteMode                   = m_hevcSeqParams->palette_mode_enabled_flag;
1765                     uint32_t depthMinus8                   = m_hevcSeqParams->bit_depth_luma_minus8;
1766                     uint32_t rdoq                          = m_hevcRdoqEnabled;
1767                     uint32_t numRef0                       = par.numRefL0;
1768                     uint32_t numRef1                       = par.numRefL1;
1769                     uint32_t Wa_22012463389                = MEDIA_IS_WA(waTable, Wa_22012463389);
1770                     uint32_t WaEnableOnlyASteppingFeatures = MEDIA_IS_WA(waTable, WaEnableOnlyASteppingFeatures);
1771                     uint32_t Wa_22011549751                = MEDIA_IS_WA(waTable, Wa_22011549751);
1772                     uint32_t Wa_14010476401                = MEDIA_IS_WA(waTable, Wa_14010476401);
1773                     uint32_t Wa_22011531258                = MEDIA_IS_WA(waTable, Wa_22011531258);
1774 
1775                     static const uint32_t dw2Lut[3][2] = { { 0x3, 0x2,}, { 0x3, 0x3,}, { 0x3, 0x3,},};
1776                     data[2] |= dw2Lut[CodingTypeMinus1][currPicRef];
1777 
1778                     static const uint32_t dw5Lut[3] = { 0xc0a000, 0xc1a000, 0xc0a000,};
1779                     data[5] |= dw5Lut[CodingTypeMinus1];
1780 
1781                     static const uint32_t dw7Lut[3][2][2][2][2] = { { { { { 0x64003, 0xe4003,}, { 0x64003, 0x64003,},}, { { 0x64003, 0xe4003,}, { 0x64003, 0x64003,},},}, { { { 0x64003, 0xe4003,}, { 0x64003, 0x64003,},}, { { 0x64003, 0xe4003,}, { 0x64003, 0x64003,},},},}, { { { { 0x64003, 0x64003,}, { 0x64003, 0x64003,},}, { { 0x64003, 0x64003,}, { 0x64003, 0x64003,},},}, { { { 0x64003, 0x64003,}, { 0x64003, 0x64003,},}, { { 0xe4003, 0xe4003,}, { 0xe4003, 0xe4003,},},},}, { { { { 0x64003, 0x64003,}, { 0x64003, 0x64003,},}, { { 0x64003, 0x64003,}, { 0x64003, 0x64003,},},}, { { { 0x64003, 0x64003,}, { 0x64003, 0x64003,},}, { { 0xe4003, 0xe4003,}, { 0xe4003, 0xe4003,},},},},};
1782                     data[7] |= dw7Lut[CodingTypeMinus1][numL0Minus1Is0][lowDelay][currPicRef][Wa_22011549751];
1783 
1784                     static const uint32_t dw8Lut[3][2] = { { 0x54555555, 0,}, { 0x55550000, 0x55550000,}, { 0x55550000, 0x55550000,},};
1785                     data[8] |= dw8Lut[CodingTypeMinus1][lowDelay];
1786 
1787                     static const uint32_t dw9Lut[3][2][2][2] = { { { { 0x425555, 0x25555, }, { 0x425555, 0x425555, }, }, { { 0x420000, 0x20000, }, { 0x420000, 0x420000, }, },  }, { { { 0x420000, 0x420000, }, { 0x420000, 0x420000, }, }, { { 0x420000, 0x420000, }, { 0x420000, 0x420000, }, },  }, { { { 0x420000, 0x420000, }, { 0x420000, 0x420000, }, }, { { 0x420000, 0x420000, }, { 0x420000, 0x420000, }, }, }, };
1788                     data[9] |= dw9Lut[CodingTypeMinus1][lowDelay][currPicRef][Wa_22011549751];
1789 
1790                     data[12] |= 0x89800dc0;
1791 
1792                     static const uint32_t dw37Lut[2] = { 0, 0x40,};
1793                     data[37] |= dw37Lut[currPicRef];
1794 
1795                     static const uint32_t dw39Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x8000fc, 0x10001f8, 0x20003f0, 0x40007e0, 0x8000fc0,},};
1796                     data[39] |= dw39Lut[paletteMode][depthMinus8];
1797 
1798                     static const uint32_t dw40Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0xb10080, 0x1620100, 0x2c40200, 0x5880400, 0xb100800,},};
1799                     data[40] |= dw40Lut[paletteMode][depthMinus8];
1800 
1801                     static const uint32_t dw41Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x300aa, 0x60154, 0xc02a8, 0x180550, 0x300aa0,},};
1802                     data[41] |= dw41Lut[paletteMode][depthMinus8];
1803 
1804                     static const uint32_t dw42Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0xd30069, 0x1a600d2, 0x34c01a4, 0x6980348, 0xd300690,},};
1805                     data[42] |= dw42Lut[paletteMode][depthMinus8];
1806 
1807                     static const uint32_t dw43Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0xe000e9, 0x1c001d2, 0x38003a4, 0x7000748, 0xe000e90,},};
1808                     data[43] |= dw43Lut[paletteMode][depthMinus8];
1809 
1810                     static const uint32_t dw44Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x940003, 0x1280006, 0x250000c, 0x4a00018, 0x9400030,},};
1811                     data[44] |= dw44Lut[paletteMode][depthMinus8];
1812 
1813                     static const uint32_t dw45Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x56004d, 0xac009a, 0x1580134, 0x2b00268, 0x56004d0,},};
1814                     data[45] |= dw45Lut[paletteMode][depthMinus8];
1815 
1816                     static const uint32_t dw46Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x9500fd, 0x12a01fa, 0x25403f4, 0x4a807e8, 0x9500fd0,},};
1817                     data[46] |= dw46Lut[paletteMode][depthMinus8];
1818 
1819                     static const uint32_t dw47Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x17002d, 0x2e005a, 0x5c00b4, 0xb80168, 0x17002d0,},};
1820                     data[47] |= dw47Lut[paletteMode][depthMinus8];
1821 
1822                     static const uint32_t dw48Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0xfd001f, 0x1fa003e, 0x3f4007c, 0x7e800f8, 0xfd001f0,},};
1823                     data[48] |= dw48Lut[paletteMode][depthMinus8];
1824 
1825                     static const uint32_t dw49Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x2006c, 0x400d8, 0x801b0, 0x100360, 0x2006c0,},};
1826                     data[49] |= dw49Lut[paletteMode][depthMinus8];
1827 
1828                     static const uint32_t dw50Lut[2][5] = { { 0, 0, 0, 0, 0,}, { 0x800080, 0x1000100, 0x2000200, 0x4000400, 0x8000800,},};
1829                     data[50] |= dw50Lut[paletteMode][depthMinus8];
1830 
1831                     static const uint32_t dw51Lut[3][2][2][2][2] = { { { { { 0x22227152, 0x20007152, }, { 0x22227152, 0x20007152, }, }, { { 0x22227152, 0x20007152, }, { 0x22227152, 0x20007152, }, }, }, { { { 0x22227152, 0x22227152, }, { 0x22227152, 0x22227152, }, }, { { 0x22227152, 0x22227152, }, { 0x22227152, 0x22227152, }, }, }, }, { { { { 0x22227152, 0x22227152, }, { 0x20007152, 0x20007152, }, }, { { 0x22227152, 0x22227152, }, { 0x20007152, 0x20007152, }, }, }, { { { 0x22227152, 0x22227152, }, { 0x20007152, 0x20007152, }, }, { { 0x22227152, 0x22227152, }, { 0x20007152, 0x20007152, }, }, }, }, { { { { 0x22227152, 0x22227152, }, { 0x22227152, 0x22227152, }, }, { { 0x22227152, 0x22227152, }, { 0x22227152, 0x22227152, }, }, }, { { { 0x22227152, 0x22227152, }, { 0x22227152, 0x22227152, }, }, { { 0x22227152, 0x22227152, }, { 0x22227152, 0x22227152, }, }, }, }, };
1832                     data[51] |= dw51Lut[CodingTypeMinus1][currPicRef][paletteMode][Wa_22012463389][Wa_22011549751];
1833 
1834                     data[52] |= 0x929595a;
1835 
1836                     static const uint32_t dw53Lut[3][2][2][2][2] = { { { { { 0xffff0000, 0xffff0000, }, { 0x80000000, 0x80000000, }, }, { { 0xffff0000, 0xffff0000, }, { 0x80000000, 0x80000000, }, }, }, { { { 0xffff0000, 0xffff0000, }, { 0xffff0000, 0xffff0000, }, }, { { 0xffff0000, 0xffff0000, }, { 0xffff0000, 0xffff0000, }, }, }, }, { { { { 0xffff0000, 0xfffffff0, }, { 0xffff0000, 0xfffffff0, }, }, { { 0x80000000, 0x80000000, }, { 0x80000000, 0x80000000, }, }, }, { { { 0xffff0000, 0xfffffff0, }, { 0xffff0000, 0xfffffff0, }, }, { { 0x80000000, 0x80000000, }, { 0x80000000, 0x80000000, }, }, }, }, { { { { 0xffff0000, 0xfffffff0, }, { 0xffff0000, 0xfffffff0, }, }, { { 0xffff0000, 0xfffffff0, }, { 0xffff0000, 0xfffffff0, }, }, }, { { { 0xffff0000, 0xfffffff0, }, { 0xffff0000, 0xfffffff0, }, }, { { 0xffff0000, 0xfffffff0, }, { 0xffff0000, 0xfffffff0, }, }, }, }, };
1837                     data[53] |= dw53Lut[CodingTypeMinus1][currPicRef][Wa_22012463389][Wa_22011549751][Wa_14010476401];
1838 
1839                     static const uint32_t dw54Lut[2] = { 0xbc000004, 0x34000004,};
1840                     data[54] |= dw54Lut[Wa_22011531258];
1841 
1842                     static const uint32_t dw55Lut[2] = { 0, 0xcdef0123,};
1843                     data[55] |= dw55Lut[rdoq];
1844 
1845                     static const uint32_t dw56Lut[3][2][2][5][4][2] = { { { { { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0x300, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0x300, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},},}, { { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0x30b, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0x30b, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},},},}, { { { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0x300, 0,},},}, { { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0x30b, 0xb,},},},},}, { { { { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0x300, 0,}, { 0x300, 0,}, { 0x300, 0,}, { 0x300, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},},}, { { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0x30b, 0xb,}, { 0x30b, 0xb,}, { 0x30b, 0xb,}, { 0x30b, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},},},}, { { { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0x300, 0,}, { 0x300, 0,}, { 0x300, 0,}, { 0x300, 0,},},}, { { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0x30b, 0xb,}, { 0x30b, 0xb,}, { 0x30b, 0xb,}, { 0x30b, 0xb,},},},},}, { { { { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0x300, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0x300, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},},}, { { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0x30b, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0x30b, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},},},}, { { { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0, 0,},}, { { 0, 0,}, { 0, 0,}, { 0, 0,}, { 0x300, 0,},},}, { { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,},}, { { 0xb, 0xb,}, { 0xb, 0xb,}, { 0xb, 0xb,}, { 0x30b, 0xb,},},},},},};
1846                     data[56] |= dw56Lut[CodingTypeMinus1][currPicRef][rdoq][numRef0][numRef1][WaEnableOnlyASteppingFeatures];
1847 
1848                     static const uint32_t dw57Lut[2] = { 0, 0x508c23,};
1849                     data[57] |= dw57Lut[rdoq];
1850 
1851                     static const uint32_t dw58Lut[2] = { 0, 0x466419,};
1852                     data[58] |= dw58Lut[rdoq];
1853 
1854                     static const uint32_t dw59Lut[2] = { 0, 0x7d6c5c4b,};
1855                     data[59] |= dw59Lut[rdoq];
1856 
1857                     static const uint32_t dw60Lut[2] = { 0, 0xbfaf9e8e,};
1858                     data[60] |= dw60Lut[rdoq];
1859 
1860                     static const uint32_t dwsLut[] = {0x80000000, 0xf000000, 0x98000000, 0xcccc0000, 0x7d00fa0, 0x2bc0bb8, 0x32003e8, 0x1f4012c, 0x190, 0xecc};
1861                     data[11] |= dwsLut[0];
1862                     data[16] |= dwsLut[1];
1863                     data[19] |= dwsLut[2];
1864                     data[23] |= dwsLut[3];
1865                     data[28] |= dwsLut[4];
1866                     data[29] |= dwsLut[5];
1867                     data[30] |= dwsLut[6];
1868                     data[31] |= dwsLut[7];
1869                     data[32] |= dwsLut[8];
1870                     data[35] |= dwsLut[9];
1871 
1872                     return MOS_STATUS_SUCCESS;
1873                 });
1874 
1875             return MOS_STATUS_SUCCESS;
1876         });
1877 
1878     setting->vdencLaCmd2Settings.emplace_back(
1879         VDENC_CMD2_LAMBDA()
1880         {
1881             par.extSettings.emplace_back(
1882                 [this](uint32_t *data) {
1883 
1884                     if (!m_hevcVdencRoundingPrecisionEnabled)
1885                     {
1886                         return MOS_STATUS_SUCCESS;
1887                     }
1888 
1889                     uint8_t tmp0 = 0;
1890                     uint8_t tmp1 = 0;
1891 
1892                     if (m_hevcPicParams->CustomRoundingOffsetsParams.fields.EnableCustomRoudingIntra)
1893                     {
1894                         tmp0 = m_hevcPicParams->CustomRoundingOffsetsParams.fields.RoundingOffsetIntra;
1895                     }
1896                     else
1897                     {
1898                         if (m_hevcPicParams->CodingType == I_TYPE)
1899                         {
1900                             tmp0 = 10;
1901                         }
1902                         else if (m_hevcSeqParams->HierarchicalFlag && m_hevcPicParams->HierarchLevelPlus1 > 0)
1903                         {
1904                             //Hierachical GOP
1905                             if (m_hevcPicParams->HierarchLevelPlus1 == 1)
1906                             {
1907                                 tmp0 = 10;
1908                             }
1909                             else if (m_hevcPicParams->HierarchLevelPlus1 == 2)
1910                             {
1911                                 tmp0 = 9;
1912                             }
1913                             else
1914                             {
1915                                 tmp0 = 8;
1916                             }
1917                         }
1918                         else
1919                         {
1920                             tmp0 = 10;
1921                         }
1922                     }
1923 
1924                     if (m_hevcPicParams->CustomRoundingOffsetsParams.fields.EnableCustomRoudingInter)
1925                     {
1926                         tmp1 = m_hevcPicParams->CustomRoundingOffsetsParams.fields.RoundingOffsetInter;
1927                     }
1928                     else
1929                     {
1930                         if (m_hevcPicParams->CodingType == I_TYPE)
1931                         {
1932                             tmp1 = 4;
1933                         }
1934                         else if (m_hevcSeqParams->HierarchicalFlag && m_hevcPicParams->HierarchLevelPlus1 > 0)
1935                         {
1936                             //Hierachical GOP
1937                             if (m_hevcPicParams->HierarchLevelPlus1 == 1)
1938                             {
1939                                 tmp1 = 4;
1940                             }
1941                             else if (m_hevcPicParams->HierarchLevelPlus1 == 2)
1942                             {
1943                                 tmp1 = 3;
1944                             }
1945                             else
1946                             {
1947                                 tmp1 = 2;
1948                             }
1949                         }
1950                         else
1951                         {
1952                             tmp1 = 4;
1953                         }
1954                     }
1955                     tmp0 &= 0xf;
1956                     tmp1 &= 0xf;
1957 
1958                     data[32] |= (tmp1 << 16);
1959                     data[32] |= (tmp1 << 20);
1960                     data[32] |= (tmp0 << 24);
1961                     data[32] |= (tmp0 << 28);
1962 
1963                     data[33] |= tmp1;
1964                     data[33] |= (tmp1 << 4);
1965                     data[33] |= (tmp1 << 8);
1966                     data[33] |= (tmp1 << 12);
1967                     data[33] |= (tmp0 << 16);
1968                     data[33] |= (tmp0 << 20);
1969                     data[33] |= (tmp1 << 24);
1970                     data[33] |= (tmp1 << 28);
1971 
1972                     data[34] |= tmp1;
1973                     data[34] |= (tmp1 << 4);
1974                     data[34] |= (tmp0 << 8);
1975                     data[34] |= (tmp0 << 12);
1976                     data[34] |= (tmp1 << 16);
1977                     data[34] |= (tmp1 << 20);
1978 
1979                     return MOS_STATUS_SUCCESS;
1980                 });
1981 
1982             return MOS_STATUS_SUCCESS;
1983         });
1984 #else
1985 #define VDENC_LA_CMD2_SETTINGS_EXT
1986 #include "encode_hevc_vdenc_la_const_settings_ext.h"
1987 #undef VDENC_LA_CMD2_SETTINGS_EXT
1988 #endif  // !(_MEDIA_RESERVED)
1989 
1990     return MOS_STATUS_SUCCESS;
1991 }
1992 
1993 }  // namespace encode
1994