Debian Codegraph @

media_softlet/agnostic/common/vp/hal/feature_manager/vp_obj_factories.cpp

raw
1 /*
2 * Copyright (c) 2019-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 //!
24 //! \file vp_obj_factories.cpp
25 //! \brief Factories for vp object creation.
26 //!
27 #include "vp_obj_factories.h"
28 #include "sw_filter_handle.h"
29 using namespace vp;
30
31 /****************************************************************************************************/
32 /* HwFilterPipeFactory */
33 /****************************************************************************************************/
34
35 HwFilterPipeFactory::HwFilterPipeFactory(VpInterface &vpInterface) : m_allocator(vpInterface)
36 {
37 }
38
39 HwFilterPipeFactory::~HwFilterPipeFactory()
40 {
41 }
42
43 MOS_STATUS HwFilterPipeFactory::Create(SwFilterPipe &swfilterPipe,
44 Policy &policy, HwFilterPipe *&pHwFilterPipe)
45 {
46 VP_FUNC_CALL();
47
48 pHwFilterPipe = m_allocator.Create();
49
50 VP_PUBLIC_CHK_NULL_RETURN(pHwFilterPipe);
51 MOS_STATUS status = pHwFilterPipe->Initialize(swfilterPipe, policy);
52 if (MOS_FAILED(status))
53 {
54 Destory(pHwFilterPipe);
55 }
56 return status;
57 }
58
59 MOS_STATUS HwFilterPipeFactory::Destory(HwFilterPipe *&pHwfilterPipe)
60 {
61 VP_FUNC_CALL();
62
63 return m_allocator.Destory(pHwfilterPipe);
64 }
65
66 /****************************************************************************************************/
67 /* HwFilterFactory */
68 /****************************************************************************************************/
69
70 HwFilterFactory::HwFilterFactory(VpInterface &vpInterface) : m_allocatorVebox(vpInterface), m_allocatorVeboxSfc(vpInterface), m_allocatorRender(vpInterface), m_allocatorNpu(vpInterface)
71 {
72 }
73
74 HwFilterFactory::~HwFilterFactory()
75 {
76 }
77
78 HwFilter *HwFilterFactory::Create(HW_FILTER_PARAMS &param)
79 {
80 VP_FUNC_CALL();
81
82 HwFilter *p = nullptr;
83 switch (param.Type)
84 {
85 case EngineTypeVebox:
86 p = m_allocatorVebox.Create();
87 break;
88 case EngineTypeVeboxSfc:
89 p = m_allocatorVeboxSfc.Create();
90 break;
91 case EngineTypeRender:
92 p = m_allocatorRender.Create();
93 break;
94 case EngineTypeNpu:
95 p = m_allocatorNpu.Create();
96 break;
97 default:
98 return nullptr;
99 break;
100 }
101 if (p)
102 {
103 if (MOS_FAILED(p->Initialize(param)))
104 {
105 Destory(p);
106 return nullptr;
107 }
108 }
109 return p;
110 }
111
112 void HwFilterFactory::Destory(HwFilter *&pHwFilter)
113 {
114 VP_FUNC_CALL();
115
116 if (pHwFilter)
117 {
118 switch (pHwFilter->GetEngineType())
119 {
120 case EngineTypeVebox:
121 {
122 HwFilterVebox *p = dynamic_cast<HwFilterVebox*>(pHwFilter);
123 if (p)
124 {
125 m_allocatorVebox.Destory(p);
126 pHwFilter = nullptr;
127 }
128 else
129 {
130 VP_PUBLIC_ASSERTMESSAGE("Invalid engine type for hwFilter!");
131 MOS_Delete(pHwFilter);
132 }
133 break;
134 }
135 case EngineTypeVeboxSfc:
136 {
137 HwFilterVeboxSfc *p = dynamic_cast<HwFilterVeboxSfc*>(pHwFilter);
138 if (p)
139 {
140 m_allocatorVeboxSfc.Destory(p);
141 pHwFilter = nullptr;
142 }
143 else
144 {
145 VP_PUBLIC_ASSERTMESSAGE("Invalid engine type for hwFilter!");
146 MOS_Delete(pHwFilter);
147 }
148 break;
149 }
150 case EngineTypeRender:
151 {
152 HwFilterRender *p = dynamic_cast<HwFilterRender*>(pHwFilter);
153 if (p)
154 {
155 m_allocatorRender.Destory(p);
156 pHwFilter = nullptr;
157 }
158 else
159 {
160 VP_PUBLIC_ASSERTMESSAGE("Invalid engine type for hwFilter!");
161 MOS_Delete(pHwFilter);
162 }
163 break;
164 }
165 case EngineTypeNpu:
166 {
167 HwFilterNpu *p = dynamic_cast<HwFilterNpu *>(pHwFilter);
168 if (p)
169 {
170 m_allocatorNpu.Destory(p);
171 pHwFilter = nullptr;
172 }
173 else
174 {
175 VP_PUBLIC_ASSERTMESSAGE("Invalid engine type for hwFilter!");
176 MOS_Delete(pHwFilter);
177 }
178 break;
179 }
180 default:
181 MOS_Delete(pHwFilter);
182 return;
183 }
184 pHwFilter = nullptr;
185 }
186 }
187
188 /****************************************************************************************************/
189 /* SwFilterPipeFactory */
190 /****************************************************************************************************/
191
192 SwFilterPipeFactory::SwFilterPipeFactory(VpInterface &vpInterface) :
193 m_allocator(vpInterface),
194 m_vpInterface(vpInterface)
195 {
196 }
197
198 SwFilterPipeFactory::~SwFilterPipeFactory()
199 {
200 }
201
202 int SwFilterPipeFactory::GetPipeCountForProcessing(VP_PIPELINE_PARAMS &params)
203 {
204 VP_FUNC_CALL();
205
206 int pipeCnt = 1;
207 int featureCnt = 0;
208 auto featureHander = *m_vpInterface.GetSwFilterHandlerMap();
209 for (auto &handler : featureHander)
210 {
211 int cnt = handler.second->GetPipeCountForProcessing(params);
212 if (cnt > 1)
213 {
214 pipeCnt = cnt;
215 featureCnt++;
216 }
217 }
218 if (featureCnt > 1)
219 {
220 VP_PUBLIC_ASSERTMESSAGE("Invalid usage, only support 1 feature for multi-pipe.");
221 return 0;
222 }
223 return pipeCnt;
224 }
225
226 MOS_STATUS SwFilterPipeFactory::Update(VP_PIPELINE_PARAMS &params, int index)
227 {
228 VP_FUNC_CALL();
229
230 auto featureHander = *m_vpInterface.GetSwFilterHandlerMap();
231 for (auto &handler : featureHander)
232 {
233 VP_PUBLIC_CHK_STATUS_RETURN(handler.second->UpdateParamsForProcessing(params, index));
234 }
235 return MOS_STATUS_SUCCESS;
236 }
237
238 MOS_STATUS SwFilterPipeFactory::Create(PVP_PIPELINE_PARAMS params, std::vector<SwFilterPipe *> &swFilterPipe, VpPipelineParamFactory *pipelineParamFactory)
239 {
240 VP_FUNC_CALL();
241
242 VP_PUBLIC_CHK_NULL_RETURN(params);
243 VP_PUBLIC_CHK_NULL_RETURN(pipelineParamFactory);
244 int pipeCnt = GetPipeCountForProcessing(*params);
245 if (pipeCnt == 0)
246 {
247 return MOS_STATUS_INVALID_PARAMETER;
248 }
249
250 MT_LOG1(MT_VP_HAL_SWWFILTER, MT_NORMAL, MT_VP_HAL_PIPE_CNT, pipeCnt);
251
252 for (int index = 0; index < pipeCnt; index++)
253 {
254 VP_PIPELINE_PARAMS *tempParams = pipelineParamFactory->Clone(params);
255 VP_PUBLIC_CHK_NULL_RETURN(tempParams);
256 VP_PUBLIC_CHK_STATUS_RETURN(Update(*tempParams, index));
257
258 SwFilterPipe *pipe = m_allocator.Create();
259 if (!pipe)
260 {
261 pipelineParamFactory->Destroy(tempParams);
262 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NULL_POINTER);
263 }
264
265 FeatureRule featureRule;
266 MOS_STATUS status = pipe->Initialize(*tempParams, featureRule);
267
268 VP_PUBLIC_CHK_STATUS_RETURN(pipelineParamFactory->Destroy(tempParams));
269
270 if (MOS_FAILED(status))
271 {
272 m_allocator.Destory(pipe);
273 return status;
274 }
275
276 swFilterPipe.push_back(pipe);
277 }
278
279 return MOS_STATUS_SUCCESS;
280 }
281
282 MOS_STATUS SwFilterPipeFactory::Create(VEBOX_SFC_PARAMS *params, std::vector<SwFilterPipe*> &swFilterPipe)
283 {
284 VP_FUNC_CALL();
285
286 VP_PUBLIC_CHK_NULL_RETURN(params);
287 SwFilterPipe *pipe = m_allocator.Create();
288 VP_PUBLIC_CHK_NULL_RETURN(pipe);
289
290 MOS_STATUS status = pipe->Initialize(*params);
291
292 if (MOS_FAILED(status))
293 {
294 m_allocator.Destory(pipe);
295 return status;
296 }
297
298 swFilterPipe.push_back(pipe);
299 return status;
300 }
301
302 MOS_STATUS SwFilterPipeFactory::Create(SwFilterPipe *&swFilterPipe)
303 {
304 VP_FUNC_CALL();
305
306 swFilterPipe = m_allocator.Create();
307 VP_PUBLIC_CHK_NULL_RETURN(swFilterPipe);
308
309 return MOS_STATUS_SUCCESS;
310 }
311
312 void SwFilterPipeFactory::Destory(SwFilterPipe *&swFilterPipe)
313 {
314 VP_FUNC_CALL();
315
316 m_allocator.Destory(swFilterPipe);
317 }