Debian Codegraph @

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

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.h
25 //! \brief Factories for vp object creation.
26 //!
27 #ifndef __VP_OBJ_FACTORIES_H__
28 #define __VP_OBJ_FACTORIES_H__
29
30 #include "media_feature_manager.h"
31 #include "vp_utils.h"
32 #include "vp_pipeline_common.h"
33 #include "vp_allocator.h"
34
35 #include "sw_filter_pipe.h"
36 #include "hw_filter_pipe.h"
37
38 namespace vp
39 {
40
41 template<class Type>
42 class VpObjAllocator
43 {
44 public:
45 VpObjAllocator(VpInterface &vpInterface) : m_vpInterface(vpInterface)
46 {
47 }
48
49 virtual ~VpObjAllocator()
50 {
51 while (!m_Pool.empty())
52 {
53 Type *p = m_Pool.back();
54 m_Pool.pop_back();
55 MOS_Delete(p);
56 }
57 }
58
59 virtual Type *Create()
60 {
61 Type *obj = nullptr;
62 if (m_Pool.empty())
63 {
64 obj = MOS_New(Type, m_vpInterface);
65 }
66 else
67 {
68 obj = m_Pool.back();
69 if (obj)
70 {
71 m_Pool.pop_back();
72 }
73 }
74
75 return obj;
76 }
77
78 virtual MOS_STATUS Destory(Type *&obj)
79 {
80 if (nullptr == obj)
81 {
82 return MOS_STATUS_SUCCESS;
83 }
84 obj->Clean();
85 m_Pool.push_back(obj);
86 obj = nullptr;
87 return MOS_STATUS_SUCCESS;
88 }
89
90 private:
91 std::vector<Type *> m_Pool;
92 VpInterface &m_vpInterface;
93
94 MEDIA_CLASS_DEFINE_END(vp__VpObjAllocator)
95 };
96
97 class HwFilterPipeFactory
98 {
99 public:
100 HwFilterPipeFactory(VpInterface &vpInterface);
101
102 virtual ~HwFilterPipeFactory();
103
104 MOS_STATUS Create(SwFilterPipe &swfilterPipe,
105 Policy &policy, HwFilterPipe *&pHwFilterPipe);
106
107 MOS_STATUS Destory(HwFilterPipe *&pHwfilterPipe);
108
109 private:
110 VpObjAllocator<HwFilterPipe> m_allocator;
111
112 MEDIA_CLASS_DEFINE_END(vp__HwFilterPipeFactory)
113 };
114
115 class HwFilterFactory
116 {
117 public:
118 HwFilterFactory(VpInterface &vpInterface);
119 virtual ~HwFilterFactory();
120 HwFilter *Create(HW_FILTER_PARAMS &param);
121 void Destory(HwFilter *&pHwFilter);
122
123 private:
124 VpObjAllocator<HwFilterVebox> m_allocatorVebox;
125 VpObjAllocator<HwFilterVeboxSfc> m_allocatorVeboxSfc;
126 VpObjAllocator<HwFilterRender> m_allocatorRender;
127 VpObjAllocator<HwFilterNpu> m_allocatorNpu;
128
129 MEDIA_CLASS_DEFINE_END(vp__HwFilterFactory)
130 };
131
132 class SwFilterPipeFactory
133 {
134 public:
135 SwFilterPipeFactory(VpInterface &vpInterface);
136 virtual ~SwFilterPipeFactory();
137
138 MOS_STATUS Create(PVP_PIPELINE_PARAMS params, std::vector<SwFilterPipe *> &swFilterPipe, VpPipelineParamFactory *pipelineParamFactory);
139 MOS_STATUS Create(VEBOX_SFC_PARAMS *params, std::vector<SwFilterPipe*> &swFilterPipe);
140
141 // Create empty swFilter
142 MOS_STATUS Create(SwFilterPipe *&swFilterPipe);
143 void Destory(SwFilterPipe *&swfilterPipe);
144
145 private:
146 int GetPipeCountForProcessing(VP_PIPELINE_PARAMS &params);
147 MOS_STATUS Update(VP_PIPELINE_PARAMS &params, int index);
148 VpObjAllocator<SwFilterPipe> m_allocator;
149 VpInterface &m_vpInterface;
150
151 MEDIA_CLASS_DEFINE_END(vp__SwFilterPipeFactory)
152 };
153
154 template <class _T>
155 class SwFilterFactory
156 {
157 public:
158 SwFilterFactory(VpInterface& vpInterface) : m_allocator(vpInterface)
159 {
160 }
161 virtual ~SwFilterFactory()
162 {
163 }
164 SwFilter* Create()
165 {
166 SwFilter* swFilter = nullptr;
167 swFilter = m_allocator.Create();
168
169 if (swFilter)
170 {
171 return swFilter;
172 }
173 else
174 {
175 return nullptr;
176 }
177 }
178 void Destory(_T*& swFilter)
179 {
180 m_allocator.Destory(swFilter);
181 return;
182 }
183
184 private:
185 VpObjAllocator<_T> m_allocator;
186
187 MEDIA_CLASS_DEFINE_END(vp__SwFilterFactory)
188 };
189 }
190 #endif // !__VP_OBJ_FACTORIES_H__