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 |
|
17 #include "omxildummyaudiodec.h" |
|
18 #include "iltestuids.hrh" |
|
19 #include <openmax/il/loader/omxilsymbiancomponentif.h> |
|
20 #include <mmf/server/mmfdatabuffer.h> |
|
21 |
|
22 _LIT8(KDummyDecoderILComponentName,"OMX.SYMBIAN.AUDIO.DECODER.DUMMY"); |
|
23 const TInt KMaxComponentNameLength = 128; |
|
24 |
|
25 OMXIL_COMPONENT_ECOM_ENTRYPOINT(KUidOmxILDummyAudioDec); |
|
26 |
|
27 const TUint32 KOMXALL = 0xFFFFFFFF; |
|
28 |
|
29 const TInt KMaxComponentRoleLength = 128; |
|
30 |
|
31 const TInt KIndexInputPort = 0; |
|
32 const TInt KIndexOutputPort = 1; |
|
33 |
|
34 // Set some dummy input and output buffer sizes |
|
35 const TInt KDummyDecoderInputBufferSize = 0x2000; |
|
36 const TInt KDummyDecoderOutputBufferSize = 0x4000; |
|
37 |
|
38 //_LIT(KDummyDecoder, "DummyDecoder"); |
|
39 |
|
40 |
|
41 |
|
42 TInt COmxIlDummyAudioDec::CreateComponent(OMX_HANDLETYPE hComponent) |
|
43 { |
|
44 COmxIlDummyAudioDec* self = new COmxIlDummyAudioDec(hComponent); |
|
45 if (self==NULL) |
|
46 { |
|
47 return KErrNoMemory; |
|
48 |
|
49 } |
|
50 else |
|
51 { |
|
52 return KErrNone; |
|
53 } |
|
54 } |
|
55 |
|
56 OMX_ERRORTYPE COmxIlDummyAudioDec::GetComponentVersion( |
|
57 OMX_STRING pComponentName, |
|
58 OMX_VERSIONTYPE* pComponentVersion, |
|
59 OMX_VERSIONTYPE* pSpecVersion, |
|
60 OMX_UUIDTYPE* pComponentUUID) |
|
61 { |
|
62 TPtr8 name(reinterpret_cast<TUint8*>(pComponentName), |
|
63 KMaxComponentNameLength); |
|
64 name.Copy(KDummyDecoderILComponentName); |
|
65 name.PtrZ(); |
|
66 |
|
67 OMX_VERSIONTYPE compVer = { 1,0,0,0 }; |
|
68 OMX_VERSIONTYPE specVer = { 1,1,1,0 }; |
|
69 |
|
70 (*pComponentVersion) = compVer; |
|
71 (*pSpecVersion) = specVer; |
|
72 |
|
73 TPtr8 thisUid(reinterpret_cast<TUint8*>(*pComponentUUID), 128); //Maxsize fixed by Khronos; |
|
74 thisUid = TPtr8(reinterpret_cast<TUint8*>(this), sizeof(TUint32)); |
|
75 |
|
76 return OMX_ErrorNone; |
|
77 } |
|
78 |
|
79 |
|
80 COmxIlDummyAudioDec::COmxIlDummyAudioDec(OMX_HANDLETYPE hComponent) |
|
81 :COmxComponentImpl(hComponent) |
|
82 { |
|
83 iState = OMX_StateLoaded; |
|
84 } |
|
85 |
|
86 COmxIlDummyAudioDec::~COmxIlDummyAudioDec() |
|
87 { |
|
88 if (iState == OMX_StateExecuting) |
|
89 { |
|
90 iState = OMX_StateIdle; |
|
91 } |
|
92 } |
|
93 |
|
94 OMX_ERRORTYPE COmxIlDummyAudioDec::SendCommand( |
|
95 OMX_COMMANDTYPE Cmd, |
|
96 TUint32 nParam1, |
|
97 TAny* /*pCmdData*/) |
|
98 { |
|
99 OMX_ERRORTYPE error = OMX_ErrorNone; |
|
100 switch (Cmd) |
|
101 { |
|
102 case OMX_CommandStateSet: |
|
103 { |
|
104 OMX_STATETYPE state = (OMX_STATETYPE)nParam1; |
|
105 if (state == iState) |
|
106 { |
|
107 error = OMX_ErrorSameState; |
|
108 } |
|
109 else |
|
110 { |
|
111 // notify client of the state change |
|
112 switch (state) |
|
113 { |
|
114 case OMX_StateIdle: |
|
115 case OMX_StatePause: |
|
116 case OMX_StateExecuting: |
|
117 break; |
|
118 }; |
|
119 iState = state; |
|
120 |
|
121 EventHandlerCallback( |
|
122 OMX_EventCmdComplete, |
|
123 OMX_CommandStateSet, |
|
124 iState, |
|
125 NULL); |
|
126 } |
|
127 break; |
|
128 } |
|
129 |
|
130 case OMX_CommandFlush: |
|
131 { |
|
132 if(nParam1 == KOMXALL) |
|
133 { |
|
134 EventHandlerCallback( |
|
135 OMX_EventCmdComplete, |
|
136 OMX_CommandFlush, |
|
137 0, |
|
138 NULL); |
|
139 |
|
140 EventHandlerCallback( |
|
141 OMX_EventCmdComplete, |
|
142 OMX_CommandFlush, |
|
143 1, |
|
144 NULL); |
|
145 } |
|
146 else |
|
147 { |
|
148 EventHandlerCallback( |
|
149 OMX_EventCmdComplete, |
|
150 OMX_CommandFlush, |
|
151 nParam1, |
|
152 NULL); |
|
153 } |
|
154 |
|
155 break; |
|
156 } |
|
157 case OMX_CommandPortDisable: |
|
158 { |
|
159 if(nParam1 == KOMXALL) |
|
160 { |
|
161 EventHandlerCallback( |
|
162 OMX_EventCmdComplete, |
|
163 OMX_CommandPortDisable, |
|
164 0, |
|
165 NULL); |
|
166 |
|
167 EventHandlerCallback( |
|
168 OMX_EventCmdComplete, |
|
169 OMX_CommandPortDisable, |
|
170 1, |
|
171 NULL); |
|
172 } |
|
173 else |
|
174 { |
|
175 EventHandlerCallback( |
|
176 OMX_EventCmdComplete, |
|
177 OMX_CommandPortDisable, |
|
178 nParam1, |
|
179 NULL); |
|
180 } |
|
181 break; |
|
182 } |
|
183 } |
|
184 return error; |
|
185 } |
|
186 |
|
187 OMX_ERRORTYPE COmxIlDummyAudioDec::GetParameter( |
|
188 OMX_INDEXTYPE nParamIndex, |
|
189 TAny* ComponentParameterStructure) |
|
190 { |
|
191 switch (nParamIndex) |
|
192 { |
|
193 case OMX_IndexParamAudioInit : |
|
194 { |
|
195 OMX_PORT_PARAM_TYPE* param = static_cast<OMX_PORT_PARAM_TYPE*>(ComponentParameterStructure); |
|
196 param->nPorts = 2; |
|
197 } |
|
198 break; |
|
199 case OMX_IndexParamPortDefinition: |
|
200 { |
|
201 OMX_PARAM_PORTDEFINITIONTYPE* portDef = static_cast<OMX_PARAM_PORTDEFINITIONTYPE*>(ComponentParameterStructure); |
|
202 if (portDef->nPortIndex==0) |
|
203 { |
|
204 portDef->eDir = OMX_DirInput; |
|
205 portDef->nBufferSize = KDummyDecoderInputBufferSize; |
|
206 portDef->nBufferCountActual = iBufferCountActual0; |
|
207 } |
|
208 else |
|
209 { |
|
210 portDef->eDir = OMX_DirOutput; |
|
211 portDef->nBufferSize = KDummyDecoderOutputBufferSize; |
|
212 portDef->nBufferCountActual = iBufferCountActual1; |
|
213 } |
|
214 } |
|
215 break; |
|
216 default: |
|
217 return OMX_ErrorUnsupportedIndex; |
|
218 } |
|
219 return OMX_ErrorNone; |
|
220 } |
|
221 |
|
222 OMX_ERRORTYPE COmxIlDummyAudioDec::SetParameter( |
|
223 OMX_INDEXTYPE nIndex, |
|
224 TAny* ComponentParameterStructure) |
|
225 { |
|
226 ASSERT(iState == OMX_StateLoaded); |
|
227 switch (nIndex) |
|
228 { |
|
229 case OMX_IndexParamAudioVorbis: |
|
230 { |
|
231 // Fake this is Audio Vorbis decoder for the purpose of testing |
|
232 OMX_AUDIO_PARAM_VORBISTYPE* param = static_cast<OMX_AUDIO_PARAM_VORBISTYPE*>(ComponentParameterStructure); |
|
233 switch(param->nPortIndex) |
|
234 { |
|
235 case 0: // Input port |
|
236 { |
|
237 // nothing to set |
|
238 return OMX_ErrorNone; |
|
239 } |
|
240 case 1: // Output port |
|
241 default: |
|
242 { |
|
243 return OMX_ErrorUnsupportedIndex; |
|
244 } |
|
245 }; |
|
246 } |
|
247 case OMX_IndexParamAudioPcm: |
|
248 { |
|
249 OMX_AUDIO_PARAM_PCMMODETYPE* param = static_cast<OMX_AUDIO_PARAM_PCMMODETYPE*>(ComponentParameterStructure); |
|
250 switch(param->nPortIndex) |
|
251 { |
|
252 case 1: // Output port = PCM |
|
253 { |
|
254 return OMX_ErrorNone; |
|
255 } |
|
256 case 0: // Input port |
|
257 default: |
|
258 { |
|
259 return OMX_ErrorUnsupportedIndex; |
|
260 } |
|
261 }; |
|
262 } |
|
263 case OMX_IndexParamPortDefinition: |
|
264 { |
|
265 OMX_PARAM_PORTDEFINITIONTYPE* portDef = static_cast<OMX_PARAM_PORTDEFINITIONTYPE*>(ComponentParameterStructure); |
|
266 if (portDef->nPortIndex==0) |
|
267 { |
|
268 iBufferCountActual0 = portDef->nBufferCountActual; |
|
269 } |
|
270 else |
|
271 { |
|
272 iBufferCountActual1 = portDef->nBufferCountActual; |
|
273 } |
|
274 return OMX_ErrorNone; |
|
275 } |
|
276 default: |
|
277 { |
|
278 return OMX_ErrorUnsupportedIndex; |
|
279 } |
|
280 }; |
|
281 } |
|
282 |
|
283 OMX_ERRORTYPE COmxIlDummyAudioDec::GetConfig( |
|
284 OMX_INDEXTYPE /*nIndex*/, |
|
285 TAny* /*value*/) |
|
286 { |
|
287 return OMX_ErrorUnsupportedIndex; |
|
288 } |
|
289 |
|
290 OMX_ERRORTYPE COmxIlDummyAudioDec::SetConfig( |
|
291 OMX_INDEXTYPE /*nIndex*/, |
|
292 TAny* /*value*/) |
|
293 { |
|
294 return OMX_ErrorUnsupportedIndex; |
|
295 } |
|
296 |
|
297 OMX_ERRORTYPE COmxIlDummyAudioDec::GetExtensionIndex( |
|
298 OMX_STRING /*parameterName*/, |
|
299 OMX_INDEXTYPE* pIndexType) |
|
300 { |
|
301 // This test component returns always OMX_IndexParamPortDefinition |
|
302 *pIndexType = OMX_IndexParamPortDefinition; |
|
303 |
|
304 return OMX_ErrorNone; |
|
305 } |
|
306 |
|
307 OMX_ERRORTYPE COmxIlDummyAudioDec::GetState( |
|
308 OMX_STATETYPE* pState) |
|
309 { |
|
310 *pState = iState; |
|
311 return OMX_ErrorNone; |
|
312 } |
|
313 |
|
314 // To be implemented for DM4 |
|
315 OMX_ERRORTYPE COmxIlDummyAudioDec::ComponentTunnelRequest( |
|
316 OMX_HANDLETYPE /*hInput*/, |
|
317 TUint32 /*nInputPort*/, |
|
318 OMX_HANDLETYPE /*hOutput*/, |
|
319 TUint32 /*nOutputPort*/, |
|
320 OMX_TUNNELSETUPTYPE* /*pTunnelSetup*/) |
|
321 { |
|
322 |
|
323 // Fake everything as if it went fine |
|
324 return OMX_ErrorNone; |
|
325 } |
|
326 |
|
327 OMX_ERRORTYPE COmxIlDummyAudioDec::UseBuffer( |
|
328 OMX_BUFFERHEADERTYPE** ppBufferHeader, |
|
329 TUint32 nPortIndex, |
|
330 TAny* pAppPrivate, |
|
331 TUint32 nSizeBytes, |
|
332 TUint8* pBuffer) |
|
333 { |
|
334 ASSERT(iState == OMX_StateLoaded); |
|
335 *ppBufferHeader = new OMX_BUFFERHEADERTYPE; |
|
336 if (*ppBufferHeader != NULL) |
|
337 { |
|
338 (*ppBufferHeader)->pBuffer = pBuffer; |
|
339 (*ppBufferHeader)->pAppPrivate = pAppPrivate; |
|
340 (*ppBufferHeader)->nAllocLen = nSizeBytes; |
|
341 (*ppBufferHeader)->nFilledLen = 0; |
|
342 (*ppBufferHeader)->nFlags = 0; |
|
343 (*ppBufferHeader)->pInputPortPrivate = NULL; |
|
344 (*ppBufferHeader)->pOutputPortPrivate = NULL; |
|
345 } |
|
346 |
|
347 |
|
348 |
|
349 if (*ppBufferHeader) |
|
350 { |
|
351 TPtr8 ptr(pBuffer,nSizeBytes,nSizeBytes); |
|
352 CMMFBuffer* buffer = NULL; |
|
353 TRAPD(err, buffer = CMMFPtrBuffer::NewL(ptr)); |
|
354 if (err != KErrNone) |
|
355 { |
|
356 return OMX_ErrorInsufficientResources; |
|
357 } |
|
358 switch (nPortIndex) |
|
359 { |
|
360 case KIndexInputPort: |
|
361 { |
|
362 (*ppBufferHeader)->pInputPortPrivate = buffer; |
|
363 (*ppBufferHeader)->nInputPortIndex = nPortIndex; |
|
364 } |
|
365 break; |
|
366 case KIndexOutputPort: |
|
367 { |
|
368 (*ppBufferHeader)->pOutputPortPrivate = buffer; |
|
369 (*ppBufferHeader)->nOutputPortIndex = nPortIndex; |
|
370 } |
|
371 break; |
|
372 |
|
373 } |
|
374 return OMX_ErrorNone; |
|
375 } |
|
376 else |
|
377 { |
|
378 return OMX_ErrorInsufficientResources; |
|
379 } |
|
380 } |
|
381 |
|
382 OMX_ERRORTYPE COmxIlDummyAudioDec::AllocateBuffer( |
|
383 OMX_BUFFERHEADERTYPE** pBuffer, |
|
384 TUint32 nPortIndex, |
|
385 TAny* pAppData, |
|
386 TUint32 nSizeBytes) |
|
387 { |
|
388 ASSERT(iState == OMX_StateLoaded); |
|
389 |
|
390 *pBuffer = new OMX_BUFFERHEADERTYPE; |
|
391 if (*pBuffer != NULL) |
|
392 { |
|
393 CMMFDescriptorBuffer* buffer = NULL; |
|
394 TRAPD(err, buffer = CMMFDescriptorBuffer::NewL(nSizeBytes)); |
|
395 if (err != KErrNone) |
|
396 { |
|
397 return OMX_ErrorInsufficientResources; |
|
398 } |
|
399 (*pBuffer)->pBuffer = const_cast<TUint8*>(buffer->Data().Ptr()); |
|
400 // store our allocated memory in component's private store |
|
401 switch (nPortIndex) |
|
402 { |
|
403 case KIndexInputPort: |
|
404 (*pBuffer)->pInputPortPrivate = buffer; |
|
405 (*pBuffer)->pOutputPortPrivate = NULL; |
|
406 break; |
|
407 case KIndexOutputPort: |
|
408 (*pBuffer)->pOutputPortPrivate = buffer; |
|
409 (*pBuffer)->pInputPortPrivate = NULL; |
|
410 break; |
|
411 }; |
|
412 |
|
413 |
|
414 (*pBuffer)->nAllocLen = nSizeBytes; |
|
415 (*pBuffer)->nFilledLen = 0; |
|
416 (*pBuffer)->pAppPrivate = pAppData; |
|
417 } |
|
418 |
|
419 if (*pBuffer && (*pBuffer)->pBuffer) |
|
420 { |
|
421 return OMX_ErrorNone; |
|
422 } |
|
423 else |
|
424 { |
|
425 return OMX_ErrorInsufficientResources; |
|
426 } |
|
427 } |
|
428 |
|
429 OMX_ERRORTYPE COmxIlDummyAudioDec::FreeBuffer( |
|
430 TUint32 nPortIndex, |
|
431 OMX_BUFFERHEADERTYPE* pBuffer) |
|
432 { |
|
433 switch (nPortIndex) |
|
434 { |
|
435 case KIndexInputPort: |
|
436 { |
|
437 delete (static_cast<CMMFBuffer*>(pBuffer->pInputPortPrivate)); |
|
438 pBuffer->pInputPortPrivate = NULL; |
|
439 break; |
|
440 } |
|
441 case KIndexOutputPort: |
|
442 delete (static_cast<CMMFBuffer*>(pBuffer->pOutputPortPrivate)); |
|
443 pBuffer->pOutputPortPrivate = NULL; |
|
444 break; |
|
445 |
|
446 } |
|
447 delete pBuffer; |
|
448 return OMX_ErrorNone; |
|
449 } |
|
450 OMX_ERRORTYPE COmxIlDummyAudioDec::EmptyThisBuffer( |
|
451 OMX_BUFFERHEADERTYPE* pBuffer) |
|
452 { |
|
453 ASSERT(iState == OMX_StateExecuting || |
|
454 iState == OMX_StateIdle || |
|
455 iState == OMX_StatePause); |
|
456 EmptyBufferDoneCallback(pBuffer); |
|
457 return OMX_ErrorNone; |
|
458 } |
|
459 OMX_ERRORTYPE COmxIlDummyAudioDec::FillThisBuffer( |
|
460 OMX_BUFFERHEADERTYPE* pBuffer) |
|
461 { |
|
462 ASSERT(iState == OMX_StateExecuting || |
|
463 iState == OMX_StateIdle || |
|
464 iState == OMX_StatePause); |
|
465 |
|
466 FillBufferDoneCallback(pBuffer); |
|
467 return OMX_ErrorNone; |
|
468 } |
|
469 |
|
470 OMX_ERRORTYPE COmxIlDummyAudioDec::SetCallbacks( |
|
471 OMX_CALLBACKTYPE* pCallbacks, |
|
472 TAny* pAppData) |
|
473 { |
|
474 iCallback = pCallbacks; |
|
475 iAppData = pAppData; |
|
476 return OMX_ErrorNone; |
|
477 } |
|
478 |
|
479 OMX_ERRORTYPE COmxIlDummyAudioDec::ComponentRoleEnum( |
|
480 OMX_OUT OMX_U8 *aRole, |
|
481 OMX_IN OMX_U32 aIndex) |
|
482 { |
|
483 _LIT8(KFakeRole,"audio_decoder.vrb"); |
|
484 |
|
485 if (aIndex == 0) |
|
486 { |
|
487 TPtr8 ptr((TUint8*)aRole, 0, KMaxComponentRoleLength); |
|
488 ptr.Copy(KFakeRole); |
|
489 ptr.PtrZ(); |
|
490 |
|
491 return OMX_ErrorNone; |
|
492 } |
|
493 else |
|
494 { |
|
495 return OMX_ErrorBadParameter; |
|
496 } |
|
497 } |
|
498 |
|
499 // Callbacks for the Dummy Audio Decoder |
|
500 void COmxIlDummyAudioDec::EventHandlerCallback( |
|
501 OMX_OUT OMX_EVENTTYPE eEvent, |
|
502 OMX_OUT TUint32 nData1, |
|
503 OMX_OUT TUint32 nData2, |
|
504 OMX_OUT OMX_STRING cExtraInfo) |
|
505 { |
|
506 iCallback->EventHandler( |
|
507 this, |
|
508 iAppData, |
|
509 eEvent, |
|
510 nData1, |
|
511 nData2, |
|
512 cExtraInfo); |
|
513 } |
|
514 |
|
515 void COmxIlDummyAudioDec::FillBufferDoneCallback(OMX_BUFFERHEADERTYPE* aBuffer) |
|
516 { |
|
517 iCallback->FillBufferDone( |
|
518 *this, |
|
519 iAppData, |
|
520 aBuffer); |
|
521 } |
|
522 |
|
523 void COmxIlDummyAudioDec::EmptyBufferDoneCallback(OMX_BUFFERHEADERTYPE* aBuffer) |
|
524 { |
|
525 iCallback->EmptyBufferDone( |
|
526 *this, |
|
527 iAppData, |
|
528 aBuffer); |
|
529 } |
|
530 |
|
531 // Component Entry Point |
|
532 OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) |
|
533 { |
|
534 TInt err = COmxIlDummyAudioDec::CreateComponent(hComponent); |
|
535 if (err == KErrNone) |
|
536 return OMX_ErrorNone; |
|
537 else |
|
538 { |
|
539 // return some problem |
|
540 return OMX_ErrorInsufficientResources; |
|
541 |
|
542 } |
|
543 } |
|
544 |
|