First public contribution.
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 "MmfBtDevSoundProxy.h"
20 #include "MmfBtDevSoundServerStart.h"
21 #include "../../../inc/common/mmfBtBase.hrh"
22 #include "MmfBtAudioClientServer.h"
25 EXPORT_C void RMMFDevSoundProxy::Close()
27 RMmfSessionBase::Close();
32 EXPORT_C TInt RMMFDevSoundProxy::Open()
35 RMMFAudioServerProxy* audioServerProxy = NULL;
36 HBufC* devSoundServerName = NULL;
39 TRAP(err, iSeqName = HBufC::NewL(KMaxFixedSequenceNameLength));
46 TRAP(err, audioServerProxy = new (ELeave) RMMFAudioServerProxy());
54 err = audioServerProxy->Open();
57 delete audioServerProxy;
64 TRAP(err, devSoundServerName = audioServerProxy->GetDevSoundServerNameL());
67 audioServerProxy->Close();
68 delete audioServerProxy;
74 TPtr devSoundServerNamePtr = devSoundServerName->Des();
79 err = CreateSession(devSoundServerNamePtr, TVersion(KMMFDevSoundServerVersion,
80 KMMFDevSoundServerMinorVersionNumber,
81 KMMFDevSoundServerBuildVersionNumber));
83 if (err!=KErrNotFound && err!=KErrServerTerminated)
94 audioServerProxy->Close();
95 delete audioServerProxy;
96 delete devSoundServerName;
101 EXPORT_C TInt RMMFDevSoundProxy::SetDevSoundInfo()
103 return SendReceive(EMMFAudioLaunchRequests);
106 EXPORT_C TInt RMMFDevSoundProxy::InitializeL(TMMFState aMode)
108 TMMFDevSoundProxySettings set;
110 TMMFDevSoundProxySettingsPckg pckg(set);
111 return SendReceive(EMMFDevSoundProxyInitialize1, pckg);
114 EXPORT_C TInt RMMFDevSoundProxy::InitializeL(TUid aHWDev, TMMFState aMode)
116 TMMFDevSoundProxySettings set;
119 TMMFDevSoundProxySettingsPckg pckg(set);
120 return SendReceive(EMMFDevSoundProxyInitialize2, pckg);
123 EXPORT_C TInt RMMFDevSoundProxy::InitializeL(CArrayPtr<TUid> /*aHWDevArray*/, TMMFState /*aMode*/)
125 return SendReceive(EMMFDevSoundProxyInitialize3);
128 EXPORT_C TInt RMMFDevSoundProxy::InitializeL(TFourCC aDesiredFourCC, TMMFState aMode)
130 TMMFDevSoundProxySettings set;
131 set.iDesiredFourCC = aDesiredFourCC;
133 TMMFDevSoundProxySettingsPckg pckg(set);
134 return SendReceive(EMMFDevSoundProxyInitialize4, pckg);
137 EXPORT_C TMMFCapabilities RMMFDevSoundProxy::Capabilities()
139 TMMFDevSoundProxySettings set;
140 TMMFDevSoundProxySettingsPckg pckg(set);
141 SendReceiveResult(EMMFDevSoundProxyCapabilities,KNullDesC8,KNullDesC8,pckg);
145 EXPORT_C TMMFCapabilities RMMFDevSoundProxy::Config()
147 TMMFDevSoundProxySettings set;
148 TMMFDevSoundProxySettingsPckg pckg(set);
149 SendReceiveResult(EMMFDevSoundProxyConfig,KNullDesC8,KNullDesC8,pckg);
150 return pckg().iConfig;
153 EXPORT_C TInt RMMFDevSoundProxy::SetConfigL(const TMMFCapabilities& aConfig)
155 TMMFDevSoundProxySettings set;
156 set.iConfig = aConfig;
157 TMMFDevSoundProxySettingsPckg pckg(set);
158 return SendReceive(EMMFDevSoundProxySetConfig, pckg);
161 EXPORT_C TInt RMMFDevSoundProxy::MaxVolume()
163 TMMFDevSoundProxySettings set;
164 TMMFDevSoundProxySettingsPckg pckg(set);
165 SendReceiveResult(EMMFDevSoundProxyMaxVolume,KNullDesC8,KNullDesC8,pckg);
166 return pckg().iMaxVolume;
169 EXPORT_C TInt RMMFDevSoundProxy::Volume()
171 TMMFDevSoundProxySettings set;
172 TMMFDevSoundProxySettingsPckg pckg(set);
173 SendReceiveResult(EMMFDevSoundProxyVolume,KNullDesC8,KNullDesC8,pckg);
174 return pckg().iVolume;
177 EXPORT_C TInt RMMFDevSoundProxy::SetVolume(TInt aVolume)
179 TMMFDevSoundProxySettings set;
180 set.iVolume = aVolume;
181 TMMFDevSoundProxySettingsPckg pckg(set);
182 return SendReceive(EMMFDevSoundProxySetVolume, pckg);
185 EXPORT_C TInt RMMFDevSoundProxy::MaxGain()
187 TMMFDevSoundProxySettings set;
188 TMMFDevSoundProxySettingsPckg pckg(set);
189 SendReceiveResult(EMMFDevSoundProxyMaxGain,KNullDesC8,KNullDesC8,pckg);
190 return pckg().iMaxGain;
193 EXPORT_C TInt RMMFDevSoundProxy::Gain()
195 TMMFDevSoundProxySettings set;
196 TMMFDevSoundProxySettingsPckg pckg(set);
197 SendReceiveResult(EMMFDevSoundProxyGain,KNullDesC8,KNullDesC8,pckg);
201 EXPORT_C TInt RMMFDevSoundProxy::SetGain(TInt aGain)
203 TMMFDevSoundProxySettings set;
205 TMMFDevSoundProxySettingsPckg pckg(set);
206 return SendReceive(EMMFDevSoundProxySetGain, pckg);
209 EXPORT_C void RMMFDevSoundProxy::GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
211 TMMFDevSoundProxySettings set;
212 TMMFDevSoundProxySettingsPckg pckg(set);
213 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyPlayBalance,KNullDesC8,KNullDesC8,pckg));
214 aLeftPercentage = pckg().iLeftPercentage;
215 aRightPercentage = pckg().iRightPercentage;
218 EXPORT_C void RMMFDevSoundProxy::SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
220 TMMFDevSoundProxySettings set;
221 set.iLeftPercentage = aLeftPercentage;
222 set.iRightPercentage = aRightPercentage;
223 TMMFDevSoundProxySettingsPckg pckg(set);
224 User::LeaveIfError(SendReceive(EMMFDevSoundProxySetPlayBalance, pckg));
227 EXPORT_C void RMMFDevSoundProxy::GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
229 TMMFDevSoundProxySettings set;
230 TMMFDevSoundProxySettingsPckg pckg(set);
231 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyRecordBalance,KNullDesC8,KNullDesC8,pckg));
232 aLeftPercentage = pckg().iLeftPercentage;
233 aRightPercentage = pckg().iRightPercentage;
236 EXPORT_C void RMMFDevSoundProxy::SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
238 TMMFDevSoundProxySettings set;
239 set.iLeftPercentage = aLeftPercentage;
240 set.iRightPercentage = aRightPercentage;
241 TMMFDevSoundProxySettingsPckg pckg(set);
242 User::LeaveIfError(SendReceive(EMMFDevSoundProxySetRecordBalance, pckg));
245 EXPORT_C void RMMFDevSoundProxy::PlayInitL()
247 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayInit));
250 EXPORT_C void RMMFDevSoundProxy::RecordInitL()
252 User::LeaveIfError(SendReceive(EMMFDevSoundProxyRecordInit));
255 EXPORT_C void RMMFDevSoundProxy::PlayData()
257 TMMFDevSoundProxyHwBuf set;
258 set.iLastBuffer = iBuffer->LastBuffer();
259 TMMFDevSoundProxyHwBufPckg pckg(set);
261 SendReceive(EMMFDevSoundProxyPlayData, pckg, iBuffer->Data());
264 EXPORT_C void RMMFDevSoundProxy::RecordData()
266 SendReceive(EMMFDevSoundProxyRecordData);
269 EXPORT_C void RMMFDevSoundProxy::Stop()
271 SendReceive(EMMFDevSoundProxyStop);
274 EXPORT_C void RMMFDevSoundProxy::Pause()
276 SendReceive(EMMFDevSoundProxyPause);
279 EXPORT_C void RMMFDevSoundProxy::PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
281 TMMFDevSoundProxySettings set;
282 set.iFrequencyOne = aFrequency;
283 set.iDuration = aDuration;
284 TMMFDevSoundProxySettingsPckg pckg(set);
285 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayTone, pckg));
288 EXPORT_C void RMMFDevSoundProxy::PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
290 TMMFDevSoundProxySettings set;
291 set.iFrequencyOne = aFrequencyOne;
292 set.iFrequencyTwo = aFrequencyTwo;
293 set.iDuration = aDuration;
294 TMMFDevSoundProxySettingsPckg pckg(set);
295 SendReceive(EMMFDevSoundProxyPlayDualTone, pckg);
298 EXPORT_C void RMMFDevSoundProxy::PlayDTMFStringL(const TDesC& aDTMFString)
300 SendReceive(EMMFDevSoundProxyPlayDTMFString, aDTMFString);
303 EXPORT_C void RMMFDevSoundProxy::PlayToneSequenceL(const TDesC8& aData)
305 User::LeaveIfError(SendReceive(EMMFDevSoundProxyPlayToneSequence, aData));
308 EXPORT_C void RMMFDevSoundProxy::PlayFixedSequenceL(TInt aSequenceNumber)
310 TPckgBuf<TInt> seqNum(aSequenceNumber);
311 SendReceive(EMMFDevSoundProxyPlayFixedSequence, seqNum);
314 EXPORT_C void RMMFDevSoundProxy::SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength,
315 TTimeIntervalMicroSeconds32& aToneOffLength,
316 TTimeIntervalMicroSeconds32& aPauseLength)
318 TMMFDevSoundProxySettings set;
319 set.iToneOnLength = aToneOnLength;
320 set.iToneOffLength = aToneOffLength;
321 set.iPauseLength = aPauseLength;
322 TMMFDevSoundProxySettingsPckg pckg(set);
323 SendReceive(EMMFDevSoundProxySetDTMFLengths, pckg);
326 EXPORT_C void RMMFDevSoundProxy::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
328 TMMFDevSoundProxySettings set;
329 set.iDuration = aRampDuration;
330 TMMFDevSoundProxySettingsPckg pckg(set);
331 SendReceive(EMMFDevSoundProxySetVolumeRamp, pckg);
334 EXPORT_C void RMMFDevSoundProxy::GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings)
336 aSupportedDataTypes.Reset();
338 TMMFPrioritySettings prioritySet = aPrioritySettings;
339 TMMFPrioritySettingsPckg pckg(prioritySet);
341 TPckgBuf<TInt> numberOfElementsPckg;
342 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyGetSupportedInputDataTypes, pckg, KNullDesC8, numberOfElementsPckg));
344 HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg()*sizeof(TFourCC));
345 TPtr8 ptr = buf->Des();
348 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyCopyFourCCArrayData,KNullDesC8,KNullDesC8,ptr));
349 RDesReadStream stream(ptr);
350 CleanupClosePushL(stream);
352 for (TInt i=0; i<numberOfElementsPckg(); i++)
354 TInt err = aSupportedDataTypes.Append(stream.ReadInt32L());
356 {//note we don't destroy array because we don't own it
357 //but we do reset it as it is incomplete
358 aSupportedDataTypes.Reset();
362 CleanupStack::PopAndDestroy(2, buf);//stream, buf
366 EXPORT_C void RMMFDevSoundProxy::GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings)
368 aSupportedDataTypes.Reset();
370 TMMFPrioritySettings prioritySet = aPrioritySettings;
371 TMMFPrioritySettingsPckg pckg(prioritySet);
373 TPckgBuf<TInt> numberOfElementsPckg;
374 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyGetSupportedOutputDataTypes, pckg, KNullDesC8, numberOfElementsPckg));
376 HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg()*sizeof(TFourCC));
377 TPtr8 ptr = buf->Des();
380 User::LeaveIfError(SendReceiveResult(EMMFDevSoundProxyCopyFourCCArrayData,KNullDesC8,KNullDesC8,ptr));
381 RDesReadStream stream(ptr);
382 CleanupClosePushL(stream);
384 for (TInt i=0; i<numberOfElementsPckg(); i++)
386 TInt err = aSupportedDataTypes.Append(stream.ReadInt32L());
388 {//note we don't destroy array because we don't own it
389 //but we do reset it as it is incomplete
390 aSupportedDataTypes.Reset();
394 CleanupStack::PopAndDestroy(2, buf);//stream, buf
397 EXPORT_C TInt RMMFDevSoundProxy::SamplesRecorded()
399 TPckgBuf<TInt> numSamples;
400 SendReceiveResult(EMMFDevSoundProxySamplesRecorded, KNullDesC8, KNullDesC8, numSamples);
404 EXPORT_C TInt RMMFDevSoundProxy::SamplesPlayed()
406 TPckgBuf<TInt> numSamples;
407 SendReceiveResult(EMMFDevSoundProxySamplesPlayed, KNullDesC8, KNullDesC8, numSamples);
411 EXPORT_C void RMMFDevSoundProxy::SetToneRepeats(TInt aRepeatCount, const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
413 TPckgBuf<TInt> countRepeat(aRepeatCount);
414 TPckgBuf<TTimeIntervalMicroSeconds> repeatTS(aRepeatTrailingSilence);
415 SendReceive(EMMFDevSoundProxySetToneRepeats, countRepeat, repeatTS);
418 EXPORT_C void RMMFDevSoundProxy::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
420 TPckgBuf<TMMFPrioritySettings> prioritySet(aPrioritySettings);
421 SendReceive(EMMFDevSoundProxySetPrioritySettings, prioritySet);
424 EXPORT_C const TDesC& RMMFDevSoundProxy::FixedSequenceName(TInt aSequenceNumber)
426 TPckgBuf<TInt> seqNum(aSequenceNumber);
427 TPtr SeqNamePtr = iSeqName->Des();
429 SendReceiveResult(EMMFDevSoundProxyFixedSequenceName, seqNum, KNullDesC8, SeqNamePtr);
434 EXPORT_C void RMMFDevSoundProxy::ConvertInitL()
436 SendReceive(EMMFDevSoundProxyConvertInit);
439 EXPORT_C void RMMFDevSoundProxy::ConvertData()
441 SendReceive(EMMFDevSoundProxyConvertData);
444 EXPORT_C TAny* RMMFDevSoundProxy::CustomInterface(TUid /*aInterfaceId*/)
446 // No custom interfaces are supported at the moment so return NULL.
451 EXPORT_C TInt RMMFDevSoundProxy::FixedSequenceCount()
453 TPckgBuf<TInt> fixSeqCountPckg;
454 SendReceiveResult(EMMFDevSoundProxyFixedSequenceCount, fixSeqCountPckg);
455 return fixSeqCountPckg();
458 EXPORT_C void RMMFDevSoundProxy::ReceiveInitializeCompleteEvent(TMMFDevSoundProxyHwBufPckg& aSetPckg, TRequestStatus& aStatus)
460 aStatus = KRequestPending;
461 SendReceive(EMMFDevSoundProxyReceiveICEvent, aSetPckg, aStatus);
464 EXPORT_C void RMMFDevSoundProxy::CancelReceiveInitializeCompleteEvent()
466 SendReceive(EMMFDevSoundProxyCancelReceiveICEvent);
469 EXPORT_C void RMMFDevSoundProxy::ReceiveBufferToBeFilledEvent(TMMFDevSoundProxyHwBufPckg& aSetPckg, TRequestStatus& aStatus)
471 aStatus = KRequestPending;
472 SendReceiveResult(EMMFDevSoundProxyReceiveBTBFEvent, aSetPckg, aStatus);
475 EXPORT_C void RMMFDevSoundProxy::CancelReceiveBufferToBeFilledEvent()
477 SendReceive(EMMFDevSoundProxyCancelReceiveBTBFEvent);
480 EXPORT_C void RMMFDevSoundProxy::ReceiveBufferToBeEmptiedEvent(TMMFDevSoundProxyHwBufPckg& aSetPckg, TRequestStatus& aStatus)
482 aStatus = KRequestPending;
483 SendReceiveResult(EMMFDevSoundProxyReceiveBTBEEvent, aSetPckg, aStatus);
486 EXPORT_C void RMMFDevSoundProxy::CancelReceiveBufferToBeEmptiedEvent()
488 SendReceive(EMMFDevSoundProxyCancelReceiveBTBEEvent);
491 EXPORT_C void RMMFDevSoundProxy::ReceivePlayErrorEvent(TMMFDevSoundProxyHwBufPckg& aSetPckg, TRequestStatus& aStatus)
493 aStatus = KRequestPending;
494 SendReceive(EMMFDevSoundProxyReceivePEEvent, aSetPckg, aStatus);
497 EXPORT_C void RMMFDevSoundProxy::CancelReceivePlayErrorEvent()
499 SendReceive(EMMFDevSoundProxyCancelReceivePEEvent);
502 EXPORT_C void RMMFDevSoundProxy::ReceiveRecordErrorEvent(TMMFDevSoundProxyHwBufPckg& aSetPckg, TRequestStatus& aStatus)
504 aStatus = KRequestPending;
505 SendReceive(EMMFDevSoundProxyReceiveREEvent, aSetPckg, aStatus);
508 EXPORT_C void RMMFDevSoundProxy::CancelReceiveRecordErrorEvent()
510 SendReceive(EMMFDevSoundProxyCancelReceiveREEvent);
513 EXPORT_C void RMMFDevSoundProxy::ReceiveToneFinishedEvent(TMMFDevSoundProxyHwBufPckg& aSetPckg, TRequestStatus& aStatus)
515 aStatus = KRequestPending;
516 SendReceive(EMMFDevSoundProxyReceiveTFEvent, aSetPckg, aStatus);
519 EXPORT_C void RMMFDevSoundProxy::CancelReceiveToneFinishedEvent()
521 SendReceive(EMMFDevSoundProxyCancelReceiveTFEvent);
524 EXPORT_C void RMMFDevSoundProxy::ReceiveSendEventToClientEvent(TMMFEventPckg& aEventPckg, TRequestStatus& aStatus)
526 aStatus = KRequestPending;
527 SendReceiveResult(EMMFDevSoundProxyReceiveSETCEvent, aEventPckg, aStatus);
530 EXPORT_C void RMMFDevSoundProxy::CancelReceiveSendEventToClientEvent()
532 SendReceive(EMMFDevSoundProxyCancelReceiveSETCEvent);
535 EXPORT_C void RMMFDevSoundProxy::SetBuffer(CMMFDataBuffer* aBuffer)
542 EXPORT_C TInt RMMFDevSoundProxy::GetRecordedBufferL(CMMFDataBuffer& aBuffer)
544 return SendReceiveResult(EMMFDevSoundProxyGetRecordedBuffer, aBuffer.Data());
547 EXPORT_C TInt RMMFDevSoundProxy::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
549 TMMFDevSoundProxySettings set;
550 set.iNotificationEventUid = aEventType;
551 TMMFDevSoundProxySettingsPckg pckg(set);
552 return SendReceive(EMMFDevSoundProxyRequestResourceNotification, pckg, aNotificationRegistrationData);
555 EXPORT_C TInt RMMFDevSoundProxy::CancelRegisterAsClient(TUid aEventType)
557 TMMFDevSoundProxySettings set;
558 set.iNotificationEventUid = aEventType;
559 TMMFDevSoundProxySettingsPckg pckg(set);
560 return SendReceiveResult(EMMFDevSoundProxyCancelRequestResourceNotification, pckg);
563 EXPORT_C TInt RMMFDevSoundProxy::GetResourceNotificationData(TUid aEventType, TDes8& aNotificationData)
565 TMMFDevSoundProxySettings set;
566 set.iNotificationEventUid = aEventType;
567 TMMFDevSoundProxySettingsPckg pckg(set);
568 return SendReceiveResult(EMMFDevSoundProxyGetResourceNotificationData, pckg,KNullDesC8,aNotificationData);
571 EXPORT_C TInt RMMFDevSoundProxy::WillResumePlay()
573 return SendReceive(EMMFDevSoundProxyWillResumePlay);
576 EXPORT_C TInt RMMFDevSoundProxy::SetClientThreadInfo(TThreadId& aTid)
578 TPckgBuf<TThreadId> threadId(aTid);
579 return SendReceive(EMMFDevSoundProxySetClientThreadInfo, threadId);