os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundSessionBody.inl
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundSessionBody.inl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,536 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <mmf/server/mmfswcodecwrapper.h> //for SwCodecWrapper CustomInterfaces
1.20 +#include <mmf/server/mmfswcodecwrappercustominterfacesuids.hrh>
1.21 +#ifdef SYMBIAN_MULTIMEDIA_CODEC_API
1.22 +#include <mmf/server/mmfhwdevicesetup.h>
1.23 +#endif // SYMBIAN_MULTIMEDIA_CODEC_API
1.24 +#include "MmfDevSoundServer.h"
1.25 +#include "MmfDevSoundSessionBody.h"
1.26 +/*
1.27 + *
1.28 + * Initializes DevSound object for the mode aMode for processing audio data
1.29 + * with hardware device aHWDev.
1.30 + *
1.31 + * On completion of Initialization, the observer will be notified via call back
1.32 + * InitializeComplete().
1.33 + *
1.34 + * Leaves on failure.
1.35 + *
1.36 + * @param "MDevSoundObserver& aDevSoundObserver"
1.37 + * A reference to DevSound Observer instance.
1.38 + *
1.39 + * @param "TUid aHWDev"
1.40 + * CMMFHwDevice implementation identifier.
1.41 + *
1.42 + * @param "TMMFState aMode"
1.43 + * Mode for which this object will be used.
1.44 + *
1.45 + */
1.46 +
1.47 + #ifdef _DEBUG
1.48 +_LIT(KMMFDevSoundSessionCategory, "MMFDevSoundSessionCategory");
1.49 +inline void Panic(TInt aError)
1.50 + {
1.51 + User::Panic(KMMFDevSoundSessionCategory, aError);
1.52 + }
1.53 +enum TMMFDevSoundSessionPanics
1.54 + {
1.55 + TMMFDevSoundSessionPolicyNotInvalidated
1.56 + };
1.57 +#endif
1.58 +
1.59 +inline void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TUid aHWDev, TMMFState aMode)
1.60 + {
1.61 + TInt initError = KErrNone;
1.62 + iDevSoundObserver = &aDevSoundObserver;
1.63 +
1.64 + if (aMode == EMMFStateIdle)
1.65 + User::Leave(KErrNotSupported);
1.66 +
1.67 + iMode= static_cast<TMMFDevSoundState> (aMode);
1.68 + iHasPolicy = EFalse;
1.69 +
1.70 + if (iMode == EMMFDevSoundStateRecording)
1.71 + {//DEF037912 incase the recording capabilities differ from play
1.72 + User::LeaveIfError(InitializeFormat(iRecordFormatsSupported, iRecordFormat));
1.73 + }
1.74 +
1.75 +
1.76 + iDevSoundObserver = &aDevSoundObserver;
1.77 + iHwDeviceID.iUid = aHWDev.iUid;
1.78 + if(iCMMFHwDevice)
1.79 + {
1.80 + delete iCMMFHwDevice;
1.81 + iHwDeviceBuffer = NULL; // buffer is deleted by HwDevice delete
1.82 + iPlayCustomInterface = NULL; //custom interfaces are also invalid
1.83 + iRecordCustomInterface = NULL;
1.84 + iTimePlayedCustomInterface = NULL;
1.85 + }
1.86 +
1.87 + iCMMFHwDevice = NULL;
1.88 +
1.89 + // Load the HwDevice implementation from ECom
1.90 + TRAP(initError,iCMMFHwDevice = CMMFHwDevice::NewL(aHWDev));//trap it to get debug print
1.91 +
1.92 + if (initError == KErrNone)
1.93 + {
1.94 +#ifdef SYMBIAN_MULTIMEDIA_CODEC_API
1.95 + if (iFourCCSet)
1.96 + {
1.97 + MMdfHwDeviceSetup* setup = reinterpret_cast<MMdfHwDeviceSetup*>(iCMMFHwDevice->CustomInterface(KUidHwDeviceSetupInterface));
1.98 + if (setup!=NULL)
1.99 + {
1.100 + setup->SetDataTypesL(iSrcFourCC, iDestFourCC);
1.101 + }
1.102 + }
1.103 +#endif // SYMBIAN_MULTIMEDIA_CODEC_API
1.104 + iDevInfo.iHwDeviceObserver = this;
1.105 + initError = iCMMFHwDevice->Init(iDevInfo);
1.106 + if (initError == KErrNone)
1.107 + {
1.108 + TUid playCustomInterfaceUid;
1.109 + playCustomInterfaceUid.iUid = KMmfPlaySettingsCustomInterface;
1.110 + TUid recordCustomInterfaceUid;
1.111 + recordCustomInterfaceUid.iUid = KMmfRecordSettingsCustomInterface;
1.112 + iPlayCustomInterface =
1.113 + (MPlayCustomInterface*)iCMMFHwDevice->CustomInterface(playCustomInterfaceUid);
1.114 + if (!iPlayCustomInterface)
1.115 + {//DEF40443 need to check custom interface has been created
1.116 + initError = KErrNoMemory;//it won't if there is no memory
1.117 + }
1.118 + else
1.119 + {
1.120 + iRecordCustomInterface =
1.121 + (MRecordCustomInterface*)iCMMFHwDevice->CustomInterface(recordCustomInterfaceUid);
1.122 + if (!iRecordCustomInterface)
1.123 + initError = KErrNoMemory;
1.124 + }
1.125 + }
1.126 + }
1.127 +
1.128 + // in the InitializeComplete() call we will signal the observer that the
1.129 + // custom interface may have changed
1.130 + iDevSoundObserver->InitializeComplete(initError);
1.131 +
1.132 + if (initError)
1.133 + {
1.134 + User::Leave(initError);
1.135 + }
1.136 + __ASSERT_DEBUG(!(iHasPolicy&&(iMode == EMMFDevSoundStatePlaying)), Panic(TMMFDevSoundSessionPolicyNotInvalidated));
1.137 + }
1.138 +
1.139 +/*
1.140 + *
1.141 + * Initializes DevSound object for the mode aMode for processing audio data
1.142 + * with hardware device supporting FourCC aDesiredFourCC.
1.143 + *
1.144 + * On completion of Initialization, the observer will be notified via call back
1.145 + * InitializeComplete().
1.146 + *
1.147 + * Leaves on failure.
1.148 + *
1.149 + * @param "MDevSoundObserver& aDevSoundObserver"
1.150 + * A reference to DevSound Observer instance.
1.151 + *
1.152 + * @param "TFourCC aDesiredFourCC"
1.153 + * CMMFHwDevice implementation FourCC.
1.154 + *
1.155 + * @param "TMMFState aMode"
1.156 + * Mode for which this object will be used.
1.157 + *
1.158 + */
1.159 +inline void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TFourCC aDesiredFourCC, TMMFState aMode)
1.160 + {
1.161 + // to get HW Uid from the FourCC
1.162 + RImplInfoPtrArray plugInArray;
1.163 + TFourCC KPCM16FourCC(' ','P','1','6');
1.164 + _LIT(KNullString, "");
1.165 +
1.166 + TUid hwDevicePluginInterface = {KMmfUidPluginInterfaceHwDevice};
1.167 + TUid implUid = {0};
1.168 +
1.169 + CleanupResetAndDestroyPushL( plugInArray );
1.170 + // Get the implementation UID based on the FourCC and mode.
1.171 +#ifdef SYMBIAN_MULTIMEDIA_CODEC_API
1.172 + TInt err = KErrNone;
1.173 + RArray<TFourCC> dataTypes;
1.174 + CleanupClosePushL(dataTypes);
1.175 +
1.176 + TRAP(err, iDevSoundUtil->SeekCodecPluginsL(dataTypes, aMode, EFalse));
1.177 + // if we find a new codec plugin
1.178 + TBool found = EFalse;
1.179 + if (!err && dataTypes.Find(aDesiredFourCC)!=KErrNotFound)
1.180 + {
1.181 + TRAP(err, iDevSoundUtil->FindHwDeviceAdapterL(hwDevicePluginInterface, plugInArray));
1.182 + if (err == KErrNone)
1.183 + {
1.184 + if (aMode == EMMFDevSoundStatePlaying)
1.185 + {//destination four CC is pcm16
1.186 + iFourCCSet = ETrue;
1.187 + iSrcFourCC = aDesiredFourCC;
1.188 + iDestFourCC = KPCM16FourCC;
1.189 + }
1.190 + else if (aMode == EMMFDevSoundStateRecording)
1.191 + {//source fourCC is pcm16
1.192 + iFourCCSet = ETrue;
1.193 + iSrcFourCC = KPCM16FourCC;
1.194 + iDestFourCC = aDesiredFourCC;
1.195 + }
1.196 + found = ETrue;
1.197 + }
1.198 + }
1.199 + if (!found)
1.200 +#endif // SYMBIAN_MULTIMEDIA_CODEC_API
1.201 + {
1.202 + plugInArray.ResetAndDestroy();
1.203 + if (aMode == EMMFDevSoundStatePlaying)
1.204 + {//destination four CC is pcm16
1.205 + iFourCCSet = ETrue;
1.206 + iSrcFourCC = aDesiredFourCC;
1.207 + iDestFourCC = KPCM16FourCC;
1.208 + iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, aDesiredFourCC, KPCM16FourCC, KNullString);
1.209 + }
1.210 + else if (aMode == EMMFDevSoundStateRecording)
1.211 + {//source fourCC is pcm16
1.212 + iFourCCSet = ETrue;
1.213 + iSrcFourCC = KPCM16FourCC;
1.214 + iDestFourCC = aDesiredFourCC;
1.215 + iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, KPCM16FourCC, aDesiredFourCC, KNullString);
1.216 + }
1.217 + else
1.218 + {
1.219 + User::Leave(KErrNotSupported);//invalid aMode cant set 4CC for tone
1.220 + }
1.221 + }
1.222 +
1.223 +
1.224 + if(plugInArray.Count() == 0)
1.225 + { // couldn't find Decoder only implementation, try to get Decoder/Encoder
1.226 + iDevSoundUtil->SeekUsingFourCCL(hwDevicePluginInterface, plugInArray, aDesiredFourCC, aDesiredFourCC, KNullString);
1.227 + if(plugInArray.Count() == 0)
1.228 + User::Leave(KErrNotSupported);
1.229 + }
1.230 + implUid = plugInArray[0]->ImplementationUid(); // Just pick the first in the list
1.231 +
1.232 +#ifdef SYMBIAN_MULTIMEDIA_CODEC_API
1.233 + CleanupStack::PopAndDestroy(2, &plugInArray) ; //pluginArray, dataTypes
1.234 +#else
1.235 + CleanupStack::PopAndDestroy() ; //pluginArray
1.236 +#endif // SYMBIAN_MULTIMEDIA_CODEC_API
1.237 + // If we made it here, there we have found implementation UID
1.238 + InitializeL(aDevSoundObserver, implUid, aMode);
1.239 + __ASSERT_DEBUG(!(iHasPolicy&&(iMode == EMMFDevSoundStatePlaying)), Panic(TMMFDevSoundSessionPolicyNotInvalidated));
1.240 + }
1.241 +
1.242 +/*
1.243 + *
1.244 + * Returns the supported Audio settings.
1.245 + *
1.246 + * @return "TMMFCapabilities"
1.247 + * Device settings.
1.248 + *
1.249 + */
1.250 +inline TMMFCapabilities CMMFDevSoundSvrImp::Capabilities()
1.251 + {
1.252 + return iDeviceCapabilities;
1.253 + }
1.254 +
1.255 +/*
1.256 + *
1.257 + * Returns the current audio settings.
1.258 + *
1.259 + * @return "TMMFCapabilities"
1.260 + * Device settings.
1.261 + *
1.262 + */
1.263 +inline TMMFCapabilities CMMFDevSoundSvrImp::Config() const
1.264 + {
1.265 + return iDeviceConfig;
1.266 + }
1.267 +
1.268 +/*
1.269 + *
1.270 + * Returns an integer representing the maximum volume.
1.271 + *
1.272 + * This is the maximum value which can be passed to CMMFDevSoundProxy::SetVolume.
1.273 + *
1.274 + * @return "TInt"
1.275 + * The maximum volume. This value is platform dependent but is always
1.276 + * greater than or equal to one.
1.277 + *
1.278 + */
1.279 +inline TInt CMMFDevSoundSvrImp::MaxVolume()
1.280 + {
1.281 + return iPlayFormatsSupported().iMaxVolume;
1.282 + }
1.283 +
1.284 +/*
1.285 + *
1.286 + * Returns an integer representing the current volume.
1.287 + *
1.288 + * @return "TInt"
1.289 + * The current volume level.
1.290 + *
1.291 + */
1.292 +inline TInt CMMFDevSoundSvrImp::Volume()
1.293 + {
1.294 + return iVolume;
1.295 + }
1.296 +
1.297 +/*
1.298 + *
1.299 + * Returns an integer representing the maximum gain.
1.300 + *
1.301 + * This is the maximum value which can be passed to CMMFDevSoundProxy::SetGain.
1.302 + *
1.303 + * @return "TInt"
1.304 + * The maximum gain. This value is platform dependent but is always
1.305 + * greater than or equal to one.
1.306 + *
1.307 + */
1.308 +inline TInt CMMFDevSoundSvrImp::MaxGain()
1.309 + {
1.310 + return iRecordFormatsSupported().iMaxVolume;//uses iMaxVolume for iMaxGain
1.311 + }
1.312 +
1.313 +/*
1.314 + *
1.315 + * Returns an integer representing the current gain.
1.316 + *
1.317 + * @return "TInt"
1.318 + * The current gain level.
1.319 + *
1.320 + */
1.321 +inline TInt CMMFDevSoundSvrImp::Gain()
1.322 + {
1.323 + return iGain;
1.324 + }
1.325 +
1.326 +/*
1.327 + *
1.328 + * Returns the speaker balance set for playing.
1.329 + *
1.330 + * Leaves on failure.
1.331 + *
1.332 + * @param "TInt& aLeftPrecentage"
1.333 + * On return contains the left speaker volume percentage.
1.334 + *
1.335 + * @param "TInt& aRightPercentage"
1.336 + * On return contains the right speaker volume percentage.
1.337 + *
1.338 + */
1.339 +inline void CMMFDevSoundSvrImp::GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
1.340 + {
1.341 + aLeftPercentage = iLeftPlayBalance;
1.342 + aRightPercentage = iRightPlayBalance;
1.343 + }
1.344 +
1.345 +/*
1.346 + *
1.347 + * Returns the microphone gain balance set for recording.
1.348 + *
1.349 + * Leaves on failure.
1.350 + *
1.351 + * @param "TInt& aLeftPercentage"
1.352 + * On return contains the left microphone gain percentage.
1.353 + *
1.354 + * @param "TInt& aRightPercentage"
1.355 + * On return contains the right microphone gain percentage.
1.356 + *
1.357 + */
1.358 +inline void CMMFDevSoundSvrImp::GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage)
1.359 + {
1.360 + aLeftPercentage = iLeftRecordBalance;
1.361 + aRightPercentage = iRightRecordBalance;
1.362 + }
1.363 +
1.364 +/*
1.365 + *
1.366 + * Contine the process of recording. Once the buffer is filled with recorded
1.367 + * data, the Observer gets reference to buffer along with callback
1.368 + * BufferToBeEmptied(). After processing the buffer (copying over to a
1.369 + * different buffer or writing to file) the client should call this
1.370 + * method to continue recording process.
1.371 + *
1.372 + */
1.373 +inline TBool CMMFDevSoundSvrImp::RecordData(const RMmfIpcMessage& aMessage)
1.374 + {
1.375 + ASSERT(iDevSoundObserver);
1.376 + if(iAudioPolicyPrioritySettings.iState != EMMFStateRecordData)
1.377 + {
1.378 + PanicClient(aMessage, EMMFDevSoundRecordDataWithoutInitialize);
1.379 + return EFalse;
1.380 + }
1.381 + // Checkes if the client has a UserEnvironment capability
1.382 + if (!aMessage.HasCapability(ECapabilityUserEnvironment))
1.383 + {
1.384 + iDevSoundObserver->RecordError(KErrPermissionDenied);
1.385 + return ETrue;
1.386 + }
1.387 + if(iCMMFHwDevice)
1.388 + {
1.389 + if ((iMode == EMMFDevSoundStateRecording) && iHasPolicy)
1.390 + {
1.391 + iHwDeviceBuffer->Data().SetLength(iHwDeviceBuffer->RequestSize());
1.392 + TInt error = iCMMFHwDevice->ThisHwBufferEmptied(*iHwDeviceBuffer);
1.393 + if(error != KErrNone)
1.394 + {
1.395 + Error(error);
1.396 + iCMMFHwDevice->Stop();
1.397 + }
1.398 +
1.399 + }
1.400 + }
1.401 + return ETrue;
1.402 + }
1.403 +
1.404 +/*
1.405 + *
1.406 + * Defines the number of times the audio is to be repeated during the tone
1.407 + * playback operation.
1.408 + *
1.409 + * A period of silence can follow each playing of tone. The tone playing can
1.410 + * be repeated indefinitely.
1.411 + *
1.412 + * @param "TInt aRepeatCount"
1.413 + * The number of times the tone, together with the trailing silence,
1.414 + * is to be repeated. If this is set to KMdaRepeatForever, then the
1.415 + * tone, together with the trailing silence, is repeated indefinitely
1.416 + * or until Stop() is called. If this is set to zero, then the tone is
1.417 + * not repeated.
1.418 + *
1.419 + * Supported only during tone playing.
1.420 + *
1.421 + */
1.422 +inline void CMMFDevSoundSvrImp::SetToneRepeats(TInt aRepeatCount,
1.423 + const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
1.424 + {
1.425 + iRepeatCount = aRepeatCount;
1.426 + iRepeatTrailingSilence = aRepeatTrailingSilence;
1.427 + }
1.428 +
1.429 +/*
1.430 + *
1.431 + * Defines the priority settings that should be used for this instance.
1.432 + *
1.433 + * @param "const TMMFPrioritySettings& aPrioritySettings"
1.434 + * An class type representing the client's priority, priority
1.435 + * preference and state.
1.436 + *
1.437 + */
1.438 +inline void CMMFDevSoundSvrImp::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
1.439 + {
1.440 + iAudioPolicyPrioritySettings.iPref = aPrioritySettings.iPref;
1.441 + iAudioPolicyPrioritySettings.iPriority = aPrioritySettings.iPriority;
1.442 + }
1.443 +
1.444 +// Currently only support bitrate custom interface
1.445 +inline TAny* CMMFDevSoundSvrImp::CustomInterface(TUid aInterfaceId)
1.446 + {
1.447 + TAny* ptr = NULL;
1.448 + if (iCMMFHwDevice)
1.449 + {
1.450 + ptr = iCMMFHwDevice->CustomInterface(aInterfaceId);
1.451 + }
1.452 +
1.453 + return ptr;
1.454 + }
1.455 +
1.456 +/*
1.457 + *
1.458 + * Returns the number of available pre-defined tone sequences.
1.459 + *
1.460 + * This is the number of fixed sequence supported by DevSound by default.
1.461 + *
1.462 + * @return "TInt"
1.463 + * The fixed sequence count. This value is implementation dependent
1.464 + * but is always greater than or equal to zero.
1.465 + *
1.466 + */
1.467 +inline TInt CMMFDevSoundSvrImp::FixedSequenceCount()
1.468 + {
1.469 + return iFixedSequences->Count();
1.470 + }
1.471 +
1.472 +/*
1.473 + *
1.474 + * Returns the name assigned to a specific pre-defined tone sequence.
1.475 + *
1.476 + * This is the number of fixed sequence supported by DevSound by default.
1.477 + *
1.478 + * The function raises a panic if sequence number specified invalid.
1.479 + *
1.480 + * @return "TDesC&"
1.481 + * A reference to a Descriptor containing the fixed sequence
1.482 + * name indexed by aSequenceNumber.
1.483 + *
1.484 + * @param "TInt aSequenceNumber"
1.485 + * The index identifying the specific pre-defined tone sequence. Index
1.486 + * values are relative to zero.
1.487 + * This can be any value from zero to the value returned by a call to
1.488 + * FixedSequenceCount() - 1.
1.489 + * The function raises a panic if sequence number is not within this
1.490 + * range.
1.491 + *
1.492 + * @see FixedSequenceCount()
1.493 + *
1.494 + */
1.495 +inline const TDesC& CMMFDevSoundSvrImp::FixedSequenceName(TInt aSequenceNumber)
1.496 + {
1.497 + ASSERT((aSequenceNumber >= 0)&&(aSequenceNumber < iFixedSequences->Count()));
1.498 + return iDevSoundUtil->FixedSequenceName(aSequenceNumber);
1.499 + }
1.500 +
1.501 +/*
1.502 + *
1.503 + * Sets Id for this instance of DevSound
1.504 + *
1.505 + * @param "TInt aDevSoundId"
1.506 + * Integer value assigned by Audio Policy Server
1.507 + *
1.508 + */
1.509 +inline void CMMFDevSoundSvrImp::SetDevSoundId(TInt aDevSoundId)
1.510 + {
1.511 + iDevSoundInfo.iDevSoundId = aDevSoundId;
1.512 + }
1.513 +
1.514 +/*
1.515 + *
1.516 + * Returns information about this DevSound instance.
1.517 + *
1.518 + * This method is used by Audio Policy Server to make audio policy decisions.
1.519 + *
1.520 + * @return "TMMFDevSoundinfo"
1.521 + * A reference to TMMFDevSoundinfo object holding the current settings
1.522 + * of this DevSound instance.
1.523 + *
1.524 + */
1.525 +inline TMMFDevSoundInfo CMMFDevSoundSvrImp::DevSoundInfo()
1.526 + {
1.527 + return iDevSoundInfo;
1.528 + }
1.529 +
1.530 +
1.531 +/*
1.532 + * Updates the total bytes played.
1.533 + *
1.534 + */
1.535 +inline void CMMFDevSoundSvrImp::UpdateBytesPlayed()
1.536 + {
1.537 + if (iPlayCustomInterface)
1.538 + iPlayedBytesCount = iPlayCustomInterface->BytesPlayed();
1.539 + }