1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/a3fdevsound/src/devsoundadaptor/cdevaudiocontrol.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1235 @@
1.4 +// Copyright (c) 2006-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 +
1.20 +
1.21 +#include "cdevaudiocontrol.h"
1.22 +
1.23 +#include <a3f/audioprocessingunittypeuids.h>
1.24 +#include <mmf/server/mmfswcodecwrappercustominterfacesuids.hrh>
1.25 +#include <a3f/maudiocontext.h>
1.26 +#include <a3f/maudiostream.h>
1.27 +#include <a3f/maudiocodec.h>
1.28 +#include <a3f/maudiogaincontrol.h>
1.29 +
1.30 +
1.31 +const TInt KMicroSecondsInSecond = 1000000;
1.32 +const TInt KDefaultBufferSize = 4096;
1.33 +
1.34 +const TUint KMaxCallbacksExpected = 2;
1.35 +const TUint KDefaultSampleRate = 8000;
1.36 +const TUid KDefaultMode = {KA3FModeMonoValue};
1.37 +
1.38 +class TSampleRateTableEntry
1.39 + {
1.40 +public:
1.41 + TInt iSampleRateValue;
1.42 + TMMFSampleRate iSampleRate;
1.43 + };
1.44 +
1.45 +const TSampleRateTableEntry KRateTableLookup[] = {
1.46 + { 8000, EMMFSampleRate8000Hz },
1.47 + { 11025, EMMFSampleRate11025Hz },
1.48 + { 12000, EMMFSampleRate12000Hz },
1.49 + { 16000, EMMFSampleRate16000Hz },
1.50 + { 22050, EMMFSampleRate22050Hz },
1.51 + { 24000, EMMFSampleRate24000Hz },
1.52 + { 32000, EMMFSampleRate32000Hz },
1.53 + { 44100, EMMFSampleRate44100Hz },
1.54 + { 48000, EMMFSampleRate48000Hz },
1.55 + { 64000, EMMFSampleRate64000Hz },
1.56 + { 88200, EMMFSampleRate88200Hz },
1.57 + { 96000, EMMFSampleRate96000Hz },
1.58 + };
1.59 +const TInt KMaxSampleRateIndex = 11; // must agree with length of table
1.60 +
1.61 +class TAudioModeTableEntry
1.62 + {
1.63 +public:
1.64 + TMMFMonoStereo iAudioModeValue;
1.65 + TUid iAudioMode;
1.66 + };
1.67 +
1.68 +const TAudioModeTableEntry KModeTableLookup[] = {
1.69 + { EMMFMono, {KA3FModeMonoValue} },
1.70 + { EMMFStereo, {KA3FModeStereoNonInterleavedValue} },
1.71 + };
1.72 +
1.73 +const TInt KMaxModeIndex = 1; // must agree with length of table
1.74 +
1.75 +// ---------------------------------------------------------------------------
1.76 +// Default constructor
1.77 +// ---------------------------------------------------------------------------
1.78 +//
1.79 +CDevAudioControl::CDevAudioControl()
1.80 + {
1.81 + TRACE_CREATE();
1.82 + DP_CONTEXT(CDevAudioControl::CDevAudioControl *CD1*, CtxDevSound, DPLOCAL);
1.83 + DP_IN();
1.84 +
1.85 + // Local cache default values
1.86 + iCurrentSampleRate = KDefaultSampleRate;
1.87 + iCurrentMode = KDefaultMode;
1.88 + iOutstandingCallbacks = KMaxCallbacksExpected; //by default we expect 2 callbacks for capabilities.
1.89 + iCallbackFromAdaptor = KCallbackNone;
1.90 +
1.91 + DP_OUT();
1.92 + }
1.93 +
1.94 +
1.95 +void CDevAudioControl::ConstructL(CDevAudio* aDevAudio, MDevSoundAdaptationObserver& aDevSoundObserver)
1.96 + {
1.97 + TRACE_CREATE();
1.98 + DP_CONTEXT(CDevAudioControl::ConstructL *CD1*, CtxDevSound, DPLOCAL);
1.99 + DP_IN();
1.100 + iDevAudio = aDevAudio;
1.101 + iAdaptationObserver = &aDevSoundObserver;
1.102 +
1.103 + iObserverRegistered = EFalse;
1.104 +
1.105 + TAudioChannelGain left;
1.106 + TAudioChannelGain right;
1.107 +
1.108 + left.iLocation = TAudioChannelGain::ELeft;
1.109 + right.iLocation = TAudioChannelGain::ERight;
1.110 +
1.111 + User::LeaveIfError(iChannelGains.Append(left)); // assumed element 0 in rest of code
1.112 + User::LeaveIfError(iChannelGains.Append(right)); // assumed element 1 in rest of code
1.113 +
1.114 + // Note this could be delayed now (volume is internal to adaptor until later in cycle)
1.115 + // Needed to allow CMMFDevSound::MaxVolume and similar calls before CMMFDevSound::InitializeL
1.116 + TAny* interface(NULL);
1.117 + interface = iDevAudio->iGainControl->Interface(KUidAudioGainControl);
1.118 + iGainControl = static_cast<MAudioGainControl*>(interface);
1.119 + DP_OUT();
1.120 + }
1.121 +
1.122 +// ---------------------------------------------------------------------------
1.123 +// Destructor
1.124 +// ---------------------------------------------------------------------------
1.125 +//
1.126 +CDevAudioControl::~CDevAudioControl()
1.127 + {
1.128 + DP_CONTEXT(CDevAudioControl::~CDevAudioControl *CD1*, CtxDevSound, DPLOCAL);
1.129 + DP_IN();
1.130 + iChannelGains.Close();
1.131 + iSupportedRates.Close();
1.132 + iSupportedModes.Close();
1.133 + DP_OUT();
1.134 + }
1.135 +
1.136 +// -----------------------------------------------------------------------------
1.137 +// CacheAudioCodecIf
1.138 +//
1.139 +TInt CDevAudioControl::CacheAudioCodecIf()
1.140 + {
1.141 + DP_CONTEXT(CDevAudioControl::CacheAudioCodecIf *CD1*, CtxDevSound, DPLOCAL);
1.142 + DP_IN();
1.143 + if (iDevAudio->iAudioCodec==NULL)
1.144 + {
1.145 + DP0_RET(KErrNotReady,"%d");
1.146 + }
1.147 + TInt err = KErrNone;
1.148 + if (iAudioCodecIf==NULL)
1.149 + {
1.150 + MAudioCodec* codecInterface = static_cast<MAudioCodec*>(iDevAudio->iAudioCodec->Interface(KUidAudioCodec));
1.151 + __ASSERT_ALWAYS (codecInterface, CDevAudioControl::Panic(EAudioCodecIsNull));
1.152 + iAudioCodecIf = codecInterface;
1.153 + }
1.154 + DP0_RET(err,"%d");
1.155 + }
1.156 +
1.157 +
1.158 +// -----------------------------------------------------------------------------
1.159 +// CDevAudioControl::Initialize
1.160 +// -----------------------------------------------------------------------------
1.161 +//
1.162 +TInt CDevAudioControl::Initialize(TUid /*aFormat*/)
1.163 + {
1.164 + DP_CONTEXT(CDevAudioControl::Initialize *CD1*, CtxDevSound, DPLOCAL);
1.165 + DP_IN();
1.166 + ASSERT(EFalse);
1.167 + iObserverRegistered = EFalse;
1.168 + DP0_RET(KErrNone,"%d");
1.169 + }
1.170 +
1.171 +// -----------------------------------------------------------------------------
1.172 +// CDevAudioControl::Uninitialize
1.173 +// -----------------------------------------------------------------------------
1.174 +//
1.175 +TInt CDevAudioControl::Uninitialize()
1.176 + {
1.177 + DP_CONTEXT(CDevAudioControl::Uninitialize *CD1*, CtxDevSound, DPLOCAL);
1.178 + DP_IN();
1.179 +
1.180 + // Remove pUnits only allowed when stream is uninitialized
1.181 + TInt err = iDevAudio->iAudioStream->Uninitialize();
1.182 +
1.183 + if (err == KErrNone)
1.184 + {
1.185 + err = iDevAudio->CommitAudioContext();
1.186 + }
1.187 + if (err == KErrNone)
1.188 + {
1.189 + iDevAudio->iActiveState = EDevSoundAdaptorUninitialising;
1.190 + }
1.191 +
1.192 + DP0_RET(err,"%d");
1.193 + }
1.194 +
1.195 +// -----------------------------------------------------------------------------
1.196 +// CDevAudioControl::Unload
1.197 +// -----------------------------------------------------------------------------
1.198 +//
1.199 +TInt CDevAudioControl::Unload()
1.200 + {
1.201 + DP_CONTEXT(CDevAudioControl::Unload *CD1*, CtxDevSound, DPLOCAL);
1.202 + DP_IN();
1.203 +
1.204 + TInt err = iDevAudio->iAudioStream->Unload();
1.205 + if (err == KErrNone)
1.206 + {
1.207 + err = iDevAudio->CommitAudioContext();
1.208 + }
1.209 + if (err == KErrNone)
1.210 + {
1.211 + iDevAudio->iActiveState = EDevSoundAdaptorUnloading;
1.212 + }
1.213 +
1.214 + DP0_RET(err,"%d");
1.215 + }
1.216 +
1.217 +// -----------------------------------------------------------------------------
1.218 +// CDevAudioControl::GetCapabilities
1.219 +// -----------------------------------------------------------------------------
1.220 +//
1.221 +TInt CDevAudioControl::GetCapabilities(TMMFCapabilities& aCap)
1.222 + {
1.223 + DP_CONTEXT(CDevAudioControl::GetCapabilities *CD1*, CtxDevSound, DPLOCAL);
1.224 + DP_IN();
1.225 + // At this phase of CAP, we only care about current codec capabilities.
1.226 + // This will be supported as soon as the A3F API changes to support this are ready
1.227 + TInt err = KErrNone;
1.228 +
1.229 + if (iDevAudio->iActiveState != EDevSoundAdaptorCreated_Uninitialised)
1.230 + {
1.231 + err = CacheAudioCodecIf();
1.232 + if (err != KErrNone)
1.233 + {
1.234 + DP0_RET(err, "%d");
1.235 + }
1.236 +
1.237 + if (err == KErrNone)
1.238 + {
1.239 + err = iAudioCodecIf->GetSupportedModes(iSupportedModes);
1.240 + if (err == KErrNone)
1.241 + {
1.242 + aCap.iChannels = GetModes(iSupportedModes);
1.243 + err = iAudioCodecIf->GetSupportedSamplesRates(iSupportedRates);
1.244 +
1.245 + if (err == KErrNone)
1.246 + {
1.247 + aCap.iRate = GetSampleRates(iSupportedRates);
1.248 + }
1.249 + else
1.250 + {
1.251 + //If was a problem getting sampleRates we donīt expect callbacks and return
1.252 + iOutstandingCallbacks = 0;
1.253 + }
1.254 +
1.255 + }
1.256 + else
1.257 + {
1.258 + //If was a problem getting modes we donīt expect callbacks and return
1.259 + iOutstandingCallbacks = 0;
1.260 + }
1.261 + }
1.262 + }
1.263 + else
1.264 + {
1.265 + err = KErrNotReady;
1.266 + }
1.267 + DP0_RET(err, "%d");
1.268 + }
1.269 +
1.270 +// -----------------------------------------------------------------------------
1.271 +// CDevAudioControl::GetConfig
1.272 +// -----------------------------------------------------------------------------
1.273 +//
1.274 +TInt CDevAudioControl::GetConfig(TMMFCapabilities& aConfig)
1.275 + {
1.276 + DP_CONTEXT(CDevAudioControl::GetConfig *CD1*, CtxDevSound, DPLOCAL);
1.277 + DP_IN();
1.278 + TInt err(KErrNone);
1.279 +
1.280 + //TODO add a return error code if the sample rate or the channels are not found
1.281 + //We need to transform the local values to a supported value for the client
1.282 + aConfig.iRate = static_cast<TMMFSampleRate>(GetSampleRate(iCurrentSampleRate));
1.283 + aConfig.iChannels = static_cast<TMMFMonoStereo>(GetMode(iCurrentMode));
1.284 + aConfig.iBufferSize = KDefaultBufferSize;
1.285 +
1.286 + DP2(DLINFO, "rate 0x%x, channels 0x%x", aConfig.iRate, aConfig.iChannels);
1.287 +
1.288 + DP0_RET(err, "%d");
1.289 + }
1.290 +
1.291 +// -----------------------------------------------------------------------------
1.292 +// CDevAudioControl::SetConfig
1.293 +// -----------------------------------------------------------------------------
1.294 +//
1.295 +TInt CDevAudioControl::SetConfig(const TMMFCapabilities& aConfig)
1.296 + {
1.297 + DP_CONTEXT(CDevAudioControl::SetConfig *CD1*, CtxDevSound, DPLOCAL);
1.298 + DP_IN();
1.299 +
1.300 + // TODO need to ensure if iChannels or iSampleRate is outside known values, then
1.301 + // the code handles that gracefully and returns the appropriate error code
1.302 +
1.303 + TInt err(KErrNone);
1.304 + TUid mode = KNullUid;
1.305 + //Reset the desired values
1.306 + iDesiredSampleRate = 0;
1.307 + iDesiredMode = KNullUid;
1.308 +
1.309 + err = ResolveMode(aConfig.iChannels, mode);
1.310 + if (err != KErrNone)
1.311 + {
1.312 + DP0_RET(err, "%d");
1.313 + }
1.314 +
1.315 + err = ResolveSampleRate(aConfig.iRate, iDesiredSampleRate);
1.316 + if (err != KErrNone)
1.317 + {
1.318 + DP0_RET(err, "%d");
1.319 + }
1.320 +
1.321 + // At this phase of CAP, we only care about codec, which checks config against
1.322 + // its own capabilities. Verification against stream specific capabilities
1.323 + // should be added later on.
1.324 +
1.325 + err = CacheAudioCodecIf();
1.326 + if (err != KErrNone)
1.327 + {
1.328 + DP0_RET(err, "%d");
1.329 + }
1.330 +
1.331 + err = iAudioCodecIf->SetSampleRate(iDesiredSampleRate);
1.332 +
1.333 +
1.334 + if(err == KErrNone)
1.335 + {
1.336 + err = iAudioCodecIf->SetMode(mode);
1.337 + }
1.338 +
1.339 + if(err == KErrNone)
1.340 + {
1.341 + err = iDevAudio->CommitAudioContext();
1.342 + if (err == KErrNone)
1.343 + {
1.344 + iDesiredMode = mode;
1.345 + }
1.346 + }
1.347 +
1.348 + DP0_RET(err, "%d");
1.349 + }
1.350 +
1.351 +// -----------------------------------------------------------------------------
1.352 +// CDevAudioControl::ProcessInit
1.353 +// -----------------------------------------------------------------------------
1.354 +//
1.355 +TInt CDevAudioControl::ProcessInit()
1.356 + {
1.357 + DP_CONTEXT(CDevAudioControl::ProcessInit *CD1*, CtxDevSound, DPLOCAL);
1.358 + DP_IN();
1.359 + ASSERT(EFalse);
1.360 + DP0_RET(KErrNone,"%d");
1.361 + }
1.362 +
1.363 +// -----------------------------------------------------------------------------
1.364 +// CDevAudioControl::ProcessData
1.365 +// -----------------------------------------------------------------------------
1.366 +//
1.367 +void CDevAudioControl::ProcessData()
1.368 + {
1.369 + DP_CONTEXT(CDevAudioControl::ProcessData *CD1*, CtxDevSound, DPLOCAL);
1.370 + DP_IN();
1.371 + ASSERT(EFalse);
1.372 + DP_OUT();
1.373 + }
1.374 +
1.375 +// -----------------------------------------------------------------------------
1.376 +// CDevAudioControl::GetSamples
1.377 +// -----------------------------------------------------------------------------
1.378 +//
1.379 +TInt CDevAudioControl::GetSamples()
1.380 + {
1.381 + DP_CONTEXT(CDevAudioControl::GetSamples *CD1*, CtxDevSound, DPLOCAL);
1.382 + DP_IN();
1.383 + TInt err(KErrNone);
1.384 + TInt samplesplayed(0);
1.385 +
1.386 + TTimeIntervalMicroSeconds timeProcessed(0);
1.387 + err = iDevAudio->iAudioStream->GetStreamTime(timeProcessed);
1.388 +
1.389 + DP1(DLINFO,"CDevAudioControl::GetSamples iCurrentSampleRate %d",iCurrentSampleRate);
1.390 +
1.391 + if(err == KErrNone)
1.392 + {
1.393 + samplesplayed = (timeProcessed.Int64() * iCurrentSampleRate + KMicroSecondsInSecond/2) / TInt64(KMicroSecondsInSecond);
1.394 + }
1.395 + //TODO manage the error
1.396 +
1.397 + DP0_RET(samplesplayed, "%d");
1.398 + }
1.399 +
1.400 +// -----------------------------------------------------------------------------
1.401 +// CDevAudioControl::Stop
1.402 +// -----------------------------------------------------------------------------
1.403 +//
1.404 +TInt CDevAudioControl::Stop()
1.405 + {
1.406 + DP_CONTEXT(CDevAudioControl::Stop *CD1*, CtxDevSound, DPLOCAL);
1.407 + DP_IN();
1.408 + ASSERT(EFalse);
1.409 + DP0_RET(KErrNone, "%d");
1.410 + }
1.411 +
1.412 +// -----------------------------------------------------------------------------
1.413 +// CDevAudioControl::Pause
1.414 +// -----------------------------------------------------------------------------
1.415 +//
1.416 +TInt CDevAudioControl::Pause()
1.417 + {
1.418 + DP_CONTEXT(CDevAudioControl::Pause *CD1*, CtxDevSound, DPLOCAL);
1.419 + DP_IN();
1.420 + ASSERT(EFalse);
1.421 + DP0_RET(KErrNone, "%d");
1.422 + }
1.423 +
1.424 +// -----------------------------------------------------------------------------
1.425 +// CDevAudioControl::CustomInterface
1.426 +// -----------------------------------------------------------------------------
1.427 +//
1.428 +TAny* CDevAudioControl::CustomInterface(TUid aInterfaceId)
1.429 + {
1.430 + DP_CONTEXT(CDevAudioControl::CustomInterface *CD1*, CtxDevSound, DPLOCAL);
1.431 + DP_IN();
1.432 + TAny* ciPtr(NULL);
1.433 + TInt err = KErrNone;
1.434 + if(iDevAudio->iAudioStream)
1.435 + {
1.436 + TAny* ptr = iDevAudio->iAudioStream->Interface(KUidExtensionInferface);
1.437 + if(ptr)
1.438 + {
1.439 + MCustomInterfaceSupport* ciSupport = static_cast<MCustomInterfaceSupport*>(ptr);
1.440 + if(!iObserverRegistered)
1.441 + {
1.442 + err = ciSupport->RegisterObserver(*this);
1.443 + if(err == KErrNone)
1.444 + {
1.445 + iObserverRegistered = ETrue;
1.446 + }
1.447 + }
1.448 + err = ciSupport->RequestCustomInterface(aInterfaceId, ciPtr);
1.449 + if( err != KErrNone)
1.450 + {
1.451 + ciPtr = NULL;
1.452 + }
1.453 + }
1.454 + }
1.455 + DP0_RET(ciPtr, "0x%x");
1.456 + }
1.457 +
1.458 +// -----------------------------------------------------------------------------
1.459 +// CDevAudioControl::SetGain
1.460 +// -----------------------------------------------------------------------------
1.461 +TInt CDevAudioControl::SetGains(TInt aDevSoundGain, TInt aDevSoundMaxGain, TInt aBalance[2], const TTimeIntervalMicroSeconds& aRampDuration, TBool aBecomingActive)
1.462 + {
1.463 + DP_CONTEXT(CDevAudioControl::SetGains *CD1*, CtxDevSound, DPLOCAL);
1.464 + DP_IN();
1.465 + ASSERT(aDevSoundGain>=0 && aDevSoundGain<=aDevSoundMaxGain); // higher layer assumed to scale
1.466 + ASSERT(aBalance[ELeftCh]>=0 && aBalance[ELeftCh]<=100);
1.467 + ASSERT(aBalance[ERightCh]>=0 && aBalance[ERightCh]<=100);
1.468 + ASSERT(aDevSoundMaxGain>0); // assumed max gain is positive
1.469 + TInt a3fMaxGain;
1.470 + TInt err = iGainControl->GetMaxGain(a3fMaxGain);
1.471 + if (err==KErrNone)
1.472 + {
1.473 + iLegacyGain = TInt(TReal(aDevSoundGain)*TReal(a3fMaxGain)/TReal(aDevSoundMaxGain)+0.5);
1.474 + ASSERT(iLegacyGain>=0 && iLegacyGain<=a3fMaxGain);
1.475 + iLegacyLeft = aBalance[ELeftCh];
1.476 + iLegacyRight = aBalance[ERightCh];
1.477 +
1.478 + MapGains();
1.479 +
1.480 + // VolumeRamp is only applied when DevSound is becoming active
1.481 + if(err == KErrNone)
1.482 + {
1.483 + if (aRampDuration > 0 && aBecomingActive)
1.484 + {
1.485 + err = iGainControl->SetGain(iChannelGains, KUidGainSawTooth, aRampDuration);
1.486 + }
1.487 + else
1.488 + {
1.489 + err = iGainControl->SetGain(iChannelGains);
1.490 + }
1.491 + }
1.492 +
1.493 + // This call will result on commit only when we are already active
1.494 + // otherwise the changes will be commited by the DevAudioControl
1.495 + // It means we're here due to RequestGainAndBalance call
1.496 + if(err == KErrNone && !aBecomingActive)
1.497 + {
1.498 + err = iDevAudio->CommitAudioContext();
1.499 + }
1.500 + }
1.501 + DP0_RET(err,"%d");
1.502 + }
1.503 +
1.504 +
1.505 +// -----------------------------------------------------------------------------
1.506 +// CDevAudioControl::MapAndSetGains
1.507 +// -----------------------------------------------------------------------------
1.508 +//
1.509 +void CDevAudioControl::MapGains()
1.510 + {
1.511 + DP_CONTEXT(CDevAudioControl::MapGains *CD1*, CtxDevSound, DPLOCAL);
1.512 + DP_IN();
1.513 +
1.514 + // Map legacy values to CAP channel array.
1.515 + if ( iLegacyLeft == iLegacyRight )
1.516 + {
1.517 + iChannelGains[ELeftCh].iGain = iLegacyGain;
1.518 + iChannelGains[ERightCh].iGain = iLegacyGain;
1.519 + }
1.520 + else if ( iLegacyLeft > iLegacyRight )
1.521 + {
1.522 + iChannelGains[ELeftCh].iGain = iLegacyGain;
1.523 + iChannelGains[ERightCh].iGain =
1.524 + static_cast<TUint>((iLegacyGain*iLegacyRight)/iLegacyLeft);
1.525 + }
1.526 + else
1.527 + {
1.528 + iChannelGains[ERightCh].iGain = iLegacyGain;
1.529 + iChannelGains[ELeftCh].iGain =
1.530 + static_cast<TUint>((iLegacyGain*iLegacyLeft)/iLegacyRight);
1.531 + }
1.532 +
1.533 + DP_OUT();
1.534 + }
1.535 +
1.536 +// -----------------------------------------------------------------------------
1.537 +// CDevAudioControl::DestroyChain
1.538 +// -----------------------------------------------------------------------------
1.539 +//
1.540 +TBool CDevAudioControl::DestroyChain()
1.541 + {
1.542 + DP_CONTEXT(CDevAudioControl::DestroyChain *CD1*, CtxDevSound, DPLOCAL);
1.543 + DP_IN();
1.544 +
1.545 + TInt err = KErrNone;
1.546 + TBool readyToDestroy = EFalse;
1.547 + switch(iDevAudio->iActiveState)
1.548 + {
1.549 + case EDevSoundAdaptorActive_Active:
1.550 + case EDevSoundAdaptorPaused_Primed:
1.551 + {
1.552 + err = iDevAudio->iAudioStream->Stop();
1.553 + if(err == KErrNone)
1.554 + {
1.555 + err = iDevAudio->CommitAudioContext();
1.556 + }
1.557 + if (err == KErrNone)
1.558 + {
1.559 + iDevAudio->iActiveState = EDevSoundAdaptorStopping;
1.560 + }
1.561 + }
1.562 + break;
1.563 + case EDevSoundAdaptorInitialised_Idle:
1.564 + {
1.565 + err = iDevAudio->iAudioStream->Unload();
1.566 + if(err == KErrNone)
1.567 + {
1.568 + err = iDevAudio->CommitAudioContext();
1.569 + }
1.570 + if (err == KErrNone)
1.571 + {
1.572 + iDevAudio->iActiveState = EDevSoundAdaptorUnloading;
1.573 + }
1.574 + }
1.575 + break;
1.576 + case EDevSoundAdaptorInitialised_Initialised:
1.577 + {
1.578 + err = iDevAudio->iAudioStream->Uninitialize();
1.579 + if(err == KErrNone)
1.580 + {
1.581 + err = iDevAudio->CommitAudioContext();
1.582 + }
1.583 + if (err == KErrNone)
1.584 + {
1.585 + iDevAudio->iActiveState = EDevSoundAdaptorUninitialising;
1.586 + }
1.587 + }
1.588 + break;
1.589 + case EDevSoundAdaptorCreated_Uninitialised:
1.590 + readyToDestroy = ETrue;
1.591 + break;
1.592 + case EDevSoundAdaptorUnitialised_Uninitialised:
1.593 + //If following condition is true, then we are here because of a
1.594 + //pre-emption clash in last Commit cycle started from
1.595 + //CDevCommonControl::ContextEventUpdateWithStateEventNoError.
1.596 + if(iDevAudio->iPreviousState == EDevSoundAdaptorRemovingProcessingUnits)
1.597 + {
1.598 + err = RemoveProcessingUnits();
1.599 + break;
1.600 + }
1.601 + default:
1.602 + break;
1.603 + }
1.604 +
1.605 + // Destroy sequence fail!
1.606 + if(err != KErrNone)
1.607 + {
1.608 + DP0(DLINFO, "================ Destroy sequence fail! ================");
1.609 + readyToDestroy = ETrue;
1.610 + }
1.611 + // Set the flag only when needed
1.612 + iDevAudio->iClosing = !readyToDestroy;
1.613 + DP0_RET(readyToDestroy,"%d");
1.614 + }
1.615 +
1.616 +
1.617 +// -----------------------------------------------------------------------------
1.618 +// CDevAudioControl::RemoveProcessingUnits
1.619 +// -----------------------------------------------------------------------------
1.620 +//
1.621 +TInt CDevAudioControl::RemoveProcessingUnits()
1.622 + {
1.623 + DP_CONTEXT(CDevAudioControl::RemoveProcessingUnits *CD1*, CtxDevSound, DPLOCAL);
1.624 + DP_IN();
1.625 +
1.626 + // Remove pUnits only allowed when stream is uninitialized
1.627 + TInt err = iDevAudio->iAudioStream->RemoveProcessingUnit(iDevAudio->iAudioSource);
1.628 +
1.629 + if(err == KErrNone)
1.630 + {
1.631 + err = iDevAudio->iAudioStream->RemoveProcessingUnit(iDevAudio->iAudioSink);
1.632 + }
1.633 + if(err == KErrNone)
1.634 + {
1.635 + err = iDevAudio->iAudioStream->RemoveProcessingUnit(iDevAudio->iAudioCodec);
1.636 + }
1.637 +
1.638 + if (err == KErrNone)
1.639 + {
1.640 + err = iDevAudio->CommitAudioContext();
1.641 + }
1.642 +
1.643 + if(err == KErrNone)
1.644 + {
1.645 + iDevAudio->iActiveState = EDevSoundAdaptorRemovingProcessingUnits;
1.646 + }
1.647 + DP0_RET(err,"%d");
1.648 + }
1.649 +
1.650 +// -----------------------------------------------------------------------------
1.651 +// From class MAudioStreamObserver
1.652 +// CDevAudioControl::StateEvent
1.653 +// -----------------------------------------------------------------------------
1.654 +//
1.655 +void CDevAudioControl::StateEvent(MAudioStream& /*aStream*/,
1.656 + TInt /*aReason*/,
1.657 + TAudioState /*aNewState*/)
1.658 + {
1.659 + DP_CONTEXT(CDevAudio::StateEvent *CD1*, CtxDevSound, DPLOCAL);
1.660 + DP_IN();
1.661 + ASSERT(EFalse);
1.662 + DP_OUT();
1.663 + }
1.664 +
1.665 +// -----------------------------------------------------------------------------
1.666 +// From class MAudioStreamObserver
1.667 +// CDevAudioControl::AddProcessingUnitComplete
1.668 +// -----------------------------------------------------------------------------
1.669 +//
1.670 +void CDevAudioControl::AddProcessingUnitComplete(MAudioStream& /*aStream*/,
1.671 + MAudioProcessingUnit* /*aInstance*/,
1.672 + TInt /*aError*/)
1.673 + {
1.674 + }
1.675 +
1.676 +// -----------------------------------------------------------------------------
1.677 +// From class MAudioStreamObserver
1.678 +// CDevAudioControl::RemoveProcessingUnitComplete
1.679 +// -----------------------------------------------------------------------------
1.680 +//
1.681 +void CDevAudioControl::RemoveProcessingUnitComplete(MAudioStream& /*aStream*/,
1.682 + MAudioProcessingUnit* /*aInstance*/,
1.683 + TInt /*aError*/)
1.684 + {
1.685 + }
1.686 +
1.687 +// -----------------------------------------------------------------------------
1.688 +// From class MAudioStreamObserver
1.689 +// CDevAudioControl::ProcessingFinished
1.690 +// -----------------------------------------------------------------------------
1.691 +//
1.692 +void CDevAudioControl::ProcessingFinished(MAudioStream& /*aStream*/)
1.693 + {
1.694 + }
1.695 +
1.696 +// -----------------------------------------------------------------------------
1.697 +// From class MAudioStreamObserver
1.698 +// CDevAudioControl::FlushComplete
1.699 +// -----------------------------------------------------------------------------
1.700 +//
1.701 +void CDevAudioControl::FlushComplete (MAudioStream& /*aStream*/, TInt aError)
1.702 + {
1.703 + // no action needed - should complete as part of the ContextEvent.
1.704 + // otherwise could callback.
1.705 + TInt err = KErrNone;
1.706 +
1.707 + if(iPauseResumeSequenceDueToEmptyBuffers)
1.708 + {
1.709 + // Flush operation failed
1.710 + if(aError != KErrNone)
1.711 + {
1.712 + iPauseResumeSequenceDueToEmptyBuffers = EFalse;
1.713 + iAdaptationObserver->CallbackFromAdaptorReceived(KCallbackFlushComplete, aError);
1.714 + }
1.715 + // Handle throw-off scenarios, resume is not possible from here
1.716 + // 1. ProcessingFinished has occurred
1.717 + // 2. Preemption occurred
1.718 + else if(iCallbackFromAdaptor != KCallbackNone ||
1.719 + iDevAudio->iActiveState != EDevSoundAdaptorPaused_Primed)
1.720 + {
1.721 + iPauseResumeSequenceDueToEmptyBuffers = EFalse;
1.722 + iAdaptationObserver->CallbackFromAdaptorReceived(KCallbackFlushComplete, KErrNone);
1.723 +
1.724 + }
1.725 + else
1.726 + {
1.727 + err = Resume();
1.728 + if(err != KErrNone)
1.729 + {
1.730 + iPauseResumeSequenceDueToEmptyBuffers = EFalse;
1.731 + iAdaptationObserver->CallbackFromAdaptorReceived(KCallbackFlushComplete, aError);
1.732 + }
1.733 + // Once ContextEvent be received
1.734 + // EmptyBuffers can be considered completed
1.735 + }
1.736 + }
1.737 + // EmptyBuffers operation has concluded here
1.738 + // we didn't go through pause - resume sequence
1.739 + else
1.740 + {
1.741 + iAdaptationObserver->CallbackFromAdaptorReceived(KCallbackFlushComplete, aError);
1.742 + }
1.743 + }
1.744 +
1.745 +// -----------------------------------------------------------------------------
1.746 +// From class MAudioGainControlObserver
1.747 +// CDevAudioControl::MaxRampTimeChanged
1.748 +// -----------------------------------------------------------------------------
1.749 +//
1.750 +void CDevAudioControl::MaxRampTimeChanged(MAudioGainControl& /*aGain*/)
1.751 + {
1.752 + DP_CONTEXT(CDevAudioControl::MaxRampTimeChanged *CD1*, CtxDevSound, DPLOCAL);
1.753 + DP_IN();
1.754 + // this is not cached, no actions needed
1.755 + DP_OUT();
1.756 + }
1.757 +
1.758 +// -----------------------------------------------------------------------------
1.759 +// From class MAudioGainControlObserver
1.760 +// CDevAudioControl::MaxGainChanged
1.761 +// -----------------------------------------------------------------------------
1.762 +//
1.763 +void CDevAudioControl::MaxGainChanged(MAudioGainControl& /*aGain*/)
1.764 + {
1.765 + DP_CONTEXT(CDevAudioControl::MaxGainChanged *CD1*, CtxDevSound, DPLOCAL);
1.766 + DP_IN();
1.767 + // this is not cached, no actions needed
1.768 + DP_OUT();
1.769 + }
1.770 +
1.771 +// -----------------------------------------------------------------------------
1.772 +// From class MAudioGainControlObserver
1.773 +// CDevAudioControl::GainChanged
1.774 +// -----------------------------------------------------------------------------
1.775 +//
1.776 +void CDevAudioControl::GainChanged(MAudioGainControl& aGain, TInt aError)
1.777 + {
1.778 + DP_CONTEXT(CDevAudioControl::GainChanged *CD1*, CtxDevSound, DPLOCAL);
1.779 + DP1_IN("aError=%d", aError);
1.780 +
1.781 + if(aError != KErrNone)
1.782 + {
1.783 + // Either our request failed, or MMRC has forced some values, and we
1.784 + // have to update local values.
1.785 + aGain.GetGain(iChannelGains);
1.786 + ASSERT(iChannelGains.Count()==2);
1.787 + // Map CAP channel array to legacy values.
1.788 + // assumption: left%+right%=100
1.789 + if ( iChannelGains[ELeftCh].iGain == iChannelGains[ERightCh].iGain )
1.790 + {
1.791 + iLegacyGain = iChannelGains[ELeftCh].iGain;
1.792 + iLegacyLeft = 50;
1.793 + iLegacyRight = 50;
1.794 + }
1.795 + else if ( iChannelGains[ELeftCh].iGain > iChannelGains[ERightCh].iGain )
1.796 + {
1.797 + iLegacyGain = iChannelGains[ELeftCh].iGain;
1.798 + iLegacyLeft = static_cast<TUint>
1.799 + ((100*iLegacyGain)/(iLegacyGain+iChannelGains[ERightCh].iGain));
1.800 + iLegacyRight = 100 - iLegacyLeft;
1.801 + //(not that accurate, but sufficient for now)
1.802 + }
1.803 + else
1.804 + {
1.805 + iLegacyGain = iChannelGains[ERightCh].iGain;
1.806 + iLegacyRight = static_cast<TUint>
1.807 + ((100*iLegacyGain)/(iLegacyGain+iChannelGains[ELeftCh].iGain));
1.808 + iLegacyLeft = 100 - iLegacyRight;
1.809 + }
1.810 +
1.811 + DP3(DLINFO,"New values :iLegacyGain %d, iLegacyLeft %d, iLegacyRight %d",
1.812 + iLegacyGain,iLegacyLeft,iLegacyRight);
1.813 + }
1.814 + else
1.815 + {
1.816 + // our request completed succesfully, no need to update cached values
1.817 + // just print values in debug version
1.818 + #ifdef _DEBUG
1.819 + RArray<TAudioChannelGain> gains;
1.820 + TUint left;
1.821 + TUint right;
1.822 + TUint gain;
1.823 + aGain.GetGain(gains);
1.824 + ASSERT(gains.Count()==2);
1.825 + if ( iChannelGains[ELeftCh].iGain == iChannelGains[ERightCh].iGain )
1.826 + {
1.827 + gain = iChannelGains[ELeftCh].iGain;
1.828 + left = 50;
1.829 + right = 50;
1.830 + }
1.831 + else if ( iChannelGains[ELeftCh].iGain > iChannelGains[ERightCh].iGain )
1.832 + {
1.833 + gain = iChannelGains[ELeftCh].iGain;
1.834 + left =
1.835 + static_cast<TUint>((100*gain)/(gain+iChannelGains[ERightCh].iGain));
1.836 + right = 100 - left;
1.837 + }
1.838 + else
1.839 + {
1.840 + gain = iChannelGains[ERightCh].iGain;
1.841 + right =
1.842 + static_cast<TUint>((100*gain)/(gain+iChannelGains[ELeftCh].iGain));
1.843 + left = 100 - right;
1.844 + }
1.845 + gains.Close();
1.846 + DP3(DLINFO,"KErrNone (gain %d, left %d, right %d)", gain,left,right);
1.847 + #endif
1.848 + }
1.849 +
1.850 + DP_OUT();
1.851 + }
1.852 +
1.853 +// -----------------------------------------------------------------------------
1.854 +// From class MAudioCodecObserver
1.855 +// CDevAudioControl::SampleRateSet
1.856 +// -----------------------------------------------------------------------------
1.857 +void CDevAudioControl::SampleRateSet(TInt aError)
1.858 + {
1.859 + if(aError==KErrNone)
1.860 + {
1.861 + //Review if we call SetConfig or is only the first time that we load the codec
1.862 + if (iDesiredSampleRate > 0)
1.863 + {
1.864 + iCurrentSampleRate = iDesiredSampleRate;
1.865 + }
1.866 + }
1.867 + else
1.868 + {
1.869 + iAdaptationObserver->NotifyError(aError);
1.870 + }
1.871 + iDesiredSampleRate = 0;
1.872 + }
1.873 +
1.874 +// -----------------------------------------------------------------------------
1.875 +// From class MAudioCodecObserver
1.876 +// CDevAudioControl::ModeSet
1.877 +// -----------------------------------------------------------------------------
1.878 +void CDevAudioControl::ModeSet(TInt aError)
1.879 + {
1.880 + if(aError==KErrNone)
1.881 + {
1.882 + //Review if we call SetConfig or is only the first time that we load the codec
1.883 + if (iDesiredMode != KNullUid)
1.884 + {
1.885 + iCurrentMode = iDesiredMode;
1.886 + }
1.887 + }
1.888 + else
1.889 + {
1.890 + iAdaptationObserver->NotifyError(aError);
1.891 + }
1.892 + iDesiredMode = KNullUid;
1.893 + }
1.894 +
1.895 +// -----------------------------------------------------------------------------
1.896 +// From class MAudioCodecObserver
1.897 +// CDevAudioControl::GetSupportedSampleRatesComplete
1.898 +// -----------------------------------------------------------------------------
1.899 +void CDevAudioControl::GetSupportedSampleRatesComplete(TInt aError)
1.900 + {
1.901 + iSupportedRates.Reset();
1.902 + CompleteMessageCap(aError);
1.903 + }
1.904 +
1.905 +// -----------------------------------------------------------------------------
1.906 +// From class MAudioCodecObserver
1.907 +// CDevAudioControl::GetSupportedModesComplete
1.908 +// -----------------------------------------------------------------------------
1.909 +void CDevAudioControl::GetSupportedModesComplete(TInt aError)
1.910 + {
1.911 + iSupportedModes.Reset();
1.912 + CompleteMessageCap(aError);
1.913 + }
1.914 +
1.915 +// -----------------------------------------------------------------------------
1.916 +// CDevAudioControl::CompleteMessageCap
1.917 +// -----------------------------------------------------------------------------
1.918 +void CDevAudioControl::CompleteMessageCap(TInt aError)
1.919 + {
1.920 + if (iOutstandingCallbacks > 1) //waiting until the 2 outstanding callbacks arrival.
1.921 + {
1.922 + iOutstandingCallbacks--;
1.923 + iError = aError; //keeping the error.
1.924 + }
1.925 + else
1.926 + {
1.927 + if (iError == KErrNone)
1.928 + {
1.929 + iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
1.930 + }
1.931 + else
1.932 + {
1.933 + iAdaptationObserver->AsynchronousOperationComplete(iError, ETrue);
1.934 + }
1.935 + iError = KErrNone;
1.936 + iOutstandingCallbacks = KMaxCallbacksExpected;
1.937 + }
1.938 + }
1.939 +
1.940 +// -----------------------------------------------------------------------------
1.941 +// CDevAudioControl::SetToneData
1.942 +// -----------------------------------------------------------------------------
1.943 +//
1.944 +TInt CDevAudioControl::SetToneData(TToneData& /*aToneData*/)
1.945 + {
1.946 + DP_CONTEXT(CDevAudioControl::SetToneData *CD1*, CtxDevSound, DPLOCAL);
1.947 + DP_IN();
1.948 + DP0_RET(KErrNotSupported, "%d");
1.949 + }
1.950 +
1.951 +
1.952 +// -----------------------------------------------------------------------------
1.953 +// From class MAudioContextObserver
1.954 +// CDevAudio::ContextEvent
1.955 +// -----------------------------------------------------------------------------
1.956 +//
1.957 +void CDevAudioControl::ContextEvent(TUid aEvent, TInt aError)
1.958 + {
1.959 + DP_CONTEXT(CDevAudioControl::ContextEvent *CD1*, CtxDevSound, DPLOCAL);
1.960 + DP_IN();
1.961 +
1.962 + if(!(iAdaptationObserver->AdaptorControlsContext()))
1.963 + {
1.964 + iIgnoreAsyncOpComplete = ETrue;
1.965 + }
1.966 +
1.967 + if (aEvent == KUidA3FContextUpdateComplete)
1.968 + {
1.969 + if(iIgnoreAsyncOpComplete)
1.970 + {
1.971 + iAdaptationObserver->PreemptionFinishedCallbackReceived(ETrue);
1.972 + iIgnoreAsyncOpComplete = EFalse;
1.973 + }
1.974 + else
1.975 + {
1.976 + iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
1.977 + }
1.978 + }
1.979 + else if(aEvent == KUidA3FContextPreEmption)
1.980 + {
1.981 + //If we are in a normal pre-emption cycle, we should not be in a mid-state.
1.982 + __ASSERT_DEBUG(!iDevAudio->IsMidState(iDevAudio->iActiveState), Panic(EInvalidStateDuringPreemptionCycle));
1.983 + iIgnoreAsyncOpComplete = ETrue;
1.984 + iAdaptationObserver->PreemptionStartedCallbackReceived();
1.985 + }
1.986 + //In a clashing pre-emption cycle we must be in a commit cycle, so do nothing here - CDevCommonControl deals
1.987 + //with this case.
1.988 + DP_OUT();
1.989 + }
1.990 +
1.991 +
1.992 +// -----------------------------------------------------------------------------
1.993 +// From class MCustomInterfaceSupportObserver
1.994 +// CDevAudio::CustomInterfaceRemoval
1.995 +// -----------------------------------------------------------------------------
1.996 +//
1.997 +void CDevAudioControl::CustomInterfaceRemoval(TUid aUid, TAny* /*aPtr*/)
1.998 + {
1.999 + DP_CONTEXT(CDevAudioControl::CustomInterfaceRemoval *CD1*, CtxDevSound, DPLOCAL);
1.1000 + DP_IN();
1.1001 + // TODO: Review this functionality
1.1002 + iAdaptationObserver->InterfaceDeleted(aUid);
1.1003 + DP_OUT();
1.1004 + }
1.1005 +
1.1006 +// ---------------------------------------------------------------------------
1.1007 +// CDevAudioControl::ResolveSampleRate
1.1008 +// ---------------------------------------------------------------------------
1.1009 +TInt CDevAudioControl::ResolveSampleRate(TInt aSampleRate, TInt& aSampleRateValue)
1.1010 + {
1.1011 + DP_CONTEXT(CDevAudioControl::ResolveSampleRate, CtxDevSound, DPLOCAL);
1.1012 + DP_IN();
1.1013 + TInt err(KErrArgument);
1.1014 +
1.1015 + for (TUint i=0; i<=KMaxSampleRateIndex; i++)
1.1016 + {
1.1017 + if(KRateTableLookup[i].iSampleRate == aSampleRate)
1.1018 + {
1.1019 + aSampleRateValue = KRateTableLookup[i].iSampleRateValue;
1.1020 + err = KErrNone;
1.1021 + break;
1.1022 + }
1.1023 + }
1.1024 +
1.1025 + //To avoid the value return a non desired value.
1.1026 + if (err != KErrNone)
1.1027 + {
1.1028 + aSampleRateValue = 0;
1.1029 + }
1.1030 +
1.1031 + DP0_RET(err, "%d");
1.1032 + }
1.1033 +
1.1034 +
1.1035 +// ---------------------------------------------------------------------------
1.1036 +// CDevAudioControl::ResolveMode
1.1037 +// ---------------------------------------------------------------------------
1.1038 +TInt CDevAudioControl::ResolveMode(TUint aModeValue, TUid& aMode)
1.1039 + {
1.1040 + DP_CONTEXT(CDevAudioControl::ResolveMode *CD1*, CtxDevSound, DPLOCAL);
1.1041 + DP_IN();
1.1042 + TInt err(KErrArgument);
1.1043 +
1.1044 +
1.1045 + for (TInt i=0; i<=KMaxModeIndex; i++)
1.1046 + {
1.1047 + const TAudioModeTableEntry& entry = KModeTableLookup[i];
1.1048 + if (entry.iAudioModeValue == aModeValue)
1.1049 + {
1.1050 + aMode = entry.iAudioMode;
1.1051 + err = KErrNone;
1.1052 + break;
1.1053 + }
1.1054 + }
1.1055 +
1.1056 + DP0_RET(err,"%d");
1.1057 + }
1.1058 +
1.1059 +// ---------------------------------------------------------------------------
1.1060 +// CDevAudioControl::GetModes
1.1061 +// ---------------------------------------------------------------------------
1.1062 +TUint CDevAudioControl::GetModes(const RArray<TUid>& aMode)
1.1063 + {
1.1064 + DP_CONTEXT(CDevAudioControl::GetModes *CD1*, CtxDevSound, DPLOCAL);
1.1065 + DP_IN();
1.1066 +
1.1067 + TUint result = 0;
1.1068 + TInt count = aMode.Count();
1.1069 +
1.1070 + for (TInt i=0; i<count; i++)
1.1071 + {
1.1072 + result |= GetMode(aMode[i]);
1.1073 + }
1.1074 + DP0_RET(result,"%d");
1.1075 + }
1.1076 +
1.1077 +
1.1078 +// ---------------------------------------------------------------------------
1.1079 +// CDevAudioControl::GetMode
1.1080 +// ---------------------------------------------------------------------------
1.1081 +TUint CDevAudioControl::GetMode(TUid aMode)
1.1082 + {
1.1083 + DP_CONTEXT(CDevAudioControl::GetMode *CD1*, CtxDevSound, DPLOCAL);
1.1084 + DP_IN();
1.1085 +
1.1086 + TUint result = 0;
1.1087 +
1.1088 + for (TInt e=0; e<=KMaxModeIndex; e++)
1.1089 + {
1.1090 + if(KModeTableLookup[e].iAudioMode == aMode)
1.1091 + {
1.1092 + result = KModeTableLookup[e].iAudioModeValue;
1.1093 + break;
1.1094 + }
1.1095 + }
1.1096 + DP0_RET(result,"%d");
1.1097 + }
1.1098 +
1.1099 +// ---------------------------------------------------------------------------
1.1100 +// CDevAudioControl::GetSampleRates
1.1101 +// ---------------------------------------------------------------------------
1.1102 +TUint CDevAudioControl::GetSampleRates(const RArray<TInt>& aSampleRates)
1.1103 + {
1.1104 + DP_CONTEXT(CDevAudioControl::GetSampleRates *CD1*, CtxDevSound, DPLOCAL);
1.1105 + DP_IN();
1.1106 +
1.1107 + TUint result = 0;
1.1108 + TInt count = aSampleRates.Count();
1.1109 +
1.1110 + for (TInt i=0; i<count; i++)
1.1111 + {
1.1112 + result |= GetSampleRate(aSampleRates[i]);
1.1113 + }
1.1114 + DP0_RET(result,"%d");
1.1115 + }
1.1116 +
1.1117 +// ---------------------------------------------------------------------------
1.1118 +// CDevAudioControl::GetSampleRate
1.1119 +// ---------------------------------------------------------------------------
1.1120 +TUint CDevAudioControl::GetSampleRate(TInt aSampleRates)
1.1121 + {
1.1122 + DP_CONTEXT(CDevAudioControl::GetSampleRate *CD1*, CtxDevSound, DPLOCAL);
1.1123 + DP_IN();
1.1124 +
1.1125 + TUint result = 0;
1.1126 + TInt position = 0;
1.1127 + TInt lowerbound = 0;
1.1128 + TInt upperbound = KMaxSampleRateIndex;
1.1129 +
1.1130 + if ((aSampleRates < KRateTableLookup[lowerbound].iSampleRateValue) || (aSampleRates > KRateTableLookup[upperbound].iSampleRateValue))
1.1131 + {
1.1132 + //value request not found in the array.
1.1133 + DP0_RET(result,"%d");
1.1134 + }
1.1135 +
1.1136 + //Binary Search
1.1137 + position = ( lowerbound + upperbound) / 2;
1.1138 +
1.1139 + while((KRateTableLookup[position].iSampleRateValue != aSampleRates) && (lowerbound <= upperbound))
1.1140 + {
1.1141 + if (KRateTableLookup[position].iSampleRateValue > aSampleRates)
1.1142 + {
1.1143 + upperbound = position - 1;
1.1144 + }
1.1145 + else
1.1146 + {
1.1147 + lowerbound = position + 1;
1.1148 + }
1.1149 + position = (lowerbound + upperbound) / 2;
1.1150 + }
1.1151 +
1.1152 + result = KRateTableLookup[position].iSampleRate;
1.1153 +
1.1154 + DP0_RET(result,"%d");
1.1155 + }
1.1156 +
1.1157 +// ---------------------------------------------------------------------------
1.1158 +// CDevAudioControl::ProcessingFinishedReceived
1.1159 +// ---------------------------------------------------------------------------
1.1160 +TInt CDevAudioControl::ProcessingFinishedReceived(TBool& /*aAyncOperation*/)
1.1161 + {
1.1162 + return KErrNone;
1.1163 + }
1.1164 +
1.1165 +// ---------------------------------------------------------------------------
1.1166 +// CDevAudioControl::ProcessingError
1.1167 +// ---------------------------------------------------------------------------
1.1168 +TInt CDevAudioControl::ProcessingError(TBool& /*aAyncOperation*/)
1.1169 + {
1.1170 + return KErrNone;
1.1171 + }
1.1172 +
1.1173 +// ---------------------------------------------------------------------------
1.1174 +// CDevAudioControl::RequestEmptyBuffers
1.1175 +// ---------------------------------------------------------------------------
1.1176 +TInt CDevAudioControl::RequestEmptyBuffers()
1.1177 + {
1.1178 + DP_CONTEXT(CDevAudioControl::RequestEmptyBuffers *CD1*, CtxDevSound, DPLOCAL);
1.1179 + DP_IN();
1.1180 +
1.1181 + TInt err(KErrNotReady);
1.1182 +
1.1183 + if(iDevAudio)
1.1184 + {
1.1185 + if(iDevAudio->iActiveState == EDevSoundAdaptorPaused_Primed)
1.1186 + {
1.1187 + err = iDevAudio->iAudioStream->Flush();
1.1188 + }
1.1189 + else if (iDevAudio->iActiveState == EDevSoundAdaptorActive_Active)
1.1190 + {
1.1191 + err = Pause();
1.1192 + if(err == KErrNone)
1.1193 + {
1.1194 + iPauseResumeSequenceDueToEmptyBuffers = ETrue;
1.1195 + }
1.1196 +
1.1197 + }
1.1198 + }
1.1199 + DP0_RET(err,"%d");
1.1200 + };
1.1201 +
1.1202 +void CDevAudioControl::Panic(TDevSoundAdaptorPanicCode aCode)
1.1203 + {
1.1204 + _LIT(KMMFDevSoundAdaptorPanicCategory, "DevSoundAdaptor");
1.1205 + User::Panic(KMMFDevSoundAdaptorPanicCategory, aCode);
1.1206 + }
1.1207 +
1.1208 +// ---------------------------------------------------------------------------
1.1209 +// CDevAudioControl::GetTimePlayed
1.1210 +// ---------------------------------------------------------------------------
1.1211 +TInt CDevAudioControl::GetTimePlayed(TTimeIntervalMicroSeconds& aTime)
1.1212 + {
1.1213 + DP_CONTEXT(CDevAudioControl::GetTimePlayed *CD1*, CtxDevSound, DPLOCAL);
1.1214 + DP_IN();
1.1215 + TInt err = iDevAudio->iAudioStream->GetStreamTime(aTime);
1.1216 + DP0_RET(err,"%d");
1.1217 + }
1.1218 +
1.1219 +// ---------------------------------------------------------------------------
1.1220 +// CDevAudioControl::Resume
1.1221 +// ---------------------------------------------------------------------------
1.1222 +TBool CDevAudioControl::Resume()
1.1223 + {
1.1224 + DP_CONTEXT(CDevAudioControl::Stop *CD1*, CtxDevSound, DPLOCAL);
1.1225 + DP_IN();
1.1226 + ASSERT(EFalse);
1.1227 + DP0_RET(KErrNone, "%d");
1.1228 + }
1.1229 +
1.1230 +// -----------------------------------------------------------------------------
1.1231 +// CDevAudioControl::BufferErrorEvent
1.1232 +// -----------------------------------------------------------------------------
1.1233 +//
1.1234 +void CDevAudioControl::BufferErrorEvent()
1.1235 + {
1.1236 + ASSERT(EFalse); //This should never happen
1.1237 + }
1.1238 +// End of file