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)
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"
41 #include "ExynosVideoApi.h"
44 #define EXYNOS_LOG_TAG "Exynos_OSAL_PB"
45 #define EXYNOS_LOG_OFF
46 #include "Exynos_OSAL_Log.h"
53 OMX_ERRORTYPE Exynos_OSAL_LockPBHandle(
54 OMX_IN OMX_U32 handle,
56 OMX_IN OMX_U32 height,
57 OMX_IN OMX_COLOR_FORMATTYPE format,
58 OMX_OUT OMX_PTR planes)
62 OMX_ERRORTYPE ret = OMX_ErrorNone;
65 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
66 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
68 private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
70 Rect bounds(width, height);
71 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
72 void *vaddr[MAX_BUFFER_PLANE];
74 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
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;
85 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
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;
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;
103 vplanes[0].addr = vaddr[0];
104 vplanes[1].addr = vaddr[1];
105 vplanes[2].addr = vaddr[2];
107 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
116 OMX_ERRORTYPE Exynos_OSAL_UnlockPBHandle(OMX_IN OMX_U32 handle)
120 OMX_ERRORTYPE ret = OMX_ErrorNone;
123 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
124 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
126 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
128 if (mapper.unlock(bufferHandle) != 0) {
129 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
130 ret = OMX_ErrorUndefined;
134 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
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)
153 OMX_ERRORTYPE ret = OMX_ErrorNone;
156 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
157 MMVideoBuffer *buffer = (MMVideoBuffer *) pBuffer;
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;
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];
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]);
174 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
176 ret = Exynos_OSAL_LockPBHandle((OMX_U32)pANB->handle, width, height, format, planes);
177 *pStride = pANB->stride;
187 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort,EXYNOS_OMX_BASEPORT *pExynosInPort)
189 OMX_ERRORTYPE Exynos_OSAL_UnlockPB(OMX_IN OMX_PTR pBuffer, EXYNOS_OMX_DATA *pData)
194 OMX_ERRORTYPE ret = OMX_ErrorNone;
196 MMVideoBuffer *pSlpOutBuf = NULL;
197 DECODE_CODEC_EXTRA_BUFFERINFO *pBufferInfo = NULL;
199 pSlpOutBuf = (MMVideoBuffer *)pBuffer;
200 if (pSlpOutBuf == NULL) {
201 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pBuffer is NULL!");
202 ret = OMX_ErrorInsufficientResources;
205 memset(pSlpOutBuf, 0, sizeof(MMVideoBuffer));
207 pBufferInfo = (DECODE_CODEC_EXTRA_BUFFERINFO *)pData->extInfo;
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;
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);
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);
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);
238 if (pVideoDec->bDRMPlayerMode == OMX_TRUE) {
239 pSlpOutBuf->a[0] = 0;
240 pSlpOutBuf->a[1] = 0;
243 pSlpOutBuf->data[0] = pData->buffer.multiPlaneBuffer.dataBuffer[0];
244 pSlpOutBuf->data[1] = pData->buffer.multiPlaneBuffer.dataBuffer[1];
246 pSlpOutBuf->data[2] = 0; /* omx do not use this plane */
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;
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;
256 if(pExynosInPort->portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
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]);
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]);
268 //pSlpOutBuf->type = 1; /* use fd mode */
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]);
272 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
274 ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
283 OMX_ERRORTYPE useAndroidNativeBuffer(
284 EXYNOS_OMX_BASEPORT *pExynosPort,
285 OMX_BUFFERHEADERTYPE **ppBufferHdr,
291 OMX_ERRORTYPE ret = OMX_ErrorNone;
292 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
294 OMX_U32 width, height;
296 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
300 if (pExynosPort == NULL) {
301 ret = OMX_ErrorBadParameter;
304 if (pExynosPort->portState != OMX_StateIdle) {
305 ret = OMX_ErrorIncorrectStateOperation;
308 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
309 ret = OMX_ErrorBadPortIndex;
313 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
314 if (temp_bufferHeader == NULL) {
315 ret = OMX_ErrorInsufficientResources;
318 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
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;
331 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
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,
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;
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]);
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); */
358 *ppBufferHdr = temp_bufferHeader;
365 Exynos_OSAL_Free(temp_bufferHeader);
366 ret = OMX_ErrorInsufficientResources;
375 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
376 OMX_IN OMX_HANDLETYPE hComponent,
377 OMX_IN OMX_INDEXTYPE nIndex,
378 OMX_INOUT OMX_PTR ComponentParameterStructure)
380 OMX_ERRORTYPE ret = OMX_ErrorNone;
381 OMX_COMPONENTTYPE *pOMXComponent = NULL;
382 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
386 if (hComponent == NULL) {
387 ret = OMX_ErrorBadParameter;
391 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
392 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
393 if (ret != OMX_ErrorNone) {
397 if (pOMXComponent->pComponentPrivate == NULL) {
398 ret = OMX_ErrorBadParameter;
402 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
403 if (pExynosComponent->currentState == OMX_StateInvalid ) {
404 ret = OMX_ErrorInvalidState;
408 if (ComponentParameterStructure == NULL) {
409 ret = OMX_ErrorBadParameter;
414 #if 0 /* SLP_PLATFORM */
415 case OMX_IndexParamGetAndroidNativeBuffer:
417 GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
418 OMX_U32 portIndex = pANBParams->nPortIndex;
420 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
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__);
428 if (portIndex >= pExynosComponent->portParam.nPorts) {
429 ret = OMX_ErrorBadPortIndex;
433 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
434 * modifications since currently not defined what the 'nUsage' is for.
436 pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
437 | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
443 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
444 ret = OMX_ErrorUnsupportedIndex;
456 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
457 OMX_IN OMX_HANDLETYPE hComponent,
458 OMX_IN OMX_INDEXTYPE nIndex,
459 OMX_IN OMX_PTR ComponentParameterStructure)
461 OMX_ERRORTYPE ret = OMX_ErrorNone;
462 OMX_COMPONENTTYPE *pOMXComponent = NULL;
463 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
464 EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL;
468 if (hComponent == NULL) {
469 ret = OMX_ErrorBadParameter;
473 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
474 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
475 if (ret != OMX_ErrorNone) {
479 if (pOMXComponent->pComponentPrivate == NULL) {
480 ret = OMX_ErrorBadParameter;
484 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
485 if (pExynosComponent->currentState == OMX_StateInvalid ) {
486 ret = OMX_ErrorInvalidState;
490 if (ComponentParameterStructure == NULL) {
491 ret = OMX_ErrorBadParameter;
495 pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle;
499 case OMX_IndexParamEnablePlatformSpecificBuffers:
501 case OMX_IndexParamEnableAndroidBuffers:
504 EnableGemBuffersParams *pPBParams = (EnableGemBuffersParams *) ComponentParameterStructure;
505 OMX_U32 portIndex = pPBParams->nPortIndex;
506 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
508 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnablePlatformSpecificBuffers", __func__);
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__);
516 if (portIndex >= pExynosComponent->portParam.nPorts) {
517 ret = OMX_ErrorBadPortIndex;
521 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
522 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
523 ret = OMX_ErrorBadPortIndex;
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");
535 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->portDefinition.format.video.eColorFormat: 0x%x", pExynosPort->portDefinition.format.video.eColorFormat);
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;
543 pExynosPort->bIsPBEnabled = pPBParams->enable;
544 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "pExynosPort->bIsPBEnabled: %d", pExynosPort->bIsPBEnabled);
548 #if 0 /* SLP_PLATFORM */
549 case OMX_IndexParamUseAndroidNativeBuffer:
551 UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
552 OMX_U32 portIndex = pANBParams->nPortIndex;
553 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
554 android_native_buffer_t *pANB;
557 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
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__);
565 if (portIndex >= pExynosComponent->portParam.nPorts) {
566 ret = OMX_ErrorBadPortIndex;
570 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
571 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
572 ret = OMX_ErrorBadPortIndex;
576 if (pExynosPort->portState != OMX_StateIdle) {
577 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
578 ret = OMX_ErrorIncorrectStateOperation;
582 pANB = pANBParams->nativeBuffer.get();
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;
588 ret = useAndroidNativeBuffer(pExynosPort,
589 pANBParams->bufferHeader,
590 pANBParams->nPortIndex,
591 pANBParams->pAppPrivate,
594 if (ret != OMX_ErrorNone) {
595 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
601 case OMX_IndexParamStoreMetaDataBuffer:
603 StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
604 OMX_U32 portIndex = pANBParams->nPortIndex;
605 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
607 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
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__);
615 if (portIndex >= pExynosComponent->portParam.nPorts) {
616 ret = OMX_ErrorBadPortIndex;
620 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
621 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
622 ret = OMX_ErrorBadPortIndex;
626 pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
632 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
633 ret = OMX_ErrorUnsupportedIndex;
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)
649 OMX_ERRORTYPE ret = OMX_ErrorNone;
650 MetadataBufferType type;
655 * meta data contains the following data format.
656 * payload depends on the MetadataBufferType
657 * --------------------------------------------------------------
658 * | MetadataBufferType | payload |
659 * --------------------------------------------------------------
661 * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
662 * --------------------------------------------------------------
663 * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr |
664 * --------------------------------------------------------------
666 * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
667 * --------------------------------------------------------------
668 * | kMetadataBufferTypeGrallocSource | buffer_handle_t |
669 * --------------------------------------------------------------
672 /* MetadataBufferType */
673 Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
675 if (type == kMetadataBufferTypeCameraSource) {
676 void *pAddress = NULL;
679 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
680 ppBuf[0] = (void *)pAddress;
682 /* Address. of CbCr */
683 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
684 ppBuf[1] = (void *)pAddress;
686 } else if (type == kMetadataBufferTypeGrallocSource) {
687 buffer_handle_t pBufHandle;
689 /* buffer_handle_t */
690 Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
691 ppBuf[0] = (OMX_PTR)pBufHandle;
700 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
701 unsigned int hal_format)
703 OMX_COLOR_FORMATTYPE omx_format;
704 switch (hal_format) {
705 case HAL_PIXEL_FORMAT_YCbCr_422_I:
706 omx_format = OMX_COLOR_FormatYCbYCr;
708 case HAL_PIXEL_FORMAT_YCbCr_420_P:
709 omx_format = OMX_COLOR_FormatYUV420Planar;
711 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
712 omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
714 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
715 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
717 case HAL_PIXEL_FORMAT_ARGB888:
718 omx_format = OMX_COLOR_Format32bitARGB8888;
721 omx_format = OMX_COLOR_FormatYUV420Planar;
727 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
728 OMX_COLOR_FORMATTYPE omx_format)
730 unsigned int hal_format;
731 switch (omx_format) {
732 case OMX_COLOR_FormatYCbYCr:
733 hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
735 case OMX_COLOR_FormatYUV420Planar:
736 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
738 case OMX_COLOR_FormatYUV420SemiPlanar:
739 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
741 case OMX_SEC_COLOR_FormatNV12Tiled:
742 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
744 case OMX_COLOR_Format32bitARGB8888:
745 hal_format = HAL_PIXEL_FORMAT_ARGB888;
748 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;