os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundSessionBody.inl
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.
16 #include <mmf/server/mmfswcodecwrapper.h> //for SwCodecWrapper CustomInterfaces
17 #include <mmf/server/mmfswcodecwrappercustominterfacesuids.hrh>
18 #ifdef SYMBIAN_MULTIMEDIA_CODEC_API
19 #include <mmf/server/mmfhwdevicesetup.h>
20 #endif // SYMBIAN_MULTIMEDIA_CODEC_API
21 #include "MmfDevSoundServer.h"
22 #include "MmfDevSoundSessionBody.h"
25 * Initializes DevSound object for the mode aMode for processing audio data
26 * with hardware device aHWDev.
28 * On completion of Initialization, the observer will be notified via call back
29 * InitializeComplete().
33 * @param "MDevSoundObserver& aDevSoundObserver"
34 * A reference to DevSound Observer instance.
36 * @param "TUid aHWDev"
37 * CMMFHwDevice implementation identifier.
39 * @param "TMMFState aMode"
40 * Mode for which this object will be used.
45 _LIT(KMMFDevSoundSessionCategory, "MMFDevSoundSessionCategory");
46 inline void Panic(TInt aError)
48 User::Panic(KMMFDevSoundSessionCategory, aError);
50 enum TMMFDevSoundSessionPanics
52 TMMFDevSoundSessionPolicyNotInvalidated
56 inline void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TUid aHWDev, TMMFState aMode)
58 TInt initError = KErrNone;
59 iDevSoundObserver = &aDevSoundObserver;
61 if (aMode == EMMFStateIdle)
62 User::Leave(KErrNotSupported);
64 iMode= static_cast<TMMFDevSoundState> (aMode);
67 if (iMode == EMMFDevSoundStateRecording)
68 {//DEF037912 incase the recording capabilities differ from play
69 User::LeaveIfError(InitializeFormat(iRecordFormatsSupported, iRecordFormat));
73 iDevSoundObserver = &aDevSoundObserver;
74 iHwDeviceID.iUid = aHWDev.iUid;
78 iHwDeviceBuffer = NULL; // buffer is deleted by HwDevice delete
79 iPlayCustomInterface = NULL; //custom interfaces are also invalid
80 iRecordCustomInterface = NULL;
81 iTimePlayedCustomInterface = NULL;
86 // Load the HwDevice implementation from ECom
87 TRAP(initError,iCMMFHwDevice = CMMFHwDevice::NewL(aHWDev));//trap it to get debug print
89 if (initError == KErrNone)
91 #ifdef SYMBIAN_MULTIMEDIA_CODEC_API
94 MMdfHwDeviceSetup* setup = reinterpret_cast<MMdfHwDeviceSetup*>(iCMMFHwDevice->CustomInterface(KUidHwDeviceSetupInterface));
97 setup->SetDataTypesL(iSrcFourCC, iDestFourCC);
100 #endif // SYMBIAN_MULTIMEDIA_CODEC_API
101 iDevInfo.iHwDeviceObserver = this;
102 initError = iCMMFHwDevice->Init(iDevInfo);
103 if (initError == KErrNone)
105 TUid playCustomInterfaceUid;
106 playCustomInterfaceUid.iUid = KMmfPlaySettingsCustomInterface;
107 TUid recordCustomInterfaceUid;
108 recordCustomInterfaceUid.iUid = KMmfRecordSettingsCustomInterface;
109 iPlayCustomInterface =
110 (MPlayCustomInterface*)iCMMFHwDevice->CustomInterface(playCustomInterfaceUid);
111 if (!iPlayCustomInterface)
112 {//DEF40443 need to check custom interface has been created
113 initError = KErrNoMemory;//it won't if there is no memory
117 iRecordCustomInterface =
118 (MRecordCustomInterface*)iCMMFHwDevice->CustomInterface(recordCustomInterfaceUid);
119 if (!iRecordCustomInterface)
120 initError = KErrNoMemory;
125 // in the InitializeComplete() call we will signal the observer that the
126 // custom interface may have changed
127 iDevSoundObserver->InitializeComplete(initError);
131 User::Leave(initError);
133 __ASSERT_DEBUG(!(iHasPolicy&&(iMode == EMMFDevSoundStatePlaying)), Panic(TMMFDevSoundSessionPolicyNotInvalidated));
138 * Initializes DevSound object for the mode aMode for processing audio data
139 * with hardware device supporting FourCC aDesiredFourCC.
141 * On completion of Initialization, the observer will be notified via call back
142 * InitializeComplete().
146 * @param "MDevSoundObserver& aDevSoundObserver"
147 * A reference to DevSound Observer instance.
149 * @param "TFourCC aDesiredFourCC"
150 * CMMFHwDevice implementation FourCC.
152 * @param "TMMFState aMode"
153 * Mode for which this object will be used.
156 inline void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TFourCC aDesiredFourCC, TMMFState aMode)
158 // to get HW Uid from the FourCC
159 RImplInfoPtrArray plugInArray;
160 TFourCC KPCM16FourCC(' ','P','1','6');
161 _LIT(KNullString, "");
163 TUid hwDevicePluginInterface = {KMmfUidPluginInterfaceHwDevice};
166 CleanupResetAndDestroyPushL( plugInArray );
167 // Get the implementation UID based on the FourCC and mode.
168 #ifdef SYMBIAN_MULTIMEDIA_CODEC_API
170 RArray<TFourCC> dataTypes;
171 CleanupClosePushL(dataTypes);
173 TRAP(err, iDevSoundUtil->SeekCodecPluginsL(dataTypes, aMode, EFalse));
174 // if we find a new codec plugin
175 TBool found = EFalse;
176 if (!err && dataTypes.Find(aDesiredFourCC)!=KErrNotFound)
178 TRAP(err, iDevSoundUtil->FindHwDeviceAdapterL(hwDevicePluginInterface, plugInArray));
181 if (aMode == EMMFDevSoundStatePlaying)
182 {//destination four CC is pcm16
184 iSrcFourCC = aDesiredFourCC;
185 iDestFourCC = KPCM16FourCC;
187 else if (aMode == EMMFDevSoundStateRecording)
188 {//source fourCC is pcm16
190 iSrcFourCC = KPCM16FourCC;
191 iDestFourCC = aDesiredFourCC;
197 #endif // SYMBIAN_MULTIMEDIA_CODEC_API
199 plugInArray.ResetAndDestroy();
200 if (aMode == EMMFDevSoundStatePlaying)
201 {//destination four CC is pcm16
203 iSrcFourCC = aDesiredFourCC;
204 iDestFourCC = KPCM16FourCC;
205 iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, aDesiredFourCC, KPCM16FourCC, KNullString);
207 else if (aMode == EMMFDevSoundStateRecording)
208 {//source fourCC is pcm16
210 iSrcFourCC = KPCM16FourCC;
211 iDestFourCC = aDesiredFourCC;
212 iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, KPCM16FourCC, aDesiredFourCC, KNullString);
216 User::Leave(KErrNotSupported);//invalid aMode cant set 4CC for tone
221 if(plugInArray.Count() == 0)
222 { // couldn't find Decoder only implementation, try to get Decoder/Encoder
223 iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, aDesiredFourCC, aDesiredFourCC, KNullString);
224 if(plugInArray.Count() == 0)
225 User::Leave(KErrNotSupported);
227 implUid = plugInArray[0]->ImplementationUid(); // Just pick the first in the list
229 #ifdef SYMBIAN_MULTIMEDIA_CODEC_API
230 CleanupStack::PopAndDestroy(2, &plugInArray) ; //pluginArray, dataTypes
232 CleanupStack::PopAndDestroy() ; //pluginArray
233 #endif // SYMBIAN_MULTIMEDIA_CODEC_API
234 // If we made it here, there we have found implementation UID
235 InitializeL(aDevSoundObserver, implUid, aMode);
236 __ASSERT_DEBUG(!(iHasPolicy&&(iMode == EMMFDevSoundStatePlaying)), Panic(TMMFDevSoundSessionPolicyNotInvalidated));
241 * Returns the supported Audio settings.
243 * @return "TMMFCapabilities"
247 inline TMMFCapabilities CMMFDevSoundSvrImp::Capabilities()
249 return iDeviceCapabilities;
254 * Returns the current audio settings.
256 * @return "TMMFCapabilities"
260 inline TMMFCapabilities CMMFDevSoundSvrImp::Config() const
262 return iDeviceConfig;
267 * Returns an integer representing the maximum volume.
269 * This is the maximum value which can be passed to CMMFDevSoundProxy::SetVolume.
272 * The maximum volume. This value is platform dependent but is always
273 * greater than or equal to one.
276 inline TInt CMMFDevSoundSvrImp::MaxVolume()
278 return iPlayFormatsSupported().iMaxVolume;
283 * Returns an integer representing the current volume.
286 * The current volume level.
289 inline TInt CMMFDevSoundSvrImp::Volume()
296 * Returns an integer representing the maximum gain.
298 * This is the maximum value which can be passed to CMMFDevSoundProxy::SetGain.
301 * The maximum gain. This value is platform dependent but is always
302 * greater than or equal to one.
305 inline TInt CMMFDevSoundSvrImp::MaxGain()
307 return iRecordFormatsSupported().iMaxVolume;//uses iMaxVolume for iMaxGain
312 * Returns an integer representing the current gain.
315 * The current gain level.
318 inline TInt CMMFDevSoundSvrImp::Gain()
325 * Returns the speaker balance set for playing.
329 * @param "TInt& aLeftPrecentage"
330 * On return contains the left speaker volume percentage.
332 * @param "TInt& aRightPercentage"
333 * On return contains the right speaker volume percentage.
336 inline void CMMFDevSoundSvrImp::GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
338 aLeftPercentage = iLeftPlayBalance;
339 aRightPercentage = iRightPlayBalance;
344 * Returns the microphone gain balance set for recording.
348 * @param "TInt& aLeftPercentage"
349 * On return contains the left microphone gain percentage.
351 * @param "TInt& aRightPercentage"
352 * On return contains the right microphone gain percentage.
355 inline void CMMFDevSoundSvrImp::GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
357 aLeftPercentage = iLeftRecordBalance;
358 aRightPercentage = iRightRecordBalance;
363 * Contine the process of recording. Once the buffer is filled with recorded
364 * data, the Observer gets reference to buffer along with callback
365 * BufferToBeEmptied(). After processing the buffer (copying over to a
366 * different buffer or writing to file) the client should call this
367 * method to continue recording process.
370 inline TBool CMMFDevSoundSvrImp::RecordData(const RMmfIpcMessage& aMessage)
372 ASSERT(iDevSoundObserver);
373 if(iAudioPolicyPrioritySettings.iState != EMMFStateRecordData)
375 PanicClient(aMessage, EMMFDevSoundRecordDataWithoutInitialize);
378 // Checkes if the client has a UserEnvironment capability
379 if (!aMessage.HasCapability(ECapabilityUserEnvironment))
381 iDevSoundObserver->RecordError(KErrPermissionDenied);
386 if ((iMode == EMMFDevSoundStateRecording) && iHasPolicy)
388 iHwDeviceBuffer->Data().SetLength(iHwDeviceBuffer->RequestSize());
389 TInt error = iCMMFHwDevice->ThisHwBufferEmptied(*iHwDeviceBuffer);
390 if(error != KErrNone)
393 iCMMFHwDevice->Stop();
403 * Defines the number of times the audio is to be repeated during the tone
404 * playback operation.
406 * A period of silence can follow each playing of tone. The tone playing can
407 * be repeated indefinitely.
409 * @param "TInt aRepeatCount"
410 * The number of times the tone, together with the trailing silence,
411 * is to be repeated. If this is set to KMdaRepeatForever, then the
412 * tone, together with the trailing silence, is repeated indefinitely
413 * or until Stop() is called. If this is set to zero, then the tone is
416 * Supported only during tone playing.
419 inline void CMMFDevSoundSvrImp::SetToneRepeats(TInt aRepeatCount,
420 const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
422 iRepeatCount = aRepeatCount;
423 iRepeatTrailingSilence = aRepeatTrailingSilence;
428 * Defines the priority settings that should be used for this instance.
430 * @param "const TMMFPrioritySettings& aPrioritySettings"
431 * An class type representing the client's priority, priority
432 * preference and state.
435 inline void CMMFDevSoundSvrImp::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
437 iAudioPolicyPrioritySettings.iPref = aPrioritySettings.iPref;
438 iAudioPolicyPrioritySettings.iPriority = aPrioritySettings.iPriority;
441 // Currently only support bitrate custom interface
442 inline TAny* CMMFDevSoundSvrImp::CustomInterface(TUid aInterfaceId)
447 ptr = iCMMFHwDevice->CustomInterface(aInterfaceId);
455 * Returns the number of available pre-defined tone sequences.
457 * This is the number of fixed sequence supported by DevSound by default.
460 * The fixed sequence count. This value is implementation dependent
461 * but is always greater than or equal to zero.
464 inline TInt CMMFDevSoundSvrImp::FixedSequenceCount()
466 return iFixedSequences->Count();
471 * Returns the name assigned to a specific pre-defined tone sequence.
473 * This is the number of fixed sequence supported by DevSound by default.
475 * The function raises a panic if sequence number specified invalid.
478 * A reference to a Descriptor containing the fixed sequence
479 * name indexed by aSequenceNumber.
481 * @param "TInt aSequenceNumber"
482 * The index identifying the specific pre-defined tone sequence. Index
483 * values are relative to zero.
484 * This can be any value from zero to the value returned by a call to
485 * FixedSequenceCount() - 1.
486 * The function raises a panic if sequence number is not within this
489 * @see FixedSequenceCount()
492 inline const TDesC& CMMFDevSoundSvrImp::FixedSequenceName(TInt aSequenceNumber)
494 ASSERT((aSequenceNumber >= 0)&&(aSequenceNumber < iFixedSequences->Count()));
495 return iDevSoundUtil->FixedSequenceName(aSequenceNumber);
500 * Sets Id for this instance of DevSound
502 * @param "TInt aDevSoundId"
503 * Integer value assigned by Audio Policy Server
506 inline void CMMFDevSoundSvrImp::SetDevSoundId(TInt aDevSoundId)
508 iDevSoundInfo.iDevSoundId = aDevSoundId;
513 * Returns information about this DevSound instance.
515 * This method is used by Audio Policy Server to make audio policy decisions.
517 * @return "TMMFDevSoundinfo"
518 * A reference to TMMFDevSoundinfo object holding the current settings
519 * of this DevSound instance.
522 inline TMMFDevSoundInfo CMMFDevSoundSvrImp::DevSoundInfo()
524 return iDevSoundInfo;
529 * Updates the total bytes played.
532 inline void CMMFDevSoundSvrImp::UpdateBytesPlayed()
534 if (iPlayCustomInterface)
535 iPlayedBytesCount = iPlayCustomInterface->BytesPlayed();