2 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file Exynos_OSAL_Platform_Specific.c
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)
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"
42 #include "ExynosVideoApi.h"
45 #define EXYNOS_LOG_TAG "Exynos_OSAL_PB"
46 #define EXYNOS_LOG_OFF
47 #include "Exynos_OSAL_Log.h"
54 OMX_ERRORTYPE Exynos_OSAL_LockPBHandle(
55 OMX_IN OMX_U32 handle,
57 OMX_IN OMX_U32 height,
58 OMX_IN OMX_COLOR_FORMATTYPE format,
59 OMX_OUT OMX_PTR planes)
63 OMX_ERRORTYPE ret = OMX_ErrorNone;
66 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
67 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
69 private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
71 Rect bounds(width, height);
72 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
73 void *vaddr[MAX_BUFFER_PLANE];
75 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
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;
86 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
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;
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;
104 vplanes[0].addr = vaddr[0];
105 vplanes[1].addr = vaddr[1];
106 vplanes[2].addr = vaddr[2];
108 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
117 OMX_ERRORTYPE Exynos_OSAL_UnlockPBHandle(OMX_IN OMX_U32 handle)
121 OMX_ERRORTYPE ret = OMX_ErrorNone;
122 #ifdef TIZEN_FEATURE_E3250
124 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
125 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
127 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
129 if (mapper.unlock(bufferHandle) != 0) {
130 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
131 ret = OMX_ErrorUndefined;
135 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
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)
155 OMX_ERRORTYPE ret = OMX_ErrorNone;
156 #ifdef TIZEN_FEATURE_E3250
158 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
159 MMVideoBuffer *buffer = (MMVideoBuffer *) pBuffer;
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;
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];
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]);
176 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
178 ret = Exynos_OSAL_LockPBHandle((OMX_U32)pANB->handle, width, height, format, planes);
179 *pStride = pANB->stride;
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)
190 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData)
195 OMX_ERRORTYPE ret = OMX_ErrorNone;
196 #ifdef TIZEN_FEATURE_E3250
197 MMVideoBuffer *pSlpOutBuf = NULL;
198 DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
200 pSlpOutBuf = (MMVideoBuffer *)pBuffer;
201 if (pSlpOutBuf == NULL) {
202 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pBuffer is NULL!");
203 ret = OMX_ErrorInsufficientResources;
206 memset(pSlpOutBuf, 0, sizeof(MMVideoBuffer));
208 pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pData->extInfo;
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;
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);
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);
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);
239 if (pVideoDec->bDRMPlayerMode == OMX_TRUE) {
240 pSlpOutBuf->a[0] = 0;
241 pSlpOutBuf->a[1] = 0;
244 pSlpOutBuf->data[0] = pData->buffer.multiPlaneBuffer.dataBuffer[0];
245 pSlpOutBuf->data[1] = pData->buffer.multiPlaneBuffer.dataBuffer[1];
247 pSlpOutBuf->data[2] = 0; /* omx do not use this plane */
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;
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;
257 if(pExynosInPort->portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
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]);
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]);
268 pSlpOutBuf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO; /* use bo mode */
269 pSlpOutBuf->handle_num = 2;
270 pSlpOutBuf->plane_num = 2;
272 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "fd (%d, %d, %d) received from MFC", pSlpOutBuf->handle.dmabuf_fd[0], pSlpOutBuf->handle.dmabuf_fd[1], pSlpOutBuf->handle.dmabuf_fd[2]);
274 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
276 ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
285 OMX_ERRORTYPE useAndroidNativeBuffer(
286 EXYNOS_OMX_BASEPORT *pExynosPort,
287 OMX_BUFFERHEADERTYPE **ppBufferHdr,
293 OMX_ERRORTYPE ret = OMX_ErrorNone;
294 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
296 OMX_U32 width, height;
298 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
302 if (pExynosPort == NULL) {
303 ret = OMX_ErrorBadParameter;
306 if (pExynosPort->portState != OMX_StateIdle) {
307 ret = OMX_ErrorIncorrectStateOperation;
310 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
311 ret = OMX_ErrorBadPortIndex;
315 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
316 if (temp_bufferHeader == NULL) {
317 ret = OMX_ErrorInsufficientResources;
320 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
322 for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
323 if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
324 pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
325 pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
326 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
327 temp_bufferHeader->pBuffer = pBuffer;
328 temp_bufferHeader->nAllocLen = nSizeBytes;
329 temp_bufferHeader->pAppPrivate = pAppPrivate;
330 if (nPortIndex == INPUT_PORT_INDEX)
331 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
333 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
335 width = pExynosPort->portDefinition.format.video.nFrameWidth;
336 height = pExynosPort->portDefinition.format.video.nFrameHeight;
337 Exynos_OSAL_LockPB(temp_bufferHeader->pBuffer, width, height,
338 pExynosPort->portDefinition.format.video.eColorFormat,
341 pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
342 pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
343 pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
345 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
346 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
347 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
348 Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
349 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
350 i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
351 pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
353 pExynosPort->assignedBufferNum++;
354 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
355 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
356 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
357 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
358 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
360 *ppBufferHdr = temp_bufferHeader;
367 Exynos_OSAL_Free(temp_bufferHeader);
368 ret = OMX_ErrorInsufficientResources;
377 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
378 OMX_IN OMX_HANDLETYPE hComponent,
379 OMX_IN OMX_INDEXTYPE nIndex,
380 OMX_INOUT OMX_PTR ComponentParameterStructure)
382 OMX_ERRORTYPE ret = OMX_ErrorNone;
383 OMX_COMPONENTTYPE *pOMXComponent = NULL;
384 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
388 if (hComponent == NULL) {
389 ret = OMX_ErrorBadParameter;
393 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
394 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
395 if (ret != OMX_ErrorNone) {
399 if (pOMXComponent->pComponentPrivate == NULL) {
400 ret = OMX_ErrorBadParameter;
404 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
405 if (pExynosComponent->currentState == OMX_StateInvalid ) {
406 ret = OMX_ErrorInvalidState;
410 if (ComponentParameterStructure == NULL) {
411 ret = OMX_ErrorBadParameter;
416 #if 0 /* TIZEN_FEATURE_E3250 */
417 case OMX_IndexParamGetAndroidNativeBuffer:
419 GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
420 OMX_U32 portIndex = pANBParams->nPortIndex;
422 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
424 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
425 if (ret != OMX_ErrorNone) {
426 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
430 if (portIndex >= pExynosComponent->portParam.nPorts) {
431 ret = OMX_ErrorBadPortIndex;
435 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
436 * modifications since currently not defined what the 'nUsage' is for.
438 pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
439 | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
445 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
446 ret = OMX_ErrorUnsupportedIndex;
458 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
459 OMX_IN OMX_HANDLETYPE hComponent,
460 OMX_IN OMX_INDEXTYPE nIndex,
461 OMX_IN OMX_PTR ComponentParameterStructure)
463 OMX_ERRORTYPE ret = OMX_ErrorNone;
464 OMX_COMPONENTTYPE *pOMXComponent = NULL;
465 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
469 if (hComponent == NULL) {
470 ret = OMX_ErrorBadParameter;
474 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
475 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
476 if (ret != OMX_ErrorNone) {
480 if (pOMXComponent->pComponentPrivate == NULL) {
481 ret = OMX_ErrorBadParameter;
485 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
486 if (pExynosComponent->currentState == OMX_StateInvalid ) {
487 ret = OMX_ErrorInvalidState;
491 if (ComponentParameterStructure == NULL) {
492 ret = OMX_ErrorBadParameter;
496 switch ((int)nIndex) {
497 #ifdef TIZEN_FEATURE_E3250
498 case OMX_IndexParamEnablePlatformSpecificBuffers:
500 case OMX_IndexParamEnableAndroidBuffers:
503 EnableGemBuffersParams *pPBParams = (EnableGemBuffersParams *) ComponentParameterStructure;
504 OMX_U32 portIndex = pPBParams->nPortIndex;
505 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
507 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnablePlatformSpecificBuffers", __func__);
509 ret = Exynos_OMX_Check_SizeVersion(pPBParams, sizeof(EnableGemBuffersParams));
510 if (ret != OMX_ErrorNone) {
511 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableGemBuffersParams) is failed", __func__);
515 if (portIndex >= pExynosComponent->portParam.nPorts) {
516 ret = OMX_ErrorBadPortIndex;
520 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
521 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
522 ret = OMX_ErrorBadPortIndex;
526 #ifdef TIZEN_FEATURE_E3250
527 /* PB and DPB Buffer Sharing */
528 if ((portIndex == OUTPUT_PORT_INDEX) &&
529 ((pExynosPort->bufferProcessType & BUFFER_PBSHARE) == BUFFER_PBSHARE)) {
530 pExynosPort->bufferProcessType = BUFFER_SHARE;
531 pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
532 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on");
534 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->portDefinition.format.video.eColorFormat: 0x%x", pExynosPort->portDefinition.format.video.eColorFormat);
536 if ((portIndex == OUTPUT_PORT_INDEX) &&
537 (pExynosPort->bufferProcessType & BUFFER_COPY)) {
538 pExynosPort->bufferProcessType = BUFFER_COPY;
539 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
542 pExynosPort->bIsPBEnabled = pPBParams->enable;
543 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->bIsPBEnabled: %d", pExynosPort->bIsPBEnabled);
547 #if 0 /* TIZEN_FEATURE_E3250 */
548 case OMX_IndexParamUseAndroidNativeBuffer:
550 UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
551 OMX_U32 portIndex = pANBParams->nPortIndex;
552 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
553 android_native_buffer_t *pANB;
556 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
558 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
559 if (ret != OMX_ErrorNone) {
560 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
564 if (portIndex >= pExynosComponent->portParam.nPorts) {
565 ret = OMX_ErrorBadPortIndex;
569 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
570 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
571 ret = OMX_ErrorBadPortIndex;
575 if (pExynosPort->portState != OMX_StateIdle) {
576 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
577 ret = OMX_ErrorIncorrectStateOperation;
581 pANB = pANBParams->nativeBuffer.get();
583 /* MALI alignment restriction */
584 nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
585 nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
587 ret = useAndroidNativeBuffer(pExynosPort,
588 pANBParams->bufferHeader,
589 pANBParams->nPortIndex,
590 pANBParams->pAppPrivate,
593 if (ret != OMX_ErrorNone) {
594 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
600 case OMX_IndexParamStoreMetaDataBuffer:
602 StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
603 OMX_U32 portIndex = pANBParams->nPortIndex;
604 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
606 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
608 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
609 if (ret != OMX_ErrorNone) {
610 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
614 if (portIndex >= pExynosComponent->portParam.nPorts) {
615 ret = OMX_ErrorBadPortIndex;
619 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
620 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
621 ret = OMX_ErrorBadPortIndex;
625 pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
631 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
632 ret = OMX_ErrorUnsupportedIndex;
644 #if 0 // we can remove this later.
645 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
646 OMX_OUT OMX_PTR *ppBuf)
648 OMX_ERRORTYPE ret = OMX_ErrorNone;
649 MetadataBufferType type;
654 * meta data contains the following data format.
655 * payload depends on the MetadataBufferType
656 * --------------------------------------------------------------
657 * | MetadataBufferType | payload |
658 * --------------------------------------------------------------
660 * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
661 * --------------------------------------------------------------
662 * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr |
663 * --------------------------------------------------------------
665 * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
666 * --------------------------------------------------------------
667 * | kMetadataBufferTypeGrallocSource | buffer_handle_t |
668 * --------------------------------------------------------------
671 /* MetadataBufferType */
672 Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
674 if (type == kMetadataBufferTypeCameraSource) {
675 void *pAddress = NULL;
678 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
679 ppBuf[0] = (void *)pAddress;
681 /* Address. of CbCr */
682 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
683 ppBuf[1] = (void *)pAddress;
685 } else if (type == kMetadataBufferTypeGrallocSource) {
686 buffer_handle_t pBufHandle;
688 /* buffer_handle_t */
689 Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
690 ppBuf[0] = (OMX_PTR)pBufHandle;
699 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
700 unsigned int hal_format)
702 OMX_COLOR_FORMATTYPE omx_format;
703 switch (hal_format) {
704 case HAL_PIXEL_FORMAT_YCbCr_422_I:
705 omx_format = OMX_COLOR_FormatYCbYCr;
707 case HAL_PIXEL_FORMAT_YCbCr_420_P:
708 omx_format = OMX_COLOR_FormatYUV420Planar;
710 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
711 omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
713 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
714 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
716 case HAL_PIXEL_FORMAT_ARGB888:
717 omx_format = OMX_COLOR_Format32bitARGB8888;
720 omx_format = OMX_COLOR_FormatYUV420Planar;
726 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
727 OMX_COLOR_FORMATTYPE omx_format)
729 unsigned int hal_format;
730 switch (omx_format) {
731 case OMX_COLOR_FormatYCbYCr:
732 hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
734 case OMX_COLOR_FormatYUV420Planar:
735 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
737 case OMX_COLOR_FormatYUV420SemiPlanar:
738 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
740 case OMX_SEC_COLOR_FormatNV12Tiled:
741 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
743 case OMX_COLOR_Format32bitARGB8888:
744 hal_format = HAL_PIXEL_FORMAT_ARGB888;
747 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;