Debian Codegraph @

media_softlet/agnostic/common/codec/hal/enc/hevc/features/encode_hevc_aqm.cpp

raw
1 /*
2 * Copyright (c) 2021-2024, 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,HevcEncodeTile
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 //! \file encode_hevc_aqm.cpp
24 //! \brief Defines the common interface for hevc aqm
25 //!
26
27 #include "encode_hevc_aqm.h"
28 #include "encode_hevc_vdenc_feature_manager.h"
29 #include "encode_hevc_basic_feature.h"
30 #include "encode_vdenc_hevc_fastpass.h"
31
32 namespace encode
33 {
34 HevcEncodeAqm::HevcEncodeAqm(MediaFeatureManager *featureManager,
35 EncodeAllocator * allocator,
36 CodechalHwInterfaceNext * hwInterface,
37 void * constSettings) : EncodeAqmFeature(featureManager, allocator, hwInterface, constSettings)
38 {
39 auto encFeatureManager = dynamic_cast<EncodeHevcVdencFeatureManager *>(featureManager);
40 ENCODE_CHK_NULL_NO_STATUS_RETURN(encFeatureManager);
41
42 m_basicFeature = dynamic_cast<EncodeBasicFeature *>(encFeatureManager->GetFeature(HevcFeatureIDs::basicFeature));
43 ENCODE_CHK_NULL_NO_STATUS_RETURN(m_basicFeature);
44
45 if (HCP_CHROMA_FORMAT_YUV422 == m_basicFeature->m_chromaFormat)
46 {
47 m_enabled = false;
48 ENCODE_VERBOSEMESSAGE("422 is not supported for VDAQM feature!");
49 }
50 };
51
52 MOS_STATUS HevcEncodeAqm::Update(void *params)
53 {
54 auto basicFeature = dynamic_cast<HevcBasicFeature *>(m_basicFeature);
55 ENCODE_CHK_NULL_RETURN(basicFeature);
56
57 auto fastPassFeature = dynamic_cast<HevcVdencFastPass *>(m_featureManager->GetFeature(HevcFeatureIDs::hevcVdencFastPassFeature));
58 if (fastPassFeature && fastPassFeature->IsEnabled())
59 {
60 m_useFastPass = true;
61 m_dsWidth = fastPassFeature->GetFastPassDsWidth();
62 m_dsHeight = fastPassFeature->GetFastPassDsHeight();
63 }
64
65 if (basicFeature->m_hevcPicParams->QualityInfoSupportFlags.fields.enable_frame)
66 {
67 m_enabled = true;
68 }
69 m_numTiles = (basicFeature->m_hevcPicParams->num_tile_rows_minus1 + 1) * (basicFeature->m_hevcPicParams->num_tile_columns_minus1 + 1);
70 m_tileBasedEngine = m_numTiles > 1 ? true : false;
71 uint32_t minCodingBlkSize = basicFeature->m_hevcSeqParams->log2_min_coding_block_size_minus3 + 3;
72 if (!basicFeature->m_hevcPicParams->tiles_enabled_flag)
73 {
74 m_tile_width[0] = m_useFastPass ? (uint16_t)m_dsWidth : (1 << minCodingBlkSize) * (basicFeature->m_hevcSeqParams->wFrameWidthInMinCbMinus1 + 1);
75 m_tile_height[0] = m_useFastPass ? (uint16_t)m_dsHeight : (1 << minCodingBlkSize) * (basicFeature->m_hevcSeqParams->wFrameHeightInMinCbMinus1 + 1);
76 }
77 else
78 {
79 for (uint32_t tileIdx = 0; tileIdx < m_numTiles && tileIdx < ENCODE_VDENC_MAX_TILE_NUM; tileIdx++)
80 {
81 EncodeTileData tileData = {};
82 RUN_FEATURE_INTERFACE_RETURN(HevcEncodeTile, HevcFeatureIDs::encodeTile, GetTileByIndex, tileData, tileIdx);
83 m_tile_width[tileIdx] = ((tileData.tileWidthInMinCbMinus1 + 1) << minCodingBlkSize);
84 m_tile_height[tileIdx] = ((tileData.tileHeightInMinCbMinus1 + 1) << minCodingBlkSize);
85 }
86 }
87 #if USE_CODECHAL_DEBUG_TOOL
88 UpdateFrameDisplayOrder(basicFeature->m_pictureCodingType, basicFeature->m_hevcPicParams->CurrPicOrderCnt, basicFeature->m_hevcSeqParams->GopPicSize);
89 #endif
90 if (basicFeature->m_hevcPicParams->num_tile_columns_minus1 == 1)
91 {
92 m_numRowStore = 2;
93 }
94 ENCODE_CHK_STATUS_RETURN(EncodeAqmFeature::Update(params));
95 return MOS_STATUS_SUCCESS;
96 }
97
98 MHW_SETPAR_DECL_SRC(AQM_PIC_STATE, HevcEncodeAqm)
99 {
100 ENCODE_CHK_STATUS_RETURN(EncodeAqmFeature::MHW_SETPAR_F(AQM_PIC_STATE)(params));
101
102 params.lcuSize = LCU_SIZE_64X64;
103 params.codectype = CODECTYPE_HEVC;
104
105 return MOS_STATUS_SUCCESS;
106 }
107
108 MHW_SETPAR_DECL_SRC(HCP_PIC_STATE, HevcEncodeAqm)
109 {
110
111 params.vdaqmEnable = m_enabled;
112
113 return MOS_STATUS_SUCCESS;
114 }
115
116 MHW_SETPAR_DECL_SRC(AQM_TILE_CODING, HevcEncodeAqm)
117 {
118 auto encFeatureManager = dynamic_cast<EncodeHevcVdencFeatureManager *>(m_featureManager);
119 ENCODE_CHK_NULL_RETURN(encFeatureManager);
120
121 auto hevcTile = dynamic_cast<HevcEncodeTile *>(encFeatureManager->GetFeature(HevcFeatureIDs::encodeTile));
122 ENCODE_CHK_NULL_RETURN(hevcTile);
123
124 HevcTileInfo hevcTileInfo;
125
126 hevcTile->GetTileInfo(&hevcTileInfo);
127
128 params.tileId = hevcTileInfo.tileId;
129 params.tileColPositionInSb = hevcTileInfo.tileColPositionInSb;
130 params.tileRowPositionInSb = hevcTileInfo.tileRowPositionInSb;
131 params.tileWidthInSbMinus1 = hevcTileInfo.tileWidthInSbMinus1;
132 params.tileHeightInSbMinus1 = hevcTileInfo.tileHeightInSbMinus1;
133 params.tileNum = hevcTileInfo.tileNum;
134 params.tileGroupId = hevcTileInfo.tileGroupId;
135
136 return MOS_STATUS_SUCCESS;
137 }
138
139 MHW_SETPAR_DECL_SRC(AQM_SLICE_STATE, HevcEncodeAqm)
140 {
141 auto encFeatureManager = dynamic_cast<EncodeHevcVdencFeatureManager *>(m_featureManager);
142 ENCODE_CHK_NULL_RETURN(encFeatureManager);
143
144 auto hevcTile = dynamic_cast<HevcEncodeTile *>(encFeatureManager->GetFeature(HevcFeatureIDs::encodeTile));
145 ENCODE_CHK_NULL_RETURN(hevcTile);
146
147 HevcTileInfo hevcTileInfo;
148
149 hevcTile->GetTileInfo(&hevcTileInfo);
150
151 auto hevcBasicFeature = dynamic_cast<HevcBasicFeature *>(m_basicFeature);
152 ENCODE_CHK_NULL_RETURN(hevcBasicFeature);
153 auto picParams = hevcBasicFeature->m_hevcPicParams;
154 ENCODE_CHK_NULL_RETURN(picParams);
155 auto seqParams = hevcBasicFeature->m_hevcSeqParams;
156 ENCODE_CHK_NULL_RETURN(seqParams);
157 auto t_sliceParams = hevcBasicFeature->m_hevcSliceParams;
158 ENCODE_CHK_NULL_RETURN(t_sliceParams);
159 CODEC_HEVC_ENCODE_SLICE_PARAMS *sliceParams = (CODEC_HEVC_ENCODE_SLICE_PARAMS *)&t_sliceParams[hevcBasicFeature->m_curNumSlices];
160
161 uint32_t widthInPix = m_useFastPass ? m_dsWidth : (1 << (seqParams->log2_min_coding_block_size_minus3 + 3)) * (seqParams->wFrameWidthInMinCbMinus1 + 1);
162 uint32_t heightInPix = m_useFastPass? m_dsHeight : (1 << (seqParams->log2_min_coding_block_size_minus3 + 3)) * (seqParams->wFrameHeightInMinCbMinus1 + 1);
163
164 uint32_t ctbSize = 1 << (seqParams->log2_max_coding_block_size_minus3 + 3);
165 uint32_t widthInCtb = (widthInPix / ctbSize) + ((widthInPix % ctbSize) ? 1 : 0); // round up
166 uint32_t heightInCtb = (heightInPix / ctbSize) + ((heightInPix % ctbSize) ? 1 : 0); // round up
167 uint32_t shift = seqParams->log2_max_coding_block_size_minus3 - seqParams->log2_min_coding_block_size_minus3;
168
169 bool m_enabled = false;
170 ENCODE_CHK_STATUS_RETURN(hevcTile->IsEnabled(m_enabled));
171 if (!m_enabled)
172 {
173 params.firstSuperSlice = 0;
174 // No tiling support
175 params.tileSliceStartLcuMbY = sliceParams->slice_segment_address / widthInCtb;
176 params.nextTileSliceStartLcuMbX = (sliceParams->slice_segment_address + sliceParams->NumLCUsInSlice) / heightInCtb;
177 params.nextTileSliceStartLcuMbY = (sliceParams->slice_segment_address + sliceParams->NumLCUsInSlice) / widthInCtb;
178 }
179 else
180 {
181 params.tileSliceStartLcuMbX = hevcTileInfo.tileStartXInLCU;
182 params.tileSliceStartLcuMbY = hevcTileInfo.tileStartYInLCU;
183 params.nextTileSliceStartLcuMbX = hevcTileInfo.tileEndXInLCU;
184 params.nextTileSliceStartLcuMbY = hevcTileInfo.tileEndYInLCU;
185 }
186
187 return MOS_STATUS_SUCCESS;
188 }
189
190 #if USE_CODECHAL_DEBUG_TOOL
191 MOS_STATUS HevcEncodeAqm::UpdateFrameDisplayOrder(const uint16_t pictureCodingType, const uint32_t framePOC, const uint32_t gopPicSize)
192 {
193 auto basicFeature = dynamic_cast<HevcBasicFeature *>(m_basicFeature);
194 ENCODE_CHK_NULL_RETURN(basicFeature);
195 if (basicFeature->m_hevcPicParams->CurrPicOrderCnt == 0)
196 {
197 m_frameNumPrevious += m_gopSizePrevious;
198 }
199 uint32_t displayOrderInGOP = framePOC;
200 uint32_t displayOrderInSeq = displayOrderInGOP + m_frameNumPrevious;
201 m_gopSizePrevious = gopPicSize;
202 m_frameIdxQueue.push(displayOrderInSeq);
203 return MOS_STATUS_SUCCESS;
204 }
205 #endif
206
207 } // namespace encode