osal: added USE_IMPROVED_BUFFER support
[GitHub/LineageOS/android_hardware_samsung_slsi_openmax.git] / osal / Exynos_OSAL_Android.cpp
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>
40 #ifdef USE_DMA_BUF
41 #include <gralloc_priv.h>
42 #endif
43
44 #include "Exynos_OSAL_Semaphore.h"
45 #include "Exynos_OMX_Baseport.h"
46 #include "Exynos_OMX_Basecomponent.h"
47 #include "Exynos_OMX_Macros.h"
48 #include "Exynos_OSAL_Android.h"
49 #include "exynos_format.h"
50
51 #include "ExynosVideoApi.h"
52
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
64 static int lockCnt = 0;
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,
71 OMX_OUT OMX_PTR planes)
72 {
73 FunctionIn();
74
75 OMX_ERRORTYPE ret = OMX_ErrorNone;
76 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
77 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
78 #ifdef USE_DMA_BUF
79 private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
80 #endif
81 Rect bounds(width, height);
82 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
83 void *vaddr[MAX_BUFFER_PLANE];
84
85 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
86
87 int usage = 0;
88
89 switch (format) {
90 case OMX_COLOR_FormatYUV420Planar:
91 case OMX_COLOR_FormatYUV420SemiPlanar:
92 case OMX_SEC_COLOR_FormatNV12Tiled:
93 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
94 break;
95 case OMX_COLOR_FormatAndroidOpaque:
96 {
97 OMX_COLOR_FORMATTYPE formatType;
98 formatType = Exynos_OSAL_GetANBColorFormat((OMX_U32)priv_hnd);
99 if ((formatType == OMX_COLOR_FormatYUV420SemiPlanar) ||
100 (formatType == OMX_SEC_COLOR_FormatNV12Tiled))
101 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
102 else
103 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_VIDEO_ENCODER;
104 }
105 break;
106 default:
107 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
108 break;
109 }
110
111 if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) {
112 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__);
113 ret = OMX_ErrorUndefined;
114 goto EXIT;
115 }
116 lockCnt++;
117 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: lockCnt:%d", __func__, lockCnt);
118
119 #ifdef USE_DMA_BUF
120 vplanes[0].fd = priv_hnd->fd;
121 vplanes[0].offset = 0;
122 vplanes[1].fd = priv_hnd->fd1;
123 vplanes[1].offset = 0;
124 vplanes[2].fd = priv_hnd->fd2;
125 vplanes[2].offset = 0;
126 #endif
127 vplanes[0].addr = vaddr[0];
128 vplanes[1].addr = vaddr[1];
129 vplanes[2].addr = vaddr[2];
130
131 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
132
133 EXIT:
134 FunctionOut();
135
136 return ret;
137 }
138
139 OMX_ERRORTYPE Exynos_OSAL_UnlockANBHandle(OMX_IN OMX_U32 handle)
140 {
141 FunctionIn();
142
143 OMX_ERRORTYPE ret = OMX_ErrorNone;
144 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
145 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
146
147 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
148
149 if (mapper.unlock(bufferHandle) != 0) {
150 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
151 ret = OMX_ErrorUndefined;
152 goto EXIT;
153 }
154 lockCnt--;
155 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: lockCnt:%d", __func__, lockCnt);
156
157 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
158
159 EXIT:
160 FunctionOut();
161
162 return ret;
163 }
164
165 OMX_COLOR_FORMATTYPE Exynos_OSAL_GetANBColorFormat(OMX_IN OMX_U32 handle)
166 {
167 FunctionIn();
168
169 OMX_COLOR_FORMATTYPE ret = OMX_COLOR_FormatUnused;
170 private_handle_t *priv_hnd = (private_handle_t *) handle;
171
172 ret = Exynos_OSAL_Hal2OMXPixelFormat(priv_hnd->format);
173 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "ColorFormat: 0x%x", ret);
174
175 EXIT:
176 FunctionOut();
177
178 return ret;
179 }
180
181 OMX_ERRORTYPE Exynos_OSAL_LockANB(
182 OMX_IN OMX_PTR pBuffer,
183 OMX_IN OMX_U32 width,
184 OMX_IN OMX_U32 height,
185 OMX_IN OMX_COLOR_FORMATTYPE format,
186 OMX_OUT OMX_U32 *pStride,
187 OMX_OUT OMX_PTR planes)
188 {
189 FunctionIn();
190
191 OMX_ERRORTYPE ret = OMX_ErrorNone;
192 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
193
194 ret = Exynos_OSAL_LockANBHandle((OMX_U32)pANB->handle, width, height, format, planes);
195 *pStride = pANB->stride;
196
197 EXIT:
198 FunctionOut();
199
200 return ret;
201 }
202
203 OMX_ERRORTYPE Exynos_OSAL_UnlockANB(OMX_IN OMX_PTR pBuffer)
204 {
205 FunctionIn();
206
207 OMX_ERRORTYPE ret = OMX_ErrorNone;
208 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
209
210 ret = Exynos_OSAL_UnlockANBHandle((OMX_U32)pANB->handle);
211
212 EXIT:
213 FunctionOut();
214
215 return ret;
216 }
217
218 OMX_ERRORTYPE useAndroidNativeBuffer(
219 EXYNOS_OMX_BASEPORT *pExynosPort,
220 OMX_BUFFERHEADERTYPE **ppBufferHdr,
221 OMX_U32 nPortIndex,
222 OMX_PTR pAppPrivate,
223 OMX_U32 nSizeBytes,
224 OMX_U8 *pBuffer)
225 {
226 OMX_ERRORTYPE ret = OMX_ErrorNone;
227 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
228 unsigned int i = 0;
229 OMX_U32 width, height;
230 OMX_U32 stride;
231 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
232
233 FunctionIn();
234
235 if (pExynosPort == NULL) {
236 ret = OMX_ErrorBadParameter;
237 goto EXIT;
238 }
239 if (pExynosPort->portState != OMX_StateIdle) {
240 ret = OMX_ErrorIncorrectStateOperation;
241 goto EXIT;
242 }
243 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
244 ret = OMX_ErrorBadPortIndex;
245 goto EXIT;
246 }
247
248 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
249 if (temp_bufferHeader == NULL) {
250 ret = OMX_ErrorInsufficientResources;
251 goto EXIT;
252 }
253 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
254
255 for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
256 if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
257 pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
258 pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
259 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
260 temp_bufferHeader->pBuffer = pBuffer;
261 temp_bufferHeader->nAllocLen = nSizeBytes;
262 temp_bufferHeader->pAppPrivate = pAppPrivate;
263 if (nPortIndex == INPUT_PORT_INDEX)
264 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
265 else
266 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
267
268 width = pExynosPort->portDefinition.format.video.nFrameWidth;
269 height = pExynosPort->portDefinition.format.video.nFrameHeight;
270 Exynos_OSAL_LockANB(temp_bufferHeader->pBuffer, width, height,
271 pExynosPort->portDefinition.format.video.eColorFormat,
272 &stride, planes);
273 #ifdef USE_DMA_BUF
274 pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
275 pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
276 pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
277 #endif
278 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
279 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
280 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
281 Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
282 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
283 i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
284 pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
285
286 pExynosPort->assignedBufferNum++;
287 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
288 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
289 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
290 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
291 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
292 }
293 *ppBufferHdr = temp_bufferHeader;
294 ret = OMX_ErrorNone;
295
296 goto EXIT;
297 }
298 }
299
300 Exynos_OSAL_Free(temp_bufferHeader);
301 ret = OMX_ErrorInsufficientResources;
302
303 EXIT:
304 FunctionOut();
305
306 return ret;
307 }
308
309 OMX_ERRORTYPE Exynos_OSAL_GetANBParameter(
310 OMX_IN OMX_HANDLETYPE hComponent,
311 OMX_IN OMX_INDEXTYPE nIndex,
312 OMX_INOUT OMX_PTR ComponentParameterStructure)
313 {
314 OMX_ERRORTYPE ret = OMX_ErrorNone;
315 OMX_COMPONENTTYPE *pOMXComponent = NULL;
316 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
317
318 FunctionIn();
319
320 if (hComponent == NULL) {
321 ret = OMX_ErrorBadParameter;
322 goto EXIT;
323 }
324
325 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
326 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
327 if (ret != OMX_ErrorNone) {
328 goto EXIT;
329 }
330
331 if (pOMXComponent->pComponentPrivate == NULL) {
332 ret = OMX_ErrorBadParameter;
333 goto EXIT;
334 }
335
336 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
337 if (pExynosComponent->currentState == OMX_StateInvalid ) {
338 ret = OMX_ErrorInvalidState;
339 goto EXIT;
340 }
341
342 if (ComponentParameterStructure == NULL) {
343 ret = OMX_ErrorBadParameter;
344 goto EXIT;
345 }
346
347 switch (nIndex) {
348 case OMX_IndexParamGetAndroidNativeBuffer:
349 {
350 GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
351 OMX_U32 portIndex = pANBParams->nPortIndex;
352
353 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
354
355 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
356 if (ret != OMX_ErrorNone) {
357 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
358 goto EXIT;
359 }
360
361 if (portIndex >= pExynosComponent->portParam.nPorts) {
362 ret = OMX_ErrorBadPortIndex;
363 goto EXIT;
364 }
365
366 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
367 * modifications since currently not defined what the 'nUsage' is for.
368 */
369 pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP);
370 #if defined(USE_IMPROVED_BUFFER) && !defined(USE_CSC_HW)
371 pANBParams->nUsage |= (GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
372 #endif
373 }
374 break;
375
376 default:
377 {
378 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
379 ret = OMX_ErrorUnsupportedIndex;
380 goto EXIT;
381 }
382 break;
383 }
384
385 EXIT:
386 FunctionOut();
387
388 return ret;
389 }
390
391 OMX_ERRORTYPE Exynos_OSAL_SetANBParameter(
392 OMX_IN OMX_HANDLETYPE hComponent,
393 OMX_IN OMX_INDEXTYPE nIndex,
394 OMX_IN OMX_PTR ComponentParameterStructure)
395 {
396 OMX_ERRORTYPE ret = OMX_ErrorNone;
397 OMX_COMPONENTTYPE *pOMXComponent = NULL;
398 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
399
400 FunctionIn();
401
402 if (hComponent == NULL) {
403 ret = OMX_ErrorBadParameter;
404 goto EXIT;
405 }
406
407 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
408 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
409 if (ret != OMX_ErrorNone) {
410 goto EXIT;
411 }
412
413 if (pOMXComponent->pComponentPrivate == NULL) {
414 ret = OMX_ErrorBadParameter;
415 goto EXIT;
416 }
417
418 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
419 if (pExynosComponent->currentState == OMX_StateInvalid ) {
420 ret = OMX_ErrorInvalidState;
421 goto EXIT;
422 }
423
424 if (ComponentParameterStructure == NULL) {
425 ret = OMX_ErrorBadParameter;
426 goto EXIT;
427 }
428
429 switch (nIndex) {
430 case OMX_IndexParamEnableAndroidBuffers:
431 {
432 EnableAndroidNativeBuffersParams *pANBParams = (EnableAndroidNativeBuffersParams *) ComponentParameterStructure;
433 OMX_U32 portIndex = pANBParams->nPortIndex;
434 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
435
436 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnableAndroidNativeBuffers", __func__);
437
438 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(EnableAndroidNativeBuffersParams));
439 if (ret != OMX_ErrorNone) {
440 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableAndroidNativeBuffersParams) is failed", __func__);
441 goto EXIT;
442 }
443
444 if (portIndex >= pExynosComponent->portParam.nPorts) {
445 ret = OMX_ErrorBadPortIndex;
446 goto EXIT;
447 }
448
449 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
450 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
451 ret = OMX_ErrorBadPortIndex;
452 goto EXIT;
453 }
454
455 pExynosPort->bIsANBEnabled = pANBParams->enable;
456
457 #ifdef USE_ANB_OUTBUF_SHARE
458 /* ANB and DPB Buffer Sharing */
459 if ((portIndex == OUTPUT_PORT_INDEX) &&
460 (pExynosPort->bIsANBEnabled == OMX_TRUE) &&
461 ((pExynosPort->bufferProcessType & BUFFER_ANBSHARE) == BUFFER_ANBSHARE)) {
462 pExynosPort->bufferProcessType = BUFFER_SHARE;
463 pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
464 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on");
465 }
466 #else
467 if ((portIndex == OUTPUT_PORT_INDEX) &&
468 (pExynosPort->bufferProcessType & BUFFER_COPY)) {
469 pExynosPort->bufferProcessType = BUFFER_COPY;
470 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
471 }
472 #endif
473 }
474 break;
475
476 case OMX_IndexParamUseAndroidNativeBuffer:
477 {
478 UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
479 OMX_U32 portIndex = pANBParams->nPortIndex;
480 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
481 android_native_buffer_t *pANB;
482 OMX_U32 nSizeBytes;
483
484 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
485
486 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
487 if (ret != OMX_ErrorNone) {
488 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
489 goto EXIT;
490 }
491
492 if (portIndex >= pExynosComponent->portParam.nPorts) {
493 ret = OMX_ErrorBadPortIndex;
494 goto EXIT;
495 }
496
497 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
498 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
499 ret = OMX_ErrorBadPortIndex;
500 goto EXIT;
501 }
502
503 if (pExynosPort->portState != OMX_StateIdle) {
504 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
505 ret = OMX_ErrorIncorrectStateOperation;
506 goto EXIT;
507 }
508
509 pANB = pANBParams->nativeBuffer.get();
510
511 /* MALI alignment restriction */
512 nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
513 nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
514
515 ret = useAndroidNativeBuffer(pExynosPort,
516 pANBParams->bufferHeader,
517 pANBParams->nPortIndex,
518 pANBParams->pAppPrivate,
519 nSizeBytes,
520 (OMX_U8 *) pANB);
521 if (ret != OMX_ErrorNone) {
522 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
523 goto EXIT;
524 }
525 }
526 break;
527
528 case OMX_IndexParamStoreMetaDataBuffer:
529 {
530 StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
531 OMX_U32 portIndex = pANBParams->nPortIndex;
532 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
533
534 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
535
536 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
537 if (ret != OMX_ErrorNone) {
538 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
539 goto EXIT;
540 }
541
542 if (portIndex >= pExynosComponent->portParam.nPorts) {
543 ret = OMX_ErrorBadPortIndex;
544 goto EXIT;
545 }
546
547 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
548 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
549 ret = OMX_ErrorBadPortIndex;
550 goto EXIT;
551 }
552
553 pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
554 }
555 break;
556
557 default:
558 {
559 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
560 ret = OMX_ErrorUnsupportedIndex;
561 goto EXIT;
562 }
563 break;
564 }
565
566 EXIT:
567 FunctionOut();
568
569 return ret;
570 }
571
572 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
573 OMX_OUT OMX_PTR *ppBuf)
574 {
575 OMX_ERRORTYPE ret = OMX_ErrorNone;
576 MetadataBufferType type;
577
578 FunctionIn();
579
580 /*
581 * meta data contains the following data format.
582 * payload depends on the MetadataBufferType
583 * --------------------------------------------------------------
584 * | MetadataBufferType | payload |
585 * --------------------------------------------------------------
586 *
587 * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
588 * --------------------------------------------------------------
589 * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr |
590 * --------------------------------------------------------------
591 *
592 * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
593 * --------------------------------------------------------------
594 * | kMetadataBufferTypeGrallocSource | buffer_handle_t |
595 * --------------------------------------------------------------
596 */
597
598 /* MetadataBufferType */
599 Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
600
601 if (type == kMetadataBufferTypeCameraSource) {
602 void *pAddress = NULL;
603
604 /* Address. of Y */
605 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
606 ppBuf[0] = (void *)pAddress;
607
608 /* Address. of CbCr */
609 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
610 ppBuf[1] = (void *)pAddress;
611
612 } else if (type == kMetadataBufferTypeGrallocSource) {
613 buffer_handle_t pBufHandle;
614
615 /* buffer_handle_t */
616 Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
617 ppBuf[0] = (OMX_PTR)pBufHandle;
618 }
619
620 EXIT:
621 FunctionOut();
622
623 return ret;
624 }
625
626 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
627 unsigned int hal_format)
628 {
629 OMX_COLOR_FORMATTYPE omx_format;
630 switch (hal_format) {
631 case HAL_PIXEL_FORMAT_YCbCr_422_I:
632 omx_format = OMX_COLOR_FormatYCbYCr;
633 break;
634 case HAL_PIXEL_FORMAT_YCbCr_420_P:
635 omx_format = OMX_COLOR_FormatYUV420Planar;
636 break;
637 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
638 omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
639 break;
640 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
641 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
642 break;
643 case HAL_PIXEL_FORMAT_RGBA_8888:
644 omx_format = OMX_COLOR_Format32bitARGB8888;
645 break;
646 default:
647 omx_format = OMX_COLOR_FormatYUV420Planar;
648 break;
649 }
650 return omx_format;
651 }
652
653 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
654 OMX_COLOR_FORMATTYPE omx_format)
655 {
656 unsigned int hal_format;
657 switch (omx_format) {
658 case OMX_COLOR_FormatYCbYCr:
659 hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
660 break;
661 case OMX_COLOR_FormatYUV420Planar:
662 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
663 break;
664 case OMX_COLOR_FormatYUV420SemiPlanar:
665 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
666 break;
667 case OMX_SEC_COLOR_FormatNV12Tiled:
668 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
669 break;
670 case OMX_COLOR_Format32bitARGB8888:
671 hal_format = HAL_PIXEL_FORMAT_RGBA_8888;
672 break;
673 default:
674 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
675 break;
676 }
677 return hal_format;
678 }
679
680
681 #ifdef __cplusplus
682 }
683 #endif