1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmdevicefw/mdf/src/codecapi/puloader.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,153 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @publishedPartner
1.22 + @prototype
1.23 +*/
1.24 +
1.25 +#include <mdf/mdfprocessingunit.h>
1.26 +#include <mmf/common/mmfutilities.h>
1.27 +#include "puloader.h"
1.28 +#include <mdf/codecapiresolverdata.h>
1.29 +#include <mdf/codecapiuids.hrh>
1.30 +#include <mdf/codecapiresolver.hrh>
1.31 +#include <mm/mmcleanup.h>
1.32 +#include <ecom/ecom.h>
1.33 +
1.34 +static const TInt KMaxDataTypeLength = 126;
1.35 +
1.36 +CPuLoader* CPuLoader::NewL()
1.37 + {
1.38 + CPuLoader* self = new (ELeave) CPuLoader;
1.39 + return self;
1.40 + }
1.41 +
1.42 +
1.43 +CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL(const MMdfProcessingUnitObserver& aProcessingUnitObserver,
1.44 + TUid aImplementationUid)
1.45 + {
1.46 + CMdfProcessingUnit* pu = NULL;
1.47 + pu = CMdfProcessingUnit::NewL(aImplementationUid);
1.48 + CleanupStack::PushL(pu);
1.49 + User::LeaveIfError(pu->Create(aProcessingUnitObserver));
1.50 + CleanupStack::Pop(pu);
1.51 + return pu;
1.52 + }
1.53 +
1.54 +CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver,
1.55 + const TDesC8& aSrcDataType, const TDesC8& aDestDataType, const TUid& aImplementationType)
1.56 + {
1.57 + CCodecApiResolverData* customMatchData = CCodecApiResolverData::NewLC();
1.58 + customMatchData->SetMatchType(EMatchInputAndOutputDataFormat);
1.59 + customMatchData->SetImplementationType(aImplementationType);
1.60 + // string value of the input source data
1.61 + customMatchData->SetInputDataL(aSrcDataType);
1.62 + customMatchData->SetOutputDataL(aDestDataType);
1.63 +
1.64 + HBufC8* package = customMatchData->NewPackLC();
1.65 +
1.66 + TEComResolverParams resolverParams; // Parameters on which to match
1.67 + resolverParams.SetDataType(package->Des());
1.68 +
1.69 + RImplInfoPtrArray ecomArray;
1.70 + CleanupResetAndDestroyPushL(ecomArray);
1.71 +
1.72 + REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), resolverParams, TUid::Uid(KUidCodecApiResolverImplementation), ecomArray);
1.73 +
1.74 + // check if there are any
1.75 + TInt noOfProcessingUnits = ecomArray.Count();
1.76 +
1.77 + if(noOfProcessingUnits == 0)
1.78 + {
1.79 + User::Leave(KErrNotFound);
1.80 + }
1.81 +
1.82 + CMdfProcessingUnit *processingUnit = NULL;
1.83 + TInt index = 0;
1.84 + TInt error = KErrNone;
1.85 + do
1.86 + {
1.87 + // Iterate through the array until a plugin can be created without errors
1.88 + const CImplementationInformation& puInfo = *(ecomArray[index++]);
1.89 +
1.90 + TRAP(error, processingUnit = CMdfProcessingUnit::NewL(puInfo.ImplementationUid()));
1.91 + }
1.92 + while(index < noOfProcessingUnits && error != KErrNone);
1.93 +
1.94 + if(error)
1.95 + {
1.96 + ASSERT(!processingUnit && index <= noOfProcessingUnits);
1.97 + User::Leave(error);
1.98 + }
1.99 +
1.100 + CleanupStack::PopAndDestroy(3, customMatchData); // customMatchData, package, ecomArray
1.101 +
1.102 +
1.103 + TInt err = processingUnit->Create(aProcessingUnitObserver);
1.104 + if (err != KErrNone)
1.105 + {
1.106 + // delete processing unit before leaving
1.107 + delete processingUnit;
1.108 + User::Leave(err);
1.109 + }
1.110 + return processingUnit;
1.111 + }
1.112 +
1.113 +CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver,
1.114 + TFourCC aSrcDataType, TFourCC aDestDataType)
1.115 + {
1.116 + HBufC8* packageSrcDataType = HBufC8::NewLC(KMaxDataTypeLength);
1.117 + TPtr8 sourceDataType = packageSrcDataType->Des();
1.118 + aSrcDataType.FourCC(&sourceDataType);
1.119 +
1.120 + HBufC8* packageDestDataType = HBufC8::NewLC(KMaxDataTypeLength);
1.121 + TPtr8 destinationDataType = packageDestDataType->Des();
1.122 + aDestDataType.FourCC(&destinationDataType);
1.123 +
1.124 + CMdfProcessingUnit* processingUnit = LoadProcessingUnitL(aProcessingUnitObserver, sourceDataType, destinationDataType, TUid::Uid(KUidAudioCodec));
1.125 + CleanupStack::PopAndDestroy(2, packageSrcDataType);
1.126 + return processingUnit;
1.127 + }
1.128 +
1.129 +
1.130 +TInt CPuLoader::TunnelSetup(MMdfOutputPort& aOutputPort, MMdfInputPort& aInputPort)
1.131 + {
1.132 + TTunnelFlags tunnelFlags = EBufferReadOnly;
1.133 + TSupplierType supplierType = EBufferSupplyUnspecified;
1.134 + TUint error = KErrNone;
1.135 +
1.136 + if ((error = aOutputPort.MopTunnelRequest(aInputPort, tunnelFlags, supplierType)) != KErrNone)
1.137 + {
1.138 + return error;
1.139 + }
1.140 + return aInputPort.MipTunnelRequest(aOutputPort,tunnelFlags,supplierType);
1.141 + }
1.142 +
1.143 +
1.144 +void CPuLoader::UnloadProcessingUnit(CMdfProcessingUnit*& aPu)
1.145 + {
1.146 + delete aPu;
1.147 + aPu = NULL;
1.148 + }
1.149 +
1.150 +CPuLoader::CPuLoader()
1.151 + {
1.152 + }
1.153 +
1.154 +CPuLoader::~CPuLoader()
1.155 + {
1.156 + }