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