|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "omxildummybaseilifbody.h" |
|
17 #include "omxilcoreutils.h" |
|
18 #include "omxilspecversion.h" |
|
19 #include "milifobserver.h" |
|
20 #include "tilstructtypes.h" |
|
21 |
|
22 |
|
23 const TInt KMaxComponentNameLength = 128; |
|
24 |
|
25 |
|
26 COmxILDummyBaseILIF::CBody::CBody(COmxILDummyBaseILIF& aParent, |
|
27 MILIfObserver& aComponentIfObserver) |
|
28 : |
|
29 iParent(aParent), |
|
30 iIfObserver(aComponentIfObserver) |
|
31 { |
|
32 } |
|
33 |
|
34 COmxILDummyBaseILIF::CBody::~CBody() |
|
35 { |
|
36 iInputPorts.ResetAndDestroy(); |
|
37 iInputPorts.Close(); |
|
38 iOutputPorts.ResetAndDestroy(); |
|
39 iOutputPorts.Close(); |
|
40 delete iBufferManager; |
|
41 delete iCallbacks; |
|
42 |
|
43 ::OMX_FreeHandle(reinterpret_cast<OMX_HANDLETYPE>(iHandle)); |
|
44 } |
|
45 |
|
46 COmxILDummyBaseILIF::CBody* COmxILDummyBaseILIF::CBody::NewL(COmxILDummyBaseILIF& aParent, |
|
47 MILIfObserver& aComponentIfObserver, |
|
48 const TDesC8& aComponentName) |
|
49 { |
|
50 CBody* self = new (ELeave) CBody(aParent, aComponentIfObserver); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(aComponentName); |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 void COmxILDummyBaseILIF::CBody::ConstructL(const TDesC8& aComponentName) |
|
58 { |
|
59 iCallbacks = COmxCallbacks::NewL(iParent); |
|
60 |
|
61 RBuf8 buf; |
|
62 buf.CleanupClosePushL(); |
|
63 buf.CreateL(aComponentName, KMaxComponentNameLength); |
|
64 TUint8* name = const_cast<TUint8*>(buf.PtrZ()); |
|
65 |
|
66 OMX_ERRORTYPE errorType = ::OMX_GetHandle(reinterpret_cast<OMX_HANDLETYPE*>(&iHandle), |
|
67 reinterpret_cast<OMX_STRING>(name), |
|
68 iCallbacks, |
|
69 *iCallbacks); |
|
70 CleanupStack::PopAndDestroy(&buf); |
|
71 |
|
72 User::LeaveIfError(ConvertOmxErrorType(errorType)); |
|
73 |
|
74 iBufferManager = new (ELeave) COmxBufferManager(iHandle); |
|
75 } |
|
76 |
|
77 OMX_COMPONENTTYPE* COmxILDummyBaseILIF::CBody::Handle() const |
|
78 { |
|
79 return iHandle; |
|
80 } |
|
81 |
|
82 TInt COmxILDummyBaseILIF::CBody::OmxGetComponentVersion(TPtr8 aComponentName, |
|
83 OMX_VERSIONTYPE* aComponentVersion, |
|
84 OMX_VERSIONTYPE* aSpecVersion, |
|
85 OMX_UUIDTYPE* aComponentUUID) |
|
86 { |
|
87 ASSERT(aComponentVersion); |
|
88 ASSERT(aSpecVersion); |
|
89 ASSERT(aComponentUUID); |
|
90 TUint8* cname = const_cast<TUint8*>(aComponentName.PtrZ()); |
|
91 OMX_ERRORTYPE error = iHandle->GetComponentVersion(reinterpret_cast<OMX_HANDLETYPE>(iHandle), |
|
92 reinterpret_cast<OMX_STRING>(cname), aComponentVersion, aSpecVersion, aComponentUUID); |
|
93 |
|
94 TLex8 lex(cname); |
|
95 TInt length; |
|
96 for( length = 0; !lex.Eos(); ++length ) |
|
97 { |
|
98 lex.Inc(); |
|
99 } |
|
100 aComponentName.SetLength(length); |
|
101 return ConvertOmxErrorType(error); |
|
102 } |
|
103 |
|
104 TInt COmxILDummyBaseILIF::CBody::OmxSendCommand(OMX_COMMANDTYPE aCmd, |
|
105 TUint32 aParam, |
|
106 TAny* aCmdData) |
|
107 { |
|
108 OMX_ERRORTYPE error = iHandle->SendCommand(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aCmd, aParam, aCmdData); |
|
109 return ConvertOmxErrorType(error); |
|
110 } |
|
111 |
|
112 TInt COmxILDummyBaseILIF::CBody::OmxGetParameter(OMX_INDEXTYPE aParamIndex, |
|
113 TAny* aValue) |
|
114 { |
|
115 ASSERT(aValue); |
|
116 OMX_ERRORTYPE error = iHandle->GetParameter(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aParamIndex, aValue); |
|
117 return ConvertOmxErrorType(error); |
|
118 } |
|
119 |
|
120 TInt COmxILDummyBaseILIF::CBody::OmxSetParameter(OMX_INDEXTYPE aIndex, |
|
121 TAny* aValue) |
|
122 { |
|
123 ASSERT(aValue); |
|
124 OMX_ERRORTYPE error = iHandle->SetParameter(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aIndex, aValue); |
|
125 return ConvertOmxErrorType(error); |
|
126 } |
|
127 |
|
128 TInt COmxILDummyBaseILIF::CBody::OmxGetConfig(OMX_INDEXTYPE aIndex, |
|
129 TAny* aValue) |
|
130 { |
|
131 ASSERT(aValue); |
|
132 OMX_ERRORTYPE error = iHandle->GetConfig(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aIndex, aValue); |
|
133 return ConvertOmxErrorType(error); |
|
134 } |
|
135 |
|
136 TInt COmxILDummyBaseILIF::CBody::OmxSetConfig(OMX_INDEXTYPE aIndex, |
|
137 TAny* aValue) |
|
138 { |
|
139 ASSERT(aValue); |
|
140 OMX_ERRORTYPE error = iHandle->SetConfig(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aIndex, aValue); |
|
141 return ConvertOmxErrorType(error); |
|
142 } |
|
143 |
|
144 TInt COmxILDummyBaseILIF::CBody::OmxGetExtensionIndex(const TDesC8& aParameterName, |
|
145 OMX_INDEXTYPE* aIndexType) |
|
146 { |
|
147 HBufC8* buf = HBufC8::New(aParameterName.Length()+1); |
|
148 if (buf == NULL) |
|
149 { |
|
150 return KErrNoMemory; |
|
151 } |
|
152 else |
|
153 { |
|
154 *buf = aParameterName; |
|
155 TUint8* cstring = const_cast<TUint8*>(buf->Des().PtrZ()); |
|
156 OMX_ERRORTYPE error = iHandle->GetExtensionIndex(reinterpret_cast<OMX_HANDLETYPE>(iHandle), reinterpret_cast<char*>(cstring), aIndexType); |
|
157 delete buf; |
|
158 return ConvertOmxErrorType(error); |
|
159 } |
|
160 } |
|
161 |
|
162 TInt COmxILDummyBaseILIF::CBody::OmxGetState(OMX_STATETYPE* aState) |
|
163 { |
|
164 OMX_ERRORTYPE error = iHandle->GetState(reinterpret_cast<OMX_HANDLETYPE>(iHandle), aState); |
|
165 return ConvertOmxErrorType(error); |
|
166 } |
|
167 |
|
168 TInt COmxILDummyBaseILIF::CBody::OmxComponentTunnelRequest(TUint32 aPortInput, |
|
169 OMX_HANDLETYPE aOutput, |
|
170 TUint32 aPortOutput) |
|
171 { |
|
172 OMX_ERRORTYPE error = ::OMX_SetupTunnel(aOutput, aPortOutput, reinterpret_cast<OMX_HANDLETYPE>(iHandle), aPortInput); |
|
173 return ConvertOmxErrorType(error); |
|
174 } |
|
175 |
|
176 TInt COmxILDummyBaseILIF::CBody::OmxComponentDisconnectTunnel(TUint32 aPortInput, |
|
177 OMX_HANDLETYPE aOutput, |
|
178 TUint32 aPortOutput) |
|
179 { |
|
180 OMX_ERRORTYPE error = ::OMX_SetupTunnel(aOutput, aPortOutput, 0, 0); |
|
181 if (error == OMX_ErrorNone) |
|
182 { |
|
183 error = ::OMX_SetupTunnel(0, 0, reinterpret_cast<OMX_HANDLETYPE>(iHandle), aPortInput); |
|
184 } |
|
185 return ConvertOmxErrorType(error); |
|
186 } |
|
187 |
|
188 TInt COmxILDummyBaseILIF::CBody::OmxUseBuffer(CMMFBuffer* aBuffer, |
|
189 TUint32 aPortIndex) |
|
190 { |
|
191 ASSERT(aBuffer); |
|
192 return (iBufferManager->UseBuffer(*aBuffer, aPortIndex)); |
|
193 } |
|
194 |
|
195 CMMFBuffer* COmxILDummyBaseILIF::CBody::OmxAllocateBufferL(TUint32 aPortIndex, |
|
196 TUint32 aSizeBytes) |
|
197 { |
|
198 return (iBufferManager->AllocateBufferL(aPortIndex, aSizeBytes)); |
|
199 } |
|
200 |
|
201 TInt COmxILDummyBaseILIF::CBody::OmxFreeBuffer(CMMFBuffer* aBuffer) |
|
202 { |
|
203 ASSERT(aBuffer); |
|
204 return (iBufferManager->FreeBuffer(aBuffer)); |
|
205 } |
|
206 |
|
207 TInt COmxILDummyBaseILIF::CBody::OmxEmptyThisBuffer(const CMMFBuffer* aBuffer, |
|
208 MOmxILComponentIfObserver* aObserver) |
|
209 { |
|
210 ASSERT(aBuffer); |
|
211 return (iBufferManager->EmptyThisBuffer(aBuffer, aObserver)); |
|
212 } |
|
213 |
|
214 TInt COmxILDummyBaseILIF::CBody::OmxFillThisBuffer(CMMFBuffer* aBuffer, |
|
215 MOmxILComponentIfObserver* aObserver) |
|
216 { |
|
217 ASSERT(aBuffer); |
|
218 return (iBufferManager->FillThisBuffer(aBuffer, aObserver)); |
|
219 } |
|
220 |
|
221 TInt COmxILDummyBaseILIF::CBody::OmxComponentRoleEnum(TPtr8& aComponentRole, |
|
222 TUint32 aIndex) |
|
223 { |
|
224 TUint8* role = const_cast<TUint8*> (aComponentRole.PtrZ()); |
|
225 OMX_ERRORTYPE error = iHandle->ComponentRoleEnum(reinterpret_cast<OMX_HANDLETYPE>(iHandle), reinterpret_cast<unsigned char*>(role), aIndex); |
|
226 |
|
227 TLex8 lex(role); |
|
228 TInt length; |
|
229 for( length = 0; !lex.Eos(); ++length ) |
|
230 { |
|
231 lex.Inc(); |
|
232 } |
|
233 aComponentRole.SetLength(length); |
|
234 |
|
235 return ConvertOmxErrorType(error); |
|
236 } |
|
237 |
|
238 TInt COmxILDummyBaseILIF::CBody::SetIfToRole(const TUid& aComponentRole) |
|
239 { |
|
240 iFormat = aComponentRole; |
|
241 return KErrNone; |
|
242 } |
|
243 |
|
244 TInt COmxILDummyBaseILIF::CBody::GetIfRole(TUid& aComponentRole) const |
|
245 { |
|
246 aComponentRole = iFormat; |
|
247 return KErrNone; |
|
248 } |
|
249 |
|
250 TInt COmxILDummyBaseILIF::CBody::SetPortsL() |
|
251 { |
|
252 OMX_PORT_PARAM_TYPE param; |
|
253 param.nVersion = KOMXILSpecVersion; |
|
254 param.nSize = sizeof(OMX_PORT_PARAM_TYPE); |
|
255 TInt err = OmxGetParameter(OMX_IndexParamAudioInit, ¶m); |
|
256 |
|
257 if (err == KErrNone) |
|
258 { |
|
259 for (TInt i=0; i < param.nPorts && err == KErrNone; i++ ) |
|
260 { |
|
261 OMX_PARAM_PORTDEFINITIONTYPE portInfo; |
|
262 portInfo.nPortIndex = i; |
|
263 portInfo.nVersion = KOMXILSpecVersion; |
|
264 portInfo.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); |
|
265 err = OmxGetParameter(OMX_IndexParamPortDefinition, &portInfo); |
|
266 if (err == KErrNone) |
|
267 { |
|
268 if (portInfo.eDir == OMX_DirInput) |
|
269 { |
|
270 COmxILDummyBasePortILIF* inputPort = COmxILDummyBasePortILIF::NewL(iParent, EDirInput, portInfo.nPortIndex); |
|
271 err = iInputPorts.Append(inputPort); |
|
272 } |
|
273 else |
|
274 { |
|
275 COmxILDummyBasePortILIF* outputPort = COmxILDummyBasePortILIF::NewL(iParent, EDirOutput, portInfo.nPortIndex); |
|
276 err = iOutputPorts.Append(outputPort); |
|
277 } |
|
278 } |
|
279 } |
|
280 } |
|
281 return err; |
|
282 } |
|
283 |
|
284 TInt COmxILDummyBaseILIF::CBody::GetComponentPorts(RPointerArray<MILComponentPortIf>& aComponentPorts, |
|
285 OMX_DIRTYPE aDirection) |
|
286 { |
|
287 TInt err = KErrNone; |
|
288 if (aDirection == OMX_DirInput) |
|
289 { |
|
290 const TInt counter = iInputPorts.Count(); |
|
291 for (TInt i=0; i < counter && err == KErrNone; i++ ) |
|
292 { |
|
293 err = aComponentPorts.Append(iInputPorts[i]); |
|
294 } |
|
295 } |
|
296 else if (aDirection == OMX_DirOutput) |
|
297 { |
|
298 const TInt counter = iOutputPorts.Count(); |
|
299 for (TInt i=0; i < counter && err == KErrNone; i++ ) |
|
300 { |
|
301 err = aComponentPorts.Append(iOutputPorts[i]); |
|
302 } |
|
303 } |
|
304 else |
|
305 { |
|
306 err = KErrNotSupported; |
|
307 } |
|
308 return err; |
|
309 } |
|
310 |
|
311 TInt COmxILDummyBaseILIF::CBody::FillBufferDone(CMMFBuffer* aBuffer, |
|
312 TInt aPortIndex) |
|
313 { |
|
314 ASSERT(aBuffer); |
|
315 // Loop through all output ports to search for the interface associated to this port index |
|
316 const TInt counter = iOutputPorts.Count(); |
|
317 for (TInt i=0; i < counter; i++ ) |
|
318 { |
|
319 if (iOutputPorts[i]->PortIndex() == aPortIndex) |
|
320 { |
|
321 return (iIfObserver.BufferDelivered(iOutputPorts[i], aBuffer)); |
|
322 } |
|
323 } |
|
324 |
|
325 return KErrNotFound; |
|
326 } |
|
327 |
|
328 TInt COmxILDummyBaseILIF::CBody::EmptyBufferDone(const CMMFBuffer* aBuffer, |
|
329 TInt aPortIndex) |
|
330 { |
|
331 ASSERT(aBuffer); |
|
332 // Loop through all input ports to search for the interface associated to this port index |
|
333 const TInt counter = iInputPorts.Count(); |
|
334 for (TInt i=0; i < counter; i++ ) |
|
335 { |
|
336 if (iInputPorts[i]->PortIndex() == aPortIndex) |
|
337 { |
|
338 return (iIfObserver.BufferDelivered(iInputPorts[i], aBuffer)); |
|
339 } |
|
340 } |
|
341 |
|
342 return KErrNotFound; |
|
343 } |
|
344 |
|
345 TInt COmxILDummyBaseILIF::CBody::EventHandler(OMX_EVENTTYPE aEvent, |
|
346 TUint32 aData1, |
|
347 TUint32 aData2, |
|
348 TAny* /*aExtraInfo*/) |
|
349 { |
|
350 TInt err = KErrNone; |
|
351 TILEvent thisEvent; |
|
352 |
|
353 switch (aEvent) |
|
354 { |
|
355 case OMX_EventCmdComplete: |
|
356 { |
|
357 thisEvent.iEvent = EEventCmdComplete; |
|
358 if (aData1 == OMX_CommandStateSet) |
|
359 { |
|
360 thisEvent.iData1 = ECommandStateSet; |
|
361 OMX_STATETYPE state = static_cast<OMX_STATETYPE>(aData2); |
|
362 thisEvent.iData2 = ConvertOmxState(state); |
|
363 err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); |
|
364 break; |
|
365 } |
|
366 else if (aData1 == OMX_CommandFlush) |
|
367 { |
|
368 thisEvent.iData1 = ECommandFlush; |
|
369 thisEvent.iData2 = aData2; // Port index |
|
370 err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); |
|
371 } |
|
372 else if (aData1 == OMX_CommandPortDisable) |
|
373 { |
|
374 thisEvent.iData1 = ECommandPortDisable; |
|
375 thisEvent.iData2 = aData2; // Port index |
|
376 err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); |
|
377 } |
|
378 else if (aData1 == OMX_CommandPortEnable) |
|
379 { |
|
380 thisEvent.iData1 = ECommandPortEnable; |
|
381 thisEvent.iData2 = aData2; // Port index |
|
382 err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); |
|
383 } |
|
384 else |
|
385 { |
|
386 err = KErrNotSupported; |
|
387 } |
|
388 |
|
389 break; |
|
390 } |
|
391 case OMX_EventBufferFlag: |
|
392 { |
|
393 // Propagate the EOF up to client as KErrUnderflow |
|
394 thisEvent.iEvent = EEventBufferFlag; |
|
395 thisEvent.iData1 = aData1; |
|
396 thisEvent.iData2 = static_cast<TUint32>(KErrUnderflow); |
|
397 err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); |
|
398 break; |
|
399 } |
|
400 case OMX_EventError: |
|
401 { |
|
402 // Propagate the error up to client |
|
403 thisEvent.iEvent = EEventError; |
|
404 OMX_ERRORTYPE errorx = static_cast<OMX_ERRORTYPE>(aData1); |
|
405 thisEvent.iData1 = ConvertOmxErrorType(errorx); |
|
406 err = iIfObserver.MsgFromILComponent(&iParent, thisEvent); |
|
407 break; |
|
408 } |
|
409 default: |
|
410 { |
|
411 err = KErrNotSupported; |
|
412 } |
|
413 } |
|
414 return err; |
|
415 } |