Force to use Exynos3250 kernel header, not sc7730
[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 <mm_types.h>
32
33 #include "Exynos_OSAL_Semaphore.h"
34 #include "Exynos_OMX_Baseport.h"
35 #include "Exynos_OMX_Basecomponent.h"
36 #include "Exynos_OMX_Macros.h"
37 #include "Exynos_OMX_Vdec.h"
38 #include "Exynos_OSAL_Platform_Specific.h"
39 #include "exynos_format.h"
40
41 #include "ExynosVideoApi.h"
42
43 #undef  EXYNOS_LOG_TAG
44 #define EXYNOS_LOG_TAG    "Exynos_OSAL_PB"
45 #define EXYNOS_LOG_OFF
46 #include "Exynos_OSAL_Log.h"
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52
53 OMX_ERRORTYPE Exynos_OSAL_LockPBHandle(
54     OMX_IN OMX_U32 handle,
55     OMX_IN OMX_U32 width,
56     OMX_IN OMX_U32 height,
57     OMX_IN OMX_COLOR_FORMATTYPE format,
58     OMX_OUT OMX_PTR planes)
59 {
60     FunctionIn();
61
62     OMX_ERRORTYPE ret = OMX_ErrorNone;
63
64 #if 0
65     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
66     buffer_handle_t bufferHandle = (buffer_handle_t) handle;
67 #ifdef USE_DMA_BUF
68     private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
69 #endif
70     Rect bounds(width, height);
71     ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
72     void *vaddr[MAX_BUFFER_PLANE];
73
74     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
75
76     int usage = 0;
77
78     switch (format) {
79     case OMX_COLOR_FormatYUV420Planar:
80     case OMX_COLOR_FormatYUV420SemiPlanar:
81     case OMX_SEC_COLOR_FormatNV12Tiled:
82         usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR;
83         break;
84     default:
85         usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
86         break;
87     }
88
89     if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) {
90         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__);
91         ret = OMX_ErrorUndefined;
92         goto EXIT;
93     }
94
95 #ifdef USE_DMA_BUF
96     vplanes[0].fd = priv_hnd->fd;
97     vplanes[0].offset = 0;
98     vplanes[1].fd = priv_hnd->u_fd;
99     vplanes[1].offset = priv_hnd->uoffset;
100     vplanes[2].fd = priv_hnd->v_fd;
101     vplanes[2].offset = priv_hnd->voffset;
102 #endif
103     vplanes[0].addr = vaddr[0];
104     vplanes[1].addr = vaddr[1];
105     vplanes[2].addr = vaddr[2];
106
107     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
108 #endif
109
110 EXIT:
111     FunctionOut();
112
113     return ret;
114 }
115
116 OMX_ERRORTYPE Exynos_OSAL_UnlockPBHandle(OMX_IN OMX_U32 handle)
117 {
118     FunctionIn();
119
120     OMX_ERRORTYPE ret = OMX_ErrorNone;
121 #ifdef SLP_PLATFORM
122 #else
123     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
124     buffer_handle_t bufferHandle = (buffer_handle_t) handle;
125
126     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
127
128     if (mapper.unlock(bufferHandle) != 0) {
129         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
130         ret = OMX_ErrorUndefined;
131         goto EXIT;
132     }
133
134     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
135 #endif
136
137 EXIT:
138     FunctionOut();
139
140     return ret;
141 }
142
143 OMX_ERRORTYPE Exynos_OSAL_LockPB(
144     OMX_IN OMX_PTR pBuffer,
145     OMX_IN OMX_U32 width,
146     OMX_IN OMX_U32 height,
147     OMX_IN OMX_COLOR_FORMATTYPE format,
148     OMX_OUT OMX_U32 *pStride,
149     OMX_OUT OMX_PTR planes)
150 {
151     FunctionIn();
152
153     OMX_ERRORTYPE ret = OMX_ErrorNone;
154 #ifdef SLP_PLATFORM
155
156     ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
157     MMVideoBuffer *buffer = (MMVideoBuffer *) pBuffer;
158
159
160     vplanes[0].fd = buffer->handle.dmabuf_fd[0];
161     vplanes[0].offset = 0;
162     vplanes[1].fd = buffer->handle.dmabuf_fd[1];
163     vplanes[1].offset = 0; //priv_hnd->uoffset;
164     vplanes[2].fd = 0; //priv_hnd->v_fd;
165     vplanes[2].offset = 0; //priv_hnd->voffset;
166
167     vplanes[0].addr = buffer->data[0]; //vaddr[0];
168     vplanes[1].addr = buffer->data[1]; //vaddr[1];
169     vplanes[2].addr = NULL; //vaddr[2];
170
171     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Exynos_OSAL_LockPB:fd[0](%d)  fd[1](%d)  a[0](%p)  a[1](%p)", 
172         buffer->handle.dmabuf_fd[0], buffer->handle.dmabuf_fd[1], buffer->data[0], buffer->data[1]);
173 #else
174     android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
175
176     ret = Exynos_OSAL_LockPBHandle((OMX_U32)pANB->handle, width, height, format, planes);
177     *pStride = pANB->stride;
178 #endif
179
180 EXIT:
181     FunctionOut();
182
183     return ret;
184 }
185
186 #ifdef SLP_PLATFORM
187 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort,EXYNOS_OMX_BASEPORT *pExynosInPort)
188 #else
189 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData)
190 #endif
191 {
192     FunctionIn();
193
194     OMX_ERRORTYPE ret = OMX_ErrorNone;
195 #ifdef SLP_PLATFORM
196     MMVideoBuffer *pSlpOutBuf = NULL;
197     DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
198
199     pSlpOutBuf = (MMVideoBuffer *)pBuffer;
200     if (pSlpOutBuf == NULL) {
201       Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pBuffer is NULL!");
202       ret = OMX_ErrorInsufficientResources;
203       goto EXIT;
204     }
205     memset(pSlpOutBuf, 0, sizeof(MMVideoBuffer));
206
207     pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pData->extInfo;
208
209     if (pExynosPort->cropRectangle.nWidth != 0 && pExynosPort->cropRectangle.nHeight != 0) {
210         /* modify for h264 trim */
211         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "this has cropRectangle(h264).crop.nWidth = %d, crop.nHeight = %d",
212             pExynosPort->cropRectangle.nWidth, pExynosPort->cropRectangle.nWidth);
213         pSlpOutBuf->width[0] = pExynosPort->cropRectangle.nWidth;
214         pSlpOutBuf->width[1] = pExynosPort->cropRectangle.nWidth;
215         pSlpOutBuf->height[0] = pExynosPort->cropRectangle.nHeight;
216         pSlpOutBuf->height[1] = pExynosPort->cropRectangle.nHeight/2;
217
218
219         pSlpOutBuf->stride_width[0] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
220         pSlpOutBuf->stride_width[1] = ALIGN(pExynosPort->cropRectangle.nWidth, S5P_FIMV_NV12MT_HALIGN);
221         pSlpOutBuf->stride_height[0] = ALIGN(pExynosPort->cropRectangle.nHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
222         pSlpOutBuf->stride_height[1] = ALIGN((pExynosPort->cropRectangle.nHeight/2), S5P_FIMV_NV12MT_VALIGN);
223     } else {
224         pSlpOutBuf->width[0] = pBufferInfo->imageWidth;
225         pSlpOutBuf->width[1] = pBufferInfo->imageWidth;
226         pSlpOutBuf->height[0] = pBufferInfo->imageHeight;
227         pSlpOutBuf->height[1] = (pBufferInfo->imageHeight/2);
228
229         pSlpOutBuf->stride_width[0] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN); /* need to check. stride */
230         pSlpOutBuf->stride_width[1] = ALIGN(pBufferInfo->imageWidth, S5P_FIMV_NV12MT_HALIGN);
231         pSlpOutBuf->stride_height[0] = ALIGN(pBufferInfo->imageHeight, S5P_FIMV_NV12MT_VALIGN); /* need to check. elevation */
232         pSlpOutBuf->stride_height[1] = ALIGN((pBufferInfo->imageHeight/2), S5P_FIMV_NV12MT_VALIGN);
233     }
234
235
236
237 /*
238     if (pVideoDec->bDRMPlayerMode == OMX_TRUE) {
239         pSlpOutBuf->a[0] = 0;
240         pSlpOutBuf->a[1] = 0;
241     } else {
242 */
243         pSlpOutBuf->data[0] = pData->buffer.multiPlaneBuffer.dataBuffer[0];
244         pSlpOutBuf->data[1] = pData->buffer.multiPlaneBuffer.dataBuffer[1];
245 //    }
246     pSlpOutBuf->data[2] = 0; /* omx do not use this plane */
247
248     pSlpOutBuf->handle.dmabuf_fd[0] = pData->buffer.multiPlaneBuffer.fd[0];
249     pSlpOutBuf->handle.dmabuf_fd[1] = pData->buffer.multiPlaneBuffer.fd[1];
250     pSlpOutBuf->handle.dmabuf_fd[2] = 0;
251
252     pSlpOutBuf->handle.bo[0] = pData->buffer.multiPlaneBuffer.tbm_bo[0];
253     pSlpOutBuf->handle.bo[1] = pData->buffer.multiPlaneBuffer.tbm_bo[1];
254     pSlpOutBuf->handle.bo[2] = NULL;
255
256     if(pExynosInPort->portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
257     {
258         pSlpOutBuf->size[0] = calc_plane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
259         pSlpOutBuf->size[1] = calc_plane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
260         Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"H264 foramt and y_size=%d, uv_size=%d",pSlpOutBuf->size[0],pSlpOutBuf->size[1]);
261     } else {
262         pSlpOutBuf->size[0]= calc_yplane(pBufferInfo->imageWidth,pBufferInfo->imageHeight);
263         pSlpOutBuf->size[1] = calc_uvplane(pBufferInfo->imageWidth,(pBufferInfo->imageHeight) / 2);
264         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]);
265     }
266
267
268     //pSlpOutBuf->type = 1; /* use fd mode */
269
270     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]);
271 #else
272     android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
273
274     ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
275 #endif
276 EXIT:
277     FunctionOut();
278
279     return ret;
280 }
281
282 #if 0
283 OMX_ERRORTYPE useAndroidNativeBuffer(
284     EXYNOS_OMX_BASEPORT      *pExynosPort,
285     OMX_BUFFERHEADERTYPE **ppBufferHdr,
286     OMX_U32                nPortIndex,
287     OMX_PTR                pAppPrivate,
288     OMX_U32                nSizeBytes,
289     OMX_U8                *pBuffer)
290 {
291     OMX_ERRORTYPE         ret = OMX_ErrorNone;
292     OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
293     unsigned int          i = 0;
294     OMX_U32               width, height;
295     OMX_U32               stride;
296     ExynosVideoPlane      planes[MAX_BUFFER_PLANE];
297
298     FunctionIn();
299
300     if (pExynosPort == NULL) {
301         ret = OMX_ErrorBadParameter;
302         goto EXIT;
303     }
304     if (pExynosPort->portState != OMX_StateIdle) {
305         ret = OMX_ErrorIncorrectStateOperation;
306         goto EXIT;
307     }
308     if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
309         ret = OMX_ErrorBadPortIndex;
310         goto EXIT;
311     }
312
313     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
314     if (temp_bufferHeader == NULL) {
315         ret = OMX_ErrorInsufficientResources;
316         goto EXIT;
317     }
318     Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
319
320     for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
321         if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
322             pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
323             pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
324             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
325             temp_bufferHeader->pBuffer        = pBuffer;
326             temp_bufferHeader->nAllocLen      = nSizeBytes;
327             temp_bufferHeader->pAppPrivate    = pAppPrivate;
328             if (nPortIndex == INPUT_PORT_INDEX)
329                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
330             else
331                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
332
333             width = pExynosPort->portDefinition.format.video.nFrameWidth;
334             height = pExynosPort->portDefinition.format.video.nFrameHeight;
335             Exynos_OSAL_LockPB(temp_bufferHeader->pBuffer, width, height,
336                                 pExynosPort->portDefinition.format.video.eColorFormat,
337                                 &stride, planes);
338 #ifdef USE_DMA_BUF
339             pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
340             pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
341             pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
342 #endif
343             pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
344             pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
345             pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
346             Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
347             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
348                             i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
349                             pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
350
351             pExynosPort->assignedBufferNum++;
352             if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
353                 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
354                 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
355                 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
356                 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
357             }
358             *ppBufferHdr = temp_bufferHeader;
359             ret = OMX_ErrorNone;
360
361             goto EXIT;
362         }
363     }
364
365     Exynos_OSAL_Free(temp_bufferHeader);
366     ret = OMX_ErrorInsufficientResources;
367
368 EXIT:
369     FunctionOut();
370
371     return ret;
372 }
373 #endif
374
375 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
376     OMX_IN OMX_HANDLETYPE hComponent,
377     OMX_IN OMX_INDEXTYPE  nIndex,
378     OMX_INOUT OMX_PTR     ComponentParameterStructure)
379 {
380     OMX_ERRORTYPE          ret = OMX_ErrorNone;
381     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
382     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
383
384     FunctionIn();
385
386     if (hComponent == NULL) {
387         ret = OMX_ErrorBadParameter;
388         goto EXIT;
389     }
390
391     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
392     ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
393     if (ret != OMX_ErrorNone) {
394         goto EXIT;
395     }
396
397     if (pOMXComponent->pComponentPrivate == NULL) {
398         ret = OMX_ErrorBadParameter;
399         goto EXIT;
400     }
401
402     pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
403     if (pExynosComponent->currentState == OMX_StateInvalid ) {
404         ret = OMX_ErrorInvalidState;
405         goto EXIT;
406     }
407
408     if (ComponentParameterStructure == NULL) {
409         ret = OMX_ErrorBadParameter;
410         goto EXIT;
411     }
412
413     switch (nIndex) {
414 #if 0 /* SLP_PLATFORM */
415     case OMX_IndexParamGetAndroidNativeBuffer:
416     {
417         GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
418         OMX_U32 portIndex = pANBParams->nPortIndex;
419
420         Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
421
422         ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
423         if (ret != OMX_ErrorNone) {
424             Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
425             goto EXIT;
426         }
427
428         if (portIndex >= pExynosComponent->portParam.nPorts) {
429             ret = OMX_ErrorBadPortIndex;
430             goto EXIT;
431         }
432
433         /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
434          * modifications since currently not defined what the 'nUsage' is for.
435          */
436         pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
437                            | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
438     }
439         break;
440 #endif
441     default:
442     {
443         Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
444         ret = OMX_ErrorUnsupportedIndex;
445         goto EXIT;
446     }
447         break;
448     }
449
450 EXIT:
451     FunctionOut();
452
453     return ret;
454 }
455
456 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
457     OMX_IN OMX_HANDLETYPE hComponent,
458     OMX_IN OMX_INDEXTYPE  nIndex,
459     OMX_IN OMX_PTR        ComponentParameterStructure)
460 {
461     OMX_ERRORTYPE          ret = OMX_ErrorNone;
462     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
463     EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
464     EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = 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     pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
496
497     switch (nIndex) {
498 #ifdef SLP_PLATFORM
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 SLP_PLATFORM
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 /* SLP_PLATFORM */
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