fixed coverity issues
[platform/adaptation/ap_samsung/libomxil-e3250-v4l2.git] / openmax / osal / Exynos_OSAL_Platform_Specific.c
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_Platform_Specific.c
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 #include <string.h>
32 #include <mm_types.h>
33
34 #include "Exynos_OSAL_Semaphore.h"
35 #include "Exynos_OMX_Baseport.h"
36 #include "Exynos_OMX_Basecomponent.h"
37 #include "Exynos_OMX_Macros.h"
38 #include "Exynos_OMX_Vdec.h"
39 #include "Exynos_OSAL_Platform_Specific.h"
40 #include "exynos_format.h"
41
42 #include "ExynosVideoApi.h"
43
44 #undef  EXYNOS_LOG_TAG
45 #define EXYNOS_LOG_TAG    "Exynos_OSAL_PB"
46 #define EXYNOS_LOG_OFF
47 #include "Exynos_OSAL_Log.h"
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53
54 OMX_ERRORTYPE Exynos_OSAL_LockPBHandle(
55     OMX_IN OMX_U32 handle,
56     OMX_IN OMX_U32 width,
57     OMX_IN OMX_U32 height,
58     OMX_IN OMX_COLOR_FORMATTYPE format,
59     OMX_OUT OMX_PTR planes)
60 {
61     FunctionIn();
62
63     OMX_ERRORTYPE ret = OMX_ErrorNone;
64
65 #if 0
66     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
67     buffer_handle_t bufferHandle = (buffer_handle_t) handle;
68 #ifdef USE_DMA_BUF
69     private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
70 #endif
71     Rect bounds(width, height);
72     ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
73     void *vaddr[MAX_BUFFER_PLANE];
74
75     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
76
77     int usage = 0;
78
79     switch (format) {
80     case OMX_COLOR_FormatYUV420Planar:
81     case OMX_COLOR_FormatYUV420SemiPlanar:
82     case OMX_SEC_COLOR_FormatNV12Tiled:
83         usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR;
84         break;
85     default:
86         usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
87         break;
88     }
89
90     if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) {
91         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__);
92         ret = OMX_ErrorUndefined;
93         goto EXIT;
94     }
95
96 #ifdef USE_DMA_BUF
97     vplanes[0].fd = priv_hnd->fd;
98     vplanes[0].offset = 0;
99     vplanes[1].fd = priv_hnd->u_fd;
100     vplanes[1].offset = priv_hnd->uoffset;
101     vplanes[2].fd = priv_hnd->v_fd;
102     vplanes[2].offset = priv_hnd->voffset;
103 #endif
104     vplanes[0].addr = vaddr[0];
105     vplanes[1].addr = vaddr[1];
106     vplanes[2].addr = vaddr[2];
107
108     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
109
110 EXIT:
111 #endif
112     FunctionOut();
113
114     return ret;
115 }
116
117 OMX_ERRORTYPE Exynos_OSAL_UnlockPBHandle(OMX_IN OMX_U32 handle)
118 {
119     FunctionIn();
120
121     OMX_ERRORTYPE ret = OMX_ErrorNone;
122 #ifdef TIZEN_FEATURE_E3250
123 #else
124     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
125     buffer_handle_t bufferHandle = (buffer_handle_t) handle;
126
127     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
128
129     if (mapper.unlock(bufferHandle) != 0) {
130         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
131         ret = OMX_ErrorUndefined;
132         goto EXIT;
133     }
134
135     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
136
137 EXIT:
138 #endif
139
140     FunctionOut();
141
142     return ret;
143 }
144
145 OMX_ERRORTYPE Exynos_OSAL_LockPB(
146     OMX_IN OMX_PTR pBuffer,
147     OMX_IN OMX_U32 width,
148     OMX_IN OMX_U32 height,
149     OMX_IN OMX_COLOR_FORMATTYPE format,
150     OMX_OUT OMX_U32 *pStride,
151     OMX_OUT OMX_PTR planes)
152 {
153     FunctionIn();
154
155     OMX_ERRORTYPE ret = OMX_ErrorNone;
156 #ifdef TIZEN_FEATURE_E3250
157
158     ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
159     MMVideoBuffer *buffer = (MMVideoBuffer *) pBuffer;
160
161
162     vplanes[0].fd = buffer->handle.dmabuf_fd[0];
163     vplanes[0].offset = 0;
164     vplanes[1].fd = buffer->handle.dmabuf_fd[1];
165     vplanes[1].offset = 0; //priv_hnd->uoffset;
166     vplanes[2].fd = 0; //priv_hnd->v_fd;
167     vplanes[2].offset = 0; //priv_hnd->voffset;
168
169     vplanes[0].addr = buffer->data[0]; //vaddr[0];
170     vplanes[1].addr = buffer->data[1]; //vaddr[1];
171     vplanes[2].addr = NULL; //vaddr[2];
172
173     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Exynos_OSAL_LockPB:fd[0](%d)  fd[1](%d)  a[0](%p)  a[1](%p)",
174         buffer->handle.dmabuf_fd[0], buffer->handle.dmabuf_fd[1], buffer->data[0], buffer->data[1]);
175 #else
176     android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
177
178     ret = Exynos_OSAL_LockPBHandle((OMX_U32)pANB->handle, width, height, format, planes);
179     *pStride = pANB->stride;
180 #endif
181
182     FunctionOut();
183
184     return ret;
185 }
186
187 #ifdef TIZEN_FEATURE_E3250
188 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort,EXYNOS_OMX_BASEPORT *pExynosInPort)
189 #else
190 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData)
191 #endif
192 {
193     FunctionIn();
194
195     OMX_ERRORTYPE ret = OMX_ErrorNone;
196 #ifdef TIZEN_FEATURE_E3250
197     MMVideoBuffer *pSlpOutBuf = NULL;
198     DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
199
200     pSlpOutBuf = (MMVideoBuffer *)pBuffer;
201     if (pSlpOutBuf == NULL) {
202       Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pBuffer is NULL!");
203       ret = OMX_ErrorInsufficientResources;
204       goto EXIT;
205     }
206     memset(pSlpOutBuf, 0, sizeof(MMVideoBuffer));
207
208     pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pData->extInfo;
209
210     if (pExynosPort->cropRectangle.nWidth != 0 && pExynosPort->cropRectangle.nHeight != 0) {
211         /* modify for h264 trim */
212         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "this has cropRectangle(h264).crop.nWidth = %d, crop.nHeight = %d",
213             pExynosPort->cropRectangle.nWidth, pExynosPort->cropRectangle.nWidth);
214         pSlpOutBuf->width[0] = pExynosPort->cropRectangle.nWidth;
215         pSlpOutBuf->width[1] = pExynosPort->cropRectangle.nWidth;
216         pSlpOutBuf->height[0] = pExynosPort->cropRectangle.nHeight;
217         pSlpOutBuf->height[1] = pExynosPort->cropRectangle.nHeight/2;
218
219
220         pSlpOutBuf->stride_width[0] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
221         pSlpOutBuf->stride_width[1] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN);
222         pSlpOutBuf->stride_height[0] = ALIGN(pExynosPort->cropRectangle.nHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
223         pSlpOutBuf->stride_height[1] = ALIGN((pExynosPort->cropRectangle.nHeight/2), S5P_FIMV_NV12MT_VALIGN);
224     } else {
225         pSlpOutBuf->width[0] = pBufferInfo->imageWidth;
226         pSlpOutBuf->width[1] = pBufferInfo->imageWidth;
227         pSlpOutBuf->height[0] = pBufferInfo->imageHeight;
228         pSlpOutBuf->height[1] = (pBufferInfo->imageHeight/2);
229
230         pSlpOutBuf->stride_width[0] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
231         pSlpOutBuf->stride_width[1] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN);
232         pSlpOutBuf->stride_height[0] = ALIGN(pBufferInfo->imageHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
233         pSlpOutBuf->stride_height[1] = ALIGN((pBufferInfo->imageHeight/2), S5P_FIMV_NV12MT_VALIGN);
234     }
235
236
237
238 /*
239     if (pVideoDec->bDRMPlayerMode == OMX_TRUE) {
240         pSlpOutBuf->a[0] = 0;
241         pSlpOutBuf->a[1] = 0;
242     } else {
243 */
244         pSlpOutBuf->data[0] = pData->buffer.multiPlaneBuffer.dataBuffer[0];
245         pSlpOutBuf->data[1] = pData->buffer.multiPlaneBuffer.dataBuffer[1];
246 //    }
247     pSlpOutBuf->data[2] = 0; /* omx do not use this plane */
248
249     pSlpOutBuf->handle.dmabuf_fd[0] = pData->buffer.multiPlaneBuffer.fd[0];
250     pSlpOutBuf->handle.dmabuf_fd[1] = pData->buffer.multiPlaneBuffer.fd[1];
251     pSlpOutBuf->handle.dmabuf_fd[2] = 0;
252
253     pSlpOutBuf->handle.bo[0] = pData->buffer.multiPlaneBuffer.tbm_bo[0];
254     pSlpOutBuf->handle.bo[1] = pData->buffer.multiPlaneBuffer.tbm_bo[1];
255     pSlpOutBuf->handle.bo[2] = NULL;
256
257     if(pExynosInPort->portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
258     {
259         pSlpOutBuf->size[0] = calc_plane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
260         pSlpOutBuf->size[1] = calc_plane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
261         Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"H264 foramt and y_size=%d, uv_size=%d",pSlpOutBuf->size[0],pSlpOutBuf->size[1]);
262     } else {
263         pSlpOutBuf->size[0]= calc_yplane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
264         pSlpOutBuf->size[1] = calc_uvplane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
265         Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"foramt is %d, and y_size=%d, uv_size=%d",pExynosInPort->portDefinition.format.video.eCompressionFormat ,pSlpOutBuf->size[0],pSlpOutBuf->size[1]);
266     }
267
268     pSlpOutBuf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO; /* use bo mode */
269     pSlpOutBuf->handle_num = 2;
270     pSlpOutBuf->plane_num = 2;
271
272     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "fd (%d, %d, %d) received from MFC", pSlpOutBuf->handle.dmabuf_fd[0], pSlpOutBuf->handle.dmabuf_fd[1], pSlpOutBuf->handle.dmabuf_fd[2]);
273 #else
274     android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
275
276     ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
277 #endif
278 EXIT:
279     FunctionOut();
280
281     return ret;
282 }
283
284 #if 0
285 OMX_ERRORTYPE useAndroidNativeBuffer(
286     EXYNOS_OMX_BASEPORT      *pExynosPort,
287     OMX_BUFFERHEADERTYPE **ppBufferHdr,
288     OMX_U32                nPortIndex,
289     OMX_PTR                pAppPrivate,
290     OMX_U32                nSizeBytes,
291     OMX_U8                *pBuffer)
292 {
293     OMX_ERRORTYPE         ret = OMX_ErrorNone;
294     OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
295     unsigned int          i = 0;
296     OMX_U32               width, height;
297     OMX_U32               stride;
298     ExynosVideoPlane      planes[MAX_BUFFER_PLANE];
299
300     FunctionIn();
301
302     if (pExynosPort == NULL) {
303         ret = OMX_ErrorBadParameter;
304         goto EXIT;
305     }
306     if (pExynosPort->portState != OMX_StateIdle) {
307         ret = OMX_ErrorIncorrectStateOperation;
308         goto EXIT;
309     }
310     if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
311         ret = OMX_ErrorBadPortIndex;
312         goto EXIT;
313     }
314
315     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
316     if (temp_bufferHeader == NULL) {
317         ret = OMX_ErrorInsufficientResources;
318         goto EXIT;
319     }
320     Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
321
322     for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
323         if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
324             pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
325             pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
326             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
327             temp_bufferHeader->pBuffer        = pBuffer;
328             temp_bufferHeader->nAllocLen      = nSizeBytes;
329             temp_bufferHeader->pAppPrivate    = pAppPrivate;
330             if (nPortIndex == INPUT_PORT_INDEX)
331                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
332             else
333                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
334
335             width = pExynosPort->portDefinition.format.video.nFrameWidth;
336             height = pExynosPort->portDefinition.format.video.nFrameHeight;
337             Exynos_OSAL_LockPB(temp_bufferHeader->pBuffer, width, height,
338                                 pExynosPort->portDefinition.format.video.eColorFormat,
339                                 &stride, planes);
340 #ifdef USE_DMA_BUF
341             pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
342             pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
343             pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
344 #endif
345             pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
346             pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
347             pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
348             Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
349             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
350                             i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
351                             pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
352
353             pExynosPort->assignedBufferNum++;
354             if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
355                 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
356                 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
357                 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
358                 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
359             }
360             *ppBufferHdr = temp_bufferHeader;
361             ret = OMX_ErrorNone;
362
363             goto EXIT;
364         }
365     }
366
367     Exynos_OSAL_Free(temp_bufferHeader);
368     ret = OMX_ErrorInsufficientResources;
369
370 EXIT:
371     FunctionOut();
372
373     return ret;
374 }
375 #endif
376
377 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
378     OMX_IN OMX_HANDLETYPE hComponent,
379     OMX_IN OMX_INDEXTYPE  nIndex,
380     OMX_INOUT OMX_PTR     ComponentParameterStructure)
381 {
382     OMX_ERRORTYPE          ret = OMX_ErrorNone;
383     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
384     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
385
386     FunctionIn();
387
388     if (hComponent == NULL) {
389         ret = OMX_ErrorBadParameter;
390         goto EXIT;
391     }
392
393     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
394     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
395     if (ret != OMX_ErrorNone) {
396         goto EXIT;
397     }
398
399     if (pOMXComponent->pComponentPrivate == NULL) {
400         ret = OMX_ErrorBadParameter;
401         goto EXIT;
402     }
403
404     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
405     if (pExynosComponent->currentState == OMX_StateInvalid ) {
406         ret = OMX_ErrorInvalidState;
407         goto EXIT;
408     }
409
410     if (ComponentParameterStructure == NULL) {
411         ret = OMX_ErrorBadParameter;
412         goto EXIT;
413     }
414
415     switch (nIndex) {
416 #if 0 /* TIZEN_FEATURE_E3250 */
417     case OMX_IndexParamGetAndroidNativeBuffer:
418     {
419         GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
420         OMX_U32 portIndex = pANBParams->nPortIndex;
421
422         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
423
424         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
425         if (ret != OMX_ErrorNone) {
426             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
427             goto EXIT;
428         }
429
430         if (portIndex >= pExynosComponent->portParam.nPorts) {
431             ret = OMX_ErrorBadPortIndex;
432             goto EXIT;
433         }
434
435         /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
436          * modifications since currently not defined what the 'nUsage' is for.
437          */
438         pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
439                            | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
440     }
441         break;
442 #endif
443     default:
444     {
445         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
446         ret = OMX_ErrorUnsupportedIndex;
447         goto EXIT;
448     }
449         break;
450     }
451
452 EXIT:
453     FunctionOut();
454
455     return ret;
456 }
457
458 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
459     OMX_IN OMX_HANDLETYPE hComponent,
460     OMX_IN OMX_INDEXTYPE  nIndex,
461     OMX_IN OMX_PTR        ComponentParameterStructure)
462 {
463     OMX_ERRORTYPE          ret = OMX_ErrorNone;
464     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
465     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
466
467     FunctionIn();
468
469     if (hComponent == NULL) {
470         ret = OMX_ErrorBadParameter;
471         goto EXIT;
472     }
473
474     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
475     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
476     if (ret != OMX_ErrorNone) {
477         goto EXIT;
478     }
479
480     if (pOMXComponent->pComponentPrivate == NULL) {
481         ret = OMX_ErrorBadParameter;
482         goto EXIT;
483     }
484
485     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
486     if (pExynosComponent->currentState == OMX_StateInvalid ) {
487         ret = OMX_ErrorInvalidState;
488         goto EXIT;
489     }
490
491     if (ComponentParameterStructure == NULL) {
492         ret = OMX_ErrorBadParameter;
493         goto EXIT;
494     }
495
496     switch ((int)nIndex) {
497 #ifdef TIZEN_FEATURE_E3250
498     case OMX_IndexParamEnablePlatformSpecificBuffers:
499 #else
500     case OMX_IndexParamEnableAndroidBuffers:
501 #endif
502     {
503         EnableGemBuffersParams *pPBParams = (EnableGemBuffersParams *) ComponentParameterStructure;
504         OMX_U32 portIndex = pPBParams->nPortIndex;
505         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
506
507         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnablePlatformSpecificBuffers", __func__);
508
509         ret = Exynos_OMX_Check_SizeVersion(pPBParams, sizeof(EnableGemBuffersParams));
510         if (ret != OMX_ErrorNone) {
511             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableGemBuffersParams) is failed", __func__);
512             goto EXIT;
513         }
514
515         if (portIndex >= pExynosComponent->portParam.nPorts) {
516             ret = OMX_ErrorBadPortIndex;
517             goto EXIT;
518         }
519
520         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
521         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
522             ret = OMX_ErrorBadPortIndex;
523             goto EXIT;
524         }
525
526 #ifdef TIZEN_FEATURE_E3250
527          /* PB and DPB Buffer Sharing */
528         if ((portIndex == OUTPUT_PORT_INDEX) &&
529             ((pExynosPort->bufferProcessType & BUFFER_PBSHARE) == BUFFER_PBSHARE)) {
530             pExynosPort->bufferProcessType = BUFFER_SHARE;
531             pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
532             Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on");
533         }
534         Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->portDefinition.format.video.eColorFormat: 0x%x", pExynosPort->portDefinition.format.video.eColorFormat);
535 #else
536         if ((portIndex == OUTPUT_PORT_INDEX) &&
537             (pExynosPort->bufferProcessType & BUFFER_COPY)) {
538             pExynosPort->bufferProcessType = BUFFER_COPY;
539             pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
540         }
541 #endif
542         pExynosPort->bIsPBEnabled = pPBParams->enable;
543         Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->bIsPBEnabled: %d", pExynosPort->bIsPBEnabled);
544     }
545         break;
546
547 #if 0 /* TIZEN_FEATURE_E3250 */
548     case OMX_IndexParamUseAndroidNativeBuffer:
549     {
550         UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
551         OMX_U32 portIndex = pANBParams->nPortIndex;
552         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
553         android_native_buffer_t *pANB;
554         OMX_U32 nSizeBytes;
555
556         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
557
558         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
559         if (ret != OMX_ErrorNone) {
560             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
561             goto EXIT;
562         }
563
564         if (portIndex >= pExynosComponent->portParam.nPorts) {
565             ret = OMX_ErrorBadPortIndex;
566             goto EXIT;
567         }
568
569         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
570         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
571             ret = OMX_ErrorBadPortIndex;
572             goto EXIT;
573         }
574
575         if (pExynosPort->portState != OMX_StateIdle) {
576             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
577             ret = OMX_ErrorIncorrectStateOperation;
578             goto EXIT;
579         }
580
581         pANB = pANBParams->nativeBuffer.get();
582
583         /* MALI alignment restriction */
584         nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
585         nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
586
587         ret = useAndroidNativeBuffer(pExynosPort,
588                                      pANBParams->bufferHeader,
589                                      pANBParams->nPortIndex,
590                                      pANBParams->pAppPrivate,
591                                      nSizeBytes,
592                                      (OMX_U8 *) pANB);
593         if (ret != OMX_ErrorNone) {
594             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
595             goto EXIT;
596         }
597     }
598         break;
599
600     case OMX_IndexParamStoreMetaDataBuffer:
601     {
602         StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
603         OMX_U32 portIndex = pANBParams->nPortIndex;
604         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
605
606         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
607
608         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
609         if (ret != OMX_ErrorNone) {
610             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
611             goto EXIT;
612         }
613
614         if (portIndex >= pExynosComponent->portParam.nPorts) {
615             ret = OMX_ErrorBadPortIndex;
616             goto EXIT;
617         }
618
619         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
620         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
621             ret = OMX_ErrorBadPortIndex;
622             goto EXIT;
623         }
624
625         pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
626     }
627         break;
628 #endif
629     default:
630     {
631         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
632         ret = OMX_ErrorUnsupportedIndex;
633         goto EXIT;
634     }
635         break;
636     }
637
638 EXIT:
639     FunctionOut();
640
641     return ret;
642 }
643
644 #if 0 // we can remove this later.
645 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
646                                            OMX_OUT OMX_PTR *ppBuf)
647 {
648     OMX_ERRORTYPE      ret = OMX_ErrorNone;
649     MetadataBufferType type;
650
651     FunctionIn();
652
653 /*
654  * meta data contains the following data format.
655  * payload depends on the MetadataBufferType
656  * --------------------------------------------------------------
657  * | MetadataBufferType                         |          payload                           |
658  * --------------------------------------------------------------
659  *
660  * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
661  * --------------------------------------------------------------
662  * | kMetadataBufferTypeCameraSource  | physical addr. of Y |physical addr. of CbCr |
663  * --------------------------------------------------------------
664  *
665  * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
666  * --------------------------------------------------------------
667  * | kMetadataBufferTypeGrallocSource    | buffer_handle_t |
668  * --------------------------------------------------------------
669  */
670
671     /* MetadataBufferType */
672     Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
673
674     if (type == kMetadataBufferTypeCameraSource) {
675         void *pAddress = NULL;
676
677         /* Address. of Y */
678         Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
679         ppBuf[0] = (void *)pAddress;
680
681         /* Address. of CbCr */
682         Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
683         ppBuf[1] = (void *)pAddress;
684
685     } else if (type == kMetadataBufferTypeGrallocSource) {
686         buffer_handle_t    pBufHandle;
687
688         /* buffer_handle_t */
689         Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
690         ppBuf[0] = (OMX_PTR)pBufHandle;
691     }
692
693 EXIT:
694     FunctionOut();
695
696     return ret;
697 }
698
699 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
700     unsigned int hal_format)
701 {
702     OMX_COLOR_FORMATTYPE omx_format;
703     switch (hal_format) {
704     case HAL_PIXEL_FORMAT_YCbCr_422_I:
705         omx_format = OMX_COLOR_FormatYCbYCr;
706         break;
707     case HAL_PIXEL_FORMAT_YCbCr_420_P:
708         omx_format = OMX_COLOR_FormatYUV420Planar;
709         break;
710     case HAL_PIXEL_FORMAT_YCbCr_420_SP:
711         omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
712         break;
713     case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
714         omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
715         break;
716     case HAL_PIXEL_FORMAT_ARGB888:
717         omx_format = OMX_COLOR_Format32bitARGB8888;
718         break;
719     default:
720         omx_format = OMX_COLOR_FormatYUV420Planar;
721         break;
722     }
723     return omx_format;
724 }
725
726 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
727     OMX_COLOR_FORMATTYPE omx_format)
728 {
729     unsigned int hal_format;
730     switch (omx_format) {
731     case OMX_COLOR_FormatYCbYCr:
732         hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
733         break;
734     case OMX_COLOR_FormatYUV420Planar:
735         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
736         break;
737     case OMX_COLOR_FormatYUV420SemiPlanar:
738         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
739         break;
740     case OMX_SEC_COLOR_FormatNV12Tiled:
741         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
742         break;
743     case OMX_COLOR_Format32bitARGB8888:
744         hal_format = HAL_PIXEL_FORMAT_ARGB888;
745         break;
746     default:
747         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
748         break;
749     }
750     return hal_format;
751 }
752 #endif
753
754 #ifdef __cplusplus
755 }
756 #endif