Debian Codegraph @

media_softlet/agnostic/common/codec/hal/enc/shared/pipeline/encode_pipeline.h

raw
1 /*
2 * Copyright (c) 2018-2020, 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 //! \file encode_pipeline.h
24 //! \brief Defines the common interface for encode pipeline
25 //! \details The encode pipeline interface is further sub-divided by codec standard,
26 //! this file is for the base interface which is shared by all codecs.
27 //!
28 #ifndef __ENCODE_PIPELINE_H__
29 #define __ENCODE_PIPELINE_H__
30
31 #include "media_pipeline.h"
32
33 #include "codec_hw_next.h"
34 #include "codec_def_encode.h"
35 #include "media_scalability.h"
36 #include "encode_allocator.h"
37 #include "encode_basic_feature.h"
38 #include "encode_tracked_buffer.h"
39 #include "encode_recycle_resource.h"
40 #include "encode_mem_compression.h"
41 #include "encodecp.h"
42 #include "encode_packet_utilities.h"
43 #include "encode_scalability_defs.h"
44
45 #define CONSTRUCTPACKETID(_componentId, _subComponentId, _packetId) \
46 (_componentId << 24 | _subComponentId << 16 | _packetId)
47
48 namespace encode
49 {
50 class EncodePipeline : public MediaPipeline
51 {
52 public:
53 //!
54 //! \brief EncodePipeline constructor
55 //! \param [in] hwInterface
56 //! Pointer to CodechalHwInterface
57 //! \param [in] debugInterface
58 //! Pointer to CodechalDebugInterface
59 //!
60 EncodePipeline(
61 CodechalHwInterfaceNext *hwInterface,
62 CodechalDebugInterface *debugInterface);
63
64 virtual ~EncodePipeline() {}
65
66 virtual MOS_STATUS Prepare(void *params) override;
67
68 MOS_STATUS ContextSwitchBack();
69
70 EncodeAllocator * GetEncodeAllocator() { return m_allocator; };
71 CodechalHwInterfaceNext *GetHWInterface() { return m_hwInterface; };
72 PacketUtilities * GetPacketUtilities() { return m_packetUtilities; };
73
74 //!
75 //! \brief Get if SingleTaskPhaseSupported
76 //! \return bool
77 //! value of SingleTaskPhaseSupported
78 //!
79 bool IsSingleTaskPhaseSupported() { return m_singleTaskPhaseSupported; };
80
81 //!
82 //! \brief Get if m_singleTaskPhaseSupportedInPak
83 //! \return bool
84 //! value of m_singleTaskPhaseSupportedInPak
85 //!
86 bool IsSingleTaskPhaseSupportedInPak() { return m_singleTaskPhaseSupportedInPak; };
87
88 //!
89 //! \brief Get the Debug interface
90 //! \return CodechalDebugInterface *
91 //! pointer of m_debugInterface
92 //!
93 CodechalDebugInterface *GetDebugInterface() const { return m_debugInterface; }
94
95 //!
96 //! \brief Get the Debug interface for status report
97 //! \return CodechalDebugInterface *
98 //! pointer of m_statusReportDebugInterface
99 //!
100 CodechalDebugInterface *GetStatusReportDebugInterface() const { return m_statusReportDebugInterface; }
101 EncodeCp * GetEncodeCp() { return m_encodecp; }
102
103 //!
104 //! \brief Update frame tracking flag
105 //! \return void
106 //!
107 void SetFrameTrackingForMultiTaskPhase();
108
109 enum ComponentPacketIds
110 {
111 PACKET_COMPONENT_COMMON = 0,
112 PACKET_COMPONENT_ENCODE,
113 PACKET_COMPONENT_DECODE,
114 PACKET_COMPONENT_VP,
115 };
116
117 enum SubComponentPacketIds
118 {
119 PACKET_SUBCOMPONENT_COMMON = 0,
120 PACKET_SUBCOMPONENT_HEVC,
121 PACKET_SUBCOMPONENT_VP9,
122 PACKET_SUBCOMPONENT_AVC,
123 PACKET_SUBCOMPONENT_AV1,
124 PACKET_SUBCOMPONENT_JPEG
125 };
126
127 enum CommonPacketIds
128 {
129 basicPacket = CONSTRUCTPACKETID(PACKET_COMPONENT_ENCODE, PACKET_SUBCOMPONENT_COMMON, 0),
130 encodePreEncPacket,
131 #if _MEDIA_RESERVED
132 #define ENCODE_PACKET_IDS_EXT
133 #include "encode_pipeline_ext.h"
134 #undef ENCODE_PACKET_IDS_EXT
135 #endif
136 };
137
138 protected:
139 //!
140 //! \brief Initialize the encode pipeline
141 //! \param [in] settings
142 //! Pointer to the initialize settings
143 //! \return MOS_STATUS
144 //! MOS_STATUS_SUCCESS if success, else fail reason
145 //!
146 virtual MOS_STATUS Initialize(void *settings);
147
148 //!
149 //! \brief Uninitialize the encode pipeline
150 //! \return MOS_STATUS
151 //! MOS_STATUS_SUCCESS if success, else fail reason
152 //!
153 virtual MOS_STATUS Uninitialize();
154
155 //!
156 //! \brief User Feature Key Report
157 //! \return MOS_STATUS
158 //! MOS_STATUS_SUCCESS if success, else fail reason
159 //!
160 virtual MOS_STATUS UserFeatureReport() override;
161
162 //!
163 //! \brief Create buffer tracker, the derived class can overload it if
164 //! requires different buffer count
165 //! \return MOS_STATUS
166 //! MOS_STATUS_SUCCESS if success, else fail reason
167 //!
168 virtual MOS_STATUS CreateBufferTracker() = 0;
169
170 //!
171 //! \brief Create status report
172 //! \return MOS_STATUS
173 //! MOS_STATUS_SUCCESS if success, else fail reason
174 //!
175 virtual MOS_STATUS CreateStatusReport() = 0;
176
177 virtual MOS_STATUS GetSystemVdboxNumber();
178
179 MOS_STATUS WaitForBatchBufferComplete();
180
181 //!
182 //! \brief Finish the active packets execution
183 //! \return MOS_STATUS
184 //! MOS_STATUS_SUCCESS if success, else fail reason
185 //!
186 MOS_STATUS ExecuteActivePackets() override;
187
188 //! \brief Calculate Command Size for all packets in active packets list
189 //!
190 //! \param [in, out] commandBufferSize
191 //! cmd buffer size to calculate
192 //! \param [in, out] requestedPatchListSize
193 //! patch list size to calculate
194 //! \return uint32_t
195 //! Command size calculated
196 //!
197 MOS_STATUS CalculateCmdBufferSizeFromActivePackets(
198 uint32_t &commandBufferSize,
199 uint32_t &requestedPatchListSize);
200
201 //!
202 //! \brief Declare Regkeys in the scope of encode
203 //! \return MOS_STATUS
204 //! MOS_STATUS_SUCCESS if success, else fail reason
205 virtual MOS_STATUS InitUserSetting(MediaUserSettingSharedPtr userSettingPtr) override;
206
207 public:
208 //!
209 //! \brief Help function to get current pipe
210 //!
211 //! \return Current pipe value
212 //!
213 virtual uint8_t GetCurrentPipe()
214 {
215 return m_scalability->GetCurrentPipe();
216 }
217
218 //!
219 //! \brief Help function to get current PAK pass
220 //!
221 //! \return Current PAK pass
222 //!
223 virtual uint16_t GetCurrentPass()
224 {
225 return m_scalability->GetCurrentPass();
226 }
227
228 //!
229 //! \brief Create encode parameter
230 //! \param [in] params
231 //! Pointer to EncoderParams
232 //! \return MOS_STATUS
233 //! MOS_STATUS_SUCCESS if success, else fail reason
234 //!
235 //virtual MOS_STATUS CreateEncodeBasicFeature() { return MOS_STATUS_SUCCESS; }
236
237 //!
238 //! \brief Help function to check if current pipe is first pipe
239 //!
240 //! \return True if current pipe is first pipe, otherwise return false
241 //!
242 virtual bool IsFirstPipe()
243 {
244 return GetCurrentPipe() == 0 ? true : false;
245 }
246
247 //!
248 //! \brief Help function to check if current pipe is last pipe
249 //!
250 //! \return True if current pipe is last pipe, otherwise return false
251 //!
252 virtual bool IsLastPipe()
253 {
254 return GetCurrentPipe() == GetPipeNum() - 1 ? true : false;
255 }
256
257 //!
258 //! \brief Help function to check if current PAK pass is first pass
259 //!
260 //! \return True if current PAK pass is first pass, otherwise return false
261 //!
262 virtual bool IsFirstPass()
263 {
264 return GetCurrentPass() == 0 ? true : false;
265 }
266
267 //!
268 //! \brief Help function to check if current PAK pass is last pass
269 //!
270 //! \return True if current PAK pass is last pass, otherwise return false
271 //!
272 virtual bool IsLastPass()
273 {
274 return GetCurrentPass() == GetPassNum() - 1 ? true : false;
275 }
276
277 //!
278 //! \brief Help function to get pipe number
279 //!
280 //! \return Pipe number
281 //!
282 virtual uint8_t GetPipeNum()
283 {
284 return m_scalability->GetPipeNumber();
285 }
286
287 //!
288 //! \brief Help function to get ddi target usage
289 //!
290 //! \return DDI Target Usage
291 //!
292 virtual uint8_t GetDDITU()
293 {
294 return m_featureManager->GetDDITargetUsage();
295 }
296
297 //!
298 //! \brief Help function to get pass number
299 //!
300 //! \return Pass number
301 //!
302 virtual uint16_t GetPassNum()
303 {
304 return m_scalability->GetPassNumber();
305 }
306
307 virtual uint8_t GetCurrentRow()
308 {
309 return m_scalability->GetCurrentRow();
310 }
311
312 virtual uint8_t GetCurrentSubPass()
313 {
314 return m_scalability->GetCurrentSubPass();
315 }
316
317 EncodeMemComp *GetMmcState() { return m_mmcState; }
318
319 MOS_STATUS ExecuteResolveMetaData(PMOS_RESOURCE pInput, PMOS_RESOURCE pOutput);
320
321 MOS_STATUS ReportErrorFlag(PMOS_RESOURCE pMetadataBuffer,
322 uint32_t size, uint32_t offset, uint32_t flag);
323
324 #define CODECHAL_ENCODE_RECYCLED_BUFFER_NUM 6
325 #define VDENC_BRC_NUM_OF_PASSES 2
326
327 uint8_t m_currRecycledBufIdx = 0; //!< Current recycled buffer index
328 protected:
329 uint32_t m_standard = 0; //!< The encode state's standard
330 uint32_t m_mode = 0; //!< The encode mode
331 CODECHAL_FUNCTION m_codecFunction = CODECHAL_FUNCTION_INVALID; //!< The encode state's codec function used
332
333 CodechalHwInterfaceNext *m_hwInterface = nullptr; //!< CodechalHwInterface
334 MOS_INTERFACE * m_osInterface = nullptr;
335 EncodeAllocator * m_allocator = nullptr;
336 TrackedBuffer * m_trackedBuf = nullptr;
337 RecycleResource * m_recycleBuf = nullptr;
338 EncodeMemComp * m_mmcState = nullptr;
339 EncodeCp * m_encodecp = nullptr;
340 PacketUtilities * m_packetUtilities = nullptr;
341
342 CodechalDebugInterface *m_statusReportDebugInterface = nullptr; //!< Interface used for debug dumps in status report callback function
343
344 uint8_t m_numVdbox = 0;
345
346 bool m_singleTaskPhaseSupported = true;
347 bool m_singleTaskPhaseSupportedInPak = false;
348
349 uint32_t m_recycledBufStatusNum[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {0}; //!< Recycled buffer status num list
350
351 std::shared_ptr<EncodeScalabilityPars> m_scalPars = nullptr;
352
353 MEDIA_CLASS_DEFINE_END(encode__EncodePipeline)
354 };
355
356 } // namespace encode
357
358 #endif // !__ENCODE_PIPELINE_H__