os/mm/mmdevicefw/mdf/src/codecapi/puloader.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @publishedPartner
    19  @prototype
    20 */
    21 
    22 #include <mdf/mdfprocessingunit.h>
    23 #include <mmf/common/mmfutilities.h>
    24 #include "puloader.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>
    30 
    31 static const TInt KMaxDataTypeLength = 126;
    32 
    33 CPuLoader* CPuLoader::NewL()
    34 	{
    35 	CPuLoader* self = new (ELeave) CPuLoader;
    36 	return self;
    37 	}
    38 
    39 
    40 CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL(const MMdfProcessingUnitObserver& aProcessingUnitObserver, 
    41 		TUid aImplementationUid)
    42 	{
    43 	CMdfProcessingUnit* pu = NULL;
    44 	pu = CMdfProcessingUnit::NewL(aImplementationUid);
    45 	CleanupStack::PushL(pu);
    46 	User::LeaveIfError(pu->Create(aProcessingUnitObserver));
    47 	CleanupStack::Pop(pu);
    48 	return pu;
    49 	}
    50 	
    51 CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver, 
    52 		const TDesC8& aSrcDataType, const TDesC8& aDestDataType, const TUid& aImplementationType) 
    53 	{
    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);
    60 	
    61  	HBufC8* package  = customMatchData->NewPackLC();
    62 
    63 	TEComResolverParams resolverParams; // Parameters on which to match
    64 	resolverParams.SetDataType(package->Des());
    65 	
    66 	RImplInfoPtrArray ecomArray;
    67 	CleanupResetAndDestroyPushL(ecomArray);
    68 
    69 	REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), resolverParams, TUid::Uid(KUidCodecApiResolverImplementation), ecomArray);
    70 	
    71 	// check if there are any 
    72 	TInt noOfProcessingUnits = ecomArray.Count();
    73 
    74 	if(noOfProcessingUnits == 0)
    75 		{
    76 		User::Leave(KErrNotFound);
    77 		}
    78 
    79 	CMdfProcessingUnit *processingUnit = NULL;
    80 	TInt index = 0;
    81 	TInt error = KErrNone;
    82 	do
    83 		{
    84 		// Iterate through the array until a plugin can be created without errors
    85 		const CImplementationInformation& puInfo = *(ecomArray[index++]);
    86 		
    87 		TRAP(error, processingUnit = CMdfProcessingUnit::NewL(puInfo.ImplementationUid()));
    88 		}
    89 	while(index < noOfProcessingUnits && error != KErrNone);
    90 
    91 	if(error)
    92 		{
    93 		ASSERT(!processingUnit && index <= noOfProcessingUnits);
    94 		User::Leave(error);
    95 		}
    96 
    97 	CleanupStack::PopAndDestroy(3, customMatchData); // customMatchData, package, ecomArray	
    98 
    99 		
   100 	TInt err = processingUnit->Create(aProcessingUnitObserver);
   101 	if (err != KErrNone)
   102 		{
   103 		// delete processing unit before leaving
   104 		delete processingUnit;
   105 		User::Leave(err);
   106 		}
   107 	return processingUnit;
   108 	}
   109 	
   110 CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver, 
   111 		TFourCC aSrcDataType, TFourCC aDestDataType)
   112 	{
   113 	HBufC8* packageSrcDataType = HBufC8::NewLC(KMaxDataTypeLength);
   114 	TPtr8 sourceDataType = packageSrcDataType->Des();
   115 	aSrcDataType.FourCC(&sourceDataType);
   116 			
   117 	HBufC8* packageDestDataType = HBufC8::NewLC(KMaxDataTypeLength);
   118 	TPtr8 destinationDataType = packageDestDataType->Des();
   119 	aDestDataType.FourCC(&destinationDataType);
   120 	
   121 	CMdfProcessingUnit* processingUnit = LoadProcessingUnitL(aProcessingUnitObserver, sourceDataType, destinationDataType, TUid::Uid(KUidAudioCodec));
   122 	CleanupStack::PopAndDestroy(2, packageSrcDataType);
   123 	return processingUnit;
   124 	}
   125 
   126 
   127 TInt CPuLoader::TunnelSetup(MMdfOutputPort& aOutputPort, MMdfInputPort& aInputPort)
   128 	{
   129 	TTunnelFlags tunnelFlags = EBufferReadOnly;
   130 	TSupplierType supplierType = EBufferSupplyUnspecified;
   131 	TUint error = KErrNone;
   132 	 
   133 	if ((error = aOutputPort.MopTunnelRequest(aInputPort, tunnelFlags, supplierType)) != KErrNone)
   134 		{
   135 	 	return error;
   136 	 	}
   137 	return aInputPort.MipTunnelRequest(aOutputPort,tunnelFlags,supplierType);
   138 	}
   139 	
   140 
   141 void CPuLoader::UnloadProcessingUnit(CMdfProcessingUnit*& aPu)
   142 	{
   143 	delete aPu;
   144 	aPu = NULL;
   145 	}
   146 	
   147 CPuLoader::CPuLoader()
   148 	{
   149 	}
   150 
   151 CPuLoader::~CPuLoader()
   152 	{
   153 	}