82 { |
82 { |
83 // the key here is the destination package, which represets SetVol. Apart from value |
83 // the key here is the destination package, which represets SetVol. Apart from value |
84 // the rest of the parameters can be ignored |
84 // the rest of the parameters can be ignored |
85 TPckgBuf<TInt> volumePkg (aVol); |
85 TPckgBuf<TInt> volumePkg (aVol); |
86 TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0)); |
86 TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0)); |
87 TInt result = iCommand->CustomCommandSync(setVolDest, 0, volumePkg, KNullDesC8); |
87 TInt result = iCommand->CustomCommandSync(setVolDest, ETestSetVolIfSetVolCommand, volumePkg, KNullDesC8); |
88 return result; |
88 return result; |
89 } |
89 } |
|
90 |
|
91 TInt CA3fClientCiStubExtn::Vol(TInt aMaxVol) |
|
92 { |
|
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); |
|
97 return result; |
|
98 } |
90 |
99 |
91 // __________________________________________________________________________ |
100 // __________________________________________________________________________ |
92 // Server-side extension |
101 // Server-side extension |
93 |
102 |
94 MDevSoundCIServerExtension* CA3fServerCiStubExtn::NewL() |
103 MDevSoundCIServerExtension* CA3fServerCiStubExtn::NewL() |
168 delete iWait; |
177 delete iWait; |
169 } |
178 } |
170 |
179 |
171 TInt CSetVol::HandleMessageL(const RMmfIpcMessage& aMessage) |
180 TInt CSetVol::HandleMessageL(const RMmfIpcMessage& aMessage) |
172 { |
181 { |
173 TPckgBuf<TInt> volPckg; |
182 switch (aMessage.Function()) |
174 MmfMessageUtil::ReadL(aMessage, 1, volPckg); |
183 { |
175 UpdateA3fPointers(); // grab pointers to context, stream etc |
184 case ETestSetVolIfSetVolCommand: |
176 SetVolumeL(volPckg()); |
185 { |
177 |
186 TPckgBuf<TInt> volPckg; |
178 User::LeaveIfError(iContext->RegisterAudioContextObserver(*this)); |
187 MmfMessageUtil::ReadL(aMessage, 1, volPckg); |
179 |
188 UpdateA3fPointers(); // grab pointers to context, stream etc |
180 TInt error = iContext->Commit(); |
189 SetVolumeL(volPckg()); |
181 if (!error) |
190 |
182 { |
191 User::LeaveIfError(iContext->RegisterAudioContextObserver(*this)); |
183 iError = KErrNone; |
192 |
184 iWait->Start(); |
193 TInt error = iContext->Commit(); |
185 error = iError; |
194 if (!error) |
186 } |
195 { |
187 (void) iContext->UnregisterAudioContextObserver(*this); |
196 iError = KErrNone; |
188 |
197 iWait->Start(); |
189 aMessage.Complete(error); |
198 error = iError; |
190 return KErrNone; // KErrNone says we've handled the message |
199 } |
|
200 (void) iContext->UnregisterAudioContextObserver(*this); |
|
201 |
|
202 aMessage.Complete(error); |
|
203 return KErrNone; // KErrNone says we've handled the message |
|
204 } |
|
205 case ETestSetVolIfVolCommand: |
|
206 { |
|
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 |
|
213 } |
|
214 default: |
|
215 return KErrArgument; |
|
216 } |
191 } |
217 } |
192 |
218 |
193 void CSetVol::UpdateA3fPointers() |
219 void CSetVol::UpdateA3fPointers() |
194 { |
220 { |
195 MA3FBackdoorAccessIf* backdoor = |
221 MA3FBackdoorAccessIf* backdoor = |
222 |
248 |
223 MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl)); |
249 MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl)); |
224 User::LeaveIfError(gainControl->SetGain(channelGains)); |
250 User::LeaveIfError(gainControl->SetGain(channelGains)); |
225 CleanupStack::PopAndDestroy(&channelGains); |
251 CleanupStack::PopAndDestroy(&channelGains); |
226 } |
252 } |
|
253 |
|
254 TInt CSetVol::VolumeL(TInt aMaxVolume) |
|
255 { |
|
256 RArray<TAudioChannelGain> channelGains; |
|
257 CleanupClosePushL(channelGains); |
|
258 TInt maxGain; |
|
259 |
|
260 MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl)); |
|
261 User::LeaveIfError(gainControl->GetGain(channelGains)); |
|
262 User::LeaveIfError(gainControl->GetMaxGain(maxGain)); |
|
263 |
|
264 TInt basicVolume = (channelGains[0].iGain + channelGains[1].iGain) / 2; |
|
265 TInt result = basicVolume * aMaxVolume / maxGain; // scale to 0 to maxVolume |
|
266 |
|
267 CleanupStack::PopAndDestroy(&channelGains); |
|
268 return result; |
|
269 } |
227 |
270 |
228 void CSetVol::ContextEvent(TUid aEvent, TInt aError) |
271 void CSetVol::ContextEvent(TUid aEvent, TInt aError) |
229 { |
272 { |
230 if (aEvent==KUidA3FContextUpdateComplete || aEvent==KUidA3FContextAbort) |
273 if (aEvent==KUidA3FContextUpdateComplete || aEvent==KUidA3FContextAbort) |
231 { |
274 { |