os/mm/mmdevicefw/mdf/src/codecapi/puloader.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @publishedPartner
sl@0
    19
 @prototype
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <mdf/mdfprocessingunit.h>
sl@0
    23
#include <mmf/common/mmfutilities.h>
sl@0
    24
#include "puloader.h"
sl@0
    25
#include <mdf/codecapiresolverdata.h>
sl@0
    26
#include <mdf/codecapiuids.hrh>
sl@0
    27
#include <mdf/codecapiresolver.hrh>
sl@0
    28
#include <mm/mmcleanup.h>
sl@0
    29
#include <ecom/ecom.h>
sl@0
    30
sl@0
    31
static const TInt KMaxDataTypeLength = 126;
sl@0
    32
sl@0
    33
CPuLoader* CPuLoader::NewL()
sl@0
    34
	{
sl@0
    35
	CPuLoader* self = new (ELeave) CPuLoader;
sl@0
    36
	return self;
sl@0
    37
	}
sl@0
    38
sl@0
    39
sl@0
    40
CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL(const MMdfProcessingUnitObserver& aProcessingUnitObserver, 
sl@0
    41
		TUid aImplementationUid)
sl@0
    42
	{
sl@0
    43
	CMdfProcessingUnit* pu = NULL;
sl@0
    44
	pu = CMdfProcessingUnit::NewL(aImplementationUid);
sl@0
    45
	CleanupStack::PushL(pu);
sl@0
    46
	User::LeaveIfError(pu->Create(aProcessingUnitObserver));
sl@0
    47
	CleanupStack::Pop(pu);
sl@0
    48
	return pu;
sl@0
    49
	}
sl@0
    50
	
sl@0
    51
CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver, 
sl@0
    52
		const TDesC8& aSrcDataType, const TDesC8& aDestDataType, const TUid& aImplementationType) 
sl@0
    53
	{
sl@0
    54
	CCodecApiResolverData* customMatchData = CCodecApiResolverData::NewLC();
sl@0
    55
	customMatchData->SetMatchType(EMatchInputAndOutputDataFormat);
sl@0
    56
	customMatchData->SetImplementationType(aImplementationType);
sl@0
    57
	// string value of the input source data	
sl@0
    58
	customMatchData->SetInputDataL(aSrcDataType);
sl@0
    59
	customMatchData->SetOutputDataL(aDestDataType);
sl@0
    60
	
sl@0
    61
 	HBufC8* package  = customMatchData->NewPackLC();
sl@0
    62
sl@0
    63
	TEComResolverParams resolverParams; // Parameters on which to match
sl@0
    64
	resolverParams.SetDataType(package->Des());
sl@0
    65
	
sl@0
    66
	RImplInfoPtrArray ecomArray;
sl@0
    67
	CleanupResetAndDestroyPushL(ecomArray);
sl@0
    68
sl@0
    69
	REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), resolverParams, TUid::Uid(KUidCodecApiResolverImplementation), ecomArray);
sl@0
    70
	
sl@0
    71
	// check if there are any 
sl@0
    72
	TInt noOfProcessingUnits = ecomArray.Count();
sl@0
    73
sl@0
    74
	if(noOfProcessingUnits == 0)
sl@0
    75
		{
sl@0
    76
		User::Leave(KErrNotFound);
sl@0
    77
		}
sl@0
    78
sl@0
    79
	CMdfProcessingUnit *processingUnit = NULL;
sl@0
    80
	TInt index = 0;
sl@0
    81
	TInt error = KErrNone;
sl@0
    82
	do
sl@0
    83
		{
sl@0
    84
		// Iterate through the array until a plugin can be created without errors
sl@0
    85
		const CImplementationInformation& puInfo = *(ecomArray[index++]);
sl@0
    86
		
sl@0
    87
		TRAP(error, processingUnit = CMdfProcessingUnit::NewL(puInfo.ImplementationUid()));
sl@0
    88
		}
sl@0
    89
	while(index < noOfProcessingUnits && error != KErrNone);
sl@0
    90
sl@0
    91
	if(error)
sl@0
    92
		{
sl@0
    93
		ASSERT(!processingUnit && index <= noOfProcessingUnits);
sl@0
    94
		User::Leave(error);
sl@0
    95
		}
sl@0
    96
sl@0
    97
	CleanupStack::PopAndDestroy(3, customMatchData); // customMatchData, package, ecomArray	
sl@0
    98
sl@0
    99
		
sl@0
   100
	TInt err = processingUnit->Create(aProcessingUnitObserver);
sl@0
   101
	if (err != KErrNone)
sl@0
   102
		{
sl@0
   103
		// delete processing unit before leaving
sl@0
   104
		delete processingUnit;
sl@0
   105
		User::Leave(err);
sl@0
   106
		}
sl@0
   107
	return processingUnit;
sl@0
   108
	}
sl@0
   109
	
sl@0
   110
CMdfProcessingUnit* CPuLoader::LoadProcessingUnitL( const MMdfProcessingUnitObserver& aProcessingUnitObserver, 
sl@0
   111
		TFourCC aSrcDataType, TFourCC aDestDataType)
sl@0
   112
	{
sl@0
   113
	HBufC8* packageSrcDataType = HBufC8::NewLC(KMaxDataTypeLength);
sl@0
   114
	TPtr8 sourceDataType = packageSrcDataType->Des();
sl@0
   115
	aSrcDataType.FourCC(&sourceDataType);
sl@0
   116
			
sl@0
   117
	HBufC8* packageDestDataType = HBufC8::NewLC(KMaxDataTypeLength);
sl@0
   118
	TPtr8 destinationDataType = packageDestDataType->Des();
sl@0
   119
	aDestDataType.FourCC(&destinationDataType);
sl@0
   120
	
sl@0
   121
	CMdfProcessingUnit* processingUnit = LoadProcessingUnitL(aProcessingUnitObserver, sourceDataType, destinationDataType, TUid::Uid(KUidAudioCodec));
sl@0
   122
	CleanupStack::PopAndDestroy(2, packageSrcDataType);
sl@0
   123
	return processingUnit;
sl@0
   124
	}
sl@0
   125
sl@0
   126
sl@0
   127
TInt CPuLoader::TunnelSetup(MMdfOutputPort& aOutputPort, MMdfInputPort& aInputPort)
sl@0
   128
	{
sl@0
   129
	TTunnelFlags tunnelFlags = EBufferReadOnly;
sl@0
   130
	TSupplierType supplierType = EBufferSupplyUnspecified;
sl@0
   131
	TUint error = KErrNone;
sl@0
   132
	 
sl@0
   133
	if ((error = aOutputPort.MopTunnelRequest(aInputPort, tunnelFlags, supplierType)) != KErrNone)
sl@0
   134
		{
sl@0
   135
	 	return error;
sl@0
   136
	 	}
sl@0
   137
	return aInputPort.MipTunnelRequest(aOutputPort,tunnelFlags,supplierType);
sl@0
   138
	}
sl@0
   139
	
sl@0
   140
sl@0
   141
void CPuLoader::UnloadProcessingUnit(CMdfProcessingUnit*& aPu)
sl@0
   142
	{
sl@0
   143
	delete aPu;
sl@0
   144
	aPu = NULL;
sl@0
   145
	}
sl@0
   146
	
sl@0
   147
CPuLoader::CPuLoader()
sl@0
   148
	{
sl@0
   149
	}
sl@0
   150
sl@0
   151
CPuLoader::~CPuLoader()
sl@0
   152
	{
sl@0
   153
	}