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