Remove build warnings and fixed svace 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
269     pSlpOutBuf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO; /* use bo mode */
270
271     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]);
272 #else
273     android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
274
275     ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
276 #endif
277 EXIT:
278     FunctionOut();
279
280     return ret;
281 }
282
283 #if 0
284 OMX_ERRORTYPE useAndroidNativeBuffer(
285     EXYNOS_OMX_BASEPORT      *pExynosPort,
286     OMX_BUFFERHEADERTYPE **ppBufferHdr,
287     OMX_U32                nPortIndex,
288     OMX_PTR                pAppPrivate,
289     OMX_U32                nSizeBytes,
290     OMX_U8                *pBuffer)
291 {
292     OMX_ERRORTYPE         ret = OMX_ErrorNone;
293     OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
294     unsigned int          i = 0;
295     OMX_U32               width, height;
296     OMX_U32               stride;
297     ExynosVideoPlane      planes[MAX_BUFFER_PLANE];
298
299     FunctionIn();
300
301     if (pExynosPort == NULL) {
302         ret = OMX_ErrorBadParameter;
303         goto EXIT;
304     }
305     if (pExynosPort->portState != OMX_StateIdle) {
306         ret = OMX_ErrorIncorrectStateOperation;
307         goto EXIT;
308     }
309     if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
310         ret = OMX_ErrorBadPortIndex;
311         goto EXIT;
312     }
313
314     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
315     if (temp_bufferHeader == NULL) {
316         ret = OMX_ErrorInsufficientResources;
317         goto EXIT;
318     }
319     Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
320
321     for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
322         if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
323             pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
324             pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
325             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
326             temp_bufferHeader->pBuffer        = pBuffer;
327             temp_bufferHeader->nAllocLen      = nSizeBytes;
328             temp_bufferHeader->pAppPrivate    = pAppPrivate;
329             if (nPortIndex == INPUT_PORT_INDEX)
330                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
331             else
332                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
333
334             width = pExynosPort->portDefinition.format.video.nFrameWidth;
335             height = pExynosPort->portDefinition.format.video.nFrameHeight;
336             Exynos_OSAL_LockPB(temp_bufferHeader->pBuffer, width, height,
337                                 pExynosPort->portDefinition.format.video.eColorFormat,
338                                 &stride, planes);
339 #ifdef USE_DMA_BUF
340             pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
341             pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
342             pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
343 #endif
344             pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
345             pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
346             pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
347             Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
348             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
349                             i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
350                             pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
351
352             pExynosPort->assignedBufferNum++;
353             if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
354                 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
355                 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
356                 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
357                 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
358             }
359             *ppBufferHdr = temp_bufferHeader;
360             ret = OMX_ErrorNone;
361
362             goto EXIT;
363         }
364     }
365
366     Exynos_OSAL_Free(temp_bufferHeader);
367     ret = OMX_ErrorInsufficientResources;
368
369 EXIT:
370     FunctionOut();
371
372     return ret;
373 }
374 #endif
375
376 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
377     OMX_IN OMX_HANDLETYPE hComponent,
378     OMX_IN OMX_INDEXTYPE  nIndex,
379     OMX_INOUT OMX_PTR     ComponentParameterStructure)
380 {
381     OMX_ERRORTYPE          ret = OMX_ErrorNone;
382     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
383     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
384
385     FunctionIn();
386
387     if (hComponent == NULL) {
388         ret = OMX_ErrorBadParameter;
389         goto EXIT;
390     }
391
392     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
393     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
394     if (ret != OMX_ErrorNone) {
395         goto EXIT;
396     }
397
398     if (pOMXComponent->pComponentPrivate == NULL) {
399         ret = OMX_ErrorBadParameter;
400         goto EXIT;
401     }
402
403     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
404     if (pExynosComponent->currentState == OMX_StateInvalid ) {
405         ret = OMX_ErrorInvalidState;
406         goto EXIT;
407     }
408
409     if (ComponentParameterStructure == NULL) {
410         ret = OMX_ErrorBadParameter;
411         goto EXIT;
412     }
413
414     switch (nIndex) {
415 #if 0 /* TIZEN_FEATURE_E3250 */
416     case OMX_IndexParamGetAndroidNativeBuffer:
417     {
418         GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
419         OMX_U32 portIndex = pANBParams->nPortIndex;
420
421         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
422
423         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
424         if (ret != OMX_ErrorNone) {
425             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
426             goto EXIT;
427         }
428
429         if (portIndex >= pExynosComponent->portParam.nPorts) {
430             ret = OMX_ErrorBadPortIndex;
431             goto EXIT;
432         }
433
434         /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
435          * modifications since currently not defined what the 'nUsage' is for.
436          */
437         pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
438                            | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
439     }
440         break;
441 #endif
442     default:
443     {
444         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
445         ret = OMX_ErrorUnsupportedIndex;
446         goto EXIT;
447     }
448         break;
449     }
450
451 EXIT:
452     FunctionOut();
453
454     return ret;
455 }
456
457 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
458     OMX_IN OMX_HANDLETYPE hComponent,
459     OMX_IN OMX_INDEXTYPE  nIndex,
460     OMX_IN OMX_PTR        ComponentParameterStructure)
461 {
462     OMX_ERRORTYPE          ret = OMX_ErrorNone;
463     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
464     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
465
466     FunctionIn();
467
468     if (hComponent == NULL) {
469         ret = OMX_ErrorBadParameter;
470         goto EXIT;
471     }
472
473     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
474     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
475     if (ret != OMX_ErrorNone) {
476         goto EXIT;
477     }
478
479     if (pOMXComponent->pComponentPrivate == NULL) {
480         ret = OMX_ErrorBadParameter;
481         goto EXIT;
482     }
483
484     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
485     if (pExynosComponent->currentState == OMX_StateInvalid ) {
486         ret = OMX_ErrorInvalidState;
487         goto EXIT;
488     }
489
490     if (ComponentParameterStructure == NULL) {
491         ret = OMX_ErrorBadParameter;
492         goto EXIT;
493     }
494
495     switch (nIndex) {
496 #ifdef TIZEN_FEATURE_E3250
497     case OMX_IndexParamEnablePlatformSpecificBuffers:
498 #else
499     case OMX_IndexParamEnableAndroidBuffers:
500 #endif
501     {
502         EnableGemBuffersParams *pPBParams = (EnableGemBuffersParams *) ComponentParameterStructure;
503         OMX_U32 portIndex = pPBParams->nPortIndex;
504         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
505
506         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnablePlatformSpecificBuffers", __func__);
507
508         ret = Exynos_OMX_Check_SizeVersion(pPBParams, sizeof(EnableGemBuffersParams));
509         if (ret != OMX_ErrorNone) {
510             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableGemBuffersParams) is failed", __func__);
511             goto EXIT;
512         }
513
514         if (portIndex >= pExynosComponent->portParam.nPorts) {
515             ret = OMX_ErrorBadPortIndex;
516             goto EXIT;
517         }
518
519         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
520         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
521             ret = OMX_ErrorBadPortIndex;
522             goto EXIT;
523         }
524
525 #ifdef TIZEN_FEATURE_E3250
526          /* PB and DPB Buffer Sharing */
527         if ((portIndex == OUTPUT_PORT_INDEX) &&
528             ((pExynosPort->bufferProcessType & BUFFER_PBSHARE) == BUFFER_PBSHARE)) {
529             pExynosPort->bufferProcessType = BUFFER_SHARE;
530             pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
531             Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on");
532         }
533         Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->portDefinition.format.video.eColorFormat: 0x%x", pExynosPort->portDefinition.format.video.eColorFormat);
534 #else
535         if ((portIndex == OUTPUT_PORT_INDEX) &&
536             (pExynosPort->bufferProcessType & BUFFER_COPY)) {
537             pExynosPort->bufferProcessType = BUFFER_COPY;
538             pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
539         }
540 #endif
541         pExynosPort->bIsPBEnabled = pPBParams->enable;
542         Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->bIsPBEnabled: %d", pExynosPort->bIsPBEnabled);
543     }
544         break;
545
546 #if 0 /* TIZEN_FEATURE_E3250 */
547     case OMX_IndexParamUseAndroidNativeBuffer:
548     {
549         UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
550         OMX_U32 portIndex = pANBParams->nPortIndex;
551         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
552         android_native_buffer_t *pANB;
553         OMX_U32 nSizeBytes;
554
555         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
556
557         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
558         if (ret != OMX_ErrorNone) {
559             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
560             goto EXIT;
561         }
562
563         if (portIndex >= pExynosComponent->portParam.nPorts) {
564             ret = OMX_ErrorBadPortIndex;
565             goto EXIT;
566         }
567
568         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
569         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
570             ret = OMX_ErrorBadPortIndex;
571             goto EXIT;
572         }
573
574         if (pExynosPort->portState != OMX_StateIdle) {
575             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
576             ret = OMX_ErrorIncorrectStateOperation;
577             goto EXIT;
578         }
579
580         pANB = pANBParams->nativeBuffer.get();
581
582         /* MALI alignment restriction */
583         nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
584         nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
585
586         ret = useAndroidNativeBuffer(pExynosPort,
587                                      pANBParams->bufferHeader,
588                                      pANBParams->nPortIndex,
589                                      pANBParams->pAppPrivate,
590                                      nSizeBytes,
591                                      (OMX_U8 *) pANB);
592         if (ret != OMX_ErrorNone) {
593             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
594             goto EXIT;
595         }
596     }
597         break;
598
599     case OMX_IndexParamStoreMetaDataBuffer:
600     {
601         StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
602         OMX_U32 portIndex = pANBParams->nPortIndex;
603         EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
604
605         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
606
607         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
608         if (ret != OMX_ErrorNone) {
609             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
610             goto EXIT;
611         }
612
613         if (portIndex >= pExynosComponent->portParam.nPorts) {
614             ret = OMX_ErrorBadPortIndex;
615             goto EXIT;
616         }
617
618         pExynosPort = &pExynosComponent->pExynosPort[portIndex];
619         if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
620             ret = OMX_ErrorBadPortIndex;
621             goto EXIT;
622         }
623
624         pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
625     }
626         break;
627 #endif
628     default:
629     {
630         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
631         ret = OMX_ErrorUnsupportedIndex;
632         goto EXIT;
633     }
634         break;
635     }
636
637 EXIT:
638     FunctionOut();
639
640     return ret;
641 }
642
643 #if 0 // we can remove this later.
644 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
645                                            OMX_OUT OMX_PTR *ppBuf)
646 {
647     OMX_ERRORTYPE      ret = OMX_ErrorNone;
648     MetadataBufferType type;
649
650     FunctionIn();
651
652 /*
653  * meta data contains the following data format.
654  * payload depends on the MetadataBufferType
655  * --------------------------------------------------------------
656  * | MetadataBufferType                         |          payload                           |
657  * --------------------------------------------------------------
658  *
659  * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
660  * --------------------------------------------------------------
661  * | kMetadataBufferTypeCameraSource  | physical addr. of Y |physical addr. of CbCr |
662  * --------------------------------------------------------------
663  *
664  * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
665  * --------------------------------------------------------------
666  * | kMetadataBufferTypeGrallocSource    | buffer_handle_t |
667  * --------------------------------------------------------------
668  */
669
670     /* MetadataBufferType */
671     Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
672
673     if (type == kMetadataBufferTypeCameraSource) {
674         void *pAddress = NULL;
675
676         /* Address. of Y */
677         Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
678         ppBuf[0] = (void *)pAddress;
679
680         /* Address. of CbCr */
681         Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
682         ppBuf[1] = (void *)pAddress;
683
684     } else if (type == kMetadataBufferTypeGrallocSource) {
685         buffer_handle_t    pBufHandle;
686
687         /* buffer_handle_t */
688         Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
689         ppBuf[0] = (OMX_PTR)pBufHandle;
690     }
691
692 EXIT:
693     FunctionOut();
694
695     return ret;
696 }
697
698 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
699     unsigned int hal_format)
700 {
701     OMX_COLOR_FORMATTYPE omx_format;
702     switch (hal_format) {
703     case HAL_PIXEL_FORMAT_YCbCr_422_I:
704         omx_format = OMX_COLOR_FormatYCbYCr;
705         break;
706     case HAL_PIXEL_FORMAT_YCbCr_420_P:
707         omx_format = OMX_COLOR_FormatYUV420Planar;
708         break;
709     case HAL_PIXEL_FORMAT_YCbCr_420_SP:
710         omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
711         break;
712     case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
713         omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
714         break;
715     case HAL_PIXEL_FORMAT_ARGB888:
716         omx_format = OMX_COLOR_Format32bitARGB8888;
717         break;
718     default:
719         omx_format = OMX_COLOR_FormatYUV420Planar;
720         break;
721     }
722     return omx_format;
723 }
724
725 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
726     OMX_COLOR_FORMATTYPE omx_format)
727 {
728     unsigned int hal_format;
729     switch (omx_format) {
730     case OMX_COLOR_FormatYCbYCr:
731         hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
732         break;
733     case OMX_COLOR_FormatYUV420Planar:
734         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
735         break;
736     case OMX_COLOR_FormatYUV420SemiPlanar:
737         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
738         break;
739     case OMX_SEC_COLOR_FormatNV12Tiled:
740         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
741         break;
742     case OMX_COLOR_Format32bitARGB8888:
743         hal_format = HAL_PIXEL_FORMAT_ARGB888;
744         break;
745     default:
746         hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
747         break;
748     }
749     return hal_format;
750 }
751 #endif
752
753 #ifdef __cplusplus
754 }
755 #endif