Update contrib.
1 // Copyright (c) 2004-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.
19 #include "MmfDevSoundProxy.h"
20 #include "MmfDevSoundServerStart.h"
21 #include "MmfBase.hrh"
22 #include "MmfAudioClientServer.h"
23 #include <mmf/plugin/mmfdevsoundcustominterface.hrh>
24 #include <ecom/ecom.h>
30 This function raises a panic
33 one of the several panic codes that may be raised by this dll
35 @panic EMMFDevSoundProxyPlayDataWithoutInitialize is raised when playdata is called without initialization
36 @panic EMMFDevSoundProxyRecordDataWithoutInitialize is raised when recorddata is called without initialization
37 @panic EMMFDevSoundProxyConvertDataWithoutInitialize is raised when convertdata is called without initialization
39 GLDEF_C void Panic(TMMFDevSoundProxyPanicCodes aPanicCode)
41 User::Panic(KMMFDevSoundProxyPanicCategory, aPanicCode);
44 EXPORT_C RMMFDevSoundProxy::RMMFDevSoundProxy()
45 : iBuffer(NULL), iSeqName(NULL), iMsgQueueHandle(NULL), iAudioServerProxy (NULL)
49 EXPORT_C void RMMFDevSoundProxy::Close()
51 RMmfSessionBase::Close();
55 iAudioServerProxy->Close();
56 delete iAudioServerProxy;
62 EXPORT_C TInt RMMFDevSoundProxy::Open(RHandleBase& aMsgQueueHandle)
65 iMsgQueueHandle = &aMsgQueueHandle;
66 TRAP(err, iSeqName = HBufC::NewL(KMaxFixedSequenceNameLength));
69 TRAP(err, iAudioServerProxy = new (ELeave) RMMFAudioServerProxy());
72 err = iAudioServerProxy->Open();
75 err = SetReturnedHandle(iAudioServerProxy->GetDevSoundSessionHandle());
86 EXPORT_C TInt RMMFDevSoundProxy::SetDevSoundInfo()
88 return SendReceive(EMMFAudioLaunchRequests);
91 EXPORT_C TInt RMMFDevSoundProxy::InitializeL(TMMFState aMode)
93 TMMFDevSoundProxySettings set;
95 TMMFDevSoundProxySettingsPckg pckg(set);
96 TIpcArgs args(&pckg, *iMsgQueueHandle);
97 return RSessionBase::SendReceive(EMMFDevSoundProxyInitialize1, args);
100 EXPORT_C TInt RMMFDevSoundProxy::InitializeL(TUid aHWDev, TMMFState aMode)
102 TMMFDevSoundProxySettings set;
105 TMMFDevSoundProxySettingsPckg pckg(set);
106 TIpcArgs args(&pckg, *iMsgQueueHandle);
107 return RSessionBase::SendReceive(EMMFDevSoundProxyInitialize2, args);
110 EXPORT_C TInt RMMFDevSoundProxy::InitializeL(TFourCC aDesiredFourCC, TMMFState aMode)
112 TMMFDevSoundProxySettings set;
113 set.iDesiredFourCC = aDesiredFourCC;
115 TMMFDevSoundProxySettingsPckg pckg(set);
116 TIpcArgs args(&pckg, *iMsgQueueHandle);
117 return RSessionBase::SendReceive(EMMFDevSoundProxyInitialize4, args);
120 EXPORT_C TMMFCapabilities RMMFDevSoundProxy::Capabilities()
122 TMMFDevSoundProxySettings set;
123 TMMFDevSoundProxySettingsPckg pckg(set);
124 SendReceiveResult(EMMFDevSoundProxyCapabilities,KNullDesC8,KNullDesC8,pckg);
128 EXPORT_C TMMFCapabilities RMMFDevSoundProxy::Config()
130 TMMFDevSoundProxySettings set;
131 TMMFDevSoundProxySettingsPckg pckg(set);
132 SendReceiveResult(EMMFDevSoundProxyConfig,KNullDesC8,KNullDesC8,pckg);
133 return pckg().iConfig;
136 EXPORT_C TInt RMMFDevSoundProxy::SetConfigL(const TMMFCapabilities& aConfig)
138 TMMFDevSoundProxySettings set;
139 set.iConfig = aConfig;
140 TMMFDevSoundProxySettingsPckg pckg(set);
141 TInt err = SendReceive(EMMFDevSoundProxySetConfig, pckg);
142 User::LeaveIfError(err);
146 EXPORT_C TInt RMMFDevSoundProxy::MaxVolume()
148 TMMFDevSoundProxySettings set;
149 TMMFDevSoundProxySettingsPckg pckg(set);
150 SendReceiveResult(EMMFDevSoundProxyMaxVolume,KNullDesC8,KNullDesC8,pckg);
151 return pckg().iMaxVolume;
154 EXPORT_C TInt RMMFDevSoundProxy::Volume()
156 TMMFDevSoundProxySettings set;
157 TMMFDevSoundProxySettingsPckg pckg(set);
158 SendReceiveResult(EMMFDevSoundProxyVolume,KNullDesC8,KNullDesC8,pckg);
159 return pckg().iVolume;
162 EXPORT_C TInt RMMFDevSoundProxy::SetVolume(TInt aVolume)
164 TMMFDevSoundProxySettings set;
165 set.iVolume = aVolume;
166 TMMFDevSoundProxySettingsPckg pckg(set);
167 return SendReceive(EMMFDevSoundProxySetVolume, pckg);
170 EXPORT_C TInt RMMFDevSoundProxy::MaxGain()
172 TMMFDevSoundProxySettings set;
173 TMMFDevSoundProxySettingsPckg pckg(set);
174 SendReceiveResult(EMMFDevSoundProxyMaxGain,KNullDesC8,KNullDesC8,pckg);
175 return pckg().iMaxGain;
178 EXPORT_C TInt RMMFDevSoundProxy::Gain()
180 TMMFDevSoundProxySettings set;
181 TMMFDevSoundProxySettingsPckg pckg(set);
182 SendReceiveResult(EMMFDevSoundProxyGain,KNullDesC8,KNullDesC8,pckg);
186 EXPORT_C TInt RMMFDevSoundProxy::SetGain(TInt aGain)
188 TMMFDevSoundProxySettings set;
190 TMMFDevSoundProxySettingsPckg pckg(set);
191 return SendReceive(EMMFDevSoundProxySetGain, pckg);
194 EXPORT_C void RMMFDevSoundProxy::GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
196 TMMFDevSoundProxySettings set;
197 TMMFDevSoundProxySettingsPckg pckg(set);
198 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyPlayBalance,KNullDesC8,KNullDesC8,pckg));
199 aLeftPercentage = pckg().iLeftPercentage;
200 aRightPercentage = pckg().iRightPercentage;
203 EXPORT_C void RMMFDevSoundProxy::SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
205 TMMFDevSoundProxySettings set;
206 set.iLeftPercentage = aLeftPercentage;
207 set.iRightPercentage = aRightPercentage;
208 TMMFDevSoundProxySettingsPckg pckg(set);
209 User::LeaveIfError(SendReceive(EMMFDevSoundProxySetPlayBalance, pckg));
212 EXPORT_C void RMMFDevSoundProxy::GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
214 TMMFDevSoundProxySettings set;
215 TMMFDevSoundProxySettingsPckg pckg(set);
216 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyRecordBalance,KNullDesC8,KNullDesC8,pckg));
217 aLeftPercentage = pckg().iLeftPercentage;
218 aRightPercentage = pckg().iRightPercentage;
221 EXPORT_C void RMMFDevSoundProxy::SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
223 TMMFDevSoundProxySettings set;
224 set.iLeftPercentage = aLeftPercentage;
225 set.iRightPercentage = aRightPercentage;
226 TMMFDevSoundProxySettingsPckg pckg(set);
227 User::LeaveIfError(SendReceive(EMMFDevSoundProxySetRecordBalance, pckg));
230 EXPORT_C void RMMFDevSoundProxy::PlayInitL()
232 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayInit));
236 EXPORT_C void RMMFDevSoundProxy::RecordInitL()
238 User::LeaveIfError(SendReceive(EMMFDevSoundProxyRecordInit));
242 EXPORT_C void RMMFDevSoundProxy::PlayData()
244 __ASSERT_ALWAYS(iState == EPlaying, Panic(EMMFDevSoundProxyPlayDataWithoutInitialize));
246 TMMFDevSoundProxyHwBuf set;
247 set.iLastBuffer = iBuffer->LastBuffer();
248 TMMFDevSoundProxyHwBufPckg pckg(set);
249 SendReceive(EMMFDevSoundProxyPlayData, pckg, iBuffer->Data());
252 EXPORT_C void RMMFDevSoundProxy::RecordData()
254 __ASSERT_ALWAYS(iState == ERecording, Panic(EMMFDevSoundProxyRecordDataWithoutInitialize));
255 SendReceive(EMMFDevSoundProxyRecordData);
258 EXPORT_C void RMMFDevSoundProxy::Stop()
260 SendReceive(EMMFDevSoundProxyStop);
264 EXPORT_C void RMMFDevSoundProxy::Pause()
266 SendReceive(EMMFDevSoundProxyPause);
269 EXPORT_C void RMMFDevSoundProxy::PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
271 TMMFDevSoundProxySettings set;
272 set.iFrequencyOne = aFrequency;
273 set.iDuration = aDuration;
274 TMMFDevSoundProxySettingsPckg pckg(set);
275 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayTone, pckg));
278 EXPORT_C void RMMFDevSoundProxy::PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
280 TMMFDevSoundProxySettings set;
281 set.iFrequencyOne = aFrequencyOne;
282 set.iFrequencyTwo = aFrequencyTwo;
283 set.iDuration = aDuration;
284 TMMFDevSoundProxySettingsPckg pckg(set);
285 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayDualTone, pckg));
288 EXPORT_C void RMMFDevSoundProxy::PlayDTMFStringL(const TDesC& aDTMFString)
290 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayDTMFString, aDTMFString));
293 EXPORT_C void RMMFDevSoundProxy::PlayToneSequenceL(const TDesC8& aData)
295 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayToneSequence, aData));
298 EXPORT_C void RMMFDevSoundProxy::PlayFixedSequenceL(TInt aSequenceNumber)
300 TPckgBuf<TInt> seqNum(aSequenceNumber);
301 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayFixedSequence, seqNum));
304 EXPORT_C void RMMFDevSoundProxy::SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength,
305 TTimeIntervalMicroSeconds32& aToneOffLength,
306 TTimeIntervalMicroSeconds32& aPauseLength)
308 TMMFDevSoundProxySettings set;
309 set.iToneOnLength = aToneOnLength;
310 set.iToneOffLength = aToneOffLength;
311 set.iPauseLength = aPauseLength;
312 TMMFDevSoundProxySettingsPckg pckg(set);
313 SendReceive(EMMFDevSoundProxySetDTMFLengths, pckg);
316 EXPORT_C void RMMFDevSoundProxy::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
318 TMMFDevSoundProxySettings set;
319 set.iDuration = aRampDuration;
320 TMMFDevSoundProxySettingsPckg pckg(set);
321 SendReceive(EMMFDevSoundProxySetVolumeRamp, pckg);
324 EXPORT_C void RMMFDevSoundProxy::GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings)
326 aSupportedDataTypes.Reset();
328 TMMFPrioritySettings prioritySet = aPrioritySettings;
329 TMMFPrioritySettingsPckg pckg(prioritySet);
331 TPckgBuf<TInt> numberOfElementsPckg;
332 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyGetSupportedInputDataTypes, pckg, KNullDesC8, numberOfElementsPckg));
334 HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg()*sizeof(TFourCC));
335 TPtr8 ptr = buf->Des();
338 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyCopyFourCCArrayData,KNullDesC8,KNullDesC8,ptr));
339 RDesReadStream stream(ptr);
340 CleanupClosePushL(stream);
342 for (TInt i=0; i<numberOfElementsPckg(); i++)
344 TInt err = aSupportedDataTypes.Append(stream.ReadInt32L());
346 {//note we don't destroy array because we don't own it
347 //but we do reset it as it is incomplete
348 aSupportedDataTypes.Reset();
352 CleanupStack::PopAndDestroy(2, buf);//stream, buf
356 EXPORT_C void RMMFDevSoundProxy::GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings)
358 aSupportedDataTypes.Reset();
360 TMMFPrioritySettings prioritySet = aPrioritySettings;
361 TMMFPrioritySettingsPckg pckg(prioritySet);
363 TPckgBuf<TInt> numberOfElementsPckg;
364 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyGetSupportedOutputDataTypes, pckg, KNullDesC8, numberOfElementsPckg));
366 HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg()*sizeof(TFourCC));
367 TPtr8 ptr = buf->Des();
370 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyCopyFourCCArrayData,KNullDesC8,KNullDesC8,ptr));
371 RDesReadStream stream(ptr);
372 CleanupClosePushL(stream);
374 for (TInt i=0; i<numberOfElementsPckg(); i++)
376 TInt err = aSupportedDataTypes.Append(stream.ReadInt32L());
378 {//note we don't destroy array because we don't own it
379 //but we do reset it as it is incomplete
380 aSupportedDataTypes.Reset();
384 CleanupStack::PopAndDestroy(2, buf);//stream, buf
387 EXPORT_C TInt RMMFDevSoundProxy::SamplesRecorded()
389 TPckgBuf<TInt> numSamples;
390 SendReceiveResult(EMMFDevSoundProxySamplesRecorded, KNullDesC8, KNullDesC8, numSamples);
394 EXPORT_C TInt RMMFDevSoundProxy::SamplesPlayed()
396 TPckgBuf<TInt> numSamples;
397 SendReceiveResult(EMMFDevSoundProxySamplesPlayed, KNullDesC8, KNullDesC8, numSamples);
401 EXPORT_C void RMMFDevSoundProxy::SetToneRepeats(TInt aRepeatCount, const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
403 TPckgBuf<TInt> countRepeat(aRepeatCount);
404 TPckgBuf<TTimeIntervalMicroSeconds> repeatTS(aRepeatTrailingSilence);
405 SendReceive(EMMFDevSoundProxySetToneRepeats, countRepeat, repeatTS);
408 EXPORT_C void RMMFDevSoundProxy::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
410 TPckgBuf<TMMFPrioritySettings> prioritySet(aPrioritySettings);
411 SendReceive(EMMFDevSoundProxySetPrioritySettings, prioritySet);
414 EXPORT_C const TDesC& RMMFDevSoundProxy::FixedSequenceName(TInt aSequenceNumber)
416 TPckgBuf<TInt> seqNum(aSequenceNumber);
417 TPtr SeqNamePtr = iSeqName->Des();
419 SendReceiveResult(EMMFDevSoundProxyFixedSequenceName, seqNum, KNullDesC8, SeqNamePtr);
423 EXPORT_C TAny* RMMFDevSoundProxy::CustomInterface(TUid /*aInterfaceId*/)
425 // No custom interfaces are supported at the moment so return NULL.
430 EXPORT_C TInt RMMFDevSoundProxy::FixedSequenceCount()
432 TPckgBuf<TInt> fixSeqCountPckg;
433 SendReceiveResult(EMMFDevSoundProxyFixedSequenceCount, fixSeqCountPckg);
434 return fixSeqCountPckg();
437 EXPORT_C TInt RMMFDevSoundProxy::BufferToBeFilledData(TMMFDevSoundProxyHwBufPckg& aSetPckg)
439 // Note that there will only ever be one of these requests outstanding per session
440 return SendReceiveResult(EMMFDevSoundProxyBTBFData, aSetPckg);
443 EXPORT_C TInt RMMFDevSoundProxy::BufferToBeEmptiedData(TMMFDevSoundProxyHwBufPckg& aSetPckg)
445 // Note that there will only ever be one of these requests outstanding per session
446 return SendReceiveResult(EMMFDevSoundProxyBTBEData, aSetPckg);
449 EXPORT_C void RMMFDevSoundProxy::SetBuffer(CMMFDataBuffer* aBuffer)
458 EXPORT_C TInt RMMFDevSoundProxy::GetRecordedBufferL(CMMFDataBuffer& aBuffer)
460 return SendReceiveResult(EMMFDevSoundProxyGetRecordedBuffer, aBuffer.Data());
463 EXPORT_C TInt RMMFDevSoundProxy::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
465 TMMFDevSoundProxySettings set;
466 set.iNotificationEventUid = aEventType;
467 TMMFDevSoundProxySettingsPckg pckg(set);
468 return SendReceive(EMMFDevSoundProxyRequestResourceNotification, pckg, aNotificationRegistrationData);
471 EXPORT_C TInt RMMFDevSoundProxy::CancelRegisterAsClient(TUid aEventType)
473 TMMFDevSoundProxySettings set;
474 set.iNotificationEventUid = aEventType;
475 TMMFDevSoundProxySettingsPckg pckg(set);
476 return SendReceiveResult(EMMFDevSoundProxyCancelRequestResourceNotification, pckg);
479 EXPORT_C TInt RMMFDevSoundProxy::GetResourceNotificationData(TUid aEventType, TDes8& aNotificationData)
481 TMMFDevSoundProxySettings set;
482 set.iNotificationEventUid = aEventType;
483 TMMFDevSoundProxySettingsPckg pckg(set);
484 return SendReceiveResult(EMMFDevSoundProxyGetResourceNotificationData, pckg,KNullDesC8,aNotificationData);
487 EXPORT_C TInt RMMFDevSoundProxy::WillResumePlay()
489 return SendReceive(EMMFDevSoundProxyWillResumePlay);
492 EXPORT_C TInt RMMFDevSoundProxy::EmptyBuffers()
494 return SendReceive(EMMFDevSoundProxyEmptyBuffers);
497 EXPORT_C TInt RMMFDevSoundProxy::GetTimePlayed(TTimeIntervalMicroSeconds& aTime)
499 TTimeIntervalMicroSeconds time(0);
500 TPckgBuf<TTimeIntervalMicroSeconds> timePckg(time);
501 TInt err = SendReceiveResult(EMMFDevSoundProxyGetTimePlayed, KNullDesC8, KNullDesC8, timePckg);
509 // implementation of a simple CustomCommand() scheme
510 EXPORT_C TInt RMMFDevSoundProxy::SyncCustomCommand(TUid aUid, const TDesC8& aParam1, const TDesC8& aParam2, TDes8* aOutParam)
512 // the UID of the custom command is passed as an integer so as maintain consistency with the async methods below
513 TInt command = aUid.iUid;
517 return SendReceive(EMMFDevSoundProxySyncCustomCommand, command, aParam1, aParam2);
521 return SendReceiveResult(EMMFDevSoundProxySyncCustomCommandResult, command, aParam1, aParam2, *aOutParam);
525 EXPORT_C void RMMFDevSoundProxy::AsyncCustomCommand(TUid aUid, TRequestStatus& aStatus, const TDesC8& aParam1, const TDesC8& aParam2, TDes8* aOutParam)
527 // this seemingly only allows 1 simultaneous async call. Need an array of TRequestStatus for more than one call.
528 // the UID of the custom command is passed as an integer so as to prevent the need of a consistent UID array.
529 TInt command = aUid.iUid;
533 SendReceive(EMMFDevSoundProxyAsyncCustomCommand, command, aParam1, aParam2, aStatus);
537 SendReceiveResult(EMMFDevSoundProxyAsyncCustomCommandResult, command, aParam1, aParam2, *aOutParam, aStatus);
541 EXPORT_C TInt RMMFDevSoundProxy::SetClientThreadInfo(TThreadId& aTid)
543 TPckgBuf<TThreadId> threadId(aTid);
544 return SendReceive(EMMFDevSoundProxySetClientThreadInfo, threadId);