Commit | Line | Data |
---|---|---|
c6f4bc34 YK |
1 | /* |
2 | * Copyright 2012 Samsung Electronics S.LSI Co. LTD | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | /* | |
18 | * @file Exynos_OSAL_Android.cpp | |
19 | * @brief | |
20 | * @author Seungbeom Kim (sbcrux.kim@samsung.com) | |
21 | * @author Hyeyeon Chung (hyeon.chung@samsung.com) | |
22 | * @author Yunji Kim (yunji.kim@samsung.com) | |
23 | * @author Jinsung Yang (jsgood.yang@samsung.com) | |
24 | * @version 2.0.0 | |
25 | * @history | |
26 | * 2012.02.20 : Create | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | ||
32 | #include <system/window.h> | |
33 | #include <ui/GraphicBuffer.h> | |
34 | #include <ui/GraphicBufferMapper.h> | |
35 | #include <ui/Rect.h> | |
36 | #include <media/hardware/HardwareAPI.h> | |
37 | #include <hardware/hardware.h> | |
38 | #include <media/hardware/OMXPluginBase.h> | |
39 | #include <media/hardware/MetadataBufferType.h> | |
faa0e22c | 40 | #ifdef USE_DMA_BUF |
c6f4bc34 | 41 | #include <gralloc_priv.h> |
faa0e22c | 42 | #endif |
c6f4bc34 | 43 | |
107c5289 | 44 | #include "exynos_format.h" |
c6f4bc34 YK |
45 | #include "Exynos_OSAL_Semaphore.h" |
46 | #include "Exynos_OMX_Baseport.h" | |
47 | #include "Exynos_OMX_Basecomponent.h" | |
48 | #include "Exynos_OMX_Macros.h" | |
c6f4bc34 | 49 | #include "Exynos_OSAL_Android.h" |
c6f4bc34 | 50 | |
e4e150b8 HK |
51 | #include "ExynosVideoApi.h" |
52 | ||
c6f4bc34 YK |
53 | #undef EXYNOS_LOG_TAG |
54 | #define EXYNOS_LOG_TAG "Exynos_OSAL_Android" | |
55 | #define EXYNOS_LOG_OFF | |
56 | #include "Exynos_OSAL_Log.h" | |
57 | ||
58 | using namespace android; | |
59 | ||
60 | #ifdef __cplusplus | |
61 | extern "C" { | |
62 | #endif | |
63 | ||
323488ff | 64 | static int lockCnt = 0; |
c6f4bc34 YK |
65 | |
66 | OMX_ERRORTYPE Exynos_OSAL_LockANBHandle( | |
67 | OMX_IN OMX_U32 handle, | |
68 | OMX_IN OMX_U32 width, | |
69 | OMX_IN OMX_U32 height, | |
70 | OMX_IN OMX_COLOR_FORMATTYPE format, | |
9d7f3c95 | 71 | OMX_OUT OMX_U32 *pStride, |
c6f4bc34 YK |
72 | OMX_OUT OMX_PTR planes) |
73 | { | |
74 | FunctionIn(); | |
75 | ||
76 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
77 | GraphicBufferMapper &mapper = GraphicBufferMapper::get(); | |
78 | buffer_handle_t bufferHandle = (buffer_handle_t) handle; | |
faa0e22c | 79 | #ifdef USE_DMA_BUF |
c6f4bc34 | 80 | private_handle_t *priv_hnd = (private_handle_t *) bufferHandle; |
faa0e22c | 81 | #endif |
c6f4bc34 YK |
82 | Rect bounds(width, height); |
83 | ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes; | |
84 | void *vaddr[MAX_BUFFER_PLANE]; | |
85 | ||
86 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle); | |
87 | ||
88 | int usage = 0; | |
89 | ||
90 | switch (format) { | |
91 | case OMX_COLOR_FormatYUV420Planar: | |
92 | case OMX_COLOR_FormatYUV420SemiPlanar: | |
93 | case OMX_SEC_COLOR_FormatNV12Tiled: | |
94 | usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN; | |
95 | break; | |
4f86e735 JY |
96 | case OMX_COLOR_FormatAndroidOpaque: |
97 | { | |
98 | OMX_COLOR_FORMATTYPE formatType; | |
23dc1702 | 99 | formatType = Exynos_OSAL_GetANBColorFormat((OMX_U32)priv_hnd); |
4f86e735 JY |
100 | if ((formatType == OMX_COLOR_FormatYUV420SemiPlanar) || |
101 | (formatType == OMX_SEC_COLOR_FormatNV12Tiled)) | |
102 | usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN; | |
103 | else | |
104 | usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_VIDEO_ENCODER; | |
105 | } | |
106 | break; | |
c6f4bc34 YK |
107 | default: |
108 | usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN; | |
109 | break; | |
110 | } | |
111 | ||
112 | if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) { | |
113 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__); | |
114 | ret = OMX_ErrorUndefined; | |
115 | goto EXIT; | |
116 | } | |
323488ff SK |
117 | lockCnt++; |
118 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: lockCnt:%d", __func__, lockCnt); | |
c6f4bc34 | 119 | |
faa0e22c | 120 | #ifdef USE_DMA_BUF |
c6f4bc34 YK |
121 | vplanes[0].fd = priv_hnd->fd; |
122 | vplanes[0].offset = 0; | |
c6f4bc34 YK |
123 | vplanes[1].fd = priv_hnd->fd1; |
124 | vplanes[1].offset = 0; | |
c6f4bc34 YK |
125 | vplanes[2].fd = priv_hnd->fd2; |
126 | vplanes[2].offset = 0; | |
faa0e22c SKR |
127 | #endif |
128 | vplanes[0].addr = vaddr[0]; | |
129 | vplanes[1].addr = vaddr[1]; | |
c6f4bc34 YK |
130 | vplanes[2].addr = vaddr[2]; |
131 | ||
9d7f3c95 SK |
132 | *pStride = priv_hnd->stride; |
133 | ||
c6f4bc34 YK |
134 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr); |
135 | ||
136 | EXIT: | |
137 | FunctionOut(); | |
138 | ||
139 | return ret; | |
140 | } | |
141 | ||
142 | OMX_ERRORTYPE Exynos_OSAL_UnlockANBHandle(OMX_IN OMX_U32 handle) | |
143 | { | |
144 | FunctionIn(); | |
145 | ||
146 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
147 | GraphicBufferMapper &mapper = GraphicBufferMapper::get(); | |
148 | buffer_handle_t bufferHandle = (buffer_handle_t) handle; | |
149 | ||
150 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle); | |
151 | ||
152 | if (mapper.unlock(bufferHandle) != 0) { | |
153 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__); | |
154 | ret = OMX_ErrorUndefined; | |
155 | goto EXIT; | |
156 | } | |
323488ff SK |
157 | lockCnt--; |
158 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: lockCnt:%d", __func__, lockCnt); | |
c6f4bc34 YK |
159 | |
160 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle); | |
161 | ||
162 | EXIT: | |
163 | FunctionOut(); | |
164 | ||
165 | return ret; | |
166 | } | |
167 | ||
168 | OMX_COLOR_FORMATTYPE Exynos_OSAL_GetANBColorFormat(OMX_IN OMX_U32 handle) | |
169 | { | |
170 | FunctionIn(); | |
171 | ||
172 | OMX_COLOR_FORMATTYPE ret = OMX_COLOR_FormatUnused; | |
173 | private_handle_t *priv_hnd = (private_handle_t *) handle; | |
174 | ||
175 | ret = Exynos_OSAL_Hal2OMXPixelFormat(priv_hnd->format); | |
176 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "ColorFormat: 0x%x", ret); | |
177 | ||
178 | EXIT: | |
179 | FunctionOut(); | |
180 | ||
181 | return ret; | |
182 | } | |
183 | ||
c6f4bc34 YK |
184 | OMX_ERRORTYPE useAndroidNativeBuffer( |
185 | EXYNOS_OMX_BASEPORT *pExynosPort, | |
186 | OMX_BUFFERHEADERTYPE **ppBufferHdr, | |
187 | OMX_U32 nPortIndex, | |
188 | OMX_PTR pAppPrivate, | |
189 | OMX_U32 nSizeBytes, | |
190 | OMX_U8 *pBuffer) | |
191 | { | |
192 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
193 | OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; | |
194 | unsigned int i = 0; | |
195 | OMX_U32 width, height; | |
196 | OMX_U32 stride; | |
197 | ExynosVideoPlane planes[MAX_BUFFER_PLANE]; | |
198 | ||
199 | FunctionIn(); | |
200 | ||
201 | if (pExynosPort == NULL) { | |
202 | ret = OMX_ErrorBadParameter; | |
203 | goto EXIT; | |
204 | } | |
205 | if (pExynosPort->portState != OMX_StateIdle) { | |
206 | ret = OMX_ErrorIncorrectStateOperation; | |
207 | goto EXIT; | |
208 | } | |
209 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { | |
210 | ret = OMX_ErrorBadPortIndex; | |
211 | goto EXIT; | |
212 | } | |
213 | ||
214 | temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE)); | |
215 | if (temp_bufferHeader == NULL) { | |
216 | ret = OMX_ErrorInsufficientResources; | |
217 | goto EXIT; | |
218 | } | |
219 | Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE)); | |
220 | ||
221 | for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) { | |
222 | if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) { | |
9d7f3c95 SK |
223 | OMX_U32 stride; |
224 | ||
c6f4bc34 YK |
225 | pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader; |
226 | pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED); | |
227 | INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE); | |
228 | temp_bufferHeader->pBuffer = pBuffer; | |
229 | temp_bufferHeader->nAllocLen = nSizeBytes; | |
230 | temp_bufferHeader->pAppPrivate = pAppPrivate; | |
231 | if (nPortIndex == INPUT_PORT_INDEX) | |
232 | temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX; | |
233 | else | |
234 | temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX; | |
235 | ||
236 | width = pExynosPort->portDefinition.format.video.nFrameWidth; | |
237 | height = pExynosPort->portDefinition.format.video.nFrameHeight; | |
9d7f3c95 | 238 | Exynos_OSAL_LockANBHandle((OMX_U32)temp_bufferHeader->pBuffer, width, height, |
c6f4bc34 YK |
239 | pExynosPort->portDefinition.format.video.eColorFormat, |
240 | &stride, planes); | |
faa0e22c | 241 | #ifdef USE_DMA_BUF |
c6f4bc34 | 242 | pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd; |
c6f4bc34 | 243 | pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd; |
c6f4bc34 | 244 | pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd; |
faa0e22c SKR |
245 | #endif |
246 | pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr; | |
247 | pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr; | |
c6f4bc34 | 248 | pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr; |
9d7f3c95 | 249 | Exynos_OSAL_UnlockANBHandle((OMX_U32)temp_bufferHeader->pBuffer); |
faa0e22c SKR |
250 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ", |
251 | i, pExynosPort->extendBufferHeader[i].pYUVBuf[0], | |
252 | pExynosPort->extendBufferHeader[i].pYUVBuf[1]); | |
c6f4bc34 YK |
253 | |
254 | pExynosPort->assignedBufferNum++; | |
255 | if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) { | |
256 | pExynosPort->portDefinition.bPopulated = OMX_TRUE; | |
257 | /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */ | |
258 | Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource); | |
259 | /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */ | |
260 | } | |
261 | *ppBufferHdr = temp_bufferHeader; | |
262 | ret = OMX_ErrorNone; | |
263 | ||
264 | goto EXIT; | |
265 | } | |
266 | } | |
267 | ||
268 | Exynos_OSAL_Free(temp_bufferHeader); | |
269 | ret = OMX_ErrorInsufficientResources; | |
270 | ||
271 | EXIT: | |
272 | FunctionOut(); | |
273 | ||
274 | return ret; | |
275 | } | |
276 | ||
277 | OMX_ERRORTYPE Exynos_OSAL_GetANBParameter( | |
278 | OMX_IN OMX_HANDLETYPE hComponent, | |
279 | OMX_IN OMX_INDEXTYPE nIndex, | |
280 | OMX_INOUT OMX_PTR ComponentParameterStructure) | |
281 | { | |
282 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
283 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
284 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
285 | ||
286 | FunctionIn(); | |
287 | ||
288 | if (hComponent == NULL) { | |
289 | ret = OMX_ErrorBadParameter; | |
290 | goto EXIT; | |
291 | } | |
292 | ||
293 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
294 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
295 | if (ret != OMX_ErrorNone) { | |
296 | goto EXIT; | |
297 | } | |
298 | ||
299 | if (pOMXComponent->pComponentPrivate == NULL) { | |
300 | ret = OMX_ErrorBadParameter; | |
301 | goto EXIT; | |
302 | } | |
303 | ||
304 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
305 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
306 | ret = OMX_ErrorInvalidState; | |
307 | goto EXIT; | |
308 | } | |
309 | ||
310 | if (ComponentParameterStructure == NULL) { | |
311 | ret = OMX_ErrorBadParameter; | |
312 | goto EXIT; | |
313 | } | |
314 | ||
315 | switch (nIndex) { | |
316 | case OMX_IndexParamGetAndroidNativeBuffer: | |
317 | { | |
318 | GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure; | |
319 | OMX_U32 portIndex = pANBParams->nPortIndex; | |
320 | ||
321 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__); | |
322 | ||
323 | ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams)); | |
324 | if (ret != OMX_ErrorNone) { | |
325 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__); | |
326 | goto EXIT; | |
327 | } | |
328 | ||
329 | if (portIndex >= pExynosComponent->portParam.nPorts) { | |
330 | ret = OMX_ErrorBadPortIndex; | |
331 | goto EXIT; | |
332 | } | |
333 | ||
334 | /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any | |
335 | * modifications since currently not defined what the 'nUsage' is for. | |
336 | */ | |
337 | pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP); | |
49c9889d TK |
338 | #if defined(USE_IMPROVED_BUFFER) && !defined(USE_CSC_HW) |
339 | pANBParams->nUsage |= (GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); | |
433e798a EC |
340 | #endif |
341 | #if defined(USE_MFC5X_ALIGNMENT) | |
342 | if ((pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].bufferProcessType & BUFFER_SHARE) && | |
343 | (pExynosComponent->pExynosPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)) { | |
344 | pANBParams->nUsage |= GRALLOC_USAGE_PRIVATE_0; | |
345 | } | |
49c9889d | 346 | #endif |
c6f4bc34 YK |
347 | } |
348 | break; | |
349 | ||
350 | default: | |
351 | { | |
352 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex); | |
353 | ret = OMX_ErrorUnsupportedIndex; | |
354 | goto EXIT; | |
355 | } | |
356 | break; | |
357 | } | |
358 | ||
359 | EXIT: | |
360 | FunctionOut(); | |
361 | ||
362 | return ret; | |
363 | } | |
364 | ||
365 | OMX_ERRORTYPE Exynos_OSAL_SetANBParameter( | |
366 | OMX_IN OMX_HANDLETYPE hComponent, | |
367 | OMX_IN OMX_INDEXTYPE nIndex, | |
368 | OMX_IN OMX_PTR ComponentParameterStructure) | |
369 | { | |
370 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
371 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
372 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
373 | ||
374 | FunctionIn(); | |
375 | ||
376 | if (hComponent == NULL) { | |
377 | ret = OMX_ErrorBadParameter; | |
378 | goto EXIT; | |
379 | } | |
380 | ||
381 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
382 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
383 | if (ret != OMX_ErrorNone) { | |
384 | goto EXIT; | |
385 | } | |
386 | ||
387 | if (pOMXComponent->pComponentPrivate == NULL) { | |
388 | ret = OMX_ErrorBadParameter; | |
389 | goto EXIT; | |
390 | } | |
391 | ||
392 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
393 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
394 | ret = OMX_ErrorInvalidState; | |
395 | goto EXIT; | |
396 | } | |
397 | ||
398 | if (ComponentParameterStructure == NULL) { | |
399 | ret = OMX_ErrorBadParameter; | |
400 | goto EXIT; | |
401 | } | |
402 | ||
c6f4bc34 YK |
403 | switch (nIndex) { |
404 | case OMX_IndexParamEnableAndroidBuffers: | |
405 | { | |
c6f4bc34 YK |
406 | EnableAndroidNativeBuffersParams *pANBParams = (EnableAndroidNativeBuffersParams *) ComponentParameterStructure; |
407 | OMX_U32 portIndex = pANBParams->nPortIndex; | |
408 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
409 | ||
410 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnableAndroidNativeBuffers", __func__); | |
411 | ||
412 | ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(EnableAndroidNativeBuffersParams)); | |
413 | if (ret != OMX_ErrorNone) { | |
414 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableAndroidNativeBuffersParams) is failed", __func__); | |
415 | goto EXIT; | |
416 | } | |
417 | ||
418 | if (portIndex >= pExynosComponent->portParam.nPorts) { | |
419 | ret = OMX_ErrorBadPortIndex; | |
420 | goto EXIT; | |
421 | } | |
422 | ||
423 | pExynosPort = &pExynosComponent->pExynosPort[portIndex]; | |
424 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { | |
425 | ret = OMX_ErrorBadPortIndex; | |
426 | goto EXIT; | |
427 | } | |
823175dd TK |
428 | |
429 | pExynosPort->bIsANBEnabled = pANBParams->enable; | |
430 | ||
8822b6c4 YK |
431 | #ifdef USE_ANB_OUTBUF_SHARE |
432 | /* ANB and DPB Buffer Sharing */ | |
c6f4bc34 | 433 | if ((portIndex == OUTPUT_PORT_INDEX) && |
433e798a EC |
434 | (pExynosPort->bIsANBEnabled == OMX_TRUE)) { |
435 | if ((pExynosPort->bufferProcessType & BUFFER_ANBSHARE) == BUFFER_ANBSHARE) { | |
436 | pExynosPort->bufferProcessType = BUFFER_SHARE; | |
437 | pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled; | |
438 | Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on"); | |
439 | } else { | |
440 | pExynosPort->bufferProcessType = BUFFER_COPY; | |
441 | pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; | |
442 | } | |
8822b6c4 YK |
443 | } |
444 | #else | |
445 | if ((portIndex == OUTPUT_PORT_INDEX) && | |
446 | (pExynosPort->bufferProcessType & BUFFER_COPY)) { | |
447 | pExynosPort->bufferProcessType = BUFFER_COPY; | |
448 | pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; | |
c6f4bc34 | 449 | } |
8822b6c4 | 450 | #endif |
c6f4bc34 YK |
451 | } |
452 | break; | |
453 | ||
454 | case OMX_IndexParamUseAndroidNativeBuffer: | |
455 | { | |
c6f4bc34 YK |
456 | UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure; |
457 | OMX_U32 portIndex = pANBParams->nPortIndex; | |
458 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
459 | android_native_buffer_t *pANB; | |
460 | OMX_U32 nSizeBytes; | |
461 | ||
462 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex); | |
463 | ||
464 | ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams)); | |
465 | if (ret != OMX_ErrorNone) { | |
466 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__); | |
467 | goto EXIT; | |
468 | } | |
469 | ||
470 | if (portIndex >= pExynosComponent->portParam.nPorts) { | |
471 | ret = OMX_ErrorBadPortIndex; | |
472 | goto EXIT; | |
473 | } | |
474 | ||
475 | pExynosPort = &pExynosComponent->pExynosPort[portIndex]; | |
476 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { | |
477 | ret = OMX_ErrorBadPortIndex; | |
478 | goto EXIT; | |
479 | } | |
480 | ||
481 | if (pExynosPort->portState != OMX_StateIdle) { | |
482 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__); | |
483 | ret = OMX_ErrorIncorrectStateOperation; | |
484 | goto EXIT; | |
485 | } | |
486 | ||
487 | pANB = pANBParams->nativeBuffer.get(); | |
488 | ||
489 | /* MALI alignment restriction */ | |
490 | nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16); | |
491 | nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2; | |
492 | ||
493 | ret = useAndroidNativeBuffer(pExynosPort, | |
494 | pANBParams->bufferHeader, | |
495 | pANBParams->nPortIndex, | |
496 | pANBParams->pAppPrivate, | |
497 | nSizeBytes, | |
498 | (OMX_U8 *) pANB); | |
499 | if (ret != OMX_ErrorNone) { | |
500 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret); | |
501 | goto EXIT; | |
502 | } | |
503 | } | |
504 | break; | |
505 | ||
506 | case OMX_IndexParamStoreMetaDataBuffer: | |
507 | { | |
c6f4bc34 YK |
508 | StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure; |
509 | OMX_U32 portIndex = pANBParams->nPortIndex; | |
510 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
511 | ||
512 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__); | |
513 | ||
514 | ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams)); | |
515 | if (ret != OMX_ErrorNone) { | |
516 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__); | |
517 | goto EXIT; | |
518 | } | |
519 | ||
520 | if (portIndex >= pExynosComponent->portParam.nPorts) { | |
521 | ret = OMX_ErrorBadPortIndex; | |
522 | goto EXIT; | |
523 | } | |
524 | ||
525 | pExynosPort = &pExynosComponent->pExynosPort[portIndex]; | |
526 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { | |
527 | ret = OMX_ErrorBadPortIndex; | |
528 | goto EXIT; | |
529 | } | |
530 | ||
531 | pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData; | |
c6f4bc34 YK |
532 | } |
533 | break; | |
534 | ||
535 | default: | |
536 | { | |
537 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex); | |
538 | ret = OMX_ErrorUnsupportedIndex; | |
539 | goto EXIT; | |
540 | } | |
541 | break; | |
542 | } | |
543 | ||
544 | EXIT: | |
545 | FunctionOut(); | |
546 | ||
547 | return ret; | |
548 | } | |
549 | ||
550 | OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer, | |
551 | OMX_OUT OMX_PTR *ppBuf) | |
552 | { | |
553 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
554 | MetadataBufferType type; | |
555 | ||
556 | FunctionIn(); | |
557 | ||
558 | /* | |
559 | * meta data contains the following data format. | |
560 | * payload depends on the MetadataBufferType | |
561 | * -------------------------------------------------------------- | |
562 | * | MetadataBufferType | payload | | |
563 | * -------------------------------------------------------------- | |
564 | * | |
565 | * If MetadataBufferType is kMetadataBufferTypeCameraSource, then | |
566 | * -------------------------------------------------------------- | |
567 | * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr | | |
568 | * -------------------------------------------------------------- | |
569 | * | |
570 | * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then | |
571 | * -------------------------------------------------------------- | |
572 | * | kMetadataBufferTypeGrallocSource | buffer_handle_t | | |
573 | * -------------------------------------------------------------- | |
574 | */ | |
575 | ||
576 | /* MetadataBufferType */ | |
577 | Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType)); | |
578 | ||
433e798a EC |
579 | switch (type) { |
580 | case kMetadataBufferTypeCameraSource: | |
581 | { | |
c6f4bc34 YK |
582 | void *pAddress = NULL; |
583 | ||
584 | /* Address. of Y */ | |
585 | Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *)); | |
586 | ppBuf[0] = (void *)pAddress; | |
587 | ||
588 | /* Address. of CbCr */ | |
589 | Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *)); | |
590 | ppBuf[1] = (void *)pAddress; | |
591 | ||
433e798a EC |
592 | if ((ppBuf[0] == NULL) || (ppBuf[1] == NULL)) |
593 | ret = OMX_ErrorBadParameter; | |
594 | } | |
595 | break; | |
596 | case kMetadataBufferTypeGrallocSource: | |
597 | { | |
c6f4bc34 YK |
598 | buffer_handle_t pBufHandle; |
599 | ||
600 | /* buffer_handle_t */ | |
601 | Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t)); | |
602 | ppBuf[0] = (OMX_PTR)pBufHandle; | |
433e798a EC |
603 | |
604 | if (ppBuf[0] == NULL) | |
605 | ret = OMX_ErrorBadParameter; | |
606 | } | |
607 | break; | |
608 | default: | |
609 | { | |
610 | ret = OMX_ErrorBadParameter; | |
611 | } | |
612 | break; | |
c6f4bc34 YK |
613 | } |
614 | ||
615 | EXIT: | |
616 | FunctionOut(); | |
617 | ||
618 | return ret; | |
619 | } | |
620 | ||
7e42e410 TK |
621 | OMX_ERRORTYPE Exynos_OSAL_SetPrependSPSPPSToIDR( |
622 | OMX_PTR pComponentParameterStructure, | |
623 | OMX_PTR pbPrependSpsPpsToIdr) | |
624 | { | |
625 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
626 | PrependSPSPPSToIDRFramesParams *pANBParams = (PrependSPSPPSToIDRFramesParams *)pComponentParameterStructure; | |
627 | ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(PrependSPSPPSToIDRFramesParams)); | |
628 | if (ret != OMX_ErrorNone) { | |
629 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(PrependSPSPPSToIDRFramesParams) is failed", __func__); | |
630 | goto EXIT; | |
631 | } | |
632 | ||
633 | (*((OMX_BOOL *)pbPrependSpsPpsToIdr)) = pANBParams->bEnable; | |
634 | ||
635 | EXIT: | |
636 | return ret; | |
637 | } | |
638 | ||
c6f4bc34 YK |
639 | OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat( |
640 | unsigned int hal_format) | |
641 | { | |
642 | OMX_COLOR_FORMATTYPE omx_format; | |
643 | switch (hal_format) { | |
644 | case HAL_PIXEL_FORMAT_YCbCr_422_I: | |
645 | omx_format = OMX_COLOR_FormatYCbYCr; | |
646 | break; | |
647 | case HAL_PIXEL_FORMAT_YCbCr_420_P: | |
648 | omx_format = OMX_COLOR_FormatYUV420Planar; | |
649 | break; | |
650 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: | |
651 | omx_format = OMX_COLOR_FormatYUV420SemiPlanar; | |
652 | break; | |
c6f4bc34 YK |
653 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: |
654 | omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled; | |
655 | break; | |
433e798a | 656 | case HAL_PIXEL_FORMAT_BGRA_8888: |
c6f4bc34 YK |
657 | omx_format = OMX_COLOR_Format32bitARGB8888; |
658 | break; | |
433e798a EC |
659 | case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP: |
660 | omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV21Linear; | |
661 | break; | |
662 | case HAL_PIXEL_FORMAT_EXYNOS_YV12: | |
663 | omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatYVU420Planar; | |
664 | break; | |
665 | case HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888: | |
666 | omx_format = OMX_COLOR_Format32bitBGRA8888; | |
667 | break; | |
c6f4bc34 YK |
668 | default: |
669 | omx_format = OMX_COLOR_FormatYUV420Planar; | |
670 | break; | |
671 | } | |
672 | return omx_format; | |
673 | } | |
674 | ||
675 | unsigned int Exynos_OSAL_OMX2HalPixelFormat( | |
676 | OMX_COLOR_FORMATTYPE omx_format) | |
677 | { | |
678 | unsigned int hal_format; | |
679 | switch (omx_format) { | |
680 | case OMX_COLOR_FormatYCbYCr: | |
681 | hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I; | |
682 | break; | |
683 | case OMX_COLOR_FormatYUV420Planar: | |
684 | hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P; | |
685 | break; | |
686 | case OMX_COLOR_FormatYUV420SemiPlanar: | |
687 | hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP; | |
688 | break; | |
c6f4bc34 YK |
689 | case OMX_SEC_COLOR_FormatNV12Tiled: |
690 | hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED; | |
691 | break; | |
692 | case OMX_COLOR_Format32bitARGB8888: | |
433e798a EC |
693 | hal_format = HAL_PIXEL_FORMAT_BGRA_8888; |
694 | break; | |
695 | case OMX_SEC_COLOR_FormatNV21Linear: | |
696 | hal_format = HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP; | |
697 | break; | |
698 | case OMX_SEC_COLOR_FormatYVU420Planar: | |
699 | hal_format = HAL_PIXEL_FORMAT_EXYNOS_YV12; | |
c6f4bc34 | 700 | break; |
433e798a EC |
701 | case OMX_COLOR_Format32bitBGRA8888: |
702 | hal_format = HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888; | |
703 | break; | |
c6f4bc34 YK |
704 | default: |
705 | hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P; | |
706 | break; | |
707 | } | |
708 | return hal_format; | |
709 | } | |
710 | ||
711 | ||
712 | #ifdef __cplusplus | |
713 | } | |
714 | #endif |