os/mm/mmlibs/mmfw/tsrc/mmfunittest/DevSoundTest/a3fcistubextn/a3fcistubextn.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/DevSoundTest/a3fcistubextn/a3fcistubextn.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,308 @@
     1.4 +// Copyright (c) 2008-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 +#include "a3fcistubextn.h"
    1.20 +#include <ecom/ecom.h>
    1.21 +#include <ecom/implementationproxy.h>
    1.22 +#include "a3fcistubextn.hrh"
    1.23 +
    1.24 +#include <a3f/maudiocontext.h>
    1.25 +#include <a3f/maudiostream.h>
    1.26 +#include <a3f/maudioprocessingunit.h>
    1.27 +#include <a3f/maudiogaincontrol.h>
    1.28 +#include <a3f/audioprocessingunittypeuids.h>
    1.29 +
    1.30 +//      
    1.31 +#include "a3fbackdooraccess.h"
    1.32 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.33 +#include <mmf/common/mmfipcserver.h>
    1.34 +#endif
    1.35 +
    1.36 +
    1.37 +// __________________________________________________________________________
    1.38 +// Client-side extension
    1.39 +
    1.40 +MDevSoundCIClientExtension* CA3fClientCiStubExtn::NewL()
    1.41 +	{
    1.42 +	CA3fClientCiStubExtn* self = new (ELeave) CA3fClientCiStubExtn;
    1.43 +	return self;
    1.44 +	}
    1.45 +	
    1.46 +CA3fClientCiStubExtn::~CA3fClientCiStubExtn()
    1.47 +	{
    1.48 +	delete iDummyBuffer;
    1.49 +	REComSession::DestroyedImplementation(iKey);
    1.50 +	}
    1.51 +	
    1.52 +TInt CA3fClientCiStubExtn::Setup(MCustomCommand& aCustomCommand)
    1.53 +	{
    1.54 +	iCommand = &aCustomCommand;
    1.55 +	iDummyBuffer=KNullDesC().Alloc(); // dummy buffer simulates some allocs
    1.56 +	if (!iDummyBuffer)
    1.57 +		{
    1.58 +		return KErrNoMemory;
    1.59 +		}
    1.60 +	return KErrNone;
    1.61 +	}
    1.62 +	
    1.63 +TInt CA3fClientCiStubExtn::CustomInterfaceExtension(TUid aUid, TAny*& aInterface)
    1.64 +	{
    1.65 +	if (aUid==KUidTestSetVolIf)
    1.66 +		{
    1.67 +		MTestSetVolIf* interface = this;
    1.68 +		aInterface = interface;
    1.69 +		return KErrNone;
    1.70 +		}
    1.71 +	return KErrNotSupported;
    1.72 +	}
    1.73 +	
    1.74 +void CA3fClientCiStubExtn::Release()
    1.75 +	{
    1.76 +	delete this;
    1.77 +	}
    1.78 +
    1.79 +void CA3fClientCiStubExtn::PassDestructorKey(TUid aDestructorKey)
    1.80 +	{
    1.81 +	iKey = aDestructorKey;
    1.82 +	}
    1.83 +	
    1.84 +TInt CA3fClientCiStubExtn::SetVol(TInt aVol)
    1.85 +	{
    1.86 +	// the key here is the destination package, which represets SetVol. Apart from value
    1.87 +	// the rest of the parameters can be ignored
    1.88 +	TPckgBuf<TInt> volumePkg (aVol);
    1.89 +	TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0));
    1.90 +	TInt result = iCommand->CustomCommandSync(setVolDest, ETestSetVolIfSetVolCommand, volumePkg, KNullDesC8);
    1.91 +	return result;
    1.92 +	}
    1.93 +
    1.94 +TInt CA3fClientCiStubExtn::Vol(TInt aMaxVol)
    1.95 +    {
    1.96 +    // again the key is is the destination package
    1.97 +    TPckgBuf<TInt> maxVolPkg (aMaxVol);
    1.98 +    TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0));
    1.99 +    TInt result = iCommand->CustomCommandSync(setVolDest, ETestSetVolIfVolCommand, maxVolPkg, KNullDesC8);
   1.100 +    return result;
   1.101 +    }
   1.102 +
   1.103 +// __________________________________________________________________________
   1.104 +// Server-side extension
   1.105 +
   1.106 +MDevSoundCIServerExtension* CA3fServerCiStubExtn::NewL()
   1.107 +	{
   1.108 +	CA3fServerCiStubExtn* self = new (ELeave) CA3fServerCiStubExtn;
   1.109 +	return self;
   1.110 +	}
   1.111 +	
   1.112 +CA3fServerCiStubExtn::~CA3fServerCiStubExtn()
   1.113 +	{
   1.114 +	delete iDummyBuffer;
   1.115 +	delete iSetVol;
   1.116 +	REComSession::DestroyedImplementation(iKey);
   1.117 +	}
   1.118 +	
   1.119 +TInt CA3fServerCiStubExtn::Setup(MCustomInterface& aCustomInterface)
   1.120 +	{
   1.121 +	iInterface = &aCustomInterface;
   1.122 +	iDummyBuffer=KNullDesC().Alloc(); // dummy buffer simulates some allocs
   1.123 +	if (!iDummyBuffer)
   1.124 +		{
   1.125 +		return KErrNoMemory;
   1.126 +		}
   1.127 +	return KErrNone;
   1.128 +	}
   1.129 +	
   1.130 +TInt CA3fServerCiStubExtn::HandleMessageL(const RMmfIpcMessage& aMessage)
   1.131 +	{
   1.132 +	TMMFMessageDestinationPckg destinationPckg;
   1.133 +	MmfMessageUtil::ReadL(aMessage, 0, destinationPckg);
   1.134 +	if (destinationPckg().InterfaceId()==KUidTestSetVolIf)
   1.135 +		{
   1.136 +		CSetVol* volHandler = CSetVol::NewL(*iInterface);
   1.137 +		CleanupStack::PushL(volHandler);
   1.138 +		TInt result = volHandler->HandleMessageL(aMessage);
   1.139 +		CleanupStack::Pop(volHandler);
   1.140 +		return result;
   1.141 +		}
   1.142 +
   1.143 +	return KErrNotSupported;
   1.144 +	}
   1.145 +	
   1.146 +void CA3fServerCiStubExtn::Release()
   1.147 +	{
   1.148 +	delete this;
   1.149 +	}
   1.150 +
   1.151 +void CA3fServerCiStubExtn::PassDestructorKey(TUid aDestructorKey)
   1.152 +	{
   1.153 +	iKey = aDestructorKey;
   1.154 +	}
   1.155 +	
   1.156 +// CSetVol
   1.157 +
   1.158 +CSetVol* CSetVol::NewL(MCustomInterface& aCustomInterface)
   1.159 +	{
   1.160 +	CSetVol* self = new (ELeave) CSetVol(aCustomInterface);
   1.161 +	CleanupStack::PushL(self);
   1.162 +	self->ConstructL();
   1.163 +	CleanupStack::Pop(self);
   1.164 +	return self;
   1.165 +	}
   1.166 +	
   1.167 +CSetVol::CSetVol(MCustomInterface& aCustomInterface):
   1.168 +	iInterface(&aCustomInterface)
   1.169 +	{
   1.170 +	// do nothing
   1.171 +	}
   1.172 +		
   1.173 +void CSetVol::ConstructL()
   1.174 +	{
   1.175 +	iWait = new (ELeave) CActiveSchedulerWait();
   1.176 +	}
   1.177 +	
   1.178 +CSetVol::~CSetVol()
   1.179 +	{
   1.180 +	delete iWait;
   1.181 +	}
   1.182 +	
   1.183 +TInt CSetVol::HandleMessageL(const RMmfIpcMessage& aMessage)
   1.184 +	{
   1.185 +    switch (aMessage.Function())
   1.186 +        {
   1.187 +        case ETestSetVolIfSetVolCommand:
   1.188 +            {
   1.189 +            TPckgBuf<TInt> volPckg;
   1.190 +            MmfMessageUtil::ReadL(aMessage, 1, volPckg);
   1.191 +            UpdateA3fPointers(); // grab pointers to context, stream etc
   1.192 +            SetVolumeL(volPckg());
   1.193 +
   1.194 +            User::LeaveIfError(iContext->RegisterAudioContextObserver(*this));
   1.195 +
   1.196 +            TInt error = iContext->Commit();
   1.197 +            if (!error)
   1.198 +                {
   1.199 +                iError = KErrNone;
   1.200 +                iWait->Start();
   1.201 +                error = iError;
   1.202 +                }
   1.203 +            (void) iContext->UnregisterAudioContextObserver(*this);
   1.204 +
   1.205 +            aMessage.Complete(error);
   1.206 +            return KErrNone; // KErrNone says we've handled the message
   1.207 +            }
   1.208 +        case ETestSetVolIfVolCommand:
   1.209 +            {
   1.210 +            TPckgBuf<TInt> maxVolPckg;
   1.211 +            MmfMessageUtil::ReadL(aMessage, 1, maxVolPckg);
   1.212 +            UpdateA3fPointers(); // grab pointers to context, stream etc
   1.213 +            TInt result = VolumeL(maxVolPckg());
   1.214 +            aMessage.Complete(result);
   1.215 +            return KErrNone; // KErrNone says we've handled the message
   1.216 +            }
   1.217 +        default:
   1.218 +            return KErrArgument;
   1.219 +        }
   1.220 +	}
   1.221 +	
   1.222 +void CSetVol::UpdateA3fPointers()
   1.223 +	{
   1.224 +	MA3FBackdoorAccessIf* backdoor = 
   1.225 +		static_cast<MA3FBackdoorAccessIf*>(iInterface->CustomInterface(KA3FBackdoorAccessIfUid));
   1.226 +	if (backdoor)
   1.227 +		{
   1.228 +		iContext = backdoor->AudioContext();
   1.229 +		iStream = backdoor->AudioStream();
   1.230 +		iGain = backdoor->ProcessingUnit(KUidAudioGainControl);
   1.231 +		}
   1.232 +	else
   1.233 +		{
   1.234 +		iContext = NULL;
   1.235 +		iStream = NULL;
   1.236 +		iGain = NULL;
   1.237 +		}
   1.238 +	}
   1.239 +	
   1.240 +void CSetVol::SetVolumeL(TInt aVolume)
   1.241 +	{
   1.242 +	RArray<TAudioChannelGain>	channelGains;
   1.243 +	CleanupClosePushL(channelGains);
   1.244 +	TAudioChannelGain left;
   1.245 +	TAudioChannelGain right;	
   1.246 +	left.iLocation = TAudioChannelGain::ELeft;
   1.247 +	right.iLocation = TAudioChannelGain::ERight;
   1.248 +	left.iGain = right.iGain = aVolume;
   1.249 +	User::LeaveIfError(channelGains.Append(left)); // assumed element 0 in rest of code
   1.250 +	User::LeaveIfError(channelGains.Append(right)); // assumed element 1 in rest of code
   1.251 +
   1.252 +	MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl));
   1.253 +	User::LeaveIfError(gainControl->SetGain(channelGains));	
   1.254 +	CleanupStack::PopAndDestroy(&channelGains);
   1.255 +	}
   1.256 +
   1.257 +TInt CSetVol::VolumeL(TInt aMaxVolume)
   1.258 +    {
   1.259 +    RArray<TAudioChannelGain>   channelGains;
   1.260 +    CleanupClosePushL(channelGains);
   1.261 +    TInt maxGain;
   1.262 +
   1.263 +    MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl));
   1.264 +    User::LeaveIfError(gainControl->GetGain(channelGains));
   1.265 +    User::LeaveIfError(gainControl->GetMaxGain(maxGain));
   1.266 +
   1.267 +    TInt basicVolume = (channelGains[0].iGain + channelGains[1].iGain) / 2;
   1.268 +    TInt result = basicVolume * aMaxVolume / maxGain; // scale to 0 to maxVolume
   1.269 +
   1.270 +    CleanupStack::PopAndDestroy(&channelGains);
   1.271 +    return result;
   1.272 +    }
   1.273 +	
   1.274 +void CSetVol::ContextEvent(TUid aEvent, TInt aError)
   1.275 +	{
   1.276 +	if (aEvent==KUidA3FContextUpdateComplete || aEvent==KUidA3FContextAbort)
   1.277 +		{
   1.278 +		// we are going to assume the SetGain() works and use the end of
   1.279 +		// the ContextEvent. Really should observe the gain itself
   1.280 +		if (aError)
   1.281 +			{
   1.282 +			iError = aError;
   1.283 +			}
   1.284 +		iWait->AsyncStop();
   1.285 +		}
   1.286 +	}
   1.287 +		
   1.288 +//
   1.289 +// ImplementationTable
   1.290 +//
   1.291 +
   1.292 +const TImplementationProxy ImplementationTable[] = 
   1.293 +	{
   1.294 +	IMPLEMENTATION_PROXY_ENTRY(KUidA3fClientCiStubExtn, CA3fClientCiStubExtn::NewL),
   1.295 +	IMPLEMENTATION_PROXY_ENTRY(KUidA3fServerCiStubExtn, CA3fServerCiStubExtn::NewL),
   1.296 +	};
   1.297 +
   1.298 +
   1.299 +//
   1.300 +// ImplementationGroupProxy
   1.301 +//
   1.302 +//
   1.303 +
   1.304 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   1.305 +	{
   1.306 +	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   1.307 +
   1.308 +	return ImplementationTable;
   1.309 +	}
   1.310 +
   1.311 +