1 /*
2 *
3 * Copyright 2013 Rockchip Electronics Co., LTD.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * @file Rockchip_OMX_Baseport.c
20 * @brief
21 * @author csy (csy@rock-chips.com)
22 * @version 1.0.0
23 * @history
24 * 2013.11.26 : Create
25 */
26
27 #undef ROCKCHIP_LOG_TAG
28 #define ROCKCHIP_LOG_TAG "omx_base_port"
29
30 #include "Rockchip_OMX_Baseport.h"
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include "Rockchip_OMX_Macros.h"
35 #include "Rockchip_OSAL_Event.h"
36 #include "Rockchip_OSAL_Semaphore.h"
37 #include "Rockchip_OSAL_Mutex.h"
38 #include "Rockchip_OMX_Basecomponent.h"
39 #include "Rockchip_OSAL_OHOS.h"
40 #include "Rockchip_OSAL_Log.h"
41 #include "omx_video_global.h"
42
43 OMX_U32 omx_vdec_debug = 0;
44 OMX_U32 omx_venc_debug = 0;
45
46
Rkvpu_OMX_InputBufferReturn(OMX_COMPONENTTYPE * pOMXComponent,OMX_BUFFERHEADERTYPE * bufferHeader)47 OMX_ERRORTYPE Rkvpu_OMX_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, OMX_BUFFERHEADERTYPE* bufferHeader)
48 {
49 OMX_ERRORTYPE ret = OMX_ErrorNone;
50 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
51 ROCKCHIP_OMX_BASEPORT *pRockchipPort = &pRockchipComponent->pRockchipPort[INPUT_PORT_INDEX];
52 OMX_U32 i = 0;
53
54 Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
55 for (i = 0; i < pRockchipPort->portDefinition.nBufferCountActual; i++) {
56 if (bufferHeader == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
57 pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_FALSE;
58 break;
59 }
60 }
61
62 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: empty buffer done(%p) timeus: %lld us, flags: 0x%lx",
63 pRockchipComponent->componentName,
64 bufferHeader->pBuffer,
65 bufferHeader->nTimeStamp,
66 bufferHeader->nFlags);
67
68 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
69 pRockchipComponent->pCallbacks->EmptyBufferDone(pOMXComponent, pRockchipComponent->callbackData, bufferHeader);
70
71 return ret;
72 }
73
Rockchip_OMX_OutputBufferReturn(OMX_COMPONENTTYPE * pOMXComponent,OMX_BUFFERHEADERTYPE * bufferHeader)74 OMX_ERRORTYPE Rockchip_OMX_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, OMX_BUFFERHEADERTYPE* bufferHeader)
75 {
76 OMX_ERRORTYPE ret = OMX_ErrorNone;
77 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
78 ROCKCHIP_OMX_BASEPORT *pRockchipPort = &pRockchipComponent->pRockchipPort[OUTPUT_PORT_INDEX];
79 OMX_U32 i = 0;
80
81 Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
82 for (i = 0; i < MAX_BUFFER_NUM; i++) {
83 if (bufferHeader == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
84 pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_FALSE;
85 break;
86 }
87 }
88
89 if (bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) {
90 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: fill EOS buffer done(%p) timeus: %lld us, flags: 0x%lx",
91 pRockchipComponent->componentName,
92 bufferHeader->pBuffer,
93 bufferHeader->nTimeStamp,
94 bufferHeader->nFlags);
95 } else {
96 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: fill buffer done(%p) timeus: %lld us, flags: 0x%lx",
97 pRockchipComponent->componentName,
98 bufferHeader->pBuffer,
99 bufferHeader->nTimeStamp,
100 bufferHeader->nFlags);
101 }
102
103 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
104 pRockchipComponent->pCallbacks->FillBufferDone(pOMXComponent, pRockchipComponent->callbackData, bufferHeader);
105
106 goto EXIT;
107 EXIT:
108 omx_trace("bufferHeader:0x%p", bufferHeader);
109 return ret;
110 }
111
Rockchip_OMX_BufferFlushProcess(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 nPortIndex,OMX_BOOL bEvent)112 OMX_ERRORTYPE Rockchip_OMX_BufferFlushProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent)
113 {
114 OMX_ERRORTYPE ret = OMX_ErrorNone;
115 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
116 OMX_S32 portIndex = 0;
117 OMX_U32 i = 0, cnt = 0;
118
119 FunctionIn();
120
121 if (pOMXComponent == NULL) {
122 ret = OMX_ErrorBadParameter;
123 goto EXIT;
124 }
125 ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
126 if (ret != OMX_ErrorNone) {
127 goto EXIT;
128 }
129
130 if (pOMXComponent->pComponentPrivate == NULL) {
131 ret = OMX_ErrorBadParameter;
132 goto EXIT;
133 }
134 pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
135
136 cnt = (nPortIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
137
138 for (i = 0; i < cnt; i++) {
139 if (nPortIndex == ALL_PORT_INDEX)
140 portIndex = i;
141 else
142 portIndex = nPortIndex;
143
144 pRockchipComponent->rockchip_BufferFlush(pOMXComponent, portIndex, bEvent);
145 }
146
147 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: buffer flush.", pRockchipComponent->componentName);
148
149 EXIT:
150 if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pRockchipComponent != NULL)) {
151 omx_err("ERROR");
152 pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
153 pRockchipComponent->callbackData,
154 OMX_EventError,
155 ret, 0, NULL);
156 }
157
158 FunctionOut();
159
160 return ret;
161 }
162
Rockchip_OMX_EnablePort(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 portIndex)163 OMX_ERRORTYPE Rockchip_OMX_EnablePort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
164 {
165 OMX_ERRORTYPE ret = OMX_ErrorNone;
166 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
167 ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
168
169 FunctionIn();
170
171 pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
172
173 if ((pRockchipComponent->currentState != OMX_StateLoaded) &&
174 (pRockchipComponent->currentState != OMX_StateWaitForResources)) {
175 Rockchip_OSAL_SemaphoreWait(pRockchipPort->loadedResource);
176
177 if (pRockchipPort->exceptionFlag == INVALID_STATE) {
178 pRockchipPort->exceptionFlag = NEED_PORT_DISABLE;
179 goto EXIT;
180 }
181 pRockchipPort->portDefinition.bPopulated = OMX_TRUE;
182 }
183 pRockchipPort->exceptionFlag = GENERAL_STATE;
184 pRockchipPort->portDefinition.bEnabled = OMX_TRUE;
185 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: now enable %s port.",
186 pRockchipComponent->componentName,
187 portIndex == INPUT_PORT_INDEX ? "input" : "output");
188
189 ret = OMX_ErrorNone;
190
191 EXIT:
192 FunctionOut();
193
194 return ret;
195 }
196
Rockchip_OMX_PortEnableProcess(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 nPortIndex)197 OMX_ERRORTYPE Rockchip_OMX_PortEnableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
198 {
199 OMX_ERRORTYPE ret = OMX_ErrorNone;
200 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
201 OMX_S32 portIndex = 0;
202 OMX_U32 i = 0, cnt = 0;
203
204 FunctionIn();
205
206 if (pOMXComponent == NULL) {
207 ret = OMX_ErrorBadParameter;
208 goto EXIT;
209 }
210 ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
211 if (ret != OMX_ErrorNone) {
212 goto EXIT;
213 }
214
215 if (pOMXComponent->pComponentPrivate == NULL) {
216 ret = OMX_ErrorBadParameter;
217 goto EXIT;
218 }
219 pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
220
221 cnt = (nPortIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
222
223 for (i = 0; i < cnt; i++) {
224 if (nPortIndex == ALL_PORT_INDEX)
225 portIndex = i;
226 else
227 portIndex = nPortIndex;
228
229 ret = Rockchip_OMX_EnablePort(pOMXComponent, portIndex);
230 if (ret == OMX_ErrorNone) {
231 pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
232 pRockchipComponent->callbackData,
233 OMX_EventCmdComplete,
234 OMX_CommandPortEnable, portIndex, NULL);
235 }
236 }
237
238 EXIT:
239 if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pRockchipComponent != NULL)) {
240 pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
241 pRockchipComponent->callbackData,
242 OMX_EventError,
243 ret, 0, NULL);
244 }
245
246 FunctionOut();
247
248 return ret;
249 }
250
Rockchip_OMX_DisablePort(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 portIndex)251 OMX_ERRORTYPE Rockchip_OMX_DisablePort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
252 {
253 OMX_ERRORTYPE ret = OMX_ErrorNone;
254 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
255 ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
256 ROCKCHIP_OMX_MESSAGE *message;
257
258 FunctionIn();
259
260 pRockchipPort = &pRockchipComponent->pRockchipPort[portIndex];
261
262 if (!CHECK_PORT_ENABLED(pRockchipPort)) {
263 ret = OMX_ErrorNone;
264 goto EXIT;
265 }
266
267 if (pRockchipComponent->currentState != OMX_StateLoaded) {
268 if (CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)) {
269 while (Rockchip_OSAL_GetElemNum(&pRockchipPort->bufferQ) > 0) {
270 message = (ROCKCHIP_OMX_MESSAGE*)Rockchip_OSAL_Dequeue(&pRockchipPort->bufferQ);
271 Rockchip_OSAL_Free(message);
272 }
273 }
274 pRockchipPort->portDefinition.bPopulated = OMX_FALSE;
275 Rockchip_OSAL_SemaphoreWait(pRockchipPort->unloadedResource);
276 }
277
278 if (pRockchipComponent->codecType == HW_VIDEO_DEC_CODEC
279 && portIndex == OUTPUT_PORT_INDEX) {
280 ret = Rkvpu_ComputeDecBufferCount((OMX_HANDLETYPE)pOMXComponent);
281 if (ret != OMX_ErrorNone) {
282 omx_err("compute decoder buffer count failed!");
283 goto EXIT;
284 }
285 }
286 pRockchipPort->portDefinition.bEnabled = OMX_FALSE;
287 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: now disable %s port.",
288 pRockchipComponent->componentName,
289 portIndex == INPUT_PORT_INDEX ? "input" : "output");
290
291 ret = OMX_ErrorNone;
292
293 EXIT:
294 FunctionOut();
295
296 return ret;
297 }
298
Rockchip_OMX_PortDisableProcess(OMX_COMPONENTTYPE * pOMXComponent,OMX_S32 nPortIndex)299 OMX_ERRORTYPE Rockchip_OMX_PortDisableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
300 {
301 OMX_ERRORTYPE ret = OMX_ErrorNone;
302 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
303 OMX_S32 portIndex = 0;
304 OMX_U32 i = 0, cnt = 0;
305
306 FunctionIn();
307
308 if (pOMXComponent == NULL) {
309 ret = OMX_ErrorBadParameter;
310 goto EXIT;
311 }
312 ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
313 if (ret != OMX_ErrorNone) {
314 goto EXIT;
315 }
316
317 if (pOMXComponent->pComponentPrivate == NULL) {
318 ret = OMX_ErrorBadParameter;
319 goto EXIT;
320 }
321 pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
322
323 cnt = (nPortIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
324
325 /* port flush */
326 for (i = 0; i < cnt; i++) {
327 if (nPortIndex == ALL_PORT_INDEX)
328 portIndex = i;
329 else
330 portIndex = nPortIndex;
331
332 Rockchip_OMX_BufferFlushProcess(pOMXComponent, portIndex, OMX_FALSE);
333 }
334
335 for (i = 0; i < cnt; i++) {
336 if (nPortIndex == ALL_PORT_INDEX)
337 portIndex = i;
338 else
339 portIndex = nPortIndex;
340
341 ret = Rockchip_OMX_DisablePort(pOMXComponent, portIndex);
342 pRockchipComponent->pRockchipPort[portIndex].bIsPortDisabled = OMX_FALSE;
343 if (ret == OMX_ErrorNone) {
344 pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
345 pRockchipComponent->callbackData,
346 OMX_EventCmdComplete,
347 OMX_CommandPortDisable, portIndex, NULL);
348 }
349 }
350
351 EXIT:
352 if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pRockchipComponent != NULL)) {
353 pRockchipComponent->pCallbacks->EventHandler(pOMXComponent,
354 pRockchipComponent->callbackData,
355 OMX_EventError,
356 ret, 0, NULL);
357 }
358
359 FunctionOut();
360
361 return ret;
362 }
363
Rockchip_OMX_EmptyThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)364 OMX_ERRORTYPE Rockchip_OMX_EmptyThisBuffer(
365 OMX_IN OMX_HANDLETYPE hComponent,
366 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
367 {
368 OMX_ERRORTYPE ret = OMX_ErrorNone;
369 OMX_COMPONENTTYPE *pOMXComponent = NULL;
370 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
371 ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
372 OMX_BOOL findBuffer = OMX_FALSE;
373 ROCKCHIP_OMX_MESSAGE *message;
374 OMX_U32 i = 0;
375
376 FunctionIn();
377
378 if (hComponent == NULL) {
379 ret = OMX_ErrorBadParameter;
380 goto EXIT;
381 }
382 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
383 ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
384 if (ret != OMX_ErrorNone) {
385 goto EXIT;
386 }
387
388 if (pOMXComponent->pComponentPrivate == NULL) {
389 ret = OMX_ErrorBadParameter;
390 goto EXIT;
391 }
392 pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
393 if (pRockchipComponent->currentState == OMX_StateInvalid) {
394 ret = OMX_ErrorInvalidState;
395 goto EXIT;
396 }
397
398 if (pBuffer == NULL) {
399 ret = OMX_ErrorBadParameter;
400 goto EXIT;
401 }
402 if (pBuffer->nInputPortIndex != INPUT_PORT_INDEX) {
403 ret = OMX_ErrorBadPortIndex;
404 goto EXIT;
405 }
406
407 ret = Rockchip_OMX_Check_SizeVersion(pBuffer, sizeof(OMX_BUFFERHEADERTYPE));
408 if (ret != OMX_ErrorNone) {
409 goto EXIT;
410 }
411
412 if ((pRockchipComponent->currentState != OMX_StateIdle) &&
413 (pRockchipComponent->currentState != OMX_StateExecuting) &&
414 (pRockchipComponent->currentState != OMX_StatePause)) {
415 ret = OMX_ErrorIncorrectStateOperation;
416 goto EXIT;
417 }
418
419 pRockchipPort = &pRockchipComponent->pRockchipPort[INPUT_PORT_INDEX];
420 if ((!CHECK_PORT_ENABLED(pRockchipPort)) ||
421 (CHECK_PORT_BEING_FLUSHED(pRockchipPort) &&
422 (!CHECK_PORT_TUNNELED(pRockchipPort) || !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort))) ||
423 ((pRockchipComponent->transientState == ROCKCHIP_OMX_TransStateExecutingToIdle) &&
424 (CHECK_PORT_TUNNELED(pRockchipPort) && !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)))) {
425 ret = OMX_ErrorIncorrectStateOperation;
426 goto EXIT;
427 }
428
429 Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
430 for (i = 0; i < pRockchipPort->portDefinition.nBufferCountActual; i++) {
431 if (pBuffer == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
432 pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_TRUE;
433 findBuffer = OMX_TRUE;
434 break;
435 }
436 }
437
438 if (findBuffer == OMX_FALSE) {
439 ret = OMX_ErrorBadParameter;
440 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
441 goto EXIT;
442 }
443
444 if (pBuffer->nFlags & OMX_BUFFERFLAG_EXTRADATA) {
445 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: empty this extradata buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
446 pRockchipComponent->componentName,
447 pBuffer->pBuffer,
448 pBuffer->nTimeStamp,
449 pBuffer->nFilledLen,
450 pBuffer->nFlags);
451 omx_info("[%s]: empty this extradata buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
452 pRockchipComponent->componentName,
453 pBuffer->pBuffer,
454 pBuffer->nTimeStamp,
455 pBuffer->nFilledLen,
456 pBuffer->nFlags);
457
458 } else if (pBuffer->nFlags & OMX_BUFFERFLAG_EOS) {
459 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: empty this EOS buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
460 pRockchipComponent->componentName,
461 pBuffer->pBuffer,
462 pBuffer->nTimeStamp,
463 pBuffer->nFilledLen,
464 pBuffer->nFlags);
465 omx_info("[%s]: empty this EOS buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
466 pRockchipComponent->componentName,
467 pBuffer->pBuffer,
468 pBuffer->nTimeStamp,
469 pBuffer->nFilledLen,
470 pBuffer->nFlags);
471 } else {
472 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: empty this buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
473 pRockchipComponent->componentName,
474 pBuffer->pBuffer,
475 pBuffer->nTimeStamp,
476 pBuffer->nFilledLen,
477 pBuffer->nFlags);
478 omx_info("[%s]: empty this buffer(%p) timeus: %lld us, size: %ld, flags: 0x%lx",
479 pRockchipComponent->componentName,
480 pBuffer->pBuffer,
481 pBuffer->nTimeStamp,
482 pBuffer->nFilledLen,
483 pBuffer->nFlags);
484 }
485
486 message = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_MESSAGE));
487 if (message == NULL) {
488 ret = OMX_ErrorInsufficientResources;
489 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
490 goto EXIT;
491 }
492 message->messageType = ROCKCHIP_OMX_CommandEmptyBuffer;
493 message->messageParam = (OMX_U32) i;
494 message->pCmdData = (OMX_PTR)pBuffer;
495
496 ret = Rockchip_OSAL_Queue(&pRockchipPort->bufferQ, (void *)message);
497
498 if (ret != 0) {
499 ret = OMX_ErrorUndefined;
500 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
501 goto EXIT;
502 }
503 ret = Rockchip_OSAL_SemaphorePost(pRockchipPort->bufferSemID);
504 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
505
506 EXIT:
507 FunctionOut();
508
509 return ret;
510 }
511
Rockchip_OMX_FillThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)512 OMX_ERRORTYPE Rockchip_OMX_FillThisBuffer(
513 OMX_IN OMX_HANDLETYPE hComponent,
514 OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
515 {
516 OMX_ERRORTYPE ret = OMX_ErrorNone;
517 OMX_COMPONENTTYPE *pOMXComponent = NULL;
518 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
519 ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
520 OMX_BOOL findBuffer = OMX_FALSE;
521 ROCKCHIP_OMX_MESSAGE *message;
522 OMX_U32 i = 0;
523
524 FunctionIn();
525
526 if (hComponent == NULL) {
527 ret = OMX_ErrorBadParameter;
528 goto EXIT;
529 }
530 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
531 ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
532 if (ret != OMX_ErrorNone) {
533 goto EXIT;
534 }
535
536 if (pOMXComponent->pComponentPrivate == NULL) {
537 ret = OMX_ErrorBadParameter;
538 goto EXIT;
539 }
540 pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
541 if (pRockchipComponent->currentState == OMX_StateInvalid) {
542 ret = OMX_ErrorInvalidState;
543 goto EXIT;
544 }
545
546 if (pBuffer == NULL) {
547 ret = OMX_ErrorBadParameter;
548 goto EXIT;
549 }
550 if (pBuffer->nOutputPortIndex != OUTPUT_PORT_INDEX) {
551 ret = OMX_ErrorBadPortIndex;
552 goto EXIT;
553 }
554
555 ret = Rockchip_OMX_Check_SizeVersion(pBuffer, sizeof(OMX_BUFFERHEADERTYPE));
556 if (ret != OMX_ErrorNone) {
557 goto EXIT;
558 }
559
560 if ((pRockchipComponent->currentState != OMX_StateIdle) &&
561 (pRockchipComponent->currentState != OMX_StateExecuting) &&
562 (pRockchipComponent->currentState != OMX_StatePause)) {
563 ret = OMX_ErrorIncorrectStateOperation;
564 goto EXIT;
565 }
566
567 pRockchipPort = &pRockchipComponent->pRockchipPort[OUTPUT_PORT_INDEX];
568
569 if ((!CHECK_PORT_ENABLED(pRockchipPort)) ||
570 (CHECK_PORT_BEING_FLUSHED(pRockchipPort) && (!CHECK_PORT_TUNNELED(pRockchipPort) ||
571 !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort))) ||
572 ((pRockchipComponent->transientState == ROCKCHIP_OMX_TransStateExecutingToIdle) &&
573 (CHECK_PORT_TUNNELED(pRockchipPort) && !CHECK_PORT_BUFFER_SUPPLIER(pRockchipPort)))) {
574 ret = OMX_ErrorIncorrectStateOperation;
575 goto EXIT;
576 }
577
578 Rockchip_OSAL_MutexLock(pRockchipPort->hPortMutex);
579 for (i = 0; i < MAX_BUFFER_NUM; i++) {
580 if (pBuffer == pRockchipPort->extendBufferHeader[i].OMXBufferHeader) {
581 pRockchipPort->extendBufferHeader[i].bBufferInOMX = OMX_TRUE;
582 findBuffer = OMX_TRUE;
583 break;
584 }
585 }
586
587 if (findBuffer == OMX_FALSE) {
588 ret = OMX_ErrorBadParameter;
589 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
590 goto EXIT;
591 }
592
593 VIDEO_DBG(VIDEO_DBG_LOG_PORT, "[%s]: fill this buffer(%p) flags: 0x%lx",
594 pRockchipComponent->componentName,
595 pBuffer->pBuffer,
596 pBuffer->nFlags);
597
598 omx_info("[%s]: fill this buffer(%p) flags: 0x%lx",
599 pRockchipComponent->componentName,
600 pBuffer->pBuffer,
601 pBuffer->nFlags);
602
603 if (pRockchipPort->bufferProcessType == BUFFER_SHARE) {
604 Rockchip_OSAL_Fd2VpumemPool(pRockchipComponent, pRockchipPort->extendBufferHeader[i].OMXBufferHeader);
605 } else {
606 message = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_MESSAGE));
607 if (message == NULL) {
608 ret = OMX_ErrorInsufficientResources;
609 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
610 goto EXIT;
611 }
612 message->messageType = ROCKCHIP_OMX_CommandFillBuffer;
613 message->messageParam = (OMX_U32) i;
614 message->pCmdData = (OMX_PTR)pBuffer;
615
616 ret = Rockchip_OSAL_Queue(&pRockchipPort->bufferQ, (void *)message);
617 if (ret != 0) {
618 ret = OMX_ErrorUndefined;
619 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
620 goto EXIT;
621 }
622 }
623
624 ret = Rockchip_OSAL_SemaphorePost(pRockchipPort->bufferSemID);
625 Rockchip_OSAL_MutexUnlock(pRockchipPort->hPortMutex);
626
627 EXIT:
628 FunctionOut();
629
630 return ret;
631 }
632
Rockchip_OMX_Port_Constructor(OMX_HANDLETYPE hComponent)633 OMX_ERRORTYPE Rockchip_OMX_Port_Constructor(OMX_HANDLETYPE hComponent)
634 {
635 OMX_ERRORTYPE ret = OMX_ErrorNone;
636 OMX_COMPONENTTYPE *pOMXComponent = NULL;
637 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
638 ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
639 ROCKCHIP_OMX_BASEPORT *pRockchipInputPort = NULL;
640 ROCKCHIP_OMX_BASEPORT *pRockchipOutputPort = NULL;
641
642 FunctionIn();
643
644 if (hComponent == NULL) {
645 ret = OMX_ErrorBadParameter;
646 omx_err("OMX_ErrorBadParameter, Line:%d", __LINE__);
647 goto EXIT;
648 }
649 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
650 ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
651 if (ret != OMX_ErrorNone) {
652 goto EXIT;
653 }
654
655 if (pOMXComponent->pComponentPrivate == NULL) {
656 ret = OMX_ErrorBadParameter;
657 omx_err("OMX_ErrorBadParameter, Line:%d", __LINE__);
658 goto EXIT;
659 }
660 pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
661
662 INIT_SET_SIZE_VERSION(&pRockchipComponent->portParam, OMX_PORT_PARAM_TYPE);
663 pRockchipComponent->portParam.nPorts = ALL_PORT_NUM;
664 pRockchipComponent->portParam.nStartPortNumber = INPUT_PORT_INDEX;
665
666 pRockchipPort = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BASEPORT) * ALL_PORT_NUM);
667 if (pRockchipPort == NULL) {
668 ret = OMX_ErrorInsufficientResources;
669 omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
670 goto EXIT;
671 }
672 Rockchip_OSAL_Memset(pRockchipPort, 0, sizeof(ROCKCHIP_OMX_BASEPORT) * ALL_PORT_NUM);
673 pRockchipComponent->pRockchipPort = pRockchipPort;
674
675 /* Input Port */
676 pRockchipInputPort = &pRockchipPort[INPUT_PORT_INDEX];
677
678 Rockchip_OSAL_QueueCreate(&pRockchipInputPort->bufferQ, MAX_QUEUE_ELEMENTS);
679 Rockchip_OSAL_QueueCreate(&pRockchipInputPort->securebufferQ, MAX_QUEUE_ELEMENTS);
680
681 pRockchipInputPort->extendBufferHeader =
682 Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
683 if (pRockchipInputPort->extendBufferHeader == NULL) {
684 Rockchip_OSAL_Free(pRockchipPort);
685 pRockchipPort = NULL;
686 ret = OMX_ErrorInsufficientResources;
687 omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
688 goto EXIT;
689 }
690 Rockchip_OSAL_Memset(pRockchipInputPort->extendBufferHeader, 0,
691 sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
692
693 pRockchipInputPort->bufferStateAllocate = Rockchip_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
694 if (pRockchipInputPort->bufferStateAllocate == NULL) {
695 Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
696 pRockchipInputPort->extendBufferHeader = NULL;
697 Rockchip_OSAL_Free(pRockchipPort);
698 pRockchipPort = NULL;
699 ret = OMX_ErrorInsufficientResources;
700 omx_err("OMX_ErrorInsufficientResources, Line:%d", __LINE__);
701 goto EXIT;
702 }
703 Rockchip_OSAL_Memset(pRockchipInputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);
704
705 pRockchipInputPort->bufferSemID = NULL;
706 pRockchipInputPort->assignedBufferNum = 0;
707 pRockchipInputPort->portState = OMX_StateMax;
708 pRockchipInputPort->bIsPortFlushed = OMX_FALSE;
709 pRockchipInputPort->bIsPortDisabled = OMX_FALSE;
710 pRockchipInputPort->tunneledComponent = NULL;
711 pRockchipInputPort->tunneledPort = 0;
712 pRockchipInputPort->tunnelBufferNum = 0;
713 pRockchipInputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
714 pRockchipInputPort->tunnelFlags = 0;
715 ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipInputPort->loadedResource);
716 if (ret != OMX_ErrorNone) {
717 Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
718 pRockchipInputPort->bufferStateAllocate = NULL;
719 Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
720 pRockchipInputPort->extendBufferHeader = NULL;
721 Rockchip_OSAL_Free(pRockchipPort);
722 pRockchipPort = NULL;
723 goto EXIT;
724 }
725 ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipInputPort->unloadedResource);
726 if (ret != OMX_ErrorNone) {
727 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
728 pRockchipInputPort->loadedResource = NULL;
729 Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
730 pRockchipInputPort->bufferStateAllocate = NULL;
731 Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
732 pRockchipInputPort->extendBufferHeader = NULL;
733 Rockchip_OSAL_Free(pRockchipPort);
734 pRockchipPort = NULL;
735 goto EXIT;
736 }
737
738 INIT_SET_SIZE_VERSION(&pRockchipInputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
739 pRockchipInputPort->portDefinition.nPortIndex = INPUT_PORT_INDEX;
740 pRockchipInputPort->portDefinition.eDir = OMX_DirInput;
741 pRockchipInputPort->portDefinition.nBufferCountActual = 0;
742 pRockchipInputPort->portDefinition.nBufferCountMin = 0;
743 pRockchipInputPort->portDefinition.nBufferSize = 0;
744 pRockchipInputPort->portDefinition.bEnabled = OMX_FALSE;
745 pRockchipInputPort->portDefinition.bPopulated = OMX_FALSE;
746 pRockchipInputPort->portDefinition.eDomain = OMX_PortDomainMax;
747 pRockchipInputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
748 pRockchipInputPort->portDefinition.nBufferAlignment = 0;
749 pRockchipInputPort->markType.hMarkTargetComponent = NULL;
750 pRockchipInputPort->markType.pMarkData = NULL;
751 pRockchipInputPort->exceptionFlag = GENERAL_STATE;
752
753 /* Output Port */
754 pRockchipOutputPort = &pRockchipPort[OUTPUT_PORT_INDEX];
755 /* For in case of "Output Buffer Share", MAX ELEMENTS(DPB + EDPB) */
756 Rockchip_OSAL_QueueCreate(&pRockchipOutputPort->bufferQ, MAX_QUEUE_ELEMENTS);
757
758 pRockchipOutputPort->extendBufferHeader =
759 Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
760 if (pRockchipOutputPort->extendBufferHeader == NULL) {
761 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
762 pRockchipInputPort->unloadedResource = NULL;
763 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
764 pRockchipInputPort->loadedResource = NULL;
765 Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
766 pRockchipInputPort->bufferStateAllocate = NULL;
767 Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
768 pRockchipInputPort->extendBufferHeader = NULL;
769 Rockchip_OSAL_Free(pRockchipPort);
770 pRockchipPort = NULL;
771 ret = OMX_ErrorInsufficientResources;
772 goto EXIT;
773 }
774 Rockchip_OSAL_Memset(pRockchipOutputPort->extendBufferHeader, 0,
775 sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
776
777 pRockchipOutputPort->bufferStateAllocate = Rockchip_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
778 if (pRockchipOutputPort->bufferStateAllocate == NULL) {
779 Rockchip_OSAL_Free(pRockchipOutputPort->extendBufferHeader);
780 pRockchipOutputPort->extendBufferHeader = NULL;
781
782 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
783 pRockchipInputPort->unloadedResource = NULL;
784 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
785 pRockchipInputPort->loadedResource = NULL;
786 Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
787 pRockchipInputPort->bufferStateAllocate = NULL;
788 Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
789 pRockchipInputPort->extendBufferHeader = NULL;
790 Rockchip_OSAL_Free(pRockchipPort);
791 pRockchipPort = NULL;
792 ret = OMX_ErrorInsufficientResources;
793 goto EXIT;
794 }
795 Rockchip_OSAL_Memset(pRockchipOutputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);
796
797 pRockchipOutputPort->bufferSemID = NULL;
798 pRockchipOutputPort->assignedBufferNum = 0;
799 pRockchipOutputPort->portState = OMX_StateMax;
800 pRockchipOutputPort->bIsPortFlushed = OMX_FALSE;
801 pRockchipOutputPort->bIsPortDisabled = OMX_FALSE;
802 pRockchipOutputPort->tunneledComponent = NULL;
803 pRockchipOutputPort->tunneledPort = 0;
804 pRockchipOutputPort->tunnelBufferNum = 0;
805 pRockchipOutputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
806 pRockchipOutputPort->tunnelFlags = 0;
807 ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipOutputPort->loadedResource);
808 if (ret != OMX_ErrorNone) {
809 Rockchip_OSAL_Free(pRockchipOutputPort->bufferStateAllocate);
810 pRockchipOutputPort->bufferStateAllocate = NULL;
811 Rockchip_OSAL_Free(pRockchipOutputPort->extendBufferHeader);
812 pRockchipOutputPort->extendBufferHeader = NULL;
813
814 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
815 pRockchipInputPort->unloadedResource = NULL;
816 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
817 pRockchipInputPort->loadedResource = NULL;
818 Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
819 pRockchipInputPort->bufferStateAllocate = NULL;
820 Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
821 pRockchipInputPort->extendBufferHeader = NULL;
822 Rockchip_OSAL_Free(pRockchipPort);
823 pRockchipPort = NULL;
824 goto EXIT;
825 }
826 ret = Rockchip_OSAL_SemaphoreCreate(&pRockchipOutputPort->unloadedResource);
827 if (ret != OMX_ErrorNone) {
828 Rockchip_OSAL_SemaphoreTerminate(pRockchipOutputPort->loadedResource);
829 pRockchipOutputPort->loadedResource = NULL;
830 Rockchip_OSAL_Free(pRockchipOutputPort->bufferStateAllocate);
831 pRockchipOutputPort->bufferStateAllocate = NULL;
832 Rockchip_OSAL_Free(pRockchipOutputPort->extendBufferHeader);
833 pRockchipOutputPort->extendBufferHeader = NULL;
834
835 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->unloadedResource);
836 pRockchipInputPort->unloadedResource = NULL;
837 Rockchip_OSAL_SemaphoreTerminate(pRockchipInputPort->loadedResource);
838 pRockchipInputPort->loadedResource = NULL;
839 Rockchip_OSAL_Free(pRockchipInputPort->bufferStateAllocate);
840 pRockchipInputPort->bufferStateAllocate = NULL;
841 Rockchip_OSAL_Free(pRockchipInputPort->extendBufferHeader);
842 pRockchipInputPort->extendBufferHeader = NULL;
843 Rockchip_OSAL_Free(pRockchipPort);
844 pRockchipPort = NULL;
845 goto EXIT;
846 }
847
848 INIT_SET_SIZE_VERSION(&pRockchipOutputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
849 pRockchipOutputPort->portDefinition.nPortIndex = OUTPUT_PORT_INDEX;
850 pRockchipOutputPort->portDefinition.eDir = OMX_DirOutput;
851 pRockchipOutputPort->portDefinition.nBufferCountActual = 0;
852 pRockchipOutputPort->portDefinition.nBufferCountMin = 0;
853 pRockchipOutputPort->portDefinition.nBufferSize = 0;
854 pRockchipOutputPort->portDefinition.bEnabled = OMX_FALSE;
855
856 pRockchipOutputPort->portDefinition.bPopulated = OMX_FALSE;
857 pRockchipOutputPort->portDefinition.eDomain = OMX_PortDomainMax;
858 pRockchipOutputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
859 pRockchipOutputPort->portDefinition.nBufferAlignment = 0;
860 pRockchipOutputPort->markType.hMarkTargetComponent = NULL;
861 pRockchipOutputPort->markType.pMarkData = NULL;
862 pRockchipOutputPort->exceptionFlag = GENERAL_STATE;
863
864 pRockchipComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE;
865 pRockchipComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
866 pRockchipComponent->checkTimeStamp.startTimeStamp = 0;
867 pRockchipComponent->checkTimeStamp.nStartFlags = 0x0;
868
869 pOMXComponent->EmptyThisBuffer = &Rockchip_OMX_EmptyThisBuffer;
870 pOMXComponent->FillThisBuffer = &Rockchip_OMX_FillThisBuffer;
871
872 ret = OMX_ErrorNone;
873 EXIT:
874 FunctionOut();
875
876 return ret;
877 }
878
Rockchip_OMX_Port_Destructor(OMX_HANDLETYPE hComponent)879 OMX_ERRORTYPE Rockchip_OMX_Port_Destructor(OMX_HANDLETYPE hComponent)
880 {
881 OMX_ERRORTYPE ret = OMX_ErrorNone;
882 OMX_COMPONENTTYPE *pOMXComponent = NULL;
883 ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent = NULL;
884 ROCKCHIP_OMX_BASEPORT *pRockchipPort = NULL;
885 int i = 0;
886
887 FunctionIn();
888
889 if (hComponent == NULL) {
890 ret = OMX_ErrorBadParameter;
891 goto EXIT;
892 }
893 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
894 ret = Rockchip_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
895 if (ret != OMX_ErrorNone) {
896 goto EXIT;
897 }
898 if (pOMXComponent->pComponentPrivate == NULL) {
899 ret = OMX_ErrorBadParameter;
900 goto EXIT;
901 }
902 pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
903
904 if (pRockchipComponent->transientState == ROCKCHIP_OMX_TransStateLoadedToIdle) {
905 pRockchipComponent->abendState = OMX_TRUE;
906 for (i = 0; i < ALL_PORT_NUM; i++) {
907 pRockchipPort = &pRockchipComponent->pRockchipPort[i];
908 Rockchip_OSAL_SemaphorePost(pRockchipPort->loadedResource);
909 }
910 Rockchip_OSAL_SignalWait(pRockchipComponent->abendStateEvent, DEF_MAX_WAIT_TIME);
911 Rockchip_OSAL_SignalReset(pRockchipComponent->abendStateEvent);
912 }
913
914 for (i = 0; i < ALL_PORT_NUM; i++) {
915 pRockchipPort = &pRockchipComponent->pRockchipPort[i];
916
917 Rockchip_OSAL_SemaphoreTerminate(pRockchipPort->loadedResource);
918 pRockchipPort->loadedResource = NULL;
919 Rockchip_OSAL_SemaphoreTerminate(pRockchipPort->unloadedResource);
920 pRockchipPort->unloadedResource = NULL;
921 Rockchip_OSAL_Free(pRockchipPort->bufferStateAllocate);
922 pRockchipPort->bufferStateAllocate = NULL;
923 Rockchip_OSAL_Free(pRockchipPort->extendBufferHeader);
924 pRockchipPort->extendBufferHeader = NULL;
925
926 Rockchip_OSAL_QueueTerminate(&pRockchipPort->bufferQ);
927 Rockchip_OSAL_QueueTerminate(&pRockchipPort->securebufferQ);
928 }
929 Rockchip_OSAL_Free(pRockchipComponent->pRockchipPort);
930 pRockchipComponent->pRockchipPort = NULL;
931 ret = OMX_ErrorNone;
932 EXIT:
933 FunctionOut();
934
935 return ret;
936 }
937
Rockchip_ResetDataBuffer(ROCKCHIP_OMX_DATABUFFER * pDataBuffer)938 OMX_ERRORTYPE Rockchip_ResetDataBuffer(ROCKCHIP_OMX_DATABUFFER *pDataBuffer)
939 {
940 OMX_ERRORTYPE ret = OMX_ErrorNone;
941
942 if (pDataBuffer == NULL) {
943 ret = OMX_ErrorBadParameter;
944 goto EXIT;
945 }
946
947 pDataBuffer->dataValid = OMX_FALSE;
948 pDataBuffer->dataLen = 0;
949 pDataBuffer->remainDataLen = 0;
950 pDataBuffer->usedDataLen = 0;
951 pDataBuffer->bufferHeader = NULL;
952 pDataBuffer->nFlags = 0;
953 pDataBuffer->timeStamp = 0;
954 pDataBuffer->pPrivate = NULL;
955
956 EXIT:
957 return ret;
958 }
959
Rockchip_ResetCodecData(ROCKCHIP_OMX_DATA * pData)960 OMX_ERRORTYPE Rockchip_ResetCodecData(ROCKCHIP_OMX_DATA *pData)
961 {
962 OMX_ERRORTYPE ret = OMX_ErrorNone;
963
964 if (pData == NULL) {
965 ret = OMX_ErrorBadParameter;
966 goto EXIT;
967 }
968
969 pData->dataLen = 0;
970 pData->usedDataLen = 0;
971 pData->remainDataLen = 0;
972 pData->nFlags = 0;
973 pData->timeStamp = 0;
974 pData->pPrivate = NULL;
975 pData->bufferHeader = NULL;
976 pData->allocSize = 0;
977
978 EXIT:
979 return ret;
980 }
981
Rockchip_Shared_BufferToData(ROCKCHIP_OMX_DATABUFFER * pUseBuffer,ROCKCHIP_OMX_DATA * pData,ROCKCHIP_OMX_PLANE nPlane)982 OMX_ERRORTYPE Rockchip_Shared_BufferToData(
983 ROCKCHIP_OMX_DATABUFFER *pUseBuffer,
984 ROCKCHIP_OMX_DATA *pData,
985 ROCKCHIP_OMX_PLANE nPlane)
986 {
987 OMX_ERRORTYPE ret = OMX_ErrorNone;
988
989 if (nPlane == ONE_PLANE) {
990 /* Case of Shared Buffer, Only support singlePlaneBuffer */
991 pData->buffer.singlePlaneBuffer.dataBuffer = pUseBuffer->bufferHeader->pBuffer;
992 } else {
993 omx_err("Can not support plane");
994 ret = OMX_ErrorNotImplemented;
995 goto EXIT;
996 }
997
998 pData->allocSize = pUseBuffer->allocSize;
999 pData->dataLen = pUseBuffer->dataLen;
1000 pData->usedDataLen = pUseBuffer->usedDataLen;
1001 pData->remainDataLen = pUseBuffer->remainDataLen;
1002 pData->timeStamp = pUseBuffer->timeStamp;
1003 pData->nFlags = pUseBuffer->nFlags;
1004 pData->pPrivate = pUseBuffer->pPrivate;
1005 pData->bufferHeader = pUseBuffer->bufferHeader;
1006
1007 EXIT:
1008 return ret;
1009 }
1010
Rockchip_Shared_DataToBuffer(ROCKCHIP_OMX_DATA * pData,ROCKCHIP_OMX_DATABUFFER * pUseBuffer)1011 OMX_ERRORTYPE Rockchip_Shared_DataToBuffer(ROCKCHIP_OMX_DATA *pData, ROCKCHIP_OMX_DATABUFFER *pUseBuffer)
1012 {
1013 OMX_ERRORTYPE ret = OMX_ErrorNone;
1014
1015 pUseBuffer->bufferHeader = pData->bufferHeader;
1016 pUseBuffer->allocSize = pData->allocSize;
1017 pUseBuffer->dataLen = pData->dataLen;
1018 pUseBuffer->usedDataLen = pData->usedDataLen;
1019 pUseBuffer->remainDataLen = pData->remainDataLen;
1020 pUseBuffer->timeStamp = pData->timeStamp;
1021 pUseBuffer->nFlags = pData->nFlags;
1022 pUseBuffer->pPrivate = pData->pPrivate;
1023
1024 return ret;
1025 }