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: VpObjAllocator(VpInterface & vpInterface)45 VpObjAllocator(VpInterface &vpInterface) : m_vpInterface(vpInterface) 46 { 47 } 48 ~VpObjAllocator()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 Create()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 Destory(Type * & obj)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 ¶m); 121 void Destory(HwFilter *&pHwFilter); 122 123 private: 124 VpObjAllocator<HwFilterVebox> m_allocatorVebox; 125 VpObjAllocator<HwFilterVeboxSfc> m_allocatorVeboxSfc; 126 VpObjAllocator<HwFilterRender> m_allocatorRender; 127 128 MEDIA_CLASS_DEFINE_END(vp__HwFilterFactory) 129 }; 130 131 class SwFilterPipeFactory 132 { 133 public: 134 SwFilterPipeFactory(VpInterface &vpInterface); 135 virtual ~SwFilterPipeFactory(); 136 137 MOS_STATUS Create(PVP_PIPELINE_PARAMS params, std::vector<SwFilterPipe *> &swFilterPipe, VpPipelineParamFactory *pipelineParamFactory); 138 MOS_STATUS Create(VEBOX_SFC_PARAMS *params, std::vector<SwFilterPipe*> &swFilterPipe); 139 140 // Create empty swFilter 141 MOS_STATUS Create(SwFilterPipe *&swFilterPipe); 142 void Destory(SwFilterPipe *&swfilterPipe); 143 144 private: 145 int GetPipeCountForProcessing(VP_PIPELINE_PARAMS ¶ms); 146 MOS_STATUS Update(VP_PIPELINE_PARAMS ¶ms, int index); 147 VpObjAllocator<SwFilterPipe> m_allocator; 148 VpInterface &m_vpInterface; 149 150 MEDIA_CLASS_DEFINE_END(vp__SwFilterPipeFactory) 151 }; 152 153 template <class _T> 154 class SwFilterFactory 155 { 156 public: SwFilterFactory(VpInterface & vpInterface)157 SwFilterFactory(VpInterface& vpInterface) : m_allocator(vpInterface) 158 { 159 } ~SwFilterFactory()160 virtual ~SwFilterFactory() 161 { 162 } Create()163 SwFilter* Create() 164 { 165 SwFilter* swFilter = nullptr; 166 swFilter = m_allocator.Create(); 167 168 if (swFilter) 169 { 170 return swFilter; 171 } 172 else 173 { 174 return nullptr; 175 } 176 } Destory(_T * & swFilter)177 void Destory(_T*& swFilter) 178 { 179 m_allocator.Destory(swFilter); 180 return; 181 } 182 183 private: 184 VpObjAllocator<_T> m_allocator; 185 186 MEDIA_CLASS_DEFINE_END(vp__SwFilterFactory) 187 }; 188 } 189 #endif // !__VP_OBJ_FACTORIES_H__ 190