summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libstagefrighthw/omx/base/OMX_BaseProcess.c')
-rw-r--r--libstagefrighthw/omx/base/OMX_BaseProcess.c355
1 files changed, 355 insertions, 0 deletions
diff --git a/libstagefrighthw/omx/base/OMX_BaseProcess.c b/libstagefrighthw/omx/base/OMX_BaseProcess.c
new file mode 100644
index 0000000..af1ac90
--- /dev/null
+++ b/libstagefrighthw/omx/base/OMX_BaseProcess.c
@@ -0,0 +1,355 @@
1/*
2 * Copyright (C) Texas Instruments - http://www.ti.com/
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#define LOG_TAG "OMX_BASE_PROCESS"
18
19#include <OMX_Core.h>
20#include <OMX_Component.h>
21#include <OMX_Base.h>
22#include <OMX_TI_Custom.h>
23
24static OMX_ERRORTYPE OMXBase_ProcessDataEvent(OMX_HANDLETYPE hComponent);
25
26static OMX_ERRORTYPE OMXBase_ProcessCmdEvent(OMX_HANDLETYPE hComponent,
27 OMX_COMMANDTYPE Cmd,
28 OMX_U32 nParam,
29 OMX_PTR pCmdData);
30
31
32/*
33* OMX Base ProcessTrigger Event
34*/
35OMX_ERRORTYPE OMXBase_ProcessTriggerEvent(OMX_HANDLETYPE hComponent,
36 OMX_U32 EventToSet)
37{
38 OMX_ERRORTYPE eError = OMX_ErrorNone;
39 OSAL_ERROR tStatus = OSAL_ErrNone;
40 OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent;
41 OMXBaseComp *pBaseComp = NULL;
42 OMXBaseComp_Pvt *pBaseCompPvt = NULL;
43 OMXBase_Port *pPort = NULL;
44 OMX_U32 i, nStartPort, nCount = 0;
45 OMX_BOOL bNotify = OMX_TRUE;
46
47 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate;
48 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData;
49 nStartPort = pBaseComp->nMinStartPortIndex;
50 if( EventToSet == DATAEVENT ) {
51 /*This var mey be accessed by multiple threads but it need not be mutex
52 protected*/
53 if( pBaseCompPvt->bForceNotifyOnce ) {
54 pBaseCompPvt->bForceNotifyOnce = OMX_FALSE;
55 bNotify = OMX_TRUE;
56 goto EXIT;
57 }
58
59 for( i = 0; i < (pBaseComp->nNumPorts); i++ ) {
60 pPort = pBaseComp->pPorts[i];
61 /*If port is disabled then move on*/
62 if( !pPort->sPortDef.bEnabled ) {
63 continue;
64 }
65 /*If EOS has been recd. on any one port then always send notification*/
66 if( pPort->sPortDef.eDir == OMX_DirInput && pPort->bEosRecd ) {
67 bNotify = OMX_TRUE;
68 goto EXIT;
69 }
70 }
71
72 if( pBaseComp->bNotifyForAnyPort == OMX_TRUE ) {
73 bNotify = OMX_FALSE;
74 for( i = 0; i < (pBaseComp->nNumPorts); i++ ) {
75 pPort = pBaseComp->pPorts[i];
76 /*If port is disabled then move on*/
77 if( !pPort->sPortDef.bEnabled ||
78 pPort->bIsInTransition) {
79 continue;
80 }
81 eError = pBaseCompPvt->fpDioGetCount(hComponent, nStartPort + i,
82 &nCount);
83 OMX_CHECK((eError == OMX_ErrorNone || eError ==
84 (OMX_ERRORTYPE)OMX_TI_WarningEosReceived), eError);
85 /*Resetting to ErrorNone in case EOS warning is recd.*/
86 eError = OMX_ErrorNone;
87 if((nCount >= pBaseComp->pPorts[i]->sProps.nWatermark)) {
88 bNotify = OMX_TRUE;
89 break;
90 }
91 }
92 } else {
93 for( i = 0; i < (pBaseComp->nNumPorts); i++ ) {
94 pPort = pBaseComp->pPorts[i];
95 /*If port is disabled then move on*/
96 if( !pPort->sPortDef.bEnabled ||
97 pPort->bIsInTransition) {
98 continue;
99 }
100 eError = pBaseCompPvt->fpDioGetCount(hComponent, nStartPort + i,
101 &nCount);
102 OMX_CHECK((eError == OMX_ErrorNone || eError ==
103 (OMX_ERRORTYPE)OMX_TI_WarningEosReceived), eError);
104 /*Resetting to ErrorNone in case EOS warning is recd.*/
105 eError = OMX_ErrorNone;
106 if((nCount < pBaseComp->pPorts[i]->sProps.nWatermark)) {
107 bNotify = OMX_FALSE;
108 break;
109 }
110 }
111 }
112 }
113
114EXIT:
115 if( bNotify == OMX_TRUE && eError == OMX_ErrorNone ) {
116 tStatus = OSAL_SetEvent(pBaseCompPvt->pTriggerEvent, EventToSet,
117 OSAL_EVENT_OR);
118 if( tStatus != OSAL_ErrNone ) {
119 eError = OMX_ErrorUndefined;
120 }
121 }
122 return (eError);
123}
124
125/*
126* OMX Base ProcessDataNotify
127*/
128OMX_ERRORTYPE OMXBase_ProcessDataNotify(OMX_HANDLETYPE hComponent)
129{
130 OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent;
131 OMXBaseComp *pBaseComp = NULL;
132 OMXBaseComp_Pvt *pBaseCompPvt = NULL;
133
134 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate;
135 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData;
136 pBaseCompPvt->bForceNotifyOnce = OMX_FALSE;
137 return (OMXBase_ProcessTriggerEvent(hComponent, DATAEVENT));
138}
139
140/*
141* OMXBase Process Events
142*/
143OMX_ERRORTYPE OMXBase_ProcessEvents(OMX_HANDLETYPE hComponent,
144 OMX_U32 retEvent)
145{
146 OMX_ERRORTYPE eError = OMX_ErrorNone;
147 OMX_ERRORTYPE eErrorAux = OMX_ErrorNone;
148 OSAL_ERROR tStatus = OSAL_ErrNone;
149 OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent;
150 OMXBaseComp *pBaseComp = NULL;
151 OMXBaseComp_Pvt *pBaseCompPvt = NULL;
152 OMXBase_CmdParams sCmdParams;
153 uint32_t actualSize = 0;
154 OMX_BOOL bHandleFailEvent = OMX_FALSE;
155
156
157 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate;
158 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData;
159 if( retEvent & CMDEVENT ) {
160 tStatus = OSAL_ObtainMutex(pBaseCompPvt->pCmdPipeMutex,
161 OSAL_SUSPEND);
162 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined);
163 /* process command event */
164 tStatus = OSAL_IsPipeReady(pBaseCompPvt->pCmdPipe);
165 if( tStatus != OSAL_ErrNone ) {
166 /*No command in pipe - return*/
167 tStatus = OSAL_ReleaseMutex(pBaseCompPvt->pCmdPipeMutex);
168 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined);
169 goto EXIT;
170 }
171 tStatus = OSAL_ReadFromPipe(pBaseCompPvt->pCmdPipe, &sCmdParams,
172 sizeof(OMXBase_CmdParams), &actualSize, OSAL_NO_SUSPEND);
173 if( OSAL_ErrNone != tStatus ) {
174 eError = OMX_ErrorUndefined;
175 }
176 tStatus = OSAL_ReleaseMutex(pBaseCompPvt->pCmdPipeMutex);
177 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined);
178 OMX_CHECK(eError == OMX_ErrorNone, eError);
179
180 eError = OMXBase_ProcessCmdEvent(hComponent, sCmdParams.eCmd,
181 sCmdParams.unParam, sCmdParams.pCmdData);
182 if( OMX_ErrorNone != eError ) {
183 bHandleFailEvent = OMX_TRUE;
184 goto EXIT;
185 }
186 } else if( retEvent & DATAEVENT ) {
187 /* process data Event */
188 eError = OMXBase_ProcessDataEvent(hComponent);
189 OMX_CHECK(OMX_ErrorNone == eError, eError);
190 }
191EXIT:
192 if( OMX_ErrorNone != eError ) {
193 if(eError != OMX_ErrorDynamicResourcesUnavailable) {
194 eErrorAux = pBaseCompPvt->sAppCallbacks.EventHandler(hComponent,
195 pComp->pApplicationPrivate,
196 OMX_EventError, eError,
197 OMX_StateInvalid, NULL);
198 } else {
199 eErrorAux = pBaseCompPvt->sAppCallbacks.EventHandler(hComponent,
200 pComp->pApplicationPrivate,
201 OMX_EventError, eError,
202 OMX_StateLoaded, NULL);
203 }
204 /*Component can do nothing if callback returns error*/
205 /*Just calling OMXBase_HandleFailEvent for SetState since it was the
206 * the intention. When Allocation fails while Dynamic Resources Allocation
207 * we are experiencing hang waiting forever for PortDisable event completion
208 * after attempted an unsuccessful PortEnable.
209 */
210 if( bHandleFailEvent && (eError != OMX_ErrorDynamicResourcesUnavailable) ) {
211 OMXBase_HandleFailEvent(hComponent, sCmdParams.eCmd, sCmdParams.unParam);
212 }
213 }
214 if( (OMX_ErrorNone != eError) && (eError != OMX_ErrorDynamicResourcesUnavailable) ) {
215 return (eError); //return actual error if any
216 }
217
218 return (eErrorAux);
219}
220
221/*
222* OMX Base Process Command Event
223*/
224static OMX_ERRORTYPE OMXBase_ProcessCmdEvent(OMX_HANDLETYPE hComponent,
225 OMX_COMMANDTYPE Cmd,
226 OMX_U32 nParam,
227 OMX_PTR pCmdData)
228{
229 OMX_ERRORTYPE eError = OMX_ErrorNone;
230 OSAL_ERROR tStatus = OSAL_ErrNone;
231 OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent;
232 OMXBaseComp *pBaseComp = NULL;
233 OMXBaseComp_Pvt *pBaseCompPvt = NULL;
234 OMX_U32 i, nPorts, nStartPortNum;
235 uint32_t retEvents = 0;
236
237 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate;
238 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData;
239 nPorts = pBaseComp->nNumPorts;
240 nStartPortNum = pBaseComp->nMinStartPortIndex;
241
242 switch( Cmd ) {
243 case OMX_CommandStateSet :
244 eError = OMXBase_HandleStateTransition(hComponent, nParam);
245 OMX_CHECK(OMX_ErrorNone == eError, eError);
246 break;
247
248 case OMX_CommandPortDisable :
249 /* Notify to Derived Component here so that derived component
250 receives correct param - ALL or specific port no. */
251 eError = pBaseComp->fpCommandNotify(hComponent,
252 OMX_CommandPortDisable, nParam, pCmdData);
253 OMX_CHECK(OMX_ErrorNone == eError, eError);
254
255 tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent,
256 OMXBase_CmdPortDisable, OSAL_EVENT_OR_CONSUME,
257 &retEvents, OSAL_SUSPEND);
258 OMX_CHECK(OSAL_ErrNone == tStatus,
259 OMX_ErrorInsufficientResources);
260 if( nParam == OMX_ALL ) {
261 for( i = nStartPortNum; i < nPorts; i++ ) {
262 eError = OMXBase_DisablePort(hComponent, i);
263 OMX_CHECK(OMX_ErrorNone == eError, eError);
264 }
265 } else {
266 eError = OMXBase_DisablePort(hComponent, nParam);
267 OMX_CHECK(OMX_ErrorNone == eError, eError);
268 }
269 break;
270
271 case OMX_CommandPortEnable :
272 /* Notify to Derived Component here so that derived component
273 receives correct param - ALL or specific port no. */
274 eError = pBaseComp->fpCommandNotify(hComponent,
275 OMX_CommandPortEnable, nParam, pCmdData);
276 OMX_CHECK(OMX_ErrorNone == eError, eError);
277 tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent,
278 OMXBase_CmdPortEnable, OSAL_EVENT_OR_CONSUME,
279 &retEvents, OSAL_SUSPEND);
280 OMX_CHECK(OSAL_ErrNone == tStatus,
281 OMX_ErrorInsufficientResources);
282 if( nParam == OMX_ALL ) {
283 for( i = nStartPortNum; i < nPorts; i++ ) {
284 eError = OMXBase_EnablePort(hComponent, i);
285 OMX_CHECK(OMX_ErrorNone == eError, eError);
286 }
287 } else {
288 eError = OMXBase_EnablePort(hComponent, nParam);
289 OMX_CHECK(OMX_ErrorNone == eError, eError);
290 }
291 break;
292
293 case OMX_CommandFlush :
294 if( pBaseComp->tCurState == OMX_StateLoaded ||
295 pBaseComp->tCurState == OMX_StateWaitForResources ) {
296 } else if((nParam != OMX_ALL) && (pBaseComp->pPorts
297 [nParam - nStartPortNum]->sPortDef.bEnabled == OMX_FALSE)) {
298 /*Nothing to be done for disabled port, just exit*/
299 } else {
300 /* Notify to Derived Component here so that derived component
301 receives correct param - ALL or specific port no. */
302 eError = pBaseComp->fpCommandNotify(hComponent,
303 OMX_CommandFlush, nParam, pCmdData);
304 OMX_CHECK(OMX_ErrorNone == eError, eError);
305 tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent,
306 OMXBase_CmdFlush, OSAL_EVENT_OR_CONSUME,
307 &retEvents, OSAL_SUSPEND);
308 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources);
309 if( nParam == OMX_ALL ) {
310 for( i = nStartPortNum; i < nPorts; i++ ) {
311 eError = OMXBase_FlushBuffers(hComponent, i);
312 OMX_CHECK(OMX_ErrorNone == eError, eError);
313 }
314 } else {
315 eError = OMXBase_FlushBuffers(hComponent, nParam);
316 OMX_CHECK(OMX_ErrorNone == eError, eError);
317 }
318 }
319 break;
320
321 case OMX_CommandMarkBuffer :
322 eError = pBaseComp->fpCommandNotify(hComponent, Cmd,
323 nParam, pCmdData);
324 OMX_CHECK(OMX_ErrorNone == eError, eError);
325 break;
326
327 default :
328 OSAL_ErrorTrace(" unknown command received ");
329 break;
330 }
331
332 eError = OMXBase_EventNotifyToClient(hComponent, Cmd, nParam, pCmdData);
333 OMX_CHECK(OMX_ErrorNone == eError, eError);
334
335EXIT:
336 return (eError);
337}
338
339/*
340* OMX Base Process Data Event
341*/
342static OMX_ERRORTYPE OMXBase_ProcessDataEvent(OMX_HANDLETYPE hComponent)
343{
344 OMX_ERRORTYPE eError = OMX_ErrorNone;
345 OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent;
346 OMXBaseComp *pBaseComp = NULL;
347
348 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate;
349 eError = pBaseComp->fpDataNotify(hComponent);
350 OMX_CHECK(OMX_ErrorNone == eError, eError);
351
352EXIT:
353 return (eError);
354}
355