1 /*
2 * Copyright 2015 Rockchip Electronics Co. LTD
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define MODULE_TAG "h265e_ps"
18
19 #include <string.h>
20
21 #include "mpp_mem.h"
22 #include "mpp_soc.h"
23 #include "mpp_common.h"
24
25 #include "h265e_ps.h"
26 #include "mpp_enc_ref.h"
27
28 #define MAX_UINT 0xFFFFFFFFU
29
30 typedef struct H265levelspec_t {
31 RK_U32 maxLumaSamples;
32 RK_U32 maxLumaSamplesPerSecond;
33 RK_U32 maxBitrateMain;
34 RK_U32 maxBitrateHigh;
35 RK_U32 maxCpbSizeMain;
36 RK_U32 maxCpbSizeHigh;
37 RK_U32 minCompressionRatio;
38 RK_S32 levelEnum;
39 const char* name;
40 RK_S32 levelIdc;
41 } H265levelspec;
42
43 H265levelspec levels[] = {
44 { 36864, 552960, 128, MAX_UINT, 350, MAX_UINT, 2, H265_LEVEL1, "1", 10 },
45 { 122880, 3686400, 1500, MAX_UINT, 1500, MAX_UINT, 2, H265_LEVEL2, "2", 20 },
46 { 245760, 7372800, 3000, MAX_UINT, 3000, MAX_UINT, 2, H265_LEVEL2_1, "2.1", 21 },
47 { 552960, 16588800, 6000, MAX_UINT, 6000, MAX_UINT, 2, H265_LEVEL3, "3", 30 },
48 { 983040, 33177600, 10000, MAX_UINT, 10000, MAX_UINT, 2, H265_LEVEL3_1, "3.1", 31 },
49 { 2228224, 66846720, 12000, 30000, 12000, 30000, 4, H265_LEVEL4, "4", 40 },
50 { 2228224, 133693440, 20000, 50000, 20000, 50000, 4, H265_LEVEL4_1, "4.1", 41 },
51 { 8912896, 267386880, 25000, 100000, 25000, 100000, 6, H265_LEVEL5, "5", 50 },
52 { 8912896, 534773760, 40000, 160000, 40000, 160000, 8, H265_LEVEL5_1, "5.1", 51 },
53 { 8912896, 1069547520, 60000, 240000, 60000, 240000, 8, H265_LEVEL5_2, "5.2", 52 },
54 { 35651584, 1069547520, 60000, 240000, 60000, 240000, 8, H265_LEVEL6, "6", 60 },
55 { 35651584, 2139095040, 120000, 480000, 120000, 480000, 8, H265_LEVEL6_1, "6.1", 61 },
56 { 35651584, 4278190080U, 240000, 800000, 240000, 800000, 6, H265_LEVEL6_2, "6.2", 62 },
57 { MAX_UINT, MAX_UINT, MAX_UINT, MAX_UINT, MAX_UINT, MAX_UINT, 1, H265_LEVEL8_5, "8.5", 85 },
58 };
59
init_zscan2raster(RK_S32 maxDepth,RK_S32 depth,RK_U32 startVal,RK_U32 ** curIdx)60 void init_zscan2raster(RK_S32 maxDepth, RK_S32 depth, RK_U32 startVal, RK_U32** curIdx)
61 {
62 RK_S32 stride = 1 << (maxDepth - 1);
63 if (depth == maxDepth) {
64 (*curIdx)[0] = startVal;
65 (*curIdx)++;
66 } else {
67 RK_S32 step = stride >> depth;
68 init_zscan2raster(maxDepth, depth + 1, startVal, curIdx);
69 init_zscan2raster(maxDepth, depth + 1, startVal + step, curIdx);
70 init_zscan2raster(maxDepth, depth + 1, startVal + step * stride, curIdx);
71 init_zscan2raster(maxDepth, depth + 1, startVal + step * stride + step, curIdx);
72 }
73 }
74
init_raster2zscan(RK_U32 maxCUSize,RK_U32 maxDepth,RK_U32 * raster2zscan,RK_U32 * zscan2raster)75 void init_raster2zscan(RK_U32 maxCUSize, RK_U32 maxDepth, RK_U32 *raster2zscan, RK_U32 *zscan2raster)
76 {
77 RK_U32 unitSize = maxCUSize >> (maxDepth - 1);
78 RK_U32 numPartInCUSize = (RK_U32)maxCUSize / unitSize;
79 RK_U32 i;
80
81 for ( i = 0; i < numPartInCUSize * numPartInCUSize; i++) {
82 raster2zscan[zscan2raster[i]] = i;
83 }
84 }
85
init_raster2pelxy(RK_U32 maxCUSize,RK_U32 maxDepth,RK_U32 * raster2pelx,RK_U32 * raster2pely)86 void init_raster2pelxy(RK_U32 maxCUSize, RK_U32 maxDepth, RK_U32 *raster2pelx, RK_U32 *raster2pely)
87 {
88 RK_U32 i;
89
90 RK_U32* tempx = &raster2pelx[0];
91 RK_U32* tempy = &raster2pely[0];
92
93 RK_U32 unitSize = maxCUSize >> (maxDepth - 1);
94
95 RK_U32 numPartInCUSize = maxCUSize / unitSize;
96
97 tempx[0] = 0;
98 tempx++;
99 for (i = 1; i < numPartInCUSize; i++) {
100 tempx[0] = tempx[-1] + unitSize;
101 tempx++;
102 }
103
104 for (i = 1; i < numPartInCUSize; i++) {
105 memcpy(tempx, tempx - numPartInCUSize, sizeof(RK_U32) * numPartInCUSize);
106 tempx += numPartInCUSize;
107 }
108
109 for (i = 1; i < numPartInCUSize * numPartInCUSize; i++) {
110 tempy[i] = (i / numPartInCUSize) * unitSize;
111 }
112 }
113
h265e_set_vps(H265eCtx * ctx,H265eVps * vps)114 MPP_RET h265e_set_vps(H265eCtx *ctx, H265eVps *vps)
115 {
116 RK_S32 i;
117 MppEncH265Cfg *codec = &ctx->cfg->h265;
118 ProfileTierLevel *profileTierLevel = &vps->m_ptl.m_generalPTL;
119 MppEncPrepCfg *prep = &ctx->cfg->prep;
120 MppEncRefCfg ref_cfg = ctx->cfg->ref_cfg;
121 RK_U32 maxlumas = prep->width * prep->height;
122 RK_S32 level_idc = H265_LEVEL_NONE;
123 MppEncRefCfgImpl *refs = (MppEncRefCfgImpl *)ref_cfg;
124
125 vps->m_VPSId = 0;
126 vps->m_maxTLayers = refs->max_tlayers ? refs->max_tlayers : 1;
127 vps->m_maxLayers = vps->m_maxTLayers;
128 vps->m_bTemporalIdNestingFlag = 1;
129 vps->m_numHrdParameters = 0;
130 vps->m_maxNuhReservedZeroLayerId = 0;
131 vps->m_hrdParameters = NULL;
132 vps->m_hrdOpSetIdx = NULL;
133 vps->m_cprmsPresentFlag = NULL;
134 for (i = 0; i < MAX_SUB_LAYERS; i++) {
135 vps->m_numReorderPics[i] = 0;
136 vps->m_maxDecPicBuffering[i] = MPP_MIN(MAX_REFS, MPP_MAX((vps->m_numReorderPics[i] + 3), codec->num_ref) + vps->m_numReorderPics[i]);
137 vps->m_maxLatencyIncrease[i] = 0;
138 }
139 memset(profileTierLevel->m_profileCompatibilityFlag, 0, sizeof(profileTierLevel->m_profileCompatibilityFlag));
140 memset(vps->m_ptl.m_subLayerProfilePresentFlag, 0, sizeof(vps->m_ptl.m_subLayerProfilePresentFlag));
141 memset(vps->m_ptl.m_subLayerLevelPresentFlag, 0, sizeof(vps->m_ptl.m_subLayerLevelPresentFlag));
142 for (i = 0; i < (RK_S32)MPP_ARRAY_ELEMS(levels); i++) {
143 if (levels[i].maxLumaSamples >= maxlumas) {
144 level_idc = levels[i].levelEnum;
145 break;
146 }
147 }
148
149 profileTierLevel->m_profileSpace = 0;
150 if (codec->level < level_idc) {
151 profileTierLevel->m_levelIdc = level_idc;
152 } else {
153 profileTierLevel->m_levelIdc = codec->level;
154 }
155 profileTierLevel->m_tierFlag = codec->tier ? 1 : 0;
156
157 if (prep->format == MPP_FMT_YUV400) {
158 /* general_profile_idc == 4 */
159 codec->profile = MPP_PROFILE_HEVC_FORMAT_RANGE_EXTENDIONS;
160 profileTierLevel->m_max12bitConstraintFlag = 1;
161 profileTierLevel->m_max10bitConstraintFlag = 1;
162 profileTierLevel->m_max8bitConstraintFlag = 1;
163 profileTierLevel->m_max422chromaConstraintFlag = 1;
164 profileTierLevel->m_max420chromaConstraintFlag = 1;
165 profileTierLevel->m_maxMonochromaConstraintFlag = 1;
166 profileTierLevel->m_lowerBitRateConstraintFlag = 1;
167 } else {
168 /* general_profile_idc == 2 */
169 profileTierLevel->m_profileCompatibilityFlag[2] = 1;
170 }
171
172 profileTierLevel->m_profileIdc = codec->profile;
173 profileTierLevel->m_profileCompatibilityFlag[codec->profile] = 1;
174 profileTierLevel->m_progressiveSourceFlag = 1;
175 profileTierLevel->m_nonPackedConstraintFlag = 0;
176 profileTierLevel->m_frameOnlyConstraintFlag = 0;
177 return MPP_OK;
178 }
179
h265e_set_sps(H265eCtx * ctx,H265eSps * sps,H265eVps * vps)180 MPP_RET h265e_set_sps(H265eCtx *ctx, H265eSps *sps, H265eVps *vps)
181 {
182 RK_U32 i, c;
183 MppEncH265Cfg *codec = &ctx->cfg->h265;
184 MppEncPrepCfg *prep = &ctx->cfg->prep;
185 MppEncRcCfg *rc = &ctx->cfg->rc;
186 MppEncRefCfg ref_cfg = ctx->cfg->ref_cfg;
187 MppEncVuiCfg *vui = &codec->vui;
188 MppFrameFormat fmt = prep->format;
189 RK_S32 i_timebase_num = rc->fps_out_denom;
190 RK_S32 i_timebase_den = rc->fps_out_num;
191 RK_U8 convertToBit[MAX_CU_SIZE + 1];
192 RK_U32 maxCUDepth, minCUDepth, addCUDepth;
193 RK_S32 pad[2] = {0};
194 RK_S32 minCUSize, log2MinCUSize;
195 RK_S32 tuQTMinLog2Size = 2, tuQTMaxLog2Size;
196 MppEncCpbInfo *cpb_info = mpp_enc_ref_cfg_get_cpb_info(ref_cfg);
197 RockchipSocType soc_type;
198 RK_U32 *tmp = &sps->zscan2raster[0];
199
200 memset(convertToBit, -1, sizeof(convertToBit));
201 c = 0;
202 for (i = 4; i <= MAX_CU_SIZE; i *= 2) {
203 convertToBit[i] = c;
204 c++;
205 }
206
207 maxCUDepth = (uint32_t)convertToBit[codec->max_cu_size];
208
209 minCUDepth = (codec->max_cu_size >> (maxCUDepth - 1));
210
211 tuQTMaxLog2Size = convertToBit[codec->max_cu_size] + 2 - 1;
212 soc_type = mpp_get_soc_type();
213 if (soc_type == ROCKCHIP_SOC_RK3576 || soc_type == ROCKCHIP_SOC_RV1126B) {
214 tuQTMaxLog2Size = tuQTMaxLog2Size + 1;
215 }
216
217 addCUDepth = 0;
218 while ((RK_U32)(codec->max_cu_size >> maxCUDepth) > (1u << (tuQTMinLog2Size + addCUDepth))) {
219 addCUDepth++;
220 }
221
222 maxCUDepth += addCUDepth;
223 addCUDepth++;
224 init_zscan2raster(maxCUDepth + 1, 1, 0, &tmp );
225 init_raster2zscan(codec->max_cu_size, maxCUDepth + 1, &sps->raster2zscan[0], &sps->zscan2raster[0]);
226 init_raster2pelxy(codec->max_cu_size, maxCUDepth + 1, &sps->raster2pelx[0], &sps->raster2pely[0]);
227
228 memset(&sps->m_conformanceWindow, 0, sizeof(H265eCropInfo));
229 if ((prep->width % minCUDepth) != 0) {
230 RK_U32 padsize = 0;
231 RK_U32 rem = prep->width % minCUDepth;
232 padsize = minCUDepth - rem;
233 pad[0] = padsize; //pad width
234
235 /* set the confirmation window offsets */
236 sps->m_conformanceWindow.m_enabledFlag = 1;
237 sps->m_conformanceWindow.m_winRightOffset = pad[0];
238 }
239
240 if ((prep->height % minCUDepth) != 0) {
241 RK_U32 padsize = 0;
242 RK_U32 rem = prep->height % minCUDepth;
243 padsize = minCUDepth - rem;
244 pad[1] = padsize; //pad height
245
246 /* set the confirmation window offsets */
247 sps->m_conformanceWindow.m_enabledFlag = 1;
248 sps->m_conformanceWindow.m_winBottomOffset = pad[1];
249 }
250 // pad[0] = p->sourceWidth - p->oldSourceWidth;
251 // pad[1] = p->sourceHeight - p->oldSourceHeight;
252
253 sps->m_SPSId = 0;
254 sps->m_VPSId = 0;
255 sps->m_chromaFormatIdc = (fmt == MPP_FMT_YUV400) ? H265_CHROMA_400 : H265_CHROMA_420;
256 sps->m_maxTLayers = vps->m_maxLayers;
257 sps->m_picWidthInLumaSamples = prep->width + pad[0];
258 sps->m_picHeightInLumaSamples = prep->height + pad[1];
259 sps->m_log2MinCodingBlockSize = 0;
260 sps->m_log2DiffMaxMinCodingBlockSize = 0 ;
261 sps->m_maxCUSize = codec->max_cu_size;
262 sps->m_maxCUDepth = maxCUDepth;
263 sps->m_addCUDepth = addCUDepth;
264 sps->m_RPSList.m_numberOfReferencePictureSets = 0;
265 sps->m_RPSList.m_referencePictureSets = NULL;
266
267 minCUSize = sps->m_maxCUSize >> (sps->m_maxCUDepth - addCUDepth);
268 log2MinCUSize = 0;
269 while (minCUSize > 1) {
270 minCUSize >>= 1;
271 log2MinCUSize++;
272 }
273 sps->m_log2MinCodingBlockSize = log2MinCUSize;
274 sps->m_log2DiffMaxMinCodingBlockSize = sps->m_maxCUDepth - addCUDepth;
275
276 sps->m_pcmLog2MaxSize = 5;
277 sps->m_usePCM = 0;
278 sps->m_pcmLog2MinSize = 3;
279
280
281 sps->m_bLongTermRefsPresent = 0;
282 sps->m_quadtreeTULog2MaxSize = tuQTMaxLog2Size;
283 sps->m_quadtreeTULog2MinSize = tuQTMinLog2Size;
284 sps->m_quadtreeTUMaxDepthInter = 1; //tuQTMaxInterDepth
285 sps->m_quadtreeTUMaxDepthIntra = 1; //tuQTMaxIntraDepth
286 sps->m_useLossless = 0;
287
288 for (i = 0; i < (maxCUDepth - addCUDepth); i++) {
289 sps->m_iAMPAcc[i] = codec->amp_enable;
290 }
291 sps->m_useAMP = codec->amp_enable;
292 for (i = maxCUDepth - addCUDepth; i < maxCUDepth; i++) {
293 sps->m_iAMPAcc[i] = codec->amp_enable;
294 }
295
296 sps->m_bitDepthY = 8;
297 sps->m_bitDepthC = 8;
298 sps->m_qpBDOffsetY = 0;
299 sps->m_qpBDOffsetC = 0;
300
301 sps->m_bUseSAO = codec->sao_enable;
302 sps->m_bTemporalIdNestingFlag = 1;
303
304 for (i = 0; i < sps->m_maxTLayers; i++) {
305 sps->m_maxDecPicBuffering[i] = vps->m_maxDecPicBuffering[i];
306 sps->m_numReorderPics[i] = vps->m_numReorderPics[i];
307 }
308
309 sps->m_pcmBitDepthLuma = 8;
310 sps->m_pcmBitDepthChroma = 8;
311
312 sps->m_bPCMFilterDisableFlag = 0;
313 sps->m_scalingListEnabledFlag = codec->trans_cfg.scaling_list_mode == 0 ? 0 : 1;
314
315 sps->m_bitsForPOC = 16;
316 sps->m_numLongTermRefPicSPS = 0;
317 sps->m_maxTrSize = 32;
318 sps->m_bLongTermRefsPresent = 0;
319 sps->m_TMVPFlagsPresent = codec->tmvp_enable;
320 sps->m_useStrongIntraSmoothing = codec->cu_cfg.strong_intra_smoothing_enabled_flag;
321 if (cpb_info->max_lt_cnt) {
322 sps->m_numLongTermRefPicSPS = cpb_info->max_lt_cnt;
323 sps->m_bLongTermRefsPresent = 1;
324 sps->m_TMVPFlagsPresent = 0;
325 codec->tmvp_enable = 0;
326 } else if (cpb_info->max_st_tid) {
327 sps->m_TMVPFlagsPresent = 0;
328 }
329
330 if (rc->drop_mode == MPP_ENC_RC_DROP_FRM_PSKIP) {
331 codec->tmvp_enable = 0;
332 sps->m_TMVPFlagsPresent = 0;
333 codec->sao_enable = 0;
334 sps->m_bUseSAO = 0;
335 }
336
337 sps->m_ptl = &vps->m_ptl;
338 sps->m_vuiParametersPresentFlag = vui->vui_en;
339 if (sps->m_vuiParametersPresentFlag) {
340 sps->vui.m_aspectRatioInfoPresentFlag = 0;
341 sps->vui.m_aspectRatioIdc = 0;
342 sps->vui.m_sarWidth = 0;
343 sps->vui.m_sarHeight = 0;
344 sps->vui.m_overscanInfoPresentFlag = 0;
345 sps->vui.m_overscanAppropriateFlag = 0;
346 sps->vui.m_videoSignalTypePresentFlag = 0;
347 sps->vui.m_videoFormat = MPP_FRAME_VIDEO_FMT_UNSPECIFIED;
348 if (prep->range == MPP_FRAME_RANGE_JPEG) {
349 sps->vui.m_videoFullRangeFlag = 1;
350 sps->vui.m_videoSignalTypePresentFlag = 1;
351 }
352
353 if ((prep->colorprim <= MPP_FRAME_PRI_JEDEC_P22 &&
354 prep->colorprim != MPP_FRAME_PRI_UNSPECIFIED) ||
355 (prep->colortrc <= MPP_FRAME_TRC_ARIB_STD_B67 &&
356 prep->colortrc != MPP_FRAME_TRC_UNSPECIFIED) ||
357 (prep->color <= MPP_FRAME_SPC_ICTCP &&
358 prep->color != MPP_FRAME_SPC_UNSPECIFIED)) {
359 sps->vui.m_videoSignalTypePresentFlag = 1;
360 sps->vui.m_colourDescriptionPresentFlag = 1;
361 sps->vui.m_colourPrimaries = prep->colorprim;
362 sps->vui.m_transferCharacteristics = prep->colortrc;
363 sps->vui.m_matrixCoefficients = prep->color;
364 }
365
366 sps->vui.m_chromaLocInfoPresentFlag = 0;
367 sps->vui.m_chromaSampleLocTypeTopField = 0;
368 sps->vui.m_chromaSampleLocTypeBottomField = 0;
369 sps->vui.m_neutralChromaIndicationFlag = 0;
370 sps->vui.m_fieldSeqFlag = 0;
371 sps->vui.m_frameFieldInfoPresentFlag = 0;
372 sps->vui.m_hrdParametersPresentFlag = 0;
373 sps->vui.m_bitstreamRestrictionFlag = 0;
374 sps->vui.m_tilesFixedStructureFlag = 0;
375 sps->vui.m_motionVectorsOverPicBoundariesFlag = 1;
376 sps->vui.m_restrictedRefPicListsFlag = 1;
377 sps->vui.m_minSpatialSegmentationIdc = 0;
378 sps->vui.m_maxBytesPerPicDenom = 2;
379 sps->vui.m_maxBitsPerMinCuDenom = 1;
380 sps->vui.m_log2MaxMvLengthHorizontal = 15;
381 sps->vui.m_log2MaxMvLengthVertical = 15;
382 if (vui->vui_aspect_ratio) {
383 sps->vui.m_aspectRatioInfoPresentFlag = !!vui->vui_aspect_ratio;
384 sps->vui.m_aspectRatioIdc = vui->vui_aspect_ratio;
385 }
386 sps->vui.m_timingInfo.m_timingInfoPresentFlag = 1;
387 sps->vui.m_timingInfo.m_numUnitsInTick = i_timebase_num;
388 sps->vui.m_timingInfo.m_timeScale = i_timebase_den;
389 }
390
391
392
393 for (i = 0; i < MAX_SUB_LAYERS; i++) {
394 sps->m_maxLatencyIncrease[i] = 0;
395 }
396 // sps->m_scalingList = NULL;
397 memset(sps->m_ltRefPicPocLsbSps, 0, sizeof(sps->m_ltRefPicPocLsbSps));
398 memset(sps->m_usedByCurrPicLtSPSFlag, 0, sizeof(sps->m_usedByCurrPicLtSPSFlag));
399 return 0;
400 }
401
h265e_set_pps(H265eCtx * ctx,H265ePps * pps,H265eSps * sps)402 MPP_RET h265e_set_pps(H265eCtx *ctx, H265ePps *pps, H265eSps *sps)
403 {
404 MppEncH265Cfg *codec = &ctx->cfg->h265;
405
406 pps->m_bConstrainedIntraPred = codec->const_intra_pred;
407 pps->m_PPSId = 0;
408 pps->m_SPSId = 0;
409 pps->m_picInitQPMinus26 = 0;
410 pps->m_useDQP = 1;
411 pps->m_maxCuDQPDepth = codec->trans_cfg.diff_cu_qp_delta_depth;
412 pps->m_minCuDQPSize = (sps->m_maxCUSize >> pps->m_maxCuDQPDepth);
413
414 pps->m_sps = sps;
415 pps->m_bSliceChromaQpFlag = 0;
416 pps->m_chromaCbQpOffset = codec->trans_cfg.cb_qp_offset;
417 /* rkvenc hw only support one color qp offset. Set all offset to cb offset*/
418 pps->m_chromaCrQpOffset = codec->trans_cfg.cb_qp_offset;
419
420 pps->m_entropyCodingSyncEnabledFlag = 0;
421 pps->m_bUseWeightPred = 0;
422 pps->m_useWeightedBiPred = 0;
423 pps->m_outputFlagPresentFlag = 0;
424 pps->m_signHideFlag = 0;
425 pps->m_picInitQPMinus26 = codec->intra_qp - 26;
426 pps->m_LFCrossSliceBoundaryFlag = codec->lpf_acs_sli_en;
427 pps->m_deblockingFilterControlPresentFlag = !codec->dblk_cfg.slice_deblocking_filter_disabled_flag;
428 if (pps->m_deblockingFilterControlPresentFlag) {
429 pps->m_deblockingFilterOverrideEnabledFlag = 0;
430 pps->m_picDisableDeblockingFilterFlag = 0;
431 if (!pps->m_picDisableDeblockingFilterFlag) {
432 pps->m_deblockingFilterBetaOffsetDiv2 = codec->dblk_cfg.slice_beta_offset_div2;
433 pps->m_deblockingFilterTcOffsetDiv2 = codec->dblk_cfg.slice_tc_offset_div2;
434 }
435 } else {
436 pps->m_deblockingFilterOverrideEnabledFlag = 0;
437 pps->m_picDisableDeblockingFilterFlag = 1;
438 pps->m_deblockingFilterBetaOffsetDiv2 = 0;
439 pps->m_deblockingFilterTcOffsetDiv2 = 0;
440 }
441
442 pps->m_listsModificationPresentFlag = 1;
443 pps->m_log2ParallelMergeLevelMinus2 = 0;
444 pps->m_numRefIdxL0DefaultActive = 1;
445 pps->m_numRefIdxL1DefaultActive = 1;
446 pps->m_transquantBypassEnableFlag = codec->trans_cfg.transquant_bypass_enabled_flag;
447 pps->m_useTransformSkip = codec->trans_cfg.transform_skip_enabled_flag;
448
449 pps->m_entropyCodingSyncEnabledFlag = 0;
450 pps->m_signHideFlag = 0;
451 pps->m_cabacInitPresentFlag = codec->entropy_cfg.cabac_init_flag;
452 pps->m_encCABACTableIdx = I_SLICE;
453 pps->m_sliceHeaderExtensionPresentFlag = 0;
454 pps->m_numExtraSliceHeaderBits = 0;
455 pps->m_tiles_enabled_flag = 0;
456 pps->m_bTileUniformSpacing = 0;
457 pps->m_nNumTileRowsMinus1 = 0;
458 pps->m_nNumTileColumnsMinus1 = 0;
459 pps->m_loopFilterAcrossTilesEnabledFlag = !codec->lpf_acs_tile_disable;
460 {
461 RockchipSocType soc_type = mpp_get_soc_type();
462 RK_S32 index;
463 RK_S32 mb_w = (sps->m_picWidthInLumaSamples + sps->m_maxCUSize - 1) / sps->m_maxCUSize;
464 RK_S32 mb_h = (sps->m_picHeightInLumaSamples + sps->m_maxCUSize - 1) / sps->m_maxCUSize;
465 RK_S32 tile_width;
466
467 /* check tile support on rk3566 and rk3568 */
468 if (soc_type == ROCKCHIP_SOC_RK3566 || soc_type == ROCKCHIP_SOC_RK3568) {
469 pps->m_nNumTileColumnsMinus1 = (sps->m_picWidthInLumaSamples - 1) / 1920 ;
470 } else if (soc_type == ROCKCHIP_SOC_RK3588) {
471 if (sps->m_picWidthInLumaSamples > 8192) {
472 /* 4 tile for over 8k encoding */
473 pps->m_nNumTileColumnsMinus1 = 3;
474 } else if (sps->m_picWidthInLumaSamples > 4096) {
475 /* 2 tile for 4k ~ 8k encoding */
476 pps->m_nNumTileColumnsMinus1 = 1;
477 } else {
478 /* 1 tile for less 4k encoding and use 2 tile on auto tile enabled */
479 pps->m_nNumTileColumnsMinus1 = codec->auto_tile ? 1 : 0;
480 }
481 }
482 if (pps->m_nNumTileColumnsMinus1) {
483 pps->m_tiles_enabled_flag = 1;
484 pps->m_bTileUniformSpacing = 1;
485 pps->m_loopFilterAcrossTilesEnabledFlag = !codec->lpf_acs_tile_disable;
486
487 /* calc width per tile */
488 for (index = 0; index < pps->m_nNumTileColumnsMinus1; index++) {
489 tile_width = (index + 1) * mb_w / (pps->m_nNumTileColumnsMinus1 + 1) -
490 index * mb_w / (pps->m_nNumTileColumnsMinus1 + 1);
491 pps->m_nTileColumnWidthArray[index] = tile_width;
492 pps->m_nTileRowHeightArray[index] = mb_h;
493 }
494 tile_width = mb_w - index * mb_w / (pps->m_nNumTileColumnsMinus1 + 1);
495 pps->m_nTileColumnWidthArray[index] = tile_width;
496 pps->m_nTileRowHeightArray[index] = mb_h;
497 }
498 }
499
500 return 0;
501 }
502