c87068b9bf9b481a90c665c48cfd840aa1cb4701
[GitHub/LineageOS/android_hardware_samsung_slsi_openmax.git] / osal / Exynos_OSAL_Android.cpp
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_Android.cpp
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
32 #include <system/window.h>
33 #include <ui/GraphicBuffer.h>
34 #include <ui/GraphicBufferMapper.h>
35 #include <ui/Rect.h>
36 #include <media/hardware/HardwareAPI.h>
37 #include <hardware/hardware.h>
38 #include <media/hardware/OMXPluginBase.h>
39 #include <media/hardware/MetadataBufferType.h>
40 #ifdef USE_DMA_BUF
41 #include <gralloc_priv.h>
42 #endif
43
44 #include "exynos_format.h"
45 #include "Exynos_OSAL_Semaphore.h"
46 #include "Exynos_OMX_Baseport.h"
47 #include "Exynos_OMX_Basecomponent.h"
48 #include "Exynos_OMX_Macros.h"
49 #include "Exynos_OSAL_Android.h"
50
51 #include "ExynosVideoApi.h"
52
53 #undef EXYNOS_LOG_TAG
54 #define EXYNOS_LOG_TAG "Exynos_OSAL_Android"
55 #define EXYNOS_LOG_OFF
56 #include "Exynos_OSAL_Log.h"
57
58 using namespace android;
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 static int lockCnt = 0;
65
66 OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(
67 OMX_IN OMX_U32 handle,
68 OMX_IN OMX_U32 width,
69 OMX_IN OMX_U32 height,
70 OMX_IN OMX_COLOR_FORMATTYPE format,
71 OMX_OUT OMX_PTR planes)
72 {
73 FunctionIn();
74
75 OMX_ERRORTYPE ret = OMX_ErrorNone;
76 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
77 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
78 #ifdef USE_DMA_BUF
79 private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
80 #endif
81 Rect bounds(width, height);
82 ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
83 void *vaddr[MAX_BUFFER_PLANE];
84
85 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
86
87 int usage = 0;
88
89 switch (format) {
90 case OMX_COLOR_FormatYUV420Planar:
91 case OMX_COLOR_FormatYUV420SemiPlanar:
92 case OMX_SEC_COLOR_FormatNV12Tiled:
93 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
94 break;
95 case OMX_COLOR_FormatAndroidOpaque:
96 {
97 OMX_COLOR_FORMATTYPE formatType;
98 formatType = Exynos_OSAL_GetANBColorFormat((OMX_U32)priv_hnd);
99 if ((formatType == OMX_COLOR_FormatYUV420SemiPlanar) ||
100 (formatType == OMX_SEC_COLOR_FormatNV12Tiled))
101 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
102 else
103 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_VIDEO_ENCODER;
104 }
105 break;
106 default:
107 usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
108 break;
109 }
110
111 if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) {
112 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__);
113 ret = OMX_ErrorUndefined;
114 goto EXIT;
115 }
116 lockCnt++;
117 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: lockCnt:%d", __func__, lockCnt);
118
119 #ifdef USE_DMA_BUF
120 vplanes[0].fd = priv_hnd->fd;
121 vplanes[0].offset = 0;
122 vplanes[1].fd = priv_hnd->fd1;
123 vplanes[1].offset = 0;
124 vplanes[2].fd = priv_hnd->fd2;
125 vplanes[2].offset = 0;
126 #endif
127 vplanes[0].addr = vaddr[0];
128 vplanes[1].addr = vaddr[1];
129 vplanes[2].addr = vaddr[2];
130
131 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
132
133 EXIT:
134 FunctionOut();
135
136 return ret;
137 }
138
139 OMX_ERRORTYPE Exynos_OSAL_UnlockANBHandle(OMX_IN OMX_U32 handle)
140 {
141 FunctionIn();
142
143 OMX_ERRORTYPE ret = OMX_ErrorNone;
144 GraphicBufferMapper &mapper = GraphicBufferMapper::get();
145 buffer_handle_t bufferHandle = (buffer_handle_t) handle;
146
147 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle);
148
149 if (mapper.unlock(bufferHandle) != 0) {
150 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.unlock() fail", __func__);
151 ret = OMX_ErrorUndefined;
152 goto EXIT;
153 }
154 lockCnt--;
155 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: lockCnt:%d", __func__, lockCnt);
156
157 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer unlocked: 0x%x", __func__, handle);
158
159 EXIT:
160 FunctionOut();
161
162 return ret;
163 }
164
165 OMX_COLOR_FORMATTYPE Exynos_OSAL_GetANBColorFormat(OMX_IN OMX_U32 handle)
166 {
167 FunctionIn();
168
169 OMX_COLOR_FORMATTYPE ret = OMX_COLOR_FormatUnused;
170 private_handle_t *priv_hnd = (private_handle_t *) handle;
171
172 ret = Exynos_OSAL_Hal2OMXPixelFormat(priv_hnd->format);
173 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "ColorFormat: 0x%x", ret);
174
175 EXIT:
176 FunctionOut();
177
178 return ret;
179 }
180
181 OMX_ERRORTYPE Exynos_OSAL_LockANB(
182 OMX_IN OMX_PTR pBuffer,
183 OMX_IN OMX_U32 width,
184 OMX_IN OMX_U32 height,
185 OMX_IN OMX_COLOR_FORMATTYPE format,
186 OMX_OUT OMX_U32 *pStride,
187 OMX_OUT OMX_PTR planes)
188 {
189 FunctionIn();
190
191 OMX_ERRORTYPE ret = OMX_ErrorNone;
192 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
193
194 ret = Exynos_OSAL_LockANBHandle((OMX_U32)pANB->handle, width, height, format, planes);
195 *pStride = pANB->stride;
196
197 EXIT:
198 FunctionOut();
199
200 return ret;
201 }
202
203 OMX_ERRORTYPE Exynos_OSAL_UnlockANB(OMX_IN OMX_PTR pBuffer)
204 {
205 FunctionIn();
206
207 OMX_ERRORTYPE ret = OMX_ErrorNone;
208 android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
209
210 ret = Exynos_OSAL_UnlockANBHandle((OMX_U32)pANB->handle);
211
212 EXIT:
213 FunctionOut();
214
215 return ret;
216 }
217
218 OMX_ERRORTYPE useAndroidNativeBuffer(
219 EXYNOS_OMX_BASEPORT *pExynosPort,
220 OMX_BUFFERHEADERTYPE **ppBufferHdr,
221 OMX_U32 nPortIndex,
222 OMX_PTR pAppPrivate,
223 OMX_U32 nSizeBytes,
224 OMX_U8 *pBuffer)
225 {
226 OMX_ERRORTYPE ret = OMX_ErrorNone;
227 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL;
228 unsigned int i = 0;
229 OMX_U32 width, height;
230 OMX_U32 stride;
231 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
232
233 FunctionIn();
234
235 if (pExynosPort == NULL) {
236 ret = OMX_ErrorBadParameter;
237 goto EXIT;
238 }
239 if (pExynosPort->portState != OMX_StateIdle) {
240 ret = OMX_ErrorIncorrectStateOperation;
241 goto EXIT;
242 }
243 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
244 ret = OMX_ErrorBadPortIndex;
245 goto EXIT;
246 }
247
248 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
249 if (temp_bufferHeader == NULL) {
250 ret = OMX_ErrorInsufficientResources;
251 goto EXIT;
252 }
253 Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
254
255 for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) {
256 if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
257 pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
258 pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
259 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
260 temp_bufferHeader->pBuffer = pBuffer;
261 temp_bufferHeader->nAllocLen = nSizeBytes;
262 temp_bufferHeader->pAppPrivate = pAppPrivate;
263 if (nPortIndex == INPUT_PORT_INDEX)
264 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
265 else
266 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
267
268 width = pExynosPort->portDefinition.format.video.nFrameWidth;
269 height = pExynosPort->portDefinition.format.video.nFrameHeight;
270 Exynos_OSAL_LockANB(temp_bufferHeader->pBuffer, width, height,
271 pExynosPort->portDefinition.format.video.eColorFormat,
272 &stride, planes);
273 #ifdef USE_DMA_BUF
274 pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
275 pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd;
276 pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
277 #endif
278 pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr;
279 pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
280 pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
281 Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
282 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ",
283 i, pExynosPort->extendBufferHeader[i].pYUVBuf[0],
284 pExynosPort->extendBufferHeader[i].pYUVBuf[1]);
285
286 pExynosPort->assignedBufferNum++;
287 if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) {
288 pExynosPort->portDefinition.bPopulated = OMX_TRUE;
289 /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */
290 Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource);
291 /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */
292 }
293 *ppBufferHdr = temp_bufferHeader;
294 ret = OMX_ErrorNone;
295
296 goto EXIT;
297 }
298 }
299
300 Exynos_OSAL_Free(temp_bufferHeader);
301 ret = OMX_ErrorInsufficientResources;
302
303 EXIT:
304 FunctionOut();
305
306 return ret;
307 }
308
309 OMX_ERRORTYPE Exynos_OSAL_GetANBParameter(
310 OMX_IN OMX_HANDLETYPE hComponent,
311 OMX_IN OMX_INDEXTYPE nIndex,
312 OMX_INOUT OMX_PTR ComponentParameterStructure)
313 {
314 OMX_ERRORTYPE ret = OMX_ErrorNone;
315 OMX_COMPONENTTYPE *pOMXComponent = NULL;
316 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
317
318 FunctionIn();
319
320 if (hComponent == NULL) {
321 ret = OMX_ErrorBadParameter;
322 goto EXIT;
323 }
324
325 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
326 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
327 if (ret != OMX_ErrorNone) {
328 goto EXIT;
329 }
330
331 if (pOMXComponent->pComponentPrivate == NULL) {
332 ret = OMX_ErrorBadParameter;
333 goto EXIT;
334 }
335
336 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
337 if (pExynosComponent->currentState == OMX_StateInvalid ) {
338 ret = OMX_ErrorInvalidState;
339 goto EXIT;
340 }
341
342 if (ComponentParameterStructure == NULL) {
343 ret = OMX_ErrorBadParameter;
344 goto EXIT;
345 }
346
347 switch (nIndex) {
348 case OMX_IndexParamGetAndroidNativeBuffer:
349 {
350 GetAndroidNativeBufferUsageParams *pANBParams = (GetAndroidNativeBufferUsageParams *) ComponentParameterStructure;
351 OMX_U32 portIndex = pANBParams->nPortIndex;
352
353 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamGetAndroidNativeBuffer", __func__);
354
355 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(GetAndroidNativeBufferUsageParams));
356 if (ret != OMX_ErrorNone) {
357 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(GetAndroidNativeBufferUsageParams) is failed", __func__);
358 goto EXIT;
359 }
360
361 if (portIndex >= pExynosComponent->portParam.nPorts) {
362 ret = OMX_ErrorBadPortIndex;
363 goto EXIT;
364 }
365
366 /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
367 * modifications since currently not defined what the 'nUsage' is for.
368 */
369 pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP);
370 #if defined(USE_IMPROVED_BUFFER) && !defined(USE_CSC_HW)
371 pANBParams->nUsage |= (GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
372 #endif
373 #if defined(USE_MFC5X_ALIGNMENT)
374 if ((pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].bufferProcessType & BUFFER_SHARE) &&
375 (pExynosComponent->pExynosPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)) {
376 pANBParams->nUsage |= GRALLOC_USAGE_PRIVATE_0;
377 }
378 #endif
379 }
380 break;
381
382 default:
383 {
384 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
385 ret = OMX_ErrorUnsupportedIndex;
386 goto EXIT;
387 }
388 break;
389 }
390
391 EXIT:
392 FunctionOut();
393
394 return ret;
395 }
396
397 OMX_ERRORTYPE Exynos_OSAL_SetANBParameter(
398 OMX_IN OMX_HANDLETYPE hComponent,
399 OMX_IN OMX_INDEXTYPE nIndex,
400 OMX_IN OMX_PTR ComponentParameterStructure)
401 {
402 OMX_ERRORTYPE ret = OMX_ErrorNone;
403 OMX_COMPONENTTYPE *pOMXComponent = NULL;
404 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
405
406 FunctionIn();
407
408 if (hComponent == NULL) {
409 ret = OMX_ErrorBadParameter;
410 goto EXIT;
411 }
412
413 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
414 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
415 if (ret != OMX_ErrorNone) {
416 goto EXIT;
417 }
418
419 if (pOMXComponent->pComponentPrivate == NULL) {
420 ret = OMX_ErrorBadParameter;
421 goto EXIT;
422 }
423
424 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
425 if (pExynosComponent->currentState == OMX_StateInvalid ) {
426 ret = OMX_ErrorInvalidState;
427 goto EXIT;
428 }
429
430 if (ComponentParameterStructure == NULL) {
431 ret = OMX_ErrorBadParameter;
432 goto EXIT;
433 }
434
435 switch (nIndex) {
436 case OMX_IndexParamEnableAndroidBuffers:
437 {
438 EnableAndroidNativeBuffersParams *pANBParams = (EnableAndroidNativeBuffersParams *) ComponentParameterStructure;
439 OMX_U32 portIndex = pANBParams->nPortIndex;
440 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
441
442 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamEnableAndroidNativeBuffers", __func__);
443
444 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(EnableAndroidNativeBuffersParams));
445 if (ret != OMX_ErrorNone) {
446 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(EnableAndroidNativeBuffersParams) is failed", __func__);
447 goto EXIT;
448 }
449
450 if (portIndex >= pExynosComponent->portParam.nPorts) {
451 ret = OMX_ErrorBadPortIndex;
452 goto EXIT;
453 }
454
455 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
456 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
457 ret = OMX_ErrorBadPortIndex;
458 goto EXIT;
459 }
460
461 pExynosPort->bIsANBEnabled = pANBParams->enable;
462
463 #ifdef USE_ANB_OUTBUF_SHARE
464 /* ANB and DPB Buffer Sharing */
465 if ((portIndex == OUTPUT_PORT_INDEX) &&
466 (pExynosPort->bIsANBEnabled == OMX_TRUE)) {
467 if ((pExynosPort->bufferProcessType & BUFFER_ANBSHARE) == BUFFER_ANBSHARE) {
468 pExynosPort->bufferProcessType = BUFFER_SHARE;
469 pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
470 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "output buffer sharing mode is on");
471 } else {
472 pExynosPort->bufferProcessType = BUFFER_COPY;
473 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
474 }
475 }
476 #else
477 if ((portIndex == OUTPUT_PORT_INDEX) &&
478 (pExynosPort->bufferProcessType & BUFFER_COPY)) {
479 pExynosPort->bufferProcessType = BUFFER_COPY;
480 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
481 }
482 #endif
483 }
484 break;
485
486 case OMX_IndexParamUseAndroidNativeBuffer:
487 {
488 UseAndroidNativeBufferParams *pANBParams = (UseAndroidNativeBufferParams *) ComponentParameterStructure;
489 OMX_U32 portIndex = pANBParams->nPortIndex;
490 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
491 android_native_buffer_t *pANB;
492 OMX_U32 nSizeBytes;
493
494 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamUseAndroidNativeBuffer, portIndex: %d", __func__, portIndex);
495
496 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(UseAndroidNativeBufferParams));
497 if (ret != OMX_ErrorNone) {
498 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(UseAndroidNativeBufferParams) is failed", __func__);
499 goto EXIT;
500 }
501
502 if (portIndex >= pExynosComponent->portParam.nPorts) {
503 ret = OMX_ErrorBadPortIndex;
504 goto EXIT;
505 }
506
507 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
508 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
509 ret = OMX_ErrorBadPortIndex;
510 goto EXIT;
511 }
512
513 if (pExynosPort->portState != OMX_StateIdle) {
514 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Port state should be IDLE", __func__);
515 ret = OMX_ErrorIncorrectStateOperation;
516 goto EXIT;
517 }
518
519 pANB = pANBParams->nativeBuffer.get();
520
521 /* MALI alignment restriction */
522 nSizeBytes = ALIGN(pANB->width, 16) * ALIGN(pANB->height, 16);
523 nSizeBytes += ALIGN(pANB->width / 2, 16) * ALIGN(pANB->height / 2, 16) * 2;
524
525 ret = useAndroidNativeBuffer(pExynosPort,
526 pANBParams->bufferHeader,
527 pANBParams->nPortIndex,
528 pANBParams->pAppPrivate,
529 nSizeBytes,
530 (OMX_U8 *) pANB);
531 if (ret != OMX_ErrorNone) {
532 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: useAndroidNativeBuffer is failed: err=0x%x", __func__,ret);
533 goto EXIT;
534 }
535 }
536 break;
537
538 case OMX_IndexParamStoreMetaDataBuffer:
539 {
540 StoreMetaDataInBuffersParams *pANBParams = (StoreMetaDataInBuffersParams *) ComponentParameterStructure;
541 OMX_U32 portIndex = pANBParams->nPortIndex;
542 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
543
544 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: OMX_IndexParamStoreMetaDataBuffer", __func__);
545
546 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(StoreMetaDataInBuffersParams));
547 if (ret != OMX_ErrorNone) {
548 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(StoreMetaDataInBuffersParams) is failed", __func__);
549 goto EXIT;
550 }
551
552 if (portIndex >= pExynosComponent->portParam.nPorts) {
553 ret = OMX_ErrorBadPortIndex;
554 goto EXIT;
555 }
556
557 pExynosPort = &pExynosComponent->pExynosPort[portIndex];
558 if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) {
559 ret = OMX_ErrorBadPortIndex;
560 goto EXIT;
561 }
562
563 pExynosPort->bStoreMetaData = pANBParams->bStoreMetaData;
564 }
565 break;
566
567 default:
568 {
569 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Unsupported index (%d)", __func__, nIndex);
570 ret = OMX_ErrorUnsupportedIndex;
571 goto EXIT;
572 }
573 break;
574 }
575
576 EXIT:
577 FunctionOut();
578
579 return ret;
580 }
581
582 OMX_ERRORTYPE Exynos_OSAL_GetInfoFromMetaData(OMX_IN OMX_BYTE pBuffer,
583 OMX_OUT OMX_PTR *ppBuf)
584 {
585 OMX_ERRORTYPE ret = OMX_ErrorNone;
586 MetadataBufferType type;
587
588 FunctionIn();
589
590 /*
591 * meta data contains the following data format.
592 * payload depends on the MetadataBufferType
593 * --------------------------------------------------------------
594 * | MetadataBufferType | payload |
595 * --------------------------------------------------------------
596 *
597 * If MetadataBufferType is kMetadataBufferTypeCameraSource, then
598 * --------------------------------------------------------------
599 * | kMetadataBufferTypeCameraSource | physical addr. of Y |physical addr. of CbCr |
600 * --------------------------------------------------------------
601 *
602 * If MetadataBufferType is kMetadataBufferTypeGrallocSource, then
603 * --------------------------------------------------------------
604 * | kMetadataBufferTypeGrallocSource | buffer_handle_t |
605 * --------------------------------------------------------------
606 */
607
608 /* MetadataBufferType */
609 Exynos_OSAL_Memcpy(&type, (MetadataBufferType *)pBuffer, sizeof(MetadataBufferType));
610
611 switch (type) {
612 case kMetadataBufferTypeCameraSource:
613 {
614 void *pAddress = NULL;
615
616 /* Address. of Y */
617 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType), sizeof(void *));
618 ppBuf[0] = (void *)pAddress;
619
620 /* Address. of CbCr */
621 Exynos_OSAL_Memcpy(&pAddress, pBuffer + sizeof(MetadataBufferType) + sizeof(void *), sizeof(void *));
622 ppBuf[1] = (void *)pAddress;
623
624 if ((ppBuf[0] == NULL) || (ppBuf[1] == NULL))
625 ret = OMX_ErrorBadParameter;
626 }
627 break;
628 case kMetadataBufferTypeGrallocSource:
629 {
630 buffer_handle_t pBufHandle;
631
632 /* buffer_handle_t */
633 Exynos_OSAL_Memcpy(&pBufHandle, pBuffer + sizeof(MetadataBufferType), sizeof(buffer_handle_t));
634 ppBuf[0] = (OMX_PTR)pBufHandle;
635
636 if (ppBuf[0] == NULL)
637 ret = OMX_ErrorBadParameter;
638 }
639 break;
640 default:
641 {
642 ret = OMX_ErrorBadParameter;
643 }
644 break;
645 }
646
647 EXIT:
648 FunctionOut();
649
650 return ret;
651 }
652
653 OMX_ERRORTYPE Exynos_OSAL_SetPrependSPSPPSToIDR(
654 OMX_PTR pComponentParameterStructure,
655 OMX_PTR pbPrependSpsPpsToIdr)
656 {
657 OMX_ERRORTYPE ret = OMX_ErrorNone;
658 PrependSPSPPSToIDRFramesParams *pANBParams = (PrependSPSPPSToIDRFramesParams *)pComponentParameterStructure;
659 ret = Exynos_OMX_Check_SizeVersion(pANBParams, sizeof(PrependSPSPPSToIDRFramesParams));
660 if (ret != OMX_ErrorNone) {
661 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OMX_Check_SizeVersion(PrependSPSPPSToIDRFramesParams) is failed", __func__);
662 goto EXIT;
663 }
664
665 (*((OMX_BOOL *)pbPrependSpsPpsToIdr)) = pANBParams->bEnable;
666
667 EXIT:
668 return ret;
669 }
670
671 OMX_COLOR_FORMATTYPE Exynos_OSAL_Hal2OMXPixelFormat(
672 unsigned int hal_format)
673 {
674 OMX_COLOR_FORMATTYPE omx_format;
675 switch (hal_format) {
676 case HAL_PIXEL_FORMAT_YCbCr_422_I:
677 omx_format = OMX_COLOR_FormatYCbYCr;
678 break;
679 case HAL_PIXEL_FORMAT_YCbCr_420_P:
680 omx_format = OMX_COLOR_FormatYUV420Planar;
681 break;
682 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
683 omx_format = OMX_COLOR_FormatYUV420SemiPlanar;
684 break;
685 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
686 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
687 break;
688 case HAL_PIXEL_FORMAT_BGRA_8888:
689 omx_format = OMX_COLOR_Format32bitARGB8888;
690 break;
691 case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP:
692 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV21Linear;
693 break;
694 case HAL_PIXEL_FORMAT_EXYNOS_YV12:
695 omx_format = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatYVU420Planar;
696 break;
697 case HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888:
698 omx_format = OMX_COLOR_Format32bitBGRA8888;
699 break;
700 default:
701 omx_format = OMX_COLOR_FormatYUV420Planar;
702 break;
703 }
704 return omx_format;
705 }
706
707 unsigned int Exynos_OSAL_OMX2HalPixelFormat(
708 OMX_COLOR_FORMATTYPE omx_format)
709 {
710 unsigned int hal_format;
711 switch (omx_format) {
712 case OMX_COLOR_FormatYCbYCr:
713 hal_format = HAL_PIXEL_FORMAT_YCbCr_422_I;
714 break;
715 case OMX_COLOR_FormatYUV420Planar:
716 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
717 break;
718 case OMX_COLOR_FormatYUV420SemiPlanar:
719 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
720 break;
721 case OMX_SEC_COLOR_FormatNV12Tiled:
722 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED;
723 break;
724 case OMX_COLOR_Format32bitARGB8888:
725 hal_format = HAL_PIXEL_FORMAT_BGRA_8888;
726 break;
727 case OMX_SEC_COLOR_FormatNV21Linear:
728 hal_format = HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP;
729 break;
730 case OMX_SEC_COLOR_FormatYVU420Planar:
731 hal_format = HAL_PIXEL_FORMAT_EXYNOS_YV12;
732 break;
733 case OMX_COLOR_Format32bitBGRA8888:
734 hal_format = HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888;
735 break;
736 default:
737 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
738 break;
739 }
740 return hal_format;
741 }
742
743
744 #ifdef __cplusplus
745 }
746 #endif