2 * Copyright 2016 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_Tizen.c
20 * @author Taehwan Kim (t_h.kim@samsung.com)
29 #include "Exynos_OSAL_Semaphore.h"
30 #include "Exynos_OMX_Baseport.h"
31 #include "Exynos_OMX_Basecomponent.h"
32 #include "Exynos_OMX_Macros.h"
33 #include "Exynos_OSAL_Platform.h"
34 #include "Exynos_OSAL_ETC.h"
35 #include "exynos_format.h"
37 #include "ExynosVideoApi.h"
39 #ifdef TIZEN_FEATURE_TIZEN_ALLOCATOR
40 #include <tbm_bufmgr.h>
41 #include <tbm_surface.h>
42 #include <tbm_surface_internal.h>
44 #include <mmf/mm_types.h>
48 #define EXYNOS_LOG_TAG "Exynos_OSAL_Tizen"
49 //#define EXYNOS_LOG_OFF
50 #include "Exynos_OSAL_Log.h"
56 typedef struct __EnableGemBuffersParams
59 OMX_VERSIONTYPE nVersion;
61 OMX_BOOL bStoreMetaData;
62 } EnableGemBuffersParams;
64 static OMX_ERRORTYPE setBufferProcessTypeForDecoder(EXYNOS_OMX_BASEPORT *pExynosPort)
66 OMX_ERRORTYPE ret = OMX_ErrorNone;
70 if (pExynosPort == NULL) {
71 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] invalid parameter", __FUNCTION__);
72 ret = OMX_ErrorUndefined;
76 if ((pExynosPort->bufferProcessType == BUFFER_COPY) &&
77 (pExynosPort->eMetaDataType != METADATA_TYPE_DISABLED)) {
79 if (pExynosPort->supportFormat == NULL) {
80 ret = OMX_ErrorUndefined;
81 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] supported format is empty", __FUNCTION__);
85 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
86 /* check to support NV12T format */
87 for (i = 0; pExynosPort->supportFormat[i] != OMX_COLOR_FormatUnused; i++) {
88 /* prefer to use NV12T */
89 if (pExynosPort->supportFormat[i] == (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled) {
90 pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
94 pExynosPort->bufferProcessType = BUFFER_SHARE;
96 Exynos_OSAL_Log(EXYNOS_LOG_ESSENTIAL, "[%s] output buffer sharing mode is on (%x)",
97 __FUNCTION__, pExynosPort->portDefinition.format.video.eColorFormat);
106 static void resetBufferProcessTypeForDecoder(EXYNOS_OMX_BASEPORT *pExynosPort)
110 if (pExynosPort == NULL) {
111 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] invalid parameter", __FUNCTION__);
115 pExynosPort->bufferProcessType = BUFFER_COPY;
116 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
124 OMX_ERRORTYPE Exynos_OSAL_GetParameter(
125 OMX_IN OMX_HANDLETYPE hComponent,
126 OMX_IN OMX_INDEXTYPE nIndex,
127 OMX_INOUT OMX_PTR pComponentParameterStructure)
129 OMX_ERRORTYPE ret = OMX_ErrorNone;
130 OMX_COMPONENTTYPE *pOMXComponent = NULL;
131 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
135 if (hComponent == NULL) {
136 ret = OMX_ErrorBadParameter;
140 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
141 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
142 if (ret != OMX_ErrorNone)
145 if (pOMXComponent->pComponentPrivate == NULL) {
146 ret = OMX_ErrorBadParameter;
150 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
151 if (pExynosComponent->currentState == OMX_StateInvalid) {
152 ret = OMX_ErrorInvalidState;
156 if (pComponentParameterStructure == NULL) {
157 ret = OMX_ErrorBadParameter;
161 switch ((int)nIndex) {
162 case OMX_IndexParamPortDefinition:
164 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParameterStructure;
165 EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[pPortDef->nPortIndex];
167 if (pExynosPort->eMetaDataType == METADATA_TYPE_DATA)
168 #ifdef TIZEN_FEATURE_TIZEN_ALLOCATOR
169 pPortDef->nBufferSize = (ALIGN(pExynosPort->portDefinition.format.video.nFrameWidth, 16) *
170 ALIGN(pExynosPort->portDefinition.format.video.nFrameHeight, 16) * 3) / 2;
172 pPortDef->nBufferSize = sizeof(MMVideoBuffer);
178 ret = OMX_ErrorUnsupportedIndex;
190 OMX_ERRORTYPE Exynos_OSAL_SetParameter(
191 OMX_IN OMX_HANDLETYPE hComponent,
192 OMX_IN OMX_INDEXTYPE nIndex,
193 OMX_IN OMX_PTR pComponentParameterStructure)
195 OMX_ERRORTYPE ret = OMX_ErrorNone;
196 OMX_COMPONENTTYPE *pOMXComponent = NULL;
197 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
201 if (hComponent == NULL) {
202 ret = OMX_ErrorBadParameter;
206 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
207 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
208 if (ret != OMX_ErrorNone)
211 if (pOMXComponent->pComponentPrivate == NULL) {
212 ret = OMX_ErrorBadParameter;
216 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
217 if (pExynosComponent->currentState == OMX_StateInvalid) {
218 ret = OMX_ErrorInvalidState;
222 if (pComponentParameterStructure == NULL) {
223 ret = OMX_ErrorBadParameter;
227 Exynos_OSAL_Log(EXYNOS_LOG_ESSENTIAL, "[%p][%s] index = 0x%x", pExynosComponent, __FUNCTION__, nIndex);
228 switch ((int)nIndex) {
229 case OMX_IndexParamStoreMetaDataBuffer:
231 EnableGemBuffersParams *pGBParams = (EnableGemBuffersParams *)pComponentParameterStructure;
232 OMX_U32 nPortIndex = pGBParams->nPortIndex;
233 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
235 ret = Exynos_OMX_Check_SizeVersion(pGBParams, sizeof(EnableGemBuffersParams));
236 if (ret != OMX_ErrorNone) {
237 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%p][%s] Failed to Check_SizeVersion", pExynosComponent, __FUNCTION__);
241 if (nPortIndex >= pExynosComponent->portParam.nPorts) {
242 ret = OMX_ErrorBadPortIndex;
246 if ((pExynosComponent->codecType == HW_VIDEO_DEC_SECURE_CODEC) ||
247 (pExynosComponent->codecType == HW_VIDEO_DEC_CODEC)) {
249 if (nPortIndex != OUTPUT_PORT_INDEX) {
250 ret = OMX_ErrorNotImplemented;
255 if (nPortIndex != INPUT_PORT_INDEX) {
256 ret = OMX_ErrorNotImplemented;
261 pExynosPort = &pExynosComponent->pExynosPort[nPortIndex];
262 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
263 ret = OMX_ErrorBadPortIndex;
267 Exynos_OSAL_Log(EXYNOS_LOG_ESSENTIAL, "[%p][%s][META] %s port: metadata mode(%x) -> %s",
268 pExynosComponent, __FUNCTION__,
269 (nPortIndex == INPUT_PORT_INDEX)? "input":"output",
270 pExynosPort->eMetaDataType,
271 (pGBParams->bStoreMetaData == OMX_TRUE)? "enable":"disable");
273 if ((pGBParams->bStoreMetaData == OMX_TRUE) &&
274 (pExynosPort->eMetaDataType == METADATA_TYPE_DISABLED)) {
275 pExynosPort->eMetaDataType = METADATA_TYPE_DATA;
278 /* in case of decoder output */
279 if ((nPortIndex == OUTPUT_PORT_INDEX) &&
280 ((pExynosComponent->codecType == HW_VIDEO_DEC_CODEC) ||
281 (pExynosComponent->codecType == HW_VIDEO_DEC_SECURE_CODEC))) {
282 if (pGBParams->bStoreMetaData == OMX_TRUE) {
283 ret = setBufferProcessTypeForDecoder(pExynosPort);
284 if (ret != OMX_ErrorNone)
286 } else if ((pGBParams->bStoreMetaData == OMX_FALSE) &&
287 (pExynosPort->eMetaDataType != METADATA_TYPE_DISABLED)) {
288 resetBufferProcessTypeForDecoder(pExynosPort);
292 if ((pGBParams->bStoreMetaData == OMX_FALSE) &&
293 (pExynosPort->eMetaDataType != METADATA_TYPE_DISABLED)) {
294 pExynosPort->eMetaDataType = METADATA_TYPE_DISABLED;
300 ret = OMX_ErrorUnsupportedIndex;
313 * meta data contains the following data format.
314 * 1) METADATA_TYPE_DATA
315 * --------------------------------------------------------------------
316 * | MMVideoBuffer | [DEC] out, [ENC] in
317 * --------------------------------------------------------------------
319 OMX_ERRORTYPE Exynos_OSAL_LockMetaData(
320 OMX_IN OMX_PTR pBuffer,
321 OMX_IN EXYNOS_OMX_LOCK_RANGE range,
322 OMX_OUT OMX_U32 *pStride,
323 OMX_OUT EXYNOS_OMX_MULTIPLANE_BUFFER *pBufferInfo,
324 OMX_IN EXYNOS_METADATA_TYPE eMetaType)
326 OMX_ERRORTYPE ret = OMX_ErrorNone;
330 if (pBuffer == NULL) {
331 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] invalid parameter", __FUNCTION__);
332 ret = OMX_ErrorBadParameter;
344 OMX_ERRORTYPE Exynos_OSAL_UnlockMetaData(
345 OMX_IN OMX_PTR pBuffer,
346 OMX_IN EXYNOS_METADATA_TYPE eMetaType)
348 OMX_ERRORTYPE ret = OMX_ErrorNone;
352 if (pBuffer == NULL) {
353 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] invalid parameter", __FUNCTION__);
354 ret = OMX_ErrorBadParameter;
366 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(
367 OMX_IN OMX_PTR pBuffer,
368 OMX_OUT EXYNOS_OMX_MULTIPLANE_BUFFER *pBufferInfo,
369 OMX_IN EXYNOS_METADATA_TYPE eMetaDataType)
371 OMX_ERRORTYPE ret = OMX_ErrorNone;
372 #ifdef TIZEN_FEATURE_TIZEN_ALLOCATOR
373 tbm_surface_h surface;
376 MMVideoBuffer *pMetaBuffer = NULL;
383 if ((pBuffer == NULL) ||
384 (pBufferInfo == NULL) ||
385 (eMetaDataType == METADATA_TYPE_DISABLED)) {
386 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] invalid parameter", __FUNCTION__);
387 ret = OMX_ErrorBadParameter;
391 if (eMetaDataType == METADATA_TYPE_DATA) {
392 #ifdef TIZEN_FEATURE_TIZEN_ALLOCATOR
393 surface = (tbm_surface_h)pBuffer;
395 bo[0] = tbm_surface_internal_get_bo(surface, 0);
396 bo[1] = tbm_surface_internal_get_bo(surface, 1);
398 for (i = 0; i < 2; i++) {
399 pBufferInfo->fd[i] = (unsigned long)(tbm_bo_get_handle (bo[i], TBM_DEVICE_MM).u32);
400 pBufferInfo->addr[i] = (OMX_PTR)(tbm_bo_get_handle (bo[i], TBM_DEVICE_CPU).ptr);
402 pMetaBuffer = (MMVideoBuffer *)pBuffer;
404 for (i = 0; i < pMetaBuffer->plane_num; i++) {
405 pBufferInfo->fd[i] = (unsigned long)(pMetaBuffer->handle.dmabuf_fd[i]);
406 pBufferInfo->addr[i] = (OMX_PTR)(pMetaBuffer->data[i]);
409 Exynos_OSAL_Log(EXYNOS_LOG_ESSENTIAL, "[%s] Plane[%d]: FD(%u), VA(%p)",
410 __FUNCTION__, i, pBufferInfo->fd[i], pBufferInfo->addr[i]);
413 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] not implemented yet(meta type:0x%x)", __FUNCTION__, eMetaDataType);
414 ret = OMX_ErrorNotImplemented;
424 // Porting exynos 9110, code from SM-R765(7270), But not used
425 OMX_ERRORTYPE Exynos_OSAL_SetDataLengthToMetaData(
426 OMX_IN OMX_BYTE pBuffer,
427 OMX_IN OMX_U32 dataLength,
428 OMX_IN EXYNOS_METADATA_TYPE eMetaDataType)
430 OMX_ERRORTYPE ret = OMX_ErrorNone;
434 if (pBuffer == NULL) {
435 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] invalid parameter", __FUNCTION__);
436 ret = OMX_ErrorBadParameter;
441 /* This is for that MetaData is configured by component */
449 OMX_PTR Exynos_OSAL_AllocMetaDataBuffer(
450 OMX_HANDLETYPE hSharedMemory,
451 EXYNOS_METADATA_TYPE eMetaDataType,
453 MEMORY_TYPE eMemoryType)
455 OMX_PTR pBuffer = NULL;
459 if (eMetaDataType == METADATA_TYPE_DATA) {
460 #ifdef TIZEN_FEATURE_TIZEN_ALLOCATOR
461 pBuffer = Exynos_OSAL_Malloc(sizeof(tbm_surface_h));
463 pBuffer = Exynos_OSAL_Malloc(sizeof(MMVideoBuffer));
465 if (pBuffer == NULL) {
466 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] Failed to allocate metadata buffer", __FUNCTION__);
470 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] not implemented yet(meta type:0x%x)", __FUNCTION__, eMetaDataType);
479 OMX_ERRORTYPE Exynos_OSAL_FreeMetaDataBuffer(
480 OMX_HANDLETYPE hSharedMemory,
481 EXYNOS_METADATA_TYPE eMetaDataType,
484 OMX_ERRORTYPE ret = OMX_ErrorNone;
488 if (eMetaDataType == METADATA_TYPE_DATA) {
489 Exynos_OSAL_Free(pTempBuffer);
492 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "[%s] not implemented yet(meta type:0x%x)", __FUNCTION__, eMetaDataType);
493 ret = OMX_ErrorNotImplemented;