|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 */ |
|
23 |
|
24 #include "omxilutil.h" |
|
25 #include "comxilclockprocessingfunction.h" |
|
26 #include "comxilclockcomponent.h" |
|
27 #include "clocksupervisor.h" |
|
28 #include "omxilcallbacknotificationif.h" |
|
29 #include "clockpanics.h" |
|
30 #include "omxilclock.hrh" |
|
31 |
|
32 #include "omxilspecversion.h" |
|
33 |
|
34 |
|
35 OMX_ERRORTYPE SymbianErrorToOmx(TInt aError); |
|
36 |
|
37 COmxILClockProcessingFunction* COmxILClockProcessingFunction::NewL(MOmxILCallbackNotificationIf& aCallbacks, |
|
38 COmxILClockComponent& aComponent) |
|
39 { |
|
40 COmxILClockProcessingFunction* self = new (ELeave) COmxILClockProcessingFunction(aCallbacks, aComponent); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 COmxILClockProcessingFunction::COmxILClockProcessingFunction(MOmxILCallbackNotificationIf& aCallbacks, |
|
48 COmxILClockComponent& aComponent) : |
|
49 COmxILProcessingFunction(aCallbacks), iComponent(aComponent) |
|
50 { |
|
51 } |
|
52 |
|
53 void COmxILClockProcessingFunction::ConstructL() |
|
54 { |
|
55 iClock = CClockSupervisor::NewL(*this); |
|
56 iThreadNotifier = CClockThreadNotifier::NewL(iClock); |
|
57 iThreadNotifier->IssueRequest(); |
|
58 User::LeaveIfError(iBufferMutex.CreateLocal()); |
|
59 // create a buffer queue for each port and add it to the iBufferQueues array |
|
60 for(TInt portIndex = 0; portIndex < KNumPorts; portIndex++) |
|
61 { |
|
62 CCirBuf<OMX_BUFFERHEADERTYPE*>* queue = new(ELeave) CCirBuf<OMX_BUFFERHEADERTYPE*>(); |
|
63 CleanupStack::PushL(queue); |
|
64 iBufferQueues.AppendL(queue); |
|
65 CleanupStack::Pop(queue); |
|
66 } |
|
67 } |
|
68 |
|
69 COmxILClockProcessingFunction::~COmxILClockProcessingFunction() |
|
70 { |
|
71 delete iClock; |
|
72 delete iThreadNotifier; |
|
73 iBufferMutex.Close(); |
|
74 // empty iBufferQueues and delete any CCirBuf objects |
|
75 // the CCirBuf objects don't own any buffers they contain, so we don't delete those here |
|
76 iBufferQueues.ResetAndDestroy(); |
|
77 } |
|
78 |
|
79 OMX_ERRORTYPE COmxILClockProcessingFunction::StateTransitionIndication(COmxILFsm::TStateIndex aNewState) |
|
80 { |
|
81 OMX_ERRORTYPE omxError = OMX_ErrorNone; |
|
82 |
|
83 switch(aNewState) |
|
84 { |
|
85 case COmxILFsm::ESubStateLoadedToIdle: |
|
86 { |
|
87 // allocate space for the buffer queues now the buffer count on each port is known |
|
88 for(TInt portIndex = 0; portIndex < KNumPorts; portIndex++) |
|
89 { |
|
90 TInt length = iComponent.PortBufferCount(portIndex); |
|
91 TRAPD(error, iBufferQueues[portIndex]->SetLengthL(length)); |
|
92 // error not actually a problem if queue was originally longer than we need |
|
93 if(error != KErrNone && iBufferQueues[portIndex]->Length() < length) |
|
94 { |
|
95 omxError = OMX_ErrorInsufficientResources; |
|
96 break; |
|
97 } |
|
98 } |
|
99 break; |
|
100 } |
|
101 |
|
102 case COmxILFsm::EStateExecuting: |
|
103 { |
|
104 iExecuting = ETrue; |
|
105 break; |
|
106 } |
|
107 |
|
108 case COmxILFsm::EStateIdle: |
|
109 { |
|
110 iExecuting = EFalse; |
|
111 break; |
|
112 } |
|
113 |
|
114 case COmxILFsm::EStatePause: |
|
115 { |
|
116 // NOTE we do not change iExecuting |
|
117 // The value of iExecuting maintains the direction from which |
|
118 // Paused was entered (i.e. from Idle or Executing). |
|
119 // This is because we wan't to know whether buffers are available, |
|
120 // regardless of whether we are paused or not. |
|
121 // TODO TBD is there an implicit stopping of the clock (e.g. set scale to 0)? |
|
122 break; |
|
123 } |
|
124 default: |
|
125 { |
|
126 break; |
|
127 } |
|
128 } |
|
129 |
|
130 return omxError; |
|
131 } |
|
132 |
|
133 OMX_ERRORTYPE COmxILClockProcessingFunction::BufferFlushingIndication(TUint32 aPortIndex, |
|
134 OMX_DIRTYPE /*aDirection*/) |
|
135 { |
|
136 __ASSERT_DEBUG(aPortIndex == OMX_ALL || aPortIndex < KNumPorts, Panic(EBufferFlushingInvalidPort)); |
|
137 |
|
138 if (aPortIndex == OMX_ALL || aPortIndex < KNumPorts) |
|
139 { |
|
140 iBufferMutex.Wait(); |
|
141 |
|
142 if (aPortIndex == OMX_ALL) |
|
143 { |
|
144 for (TInt portIndex = 0; portIndex < KNumPorts; portIndex++) |
|
145 { |
|
146 DoBufferFlushingIndication(portIndex); |
|
147 } |
|
148 } |
|
149 else |
|
150 { |
|
151 DoBufferFlushingIndication(aPortIndex); |
|
152 } |
|
153 |
|
154 iBufferMutex.Signal(); |
|
155 } |
|
156 |
|
157 return OMX_ErrorNone; |
|
158 } |
|
159 |
|
160 void COmxILClockProcessingFunction::DoBufferFlushingIndication(TUint32 aPortIndex) |
|
161 { |
|
162 CCirBuf<OMX_BUFFERHEADERTYPE*>& queue = *iBufferQueues[aPortIndex]; |
|
163 |
|
164 while(queue.Count() > 0) |
|
165 { |
|
166 OMX_BUFFERHEADERTYPE* buffer; |
|
167 // ignore error, we just checked Count() > 0 and we have the mutex, so a buffer |
|
168 // should definitely be there |
|
169 queue.Remove(&buffer); |
|
170 OMX_ERRORTYPE error = iCallbacks.BufferDoneNotification(buffer, aPortIndex, OMX_DirOutput); |
|
171 // the callback manager should return OMX_ErrorNone |
|
172 // the callback manager ignores any error code from the callee component since it is the component's responsibility |
|
173 // to respond to errors generated internally |
|
174 __ASSERT_DEBUG(error == OMX_ErrorNone, Panic(ECallbackManagerBufferError)); |
|
175 } |
|
176 } |
|
177 |
|
178 OMX_ERRORTYPE COmxILClockProcessingFunction::ParamIndication(OMX_INDEXTYPE /*aParamIndex*/, |
|
179 const TAny* /*apComponentParameterStructure*/) |
|
180 { |
|
181 return OMX_ErrorNone; |
|
182 } |
|
183 |
|
184 OMX_ERRORTYPE COmxILClockProcessingFunction::ConfigIndication(OMX_INDEXTYPE /*aConfigIndex*/, |
|
185 const TAny* /*apComponentConfigStructure*/) |
|
186 { |
|
187 return OMX_ErrorNone; |
|
188 } |
|
189 |
|
190 OMX_ERRORTYPE COmxILClockProcessingFunction::BufferIndication(OMX_BUFFERHEADERTYPE* apBufferHeader, |
|
191 OMX_DIRTYPE /*aDirection*/) |
|
192 { |
|
193 // add buffer to the appropriate port queue |
|
194 |
|
195 CCirBuf<OMX_BUFFERHEADERTYPE*>& queue = *iBufferQueues[apBufferHeader->nOutputPortIndex]; |
|
196 TOmxILUtil::ClearBufferContents(apBufferHeader); |
|
197 apBufferHeader->nOffset = 0; |
|
198 iBufferMutex.Wait(); |
|
199 TInt added = queue.Add(&apBufferHeader); |
|
200 // don't expect 0 (not added) as total number of buffers is known |
|
201 __ASSERT_DEBUG(added, Panic(EBufferQueueOverflow)); |
|
202 |
|
203 iBufferMutex.Signal(); |
|
204 return OMX_ErrorNone; |
|
205 } |
|
206 |
|
207 /** |
|
208 * Finds and removes an item from a CCirBuf. |
|
209 * NOTE items are NOT guaranteed to be in their original position! |
|
210 * The queue must be protected from concurrent access when calling this |
|
211 * function. |
|
212 * |
|
213 * @param aQueue queue to modify |
|
214 * @param aRemoveItem item to remove |
|
215 * @return ETrue if item was found and removed from the queue, EFalse otherwise. |
|
216 */ |
|
217 template<class T> |
|
218 static TBool RemoveFromPool(CCirBuf<T>&aQueue, T aRemoveItem) |
|
219 { |
|
220 TInt numItems = aQueue.Count(); |
|
221 for(TInt index = 0; index < numItems; index++) |
|
222 { |
|
223 T item; |
|
224 TInt removed = aQueue.Remove(&item); // ignore error since queue cannot be empty (numItems > 0) |
|
225 __ASSERT_DEBUG(removed == 1, Panic(EBufferUnderflow)); |
|
226 if(item == aRemoveItem) |
|
227 { |
|
228 return ETrue; |
|
229 } |
|
230 else |
|
231 { |
|
232 TInt added = aQueue.Add(&item); // ignore error since always space for 1 item as one has just been removed |
|
233 __ASSERT_DEBUG(added == 1, Panic(EBufferQueueOverflow)); |
|
234 } |
|
235 } |
|
236 return EFalse; |
|
237 } |
|
238 |
|
239 OMX_BOOL COmxILClockProcessingFunction::BufferRemovalIndication(OMX_BUFFERHEADERTYPE* apBufferHeader, |
|
240 OMX_DIRTYPE /*aDirection*/) |
|
241 { |
|
242 CCirBuf<OMX_BUFFERHEADERTYPE*>& queue = *iBufferQueues[apBufferHeader->nOutputPortIndex]; |
|
243 iBufferMutex.Wait(); |
|
244 // note queue may be reordered, but that's OK since these are empty buffers |
|
245 TBool removed = RemoveFromPool(queue, apBufferHeader); |
|
246 iBufferMutex.Signal(); |
|
247 |
|
248 return removed ? OMX_TRUE : OMX_FALSE; |
|
249 } |
|
250 |
|
251 /** |
|
252 * Returns a free buffer from the queue for the specified port. |
|
253 * If no buffer is ready, this method returns NULL |
|
254 * This method does not block for a buffer to become available. |
|
255 */ |
|
256 OMX_BUFFERHEADERTYPE* COmxILClockProcessingFunction::AcquireBuffer(TInt aPortIndex) |
|
257 { |
|
258 CCirBuf<OMX_BUFFERHEADERTYPE*>& queue = *iBufferQueues[aPortIndex]; |
|
259 iBufferMutex.Wait(); |
|
260 OMX_BUFFERHEADERTYPE* buffer; |
|
261 TInt count = queue.Remove(&buffer); |
|
262 iBufferMutex.Signal(); |
|
263 if(count > 0) |
|
264 { |
|
265 return buffer; |
|
266 } |
|
267 else |
|
268 { |
|
269 return NULL; |
|
270 } |
|
271 } |
|
272 |
|
273 /** |
|
274 * Sends a buffer out on a port. |
|
275 */ |
|
276 void COmxILClockProcessingFunction::SendBuffer(OMX_BUFFERHEADERTYPE* aBuffer) |
|
277 { |
|
278 OMX_ERRORTYPE error = iCallbacks.BufferDoneNotification(aBuffer, aBuffer->nOutputPortIndex, OMX_DirOutput); |
|
279 // the callback manager should return OMX_ErrorNone |
|
280 // the callback manager ignores any error code from the callee component since it is the component's responsibility |
|
281 // to respond to errors generated internally |
|
282 __ASSERT_DEBUG(error == OMX_ErrorNone, Panic(ECallbackManagerBufferError)); |
|
283 } |
|
284 |
|
285 OMX_ERRORTYPE COmxILClockProcessingFunction::ProduceRequest(OMX_INDEXTYPE aIdx, CClockSupervisor::TEntryPoint aEntryPoint, TAny* pComponentConfigStructure) |
|
286 { |
|
287 return iClock->ProduceRequest(aIdx, aEntryPoint, pComponentConfigStructure); |
|
288 } |
|
289 |
|
290 /** |
|
291 * Returns true iff the specified port is currently enabled. |
|
292 */ |
|
293 TBool COmxILClockProcessingFunction::PortEnabled(TInt aPortIndex) const |
|
294 { |
|
295 return iComponent.PortEnabled(aPortIndex); |
|
296 } |
|
297 |
|
298 TBool COmxILClockProcessingFunction::IsExecuting() const |
|
299 { |
|
300 return iExecuting; |
|
301 } |
|
302 |
|
303 /** |
|
304 * Called when CClockSupervisor encounters a fatal error and needs to transition the |
|
305 * component to OMX_StateInvalid. |
|
306 */ |
|
307 void COmxILClockProcessingFunction::InvalidateComponent() |
|
308 { |
|
309 OMX_ERRORTYPE error = iCallbacks.ErrorEventNotification(OMX_ErrorInvalidState); |
|
310 // the callback manager should return OMX_ErrorNone |
|
311 // the callback manager ignores any error code from the client since it is the client's responsibility to respond |
|
312 // to errors generated internally |
|
313 __ASSERT_DEBUG(error == OMX_ErrorNone, Panic(ECallbackManagerEventError)); |
|
314 // TODO this sends the invalidated event up to the IL client, but does not alter |
|
315 // the internal state of the component to reflect being invalid. It seems you need |
|
316 // access to private, non-exported FsmTransition to do that? |
|
317 } |
|
318 |