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]);
269 pSlpOutBuf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO; /* use bo mode */
270 pSlpOutBuf->handle_num = 2;
271 pSlpOutBuf->plane_num = 2;
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]);
275 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
277 ret = Exynos_OSAL_UnlockPBHandle((OMX_U32)pANB->handle);
286 OMX_ERRORTYPE useAndroidNativeBuffer(
287 EXYNOS_OMX_BASEPORT *pExynosPort,
288 OMX_BUFFERHEADERTYPE **ppBufferHdr,
294 OMX_ERRORTYPE ret = OMX_ErrorNone;
295 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
297 OMX_U32 width, height;
299 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
303 if (pExynosPort == NULL) {
304 ret = OMX_ErrorBadParameter;
307 if (pExynosPort->portState != OMX_StateIdle) {
308 ret = OMX_ErrorIncorrectStateOperation;
311 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
312 ret = OMX_ErrorBadPortIndex;
316 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
317 if (temp_bufferHeader == NULL) {
318 ret = OMX_ErrorInsufficientResources;
321 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
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;
334 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
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,
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;
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]);
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); */
361 *ppBufferHdr = temp_bufferHeader;
368 Exynos_OSAL_Free(temp_bufferHeader);
369 ret = OMX_ErrorInsufficientResources;
378 OMX_ERRORTYPE Exynos_OSAL_GetPBParameter(
379 OMX_IN OMX_HANDLETYPE hComponent,
380 OMX_IN OMX_INDEXTYPE nIndex,
381 OMX_INOUT OMX_PTR ComponentParameterStructure)
383 OMX_ERRORTYPE ret = OMX_ErrorNone;
384 OMX_COMPONENTTYPE *pOMXComponent = NULL;
385 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
389 if (hComponent == NULL) {
390 ret = OMX_ErrorBadParameter;
394 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
395 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
396 if (ret != OMX_ErrorNone) {
400 if (pOMXComponent->pComponentPrivate == NULL) {
401 ret = OMX_ErrorBadParameter;
405 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
406 if (pExynosComponent->currentState == OMX_StateInvalid ) {
407 ret = OMX_ErrorInvalidState;
411 if (ComponentParameterStructure == NULL) {
412 ret = OMX_ErrorBadParameter;
417 #if 0 /* TIZEN_FEATURE_E3250 */
418 case OMX_IndexParamGetAndroidNativeBuffer:
420 GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
421 OMX_U32 portIndex = pANBParams->nPortIndex;
423 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
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__);
431 if (portIndex >= pExynosComponent->portParam.nPorts) {
432 ret = OMX_ErrorBadPortIndex;
436 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
437 * modifications since currently not defined what the 'nUsage' is for.
439 pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
440 | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
446 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
447 ret = OMX_ErrorUnsupportedIndex;
459 OMX_ERRORTYPE Exynos_OSAL_SetPBParameter(
460 OMX_IN OMX_HANDLETYPE hComponent,
461 OMX_IN OMX_INDEXTYPE nIndex,
462 OMX_IN OMX_PTR ComponentParameterStructure)
464 OMX_ERRORTYPE ret = OMX_ErrorNone;
465 OMX_COMPONENTTYPE *pOMXComponent = NULL;
466 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
470 if (hComponent == NULL) {
471 ret = OMX_ErrorBadParameter;
475 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
476 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
477 if (ret != OMX_ErrorNone) {
481 if (pOMXComponent->pComponentPrivate == NULL) {
482 ret = OMX_ErrorBadParameter;
486 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
487 if (pExynosComponent->currentState == OMX_StateInvalid ) {
488 ret = OMX_ErrorInvalidState;
492 if (ComponentParameterStructure == NULL) {
493 ret = OMX_ErrorBadParameter;
497 switch ((int)nIndex) {
498 #ifdef TIZEN_FEATURE_E3250
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;
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");
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 /* TIZEN_FEATURE_E3250 */
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;