os/mm/devsound/sounddevbt/PlatSec/src/Server/AudioServer/MmfBtDevSoundSessionBody.inl
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.
16 #include <mmfbtswcodecwrapper.h> //for SwCodecWrapper CustomInterfaces
17 #include <mmfbtswcodecwrappercustominterfacesuids.hrh>
18 #include <mmf/plugin/mmfbthwdeviceimplementationuids.hrh>
21 #include <centralrepository.h> // for BT device address retrieval
22 #include "MmfBtRoutingPrioritySettings.h" //for ESpeaker, EA2DPBluetoothHeadset etc
25 * [TODO] this function is now too long to be inline
26 * Initializes DevSound object for the mode aMode for processing audio data
27 * with hardware device aHWDev.
29 * On completion of Initialization, the observer will be notified via call back
30 * InitializeComplete().
34 * @param "MDevSoundObserver& aDevSoundObserver"
35 * A reference to DevSound Observer instance.
37 * @param "TUid aHWDev"
38 * CMMFHwDevice implementation identifier.
40 * @param "TMMFState aMode"
41 * Mode for which this object will be used.
44 inline void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TUid aHWDev, TMMFState aMode)
46 TInt initError = KErrNone;
47 iDevSoundObserver = &aDevSoundObserver;
49 if (aMode == EMMFStateIdle)
51 User::Leave(KErrNotSupported);
55 // Given the mode, update the iDevInfo with the audio's route
56 if ((iMode == EMMFStateRecording)||(iMode == EMMFStatePlayingRecording))
57 {//DEF037912 incase the recording capabilities differ from play
58 User::LeaveIfError(InitializeFormat(iRecordFormatsSupported, iRecordFormat));
59 iDevInfo.iInStream.iConnection.iType = EConnectionGpp;
60 iDevInfo.iInStream.iConnection.iId = KDeviceUidMic.iUid;
62 if ((iMode == EMMFStatePlaying)||(iMode == EMMFStateTonePlaying)||(iMode == EMMFStatePlayingRecording))
64 iDevInfo.iOutStream.iConnection.iType = EConnectionGpp;
65 // If the bit on the priority settings is set indicating
66 // we are routing to the by headset then the HwDevice device id
67 // needs setting for the bluetooth headset
68 if (iAudioPolicyPrioritySettings.iPref & EA2DPBluetoothHeadset)
70 iDevInfo.iOutStream.iConnection.iId = KDeviceUidA2dpHeadset.iUid;
71 CRepository* centralRepository = NULL;
72 centralRepository = CRepository::NewL(KUidBTHeadsetRepository);
73 CleanupStack::PushL(centralRepository);
74 TInt64 btHeadsetAddress = 0;
75 TBuf<16> btHeadsetAddressString;
76 User::LeaveIfError(centralRepository->Get(0x01, btHeadsetAddressString));
77 TLex stringConverter(btHeadsetAddressString.Ptr());
78 User::LeaveIfError(stringConverter.Val(btHeadsetAddress,EHex));
79 TBTDevAddr bTDevAddr(btHeadsetAddress);
80 iDevInfo.iOutStream.iDeviceName = bTDevAddr.Des();
81 CleanupStack::Pop(centralRepository);
82 delete centralRepository;
86 iDevInfo.iOutStream.iConnection.iId = KDeviceUidSpeaker.iUid;
90 iDevSoundObserver = &aDevSoundObserver;
91 iHwDeviceID.iUid = aHWDev.iUid;
95 iHwDeviceBuffer = NULL; // buffer is deleted by HwDevice delete
96 iPlayCustomInterface = NULL; //custom interfaces are also invalid
97 iRecordCustomInterface = NULL;
100 iCMMFHwDevice = NULL;
102 // Load the HwDevice implementation from ECom
103 TRAP(initError, iCMMFHwDevice = CMMFHwDevice2::NewL(aHWDev));
105 if (initError == KErrNone)
107 iDevInfo.iHwDeviceObserver = this;
109 iCMMFHwDevice->Init(iDevInfo, iRSDHandler->iStatus);
110 iRSDHandler->Start();
112 TUid playCustomInterfaceUid;
113 playCustomInterfaceUid.iUid = KMmfPlaySettingsCustomInterface;
114 TUid recordCustomInterfaceUid;
115 recordCustomInterfaceUid.iUid = KMmfRecordSettingsCustomInterface;
116 iPlayCustomInterface =
117 (MPlayCustomInterface*)iCMMFHwDevice->CustomInterface(playCustomInterfaceUid);
118 if (!iPlayCustomInterface)
119 {//DEF40443 need to check custom interface has been created
120 initError = KErrNoMemory;//it won't if there is no memory
124 iRecordCustomInterface =
125 (MRecordCustomInterface*)iCMMFHwDevice->CustomInterface(recordCustomInterfaceUid);
126 if (!iRecordCustomInterface)
128 initError = KErrNoMemory;
135 iDevSoundObserver->InitializeComplete(initError);
136 User::Leave(initError);
142 * Initializes DevSound object for the mode aMode for processing audio data
143 * using an array of Hardware devices identified by aHWDevArray identifier
144 * array. The hardware devices are chained together with data flow starting
145 * with first array element.
147 * On completion of Initialization, the observer will be notified via call back
148 * InitializeComplete().
152 * @param "MDevSoundObserver& aDevSoundObserver"
153 * A reference to DevSound Observer instance.
155 * @param "CArrayPtr<TUid> aHWDevArray"
156 * Array of CMMFHwDevice implementation identifiers.
158 * @param "TMMFState aMode"
159 * Mode for which this object will be used.
162 inline void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& /*aDevSoundObserver*/, CArrayPtr<TUid> /*aHWDevArray*/, TMMFState /*aMode*/)
164 User::Leave(KErrNotSupported);
169 * Initializes DevSound object for the mode aMode for processing audio data
170 * with hardware device supporting FourCC aDesiredFourCC.
172 * On completion of Initialization, the observer will be notified via call back
173 * InitializeComplete().
177 * @param "MDevSoundObserver& aDevSoundObserver"
178 * A reference to DevSound Observer instance.
180 * @param "TFourCC aDesiredFourCC"
181 * CMMFHwDevice implementation FourCC.
183 * @param "TMMFState aMode"
184 * Mode for which this object will be used.
187 inline void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TFourCC aDesiredFourCC, TMMFState aMode)
189 // to get HW Uid from the FourCC
190 RImplInfoPtrArray plugInArray;
191 TFourCC KPCM16FourCC(' ','P','1','6');
192 _LIT(KNullString, "");
194 TUid hwDevicePluginInterface = {KMmfUidBtPluginInterfaceHwDevice};
197 CleanupResetAndDestroyPushL( plugInArray );
198 // Get the implementation UID based on the FourCC and mode.
199 if (aMode == EMMFStatePlaying)
200 {//destination four CC is pcm16
201 iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, aDesiredFourCC, KPCM16FourCC, KNullString);
203 else if (aMode == EMMFStateRecording)
204 {//source fourCC is pcm16
205 iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, KPCM16FourCC, aDesiredFourCC, KNullString);
207 else User::Leave(KErrNotSupported);//invalid aMode cant set 4CC for tone
209 if(plugInArray.Count() == 0)
210 { // couldn't find Decoder only implementation, try to get Decoder/Encoder
211 iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, aDesiredFourCC, aDesiredFourCC, KNullString);
212 if(plugInArray.Count() == 0)
213 User::Leave(KErrNotSupported);
215 implUid = plugInArray[0]->ImplementationUid(); // Just pick the first in the list
217 // If we made it here, there we have found implementation UID
218 InitializeL(aDevSoundObserver, implUid, aMode);
219 CleanupStack::PopAndDestroy() ; //pluginArray
224 * Returns the supported Audio settings.
226 * @return "TMMFCapabilities"
230 inline TMMFCapabilities CMMFDevSoundSvrImp::Capabilities()
232 if ((iAudioPolicyPrioritySettings.iPref & EA2DPBluetoothHeadset) && (iPlayCustomInterface))
234 //then we need to get the caps from the HwDevice
235 //actually we should get the Caps from the HwDevice in any case
236 //but am being cautious so as not to cause test regressions
237 TTaskConfig hwDeviceCaps = iPlayCustomInterface->Caps();
238 iDeviceCapabilities.iRate = hwDeviceCaps.iRate; //the two structures use the same enums so this is ok
239 if (hwDeviceCaps.iStereoMode & ETaskMono)
241 iDeviceCapabilities.iChannels = EMMFMono;
243 if (hwDeviceCaps.iStereoMode & ETaskInterleaved)
245 iDeviceCapabilities.iChannels |= EMMFStereo;
248 return iDeviceCapabilities;
253 * Returns the current audio settings.
255 * @return "TMMFCapabilities"
259 inline TMMFCapabilities CMMFDevSoundSvrImp::Config() const
261 return iDeviceConfig;
266 * Returns an integer representing the maximum volume.
268 * This is the maximum value which can be passed to CMMFDevSoundProxy::SetVolume.
271 * The maximum volume. This value is platform dependent but is always
272 * greater than or equal to one.
275 inline TInt CMMFDevSoundSvrImp::MaxVolume()
277 return iPlayFormatsSupported().iMaxVolume;
282 * Returns an integer representing the current volume.
285 * The current volume level.
288 inline TInt CMMFDevSoundSvrImp::Volume()
295 * Returns an integer representing the maximum gain.
297 * This is the maximum value which can be passed to CMMFDevSoundProxy::SetGain.
300 * The maximum gain. This value is platform dependent but is always
301 * greater than or equal to one.
304 inline TInt CMMFDevSoundSvrImp::MaxGain()
306 return iRecordFormatsSupported().iMaxVolume;//uses iMaxVolume for iMaxGain
311 * Returns an integer representing the current gain.
314 * The current gain level.
317 inline TInt CMMFDevSoundSvrImp::Gain()
324 * Returns the speaker balance set for playing.
328 * @param "TInt& aLeftPrecentage"
329 * On return contains the left speaker volume percentage.
331 * @param "TInt& aRightPercentage"
332 * On return contains the right speaker volume percentage.
335 inline void CMMFDevSoundSvrImp::GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
337 aLeftPercentage = iLeftPlayBalance;
338 aRightPercentage = iRightPlayBalance;
343 * Returns the microphone gain balance set for recording.
347 * @param "TInt& aLeftPercentage"
348 * On return contains the left microphone gain percentage.
350 * @param "TInt& aRightPercentage"
351 * On return contains the right microphone gain percentage.
354 inline void CMMFDevSoundSvrImp::GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
356 aLeftPercentage = iLeftRecordBalance;
357 aRightPercentage = iRightRecordBalance;
362 * Contine the process of recording. Once the buffer is filled with recorded
363 * data, the Observer gets reference to buffer along with callback
364 * BufferToBeEmptied(). After processing the buffer (copying over to a
365 * different buffer or writing to file) the client should call this
366 * method to continue recording process.
369 inline void CMMFDevSoundSvrImp::RecordData(const RMmfIpcMessage& aMessage)
371 ASSERT(iDevSoundObserver);
373 // Checkes if the client has a UserEnvironment capability
374 if (!aMessage.HasCapability(ECapabilityUserEnvironment))
376 iDevSoundObserver->RecordError(KErrPermissionDenied);
382 if(iMode== EMMFStateRecording)
384 iHwDeviceBuffer->Data().SetLength(iHwDeviceBuffer->RequestSize());
385 iCMMFHwDevice->ThisHwBufferEmptied(*iHwDeviceBuffer);
392 * Defines the number of times the audio is to be repeated during the tone
393 * playback operation.
395 * A period of silence can follow each playing of tone. The tone playing can
396 * be repeated indefinitely.
398 * @param "TInt aRepeatCount"
399 * The number of times the tone, together with the trailing silence,
400 * is to be repeated. If this is set to KMdaRepeatForever, then the
401 * tone, together with the trailing silence, is repeated indefinitely
402 * or until Stop() is called. If this is set to zero, then the tone is
405 * Supported only during tone playing.
408 inline void CMMFDevSoundSvrImp::SetToneRepeats(TInt aRepeatCount,
409 const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
411 iRepeatCount = aRepeatCount;
412 iRepeatTrailingSilence = aRepeatTrailingSilence;
417 * Defines the priority settings that should be used for this instance.
419 * @param "const TMMFPrioritySettings& aPrioritySettings"
420 * An class type representing the client's priority, priority
421 * preference and state.
424 inline void CMMFDevSoundSvrImp::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
426 iAudioPolicyPrioritySettings.iPref = aPrioritySettings.iPref;
427 iAudioPolicyPrioritySettings.iPriority = aPrioritySettings.iPriority;
432 * Initializes and starts conversion process. Once the process is initiated,
433 * observer's call back method BufferToBeFilled() is called with reference to
434 * the buffer into which source format data is to be read.
436 * The maximum size of data (in bytes) that can be converted is specified in
437 * CMMFBuffer::RequestSize(). Any data that is read into buffer beyond this
438 * size will be ignored.
443 inline void CMMFDevSoundSvrImp::ConvertInitL()
445 User::Leave(KErrNotSupported);
450 * Converts the data in the buffer from source format to destination format.
451 * After the data is converted to destination format, a reference to the buffer
452 * containing data in destination format is passed in the observer call back
453 * method BufferToBeEmptied().
455 * The amount of data contained in buffer is specified in
456 * CMMFBuffer::RequestSize().
459 inline void CMMFDevSoundSvrImp::ConvertData()
464 // No custom interfaces are supported so return NULL.
465 inline TAny* CMMFDevSoundSvrImp::CustomInterface(TUid /*aInterfaceId*/)
472 * Returns the number of available pre-defined tone sequences.
474 * This is the number of fixed sequence supported by DevSound by default.
477 * The fixed sequence count. This value is implementation dependent
478 * but is always greater than or equal to zero.
481 inline TInt CMMFDevSoundSvrImp::FixedSequenceCount()
483 return iFixedSequences->Count();
488 * Returns the name assigned to a specific pre-defined tone sequence.
490 * This is the number of fixed sequence supported by DevSound by default.
492 * The function raises a panic if sequence number specified invalid.
495 * A reference to a Descriptor containing the fixed sequence
496 * name indexed by aSequenceNumber.
498 * @param "TInt aSequenceNumber"
499 * The index identifying the specific pre-defined tone sequence. Index
500 * values are relative to zero.
501 * This can be any value from zero to the value returned by a call to
502 * CMdaAudioPlayerUtility::FixedSequenceCount() - 1.
503 * The function raises a panic if sequence number is not within this
507 inline const TDesC& CMMFDevSoundSvrImp::FixedSequenceName(TInt aSequenceNumber)
509 ASSERT((aSequenceNumber >= 0)&&(aSequenceNumber < iFixedSequences->Count()));
510 return iDevSoundUtil->FixedSequenceName(aSequenceNumber);
515 * Sets Id for this instance of DevSound
517 * @param "TInt aDevSoundId"
518 * Integer value assigned by Audio Policy Server
521 inline void CMMFDevSoundSvrImp::SetDevSoundId(TInt aDevSoundId)
523 iDevSoundInfo.iDevSoundId = aDevSoundId;
528 * Returns information about this DevSound instance.
530 * This method is used by Audio Policy Server to make audio policy decisions.
532 * @return "TMMFDevSoundinfo"
533 * A reference to TMMFDevSoundinfo object holding the current settings
534 * of this DevSound instance.
537 inline TMMFDevSoundInfo CMMFDevSoundSvrImp::DevSoundInfo()
539 return iDevSoundInfo;
544 * Updates the total bytes played.
547 inline void CMMFDevSoundSvrImp::UpdateBytesPlayed()
549 if (iPlayCustomInterface)
550 iPlayedBytesCount = iPlayCustomInterface->BytesPlayed();