1 /*
2 * Copyright (c) 2007-2017, 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 cm_vebox_rt.cpp
24 //! \brief Contains CmVeboxRT implementations.
25 //!
26
27 #include "cm_vebox_rt.h"
28
29 #include "cm_device_rt.h"
30 #include "cm_surface_2d_rt.h"
31
32 namespace CMRT_UMD
33 {
34 //*-----------------------------------------------------------------------------
35 //| Purpose: Create Vebox
36 //*-----------------------------------------------------------------------------
Create(CmDeviceRT * device,uint32_t index,CmVeboxRT * & cmVebox)37 int32_t CmVeboxRT::Create( CmDeviceRT* device, uint32_t index, CmVeboxRT* & cmVebox )
38 {
39 int32_t result = CM_SUCCESS;
40
41 cmVebox = new (std::nothrow) CmVeboxRT(device, index);
42 if (cmVebox)
43 {
44 result = cmVebox->Initialize();
45 if( result != CM_SUCCESS )
46 {
47 CmVeboxRT::Destroy(cmVebox);
48 }
49 }
50 else
51 {
52 CM_ASSERTMESSAGE("Error: Failed to create CmVebox due to out of system memory.");
53 result = CM_OUT_OF_HOST_MEMORY;
54 }
55 return result;
56
57 }
58
59 //*-----------------------------------------------------------------------------
60 //| Purpose: Destroy Vebox
61 //*-----------------------------------------------------------------------------
Destroy(CmVeboxRT * & cmVebox)62 int32_t CmVeboxRT::Destroy( CmVeboxRT* & cmVebox )
63 {
64 if(cmVebox)
65 {
66 /*need some work to delete vebox state*/
67 delete cmVebox;
68 cmVebox = nullptr;
69 }
70 return CM_SUCCESS;
71 }
72
CmVeboxRT(CmDeviceRT * device,uint32_t index)73 CmVeboxRT::CmVeboxRT( CmDeviceRT* device, uint32_t index ):
74 m_device( device ),
75 m_maxSurfaceIndex(VEBOX_MAX_SURFACE_COUNT),
76 m_paramBuffer( nullptr ),
77 m_indexInVeboxArray( index )
78 {
79 MOS_ZeroMemory(&m_veboxState, sizeof(m_veboxState));
80 MOS_ZeroMemory(&m_surface2D, sizeof(m_surface2D));
81 MOS_ZeroMemory(&m_surfaceCtrlBits, sizeof(m_surfaceCtrlBits));
82 }
83
~CmVeboxRT(void)84 CmVeboxRT::~CmVeboxRT( void )
85 {
86 }
87
Initialize()88 int32_t CmVeboxRT::Initialize()
89 {
90
91 for (int32_t i = 0; i < VEBOX_MAX_SURFACE_COUNT; i++)
92 {
93 m_surface2D[i] = nullptr;
94 m_surfaceCtrlBits[i] = 0;
95
96 }
97
98 return CM_SUCCESS;
99 }
100
SetParam(CmBufferUP * paramBuffer)101 CM_RT_API int32_t CmVeboxRT::SetParam(CmBufferUP *paramBuffer)
102 {
103 m_paramBuffer = paramBuffer;
104 return CM_SUCCESS;
105 }
SetState(CM_VEBOX_STATE & veboxState)106 CM_RT_API int32_t CmVeboxRT::SetState(CM_VEBOX_STATE& veboxState)
107 {
108
109 m_veboxState = veboxState;
110 return CM_SUCCESS;
111
112 }
113
SetSurfaceInternal(VEBOX_SURF_USAGE surfUsage,CmSurface2D * surface)114 int32_t CmVeboxRT::SetSurfaceInternal(VEBOX_SURF_USAGE surfUsage, CmSurface2D* surface)
115 {
116 if( (uint32_t)surfUsage < m_maxSurfaceIndex)
117 {
118 m_surface2D[surfUsage] = static_cast<CmSurface2DRT *>(surface);
119 return CM_SUCCESS;
120 }
121 else
122 {
123 CM_ASSERTMESSAGE("Error: Failed to set the internal surface.");
124 return CM_FAILURE;
125 }
126 }
127
SetSurfaceControlBitsInternal(VEBOX_SURF_USAGE surfUsage,const uint16_t ctrlBits)128 int32_t CmVeboxRT::SetSurfaceControlBitsInternal(VEBOX_SURF_USAGE surfUsage, const uint16_t ctrlBits)
129 {
130
131 if( (uint32_t)surfUsage < VEBOX_SURFACE_NUMBER )
132 {
133 m_surfaceCtrlBits[surfUsage] = ctrlBits;
134 return CM_SUCCESS;
135 }
136 else
137 {
138 CM_ASSERTMESSAGE("Error: Failed to set the internal surface control bits.");
139 return CM_FAILURE;
140 }
141 }
142
SetCurFrameInputSurface(CmSurface2D * surface)143 CM_RT_API int32_t CmVeboxRT::SetCurFrameInputSurface( CmSurface2D * surface )
144 {
145 return SetSurfaceInternal(VEBOX_CURRENT_FRAME_INPUT_SURF, surface);
146 }
147
SetCurFrameInputSurfaceControlBits(const uint16_t ctrlBits)148 CM_RT_API int32_t CmVeboxRT::SetCurFrameInputSurfaceControlBits( const uint16_t ctrlBits )
149 {
150 return SetSurfaceControlBitsInternal(VEBOX_CURRENT_FRAME_INPUT_SURF, ctrlBits);
151 }
152
SetPrevFrameInputSurface(CmSurface2D * surface)153 CM_RT_API int32_t CmVeboxRT::SetPrevFrameInputSurface( CmSurface2D * surface )
154 {
155 return SetSurfaceInternal(VEBOX_PREVIOUS_FRAME_INPUT_SURF, surface);
156 }
157
SetPrevFrameInputSurfaceControlBits(const uint16_t ctrlBits)158 CM_RT_API int32_t CmVeboxRT::SetPrevFrameInputSurfaceControlBits( const uint16_t ctrlBits )
159 {
160 return SetSurfaceControlBitsInternal(VEBOX_PREVIOUS_FRAME_INPUT_SURF, ctrlBits);
161 }
162
SetSTMMInputSurface(CmSurface2D * surface)163 CM_RT_API int32_t CmVeboxRT::SetSTMMInputSurface( CmSurface2D* surface )
164 {
165 return SetSurfaceInternal(VEBOX_STMM_INPUT_SURF, surface);
166 }
167
SetSTMMInputSurfaceControlBits(const uint16_t ctrlBits)168 CM_RT_API int32_t CmVeboxRT::SetSTMMInputSurfaceControlBits( const uint16_t ctrlBits )
169 {
170 return SetSurfaceControlBitsInternal(VEBOX_STMM_INPUT_SURF, ctrlBits);
171 }
172
SetSTMMOutputSurface(CmSurface2D * surface)173 CM_RT_API int32_t CmVeboxRT::SetSTMMOutputSurface( CmSurface2D* surface )
174 {
175 return SetSurfaceInternal(VEBOX_STMM_OUTPUT_SURF, surface);
176 }
177
SetSTMMOutputSurfaceControlBits(const uint16_t ctrlBits)178 CM_RT_API int32_t CmVeboxRT::SetSTMMOutputSurfaceControlBits( const uint16_t ctrlBits )
179 {
180 return SetSurfaceControlBitsInternal(VEBOX_STMM_OUTPUT_SURF, ctrlBits);
181 }
182
SetDenoisedCurFrameOutputSurface(CmSurface2D * surface)183 CM_RT_API int32_t CmVeboxRT::SetDenoisedCurFrameOutputSurface( CmSurface2D* surface )
184 {
185 return SetSurfaceInternal(VEBOX_DN_CURRENT_FRAME_OUTPUT_SURF, surface);
186 }
187
SetDenoisedCurOutputSurfaceControlBits(const uint16_t ctrlBits)188 CM_RT_API int32_t CmVeboxRT::SetDenoisedCurOutputSurfaceControlBits( const uint16_t ctrlBits )
189 {
190 return SetSurfaceControlBitsInternal(VEBOX_DN_CURRENT_FRAME_OUTPUT_SURF, ctrlBits);
191 }
192
SetCurFrameOutputSurface(CmSurface2D * surface)193 CM_RT_API int32_t CmVeboxRT::SetCurFrameOutputSurface( CmSurface2D* surface )
194 {
195 int32_t ret = SetSurfaceInternal(VEBOX_CURRENT_FRAME_OUTPUT_SURF, surface);
196 CmSurface2DRT* surf2D = static_cast<CmSurface2DRT *>(surface);
197 if (m_surface2D[VEBOX_LACE_ACE_RGB_HISTOGRAM_OUTPUT_SURF] == nullptr)
198 {
199 uint32_t width = 0;
200 uint32_t height = 0;
201 uint32_t pixelsize = 0;
202 CM_SURFACE_FORMAT format = CM_SURFACE_FORMAT_INVALID;
203
204 if (ret == CM_SUCCESS)
205 {
206 ret = surf2D->GetSurfaceDesc(width, height, format, pixelsize);
207 }
208 if (ret == CM_SUCCESS)
209 {
210 CmSurface2D *surface2DBase = nullptr;
211 ret = m_device->CreateSurface2D(width, height, format, surface2DBase); // allocate the histogram surface if CmIECP Enabled
212 if (surface2DBase != nullptr)
213 {
214 m_surface2D[VEBOX_LACE_ACE_RGB_HISTOGRAM_OUTPUT_SURF] = static_cast<CmSurface2DRT *>(surface2DBase);
215 m_surfaceCtrlBits[VEBOX_LACE_ACE_RGB_HISTOGRAM_OUTPUT_SURF] = m_surfaceCtrlBits[VEBOX_CURRENT_FRAME_OUTPUT_SURF];
216 }
217 }
218 }
219 return ret;
220 }
221
SetCurFrameOutputSurfaceControlBits(const uint16_t ctrlBits)222 CM_RT_API int32_t CmVeboxRT::SetCurFrameOutputSurfaceControlBits( const uint16_t ctrlBits )
223 {
224 return SetSurfaceControlBitsInternal(VEBOX_CURRENT_FRAME_OUTPUT_SURF, ctrlBits);
225 }
226
SetPrevFrameOutputSurface(CmSurface2D * surface)227 CM_RT_API int32_t CmVeboxRT::SetPrevFrameOutputSurface( CmSurface2D* surface )
228 {
229 return SetSurfaceInternal(VEBOX_PREVIOUS_FRAME_OUTPUT_SURF, surface);
230 }
231
SetPrevFrameOutputSurfaceControlBits(const uint16_t ctrlBits)232 CM_RT_API int32_t CmVeboxRT::SetPrevFrameOutputSurfaceControlBits( const uint16_t ctrlBits )
233 {
234 return SetSurfaceControlBitsInternal(VEBOX_PREVIOUS_FRAME_OUTPUT_SURF, ctrlBits);
235 }
236
SetStatisticsOutputSurface(CmSurface2D * surface)237 CM_RT_API int32_t CmVeboxRT::SetStatisticsOutputSurface( CmSurface2D* surface )
238 {
239 return SetSurfaceInternal(VEBOX_STATISTICS_OUTPUT_SURF, surface);
240 }
241
SetStatisticsOutputSurfaceControlBits(const uint16_t ctrlBits)242 CM_RT_API int32_t CmVeboxRT::SetStatisticsOutputSurfaceControlBits( const uint16_t ctrlBits )
243 {
244 return SetSurfaceControlBitsInternal(VEBOX_STATISTICS_OUTPUT_SURF, ctrlBits);
245 }
246
GetSurface(uint32_t surfUsage,CmSurface2DRT * & surface)247 int32_t CmVeboxRT::GetSurface(uint32_t surfUsage, CmSurface2DRT*& surface)
248 {
249 int hr = CM_SUCCESS;
250
251 if (surfUsage < VEBOX_SURFACE_NUMBER)
252 {
253 surface = m_surface2D[surfUsage];
254 }
255 else
256 {
257 surface = nullptr;
258 hr = CM_FAILURE;
259 }
260
261 return hr;
262 }
263
GetIndexInVeboxArray()264 uint32_t CmVeboxRT::GetIndexInVeboxArray()
265 {
266 return m_indexInVeboxArray;
267 }
268
GetState()269 CM_VEBOX_STATE CmVeboxRT::GetState()
270 {
271 return m_veboxState;
272 }
273
GetParam()274 CmBufferUP * CmVeboxRT::GetParam( )
275 {
276 return m_paramBuffer;
277 }
278
GetSurfaceControlBits(uint32_t usage)279 uint16_t CmVeboxRT::GetSurfaceControlBits(uint32_t usage)
280 {
281 if (usage < VEBOX_MAX_SURFACE_COUNT)
282 return m_surfaceCtrlBits[usage];
283 else
284 return CM_FAILURE;
285 }
286 }
287