Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include <mdf/mdfprocessingunit.h>
23 #include <mmf/common/mmfutilities.h>
25 #include <mdf/codecapiresolverdata.h>
26 #include <mdf/codecapiuids.hrh>
27 #include <mdf/codecapiresolver.hrh>
28 #include <mm/mmcleanup.h>
29 #include <ecom/ecom.h>
31 static const TInt KMaxDataTypeLength = 126;
33 CPuLoader* CPuLoader::NewL()
35 CPuLoader* self = new (ELeave) CPuLoader;
40 CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL(const MMdfProcessingUnitObserver& aProcessingUnitObserver,
41 TUid aImplementationUid)
43 CMdfProcessingUnit* pu = NULL;
44 pu = CMdfProcessingUnit::NewL(aImplementationUid);
45 CleanupStack::PushL(pu);
46 User::LeaveIfError(pu->Create(aProcessingUnitObserver));
47 CleanupStack::Pop(pu);
51 CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver,
52 const TDesC8& aSrcDataType, const TDesC8& aDestDataType, const TUid& aImplementationType)
54 CCodecApiResolverData* customMatchData = CCodecApiResolverData::NewLC();
55 customMatchData->SetMatchType(EMatchInputAndOutputDataFormat);
56 customMatchData->SetImplementationType(aImplementationType);
57 // string value of the input source data
58 customMatchData->SetInputDataL(aSrcDataType);
59 customMatchData->SetOutputDataL(aDestDataType);
61 HBufC8* package = customMatchData->NewPackLC();
63 TEComResolverParams resolverParams; // Parameters on which to match
64 resolverParams.SetDataType(package->Des());
66 RImplInfoPtrArray ecomArray;
67 CleanupResetAndDestroyPushL(ecomArray);
69 REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), resolverParams, TUid::Uid(KUidCodecApiResolverImplementation), ecomArray);
71 // check if there are any
72 TInt noOfProcessingUnits = ecomArray.Count();
74 if(noOfProcessingUnits == 0)
76 User::Leave(KErrNotFound);
79 CMdfProcessingUnit *processingUnit = NULL;
81 TInt error = KErrNone;
84 // Iterate through the array until a plugin can be created without errors
85 const CImplementationInformation& puInfo = *(ecomArray[index++]);
87 TRAP(error, processingUnit = CMdfProcessingUnit::NewL(puInfo.ImplementationUid()));
89 while(index < noOfProcessingUnits && error != KErrNone);
93 ASSERT(!processingUnit && index <= noOfProcessingUnits);
97 CleanupStack::PopAndDestroy(3, customMatchData); // customMatchData, package, ecomArray
100 TInt err = processingUnit->Create(aProcessingUnitObserver);
103 // delete processing unit before leaving
104 delete processingUnit;
107 return processingUnit;
110 CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver,
111 TFourCC aSrcDataType, TFourCC aDestDataType)
113 HBufC8* packageSrcDataType = HBufC8::NewLC(KMaxDataTypeLength);
114 TPtr8 sourceDataType = packageSrcDataType->Des();
115 aSrcDataType.FourCC(&sourceDataType);
117 HBufC8* packageDestDataType = HBufC8::NewLC(KMaxDataTypeLength);
118 TPtr8 destinationDataType = packageDestDataType->Des();
119 aDestDataType.FourCC(&destinationDataType);
121 CMdfProcessingUnit* processingUnit = LoadProcessingUnitL(aProcessingUnitObserver, sourceDataType, destinationDataType, TUid::Uid(KUidAudioCodec));
122 CleanupStack::PopAndDestroy(2, packageSrcDataType);
123 return processingUnit;
127 TInt CPuLoader::TunnelSetup(MMdfOutputPort& aOutputPort, MMdfInputPort& aInputPort)
129 TTunnelFlags tunnelFlags = EBufferReadOnly;
130 TSupplierType supplierType = EBufferSupplyUnspecified;
131 TUint error = KErrNone;
133 if ((error = aOutputPort.MopTunnelRequest(aInputPort, tunnelFlags, supplierType)) != KErrNone)
137 return aInputPort.MipTunnelRequest(aOutputPort,tunnelFlags,supplierType);
141 void CPuLoader::UnloadProcessingUnit(CMdfProcessingUnit*& aPu)
147 CPuLoader::CPuLoader()
151 CPuLoader::~CPuLoader()