Update contrib.
1 // Copyright (c) 2008-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.
16 #include "a3fcistubextn.h"
17 #include <ecom/ecom.h>
18 #include <ecom/implementationproxy.h>
19 #include "a3fcistubextn.hrh"
21 #include <a3f/maudiocontext.h>
22 #include <a3f/maudiostream.h>
23 #include <a3f/maudioprocessingunit.h>
24 #include <a3f/maudiogaincontrol.h>
25 #include <a3f/audioprocessingunittypeuids.h>
28 #include "a3fbackdooraccess.h"
29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
30 #include <mmf/common/mmfipcserver.h>
34 // __________________________________________________________________________
35 // Client-side extension
37 MDevSoundCIClientExtension* CA3fClientCiStubExtn::NewL()
39 CA3fClientCiStubExtn* self = new (ELeave) CA3fClientCiStubExtn;
43 CA3fClientCiStubExtn::~CA3fClientCiStubExtn()
46 REComSession::DestroyedImplementation(iKey);
49 TInt CA3fClientCiStubExtn::Setup(MCustomCommand& aCustomCommand)
51 iCommand = &aCustomCommand;
52 iDummyBuffer=KNullDesC().Alloc(); // dummy buffer simulates some allocs
60 TInt CA3fClientCiStubExtn::CustomInterfaceExtension(TUid aUid, TAny*& aInterface)
62 if (aUid==KUidTestSetVolIf)
64 MTestSetVolIf* interface = this;
65 aInterface = interface;
68 return KErrNotSupported;
71 void CA3fClientCiStubExtn::Release()
76 void CA3fClientCiStubExtn::PassDestructorKey(TUid aDestructorKey)
78 iKey = aDestructorKey;
81 TInt CA3fClientCiStubExtn::SetVol(TInt aVol)
83 // the key here is the destination package, which represets SetVol. Apart from value
84 // the rest of the parameters can be ignored
85 TPckgBuf<TInt> volumePkg (aVol);
86 TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0));
87 TInt result = iCommand->CustomCommandSync(setVolDest, ETestSetVolIfSetVolCommand, volumePkg, KNullDesC8);
91 TInt CA3fClientCiStubExtn::Vol(TInt aMaxVol)
93 // again the key is is the destination package
94 TPckgBuf<TInt> maxVolPkg (aMaxVol);
95 TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0));
96 TInt result = iCommand->CustomCommandSync(setVolDest, ETestSetVolIfVolCommand, maxVolPkg, KNullDesC8);
100 // __________________________________________________________________________
101 // Server-side extension
103 MDevSoundCIServerExtension* CA3fServerCiStubExtn::NewL()
105 CA3fServerCiStubExtn* self = new (ELeave) CA3fServerCiStubExtn;
109 CA3fServerCiStubExtn::~CA3fServerCiStubExtn()
113 REComSession::DestroyedImplementation(iKey);
116 TInt CA3fServerCiStubExtn::Setup(MCustomInterface& aCustomInterface)
118 iInterface = &aCustomInterface;
119 iDummyBuffer=KNullDesC().Alloc(); // dummy buffer simulates some allocs
127 TInt CA3fServerCiStubExtn::HandleMessageL(const RMmfIpcMessage& aMessage)
129 TMMFMessageDestinationPckg destinationPckg;
130 MmfMessageUtil::ReadL(aMessage, 0, destinationPckg);
131 if (destinationPckg().InterfaceId()==KUidTestSetVolIf)
133 CSetVol* volHandler = CSetVol::NewL(*iInterface);
134 CleanupStack::PushL(volHandler);
135 TInt result = volHandler->HandleMessageL(aMessage);
136 CleanupStack::Pop(volHandler);
140 return KErrNotSupported;
143 void CA3fServerCiStubExtn::Release()
148 void CA3fServerCiStubExtn::PassDestructorKey(TUid aDestructorKey)
150 iKey = aDestructorKey;
155 CSetVol* CSetVol::NewL(MCustomInterface& aCustomInterface)
157 CSetVol* self = new (ELeave) CSetVol(aCustomInterface);
158 CleanupStack::PushL(self);
160 CleanupStack::Pop(self);
164 CSetVol::CSetVol(MCustomInterface& aCustomInterface):
165 iInterface(&aCustomInterface)
170 void CSetVol::ConstructL()
172 iWait = new (ELeave) CActiveSchedulerWait();
180 TInt CSetVol::HandleMessageL(const RMmfIpcMessage& aMessage)
182 switch (aMessage.Function())
184 case ETestSetVolIfSetVolCommand:
186 TPckgBuf<TInt> volPckg;
187 MmfMessageUtil::ReadL(aMessage, 1, volPckg);
188 UpdateA3fPointers(); // grab pointers to context, stream etc
189 SetVolumeL(volPckg());
191 User::LeaveIfError(iContext->RegisterAudioContextObserver(*this));
193 TInt error = iContext->Commit();
200 (void) iContext->UnregisterAudioContextObserver(*this);
202 aMessage.Complete(error);
203 return KErrNone; // KErrNone says we've handled the message
205 case ETestSetVolIfVolCommand:
207 TPckgBuf<TInt> maxVolPckg;
208 MmfMessageUtil::ReadL(aMessage, 1, maxVolPckg);
209 UpdateA3fPointers(); // grab pointers to context, stream etc
210 TInt result = VolumeL(maxVolPckg());
211 aMessage.Complete(result);
212 return KErrNone; // KErrNone says we've handled the message
219 void CSetVol::UpdateA3fPointers()
221 MA3FBackdoorAccessIf* backdoor =
222 static_cast<MA3FBackdoorAccessIf*>(iInterface->CustomInterface(KA3FBackdoorAccessIfUid));
225 iContext = backdoor->AudioContext();
226 iStream = backdoor->AudioStream();
227 iGain = backdoor->ProcessingUnit(KUidAudioGainControl);
237 void CSetVol::SetVolumeL(TInt aVolume)
239 RArray<TAudioChannelGain> channelGains;
240 CleanupClosePushL(channelGains);
241 TAudioChannelGain left;
242 TAudioChannelGain right;
243 left.iLocation = TAudioChannelGain::ELeft;
244 right.iLocation = TAudioChannelGain::ERight;
245 left.iGain = right.iGain = aVolume;
246 User::LeaveIfError(channelGains.Append(left)); // assumed element 0 in rest of code
247 User::LeaveIfError(channelGains.Append(right)); // assumed element 1 in rest of code
249 MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl));
250 User::LeaveIfError(gainControl->SetGain(channelGains));
251 CleanupStack::PopAndDestroy(&channelGains);
254 TInt CSetVol::VolumeL(TInt aMaxVolume)
256 RArray<TAudioChannelGain> channelGains;
257 CleanupClosePushL(channelGains);
260 MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl));
261 User::LeaveIfError(gainControl->GetGain(channelGains));
262 User::LeaveIfError(gainControl->GetMaxGain(maxGain));
264 TInt basicVolume = (channelGains[0].iGain + channelGains[1].iGain) / 2;
265 TInt result = basicVolume * aMaxVolume / maxGain; // scale to 0 to maxVolume
267 CleanupStack::PopAndDestroy(&channelGains);
271 void CSetVol::ContextEvent(TUid aEvent, TInt aError)
273 if (aEvent==KUidA3FContextUpdateComplete || aEvent==KUidA3FContextAbort)
275 // we are going to assume the SetGain() works and use the end of
276 // the ContextEvent. Really should observe the gain itself
286 // ImplementationTable
289 const TImplementationProxy ImplementationTable[] =
291 IMPLEMENTATION_PROXY_ENTRY(KUidA3fClientCiStubExtn, CA3fClientCiStubExtn::NewL),
292 IMPLEMENTATION_PROXY_ENTRY(KUidA3fServerCiStubExtn, CA3fServerCiStubExtn::NewL),
297 // ImplementationGroupProxy
301 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
303 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
305 return ImplementationTable;