os/mm/devsound/a3fdevsound/src/devsoundadaptor/cdevaudio.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/a3fdevsound/src/devsoundadaptor/cdevaudio.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1109 @@
     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 "cdevaudio.h"
    1.22 +#include "cdevaudiocontrol.h"
    1.23 +#include "cdevplaycontrol.h"
    1.24 +#include "cdevrecordcontrol.h"
    1.25 +#include "cdevtonecontrol.h"
    1.26 +#include "cdevgencontrol.h"
    1.27 +
    1.28 +#include <a3f/audioprocessingunittypeuids.h>
    1.29 +#include <a3f/devsoundadaptationinfo.h>
    1.30 +#include <a3f/a3ffourcclookup.h>
    1.31 +#include <a3f/audiocontextfactory.h>
    1.32 +#include <a3f/maudioprocessingunit.h>
    1.33 +#include <a3f/maudiocontext.h>
    1.34 +#include <a3f/mcontexteffectiveclient.h>
    1.35 +#include <a3f/maudiostream.h>
    1.36 +#include <a3f/maudiocodec.h>
    1.37 +#include <a3f/maudiogaincontrol.h>
    1.38 +#include <a3f/mbuffersource.h>
    1.39 +#include <a3f/mbuffersink.h>
    1.40 +
    1.41 +#include "mglobalproperties.h"
    1.42 +
    1.43 +const TInt KMidWayBalance = 50; // 50%
    1.44 +const TInt KMaxBalance = 100; // 100%
    1.45 +const TInt KLeftChannel = 0;
    1.46 +const TInt KRightChannel = 1;
    1.47 +
    1.48 +
    1.49 +// ======== LOCAL FUNCTIONS ========
    1.50 +
    1.51 +// ======== MEMBER FUNCTIONS ========
    1.52 +
    1.53 +// ---------------------------------------------------------------------------
    1.54 +// Default constructor
    1.55 +// ---------------------------------------------------------------------------
    1.56 +//
    1.57 +CDevAudio::CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver)
    1.58 +	: iAdaptationObserver(aAdaptationObserver), iMode(EMMFStateIdle), 
    1.59 +	iActiveState(EDevSoundAdaptorCreated_Uninitialised),
    1.60 +	iActiveStreamState(EUninitialized)
    1.61 +	{
    1.62 +	TRACE_CREATE();
    1.63 +	DP_CONTEXT(CDevAudio::CDevAudio *CD1*, CtxDevSound, DPLOCAL);
    1.64 +	DP_IN();
    1.65 +		
    1.66 +	iDevSoundPlayBalance[KLeftChannel] = iDevSoundPlayBalance[KRightChannel] = KMidWayBalance;
    1.67 +	iDevSoundRecordBalance[KLeftChannel] = iDevSoundRecordBalance[KRightChannel] = KMidWayBalance;
    1.68 +
    1.69 +	DP_OUT();
    1.70 +	}
    1.71 +
    1.72 +// ---------------------------------------------------------------------------
    1.73 +// Destructor
    1.74 +// ---------------------------------------------------------------------------
    1.75 +//
    1.76 +CDevAudio::~CDevAudio()
    1.77 +	{
    1.78 +	DP_CONTEXT(CDevAudio::~CDevAudio *CD1*, CtxDevSound, DPLOCAL);
    1.79 +	DP_IN();
    1.80 +	
    1.81 +	delete iAdaptationInfo;
    1.82 +	
    1.83 +	iSupportedInputFormats.Close();
    1.84 +	iSupportedOutputFormats.Close();
    1.85 +
    1.86 +	// This part is fine at the destructor
    1.87 +	// All this is syncronous
    1.88 +	if ( iAudioContext )
    1.89 +		{
    1.90 +		if ( iGainControl )
    1.91 +			{
    1.92 +			iAudioContext->DeleteAudioProcessingUnit(iGainControl);
    1.93 +			}
    1.94 +		if ( iAudioSink )
    1.95 +			{
    1.96 +			iAudioContext->DeleteAudioProcessingUnit(iAudioSink);
    1.97 +			}
    1.98 +		if ( iAudioCodec )
    1.99 +			{
   1.100 +			iAudioContext->DeleteAudioProcessingUnit(iAudioCodec);
   1.101 +			}
   1.102 +		if ( iAudioSource )
   1.103 +			{
   1.104 +			iAudioContext->DeleteAudioProcessingUnit(iAudioSource);
   1.105 +			}
   1.106 +		if ( iAudioStream )
   1.107 +			{
   1.108 +			iAudioContext->DeleteAudioStream(iAudioStream);
   1.109 +			}
   1.110 +		}
   1.111 +
   1.112 +	iAudioContextFactory->DeleteAudioContext(iAudioContext);
   1.113 +	
   1.114 +	if ( iAudioContextFactory )
   1.115 +		{
   1.116 +		delete iAudioContextFactory;
   1.117 +		}
   1.118 +
   1.119 +	if ( iDevPlayControl )
   1.120 +		{
   1.121 +		delete iDevPlayControl;
   1.122 +		}
   1.123 +	if ( iDevRecordControl )
   1.124 +		{
   1.125 +		delete iDevRecordControl;
   1.126 +		}
   1.127 +	if ( iDevToneControl )
   1.128 +		{
   1.129 +		delete iDevToneControl;
   1.130 +		}
   1.131 +	if ( iDevGenControl )
   1.132 +		{
   1.133 +		delete iDevGenControl;
   1.134 +		}
   1.135 +	
   1.136 +	DP_OUT();
   1.137 +	}
   1.138 +
   1.139 +// -----------------------------------------------------------------------------
   1.140 +// CDevAudio::NewL
   1.141 +// Two-phased constructor.
   1.142 +// -----------------------------------------------------------------------------
   1.143 +//
   1.144 +CDevAudio* CDevAudio::NewL(MDevSoundAdaptationObserver& aAdaptationObserver, 
   1.145 +									MGlobalProperties& aGlobalProperties)
   1.146 +	{
   1.147 +	DP_STATIC_CONTEXT(CDevAudio::NewL *CD0*, CtxDevSound, DPLOCAL);
   1.148 +	DP_IN();
   1.149 +	CDevAudio* self = new (ELeave) CDevAudio(aAdaptationObserver);
   1.150 +	CleanupStack::PushL(self);
   1.151 +	self->ConstructL(aGlobalProperties);
   1.152 +	CleanupStack::Pop(self);
   1.153 +	DP0_RET(self, "0x%x");
   1.154 +	}
   1.155 +
   1.156 +
   1.157 +// -----------------------------------------------------------------------------
   1.158 +// CDevAudio::ConstructL
   1.159 +// -----------------------------------------------------------------------------
   1.160 +//
   1.161 +void CDevAudio::ConstructL(MGlobalProperties& aGlobalProperties)
   1.162 +	{
   1.163 +	DP_CONTEXT(CDevAudio::ConstructL *CD1*, CtxDevSound, DPLOCAL);
   1.164 +	DP_IN();
   1.165 +	
   1.166 +	iGlobalProperties = &aGlobalProperties;
   1.167 +
   1.168 +	iAudioContextFactory = CAudioContextFactory::NewL();
   1.169 +	
   1.170 +	User::LeaveIfError(iAudioContextFactory->CreateAudioContext(iAudioContext));
   1.171 +
   1.172 +	User::LeaveIfError(iAudioContext->CreateAudioStream(iAudioStream));
   1.173 +	
   1.174 +	User::LeaveIfError(iAudioContext->CreateAudioProcessingUnit(KUidAudioGainControl, iGainControl));
   1.175 +	User::LeaveIfError(iAudioStream->AddGainControl(iGainControl));
   1.176 +
   1.177 +	iDevPlayControl = CDevPlayControl::NewL(this, iAdaptationObserver);
   1.178 +	iDevRecordControl = CDevRecordControl::NewL(this, iAdaptationObserver);
   1.179 +	iDevToneControl = CDevToneControl::NewL(this, iAdaptationObserver);
   1.180 +	iDevGenControl = CDevGenControl::NewL(this, iAdaptationObserver);
   1.181 +	
   1.182 +	iAdaptationInfo = CA3FDevSoundAdaptationInfo::NewL(*this, const_cast<CFourCCConvertor&>(iGlobalProperties->GetFourCCConvertor()));
   1.183 +
   1.184 +	// The generic audio control is the only one receiving the callbacks at this moment
   1.185 +	iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevGenControl);
   1.186 +	TInt err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
   1.187 +	if ((err != KErrNone) && (err != KErrAlreadyExists))
   1.188 +		{
   1.189 +		User::Leave(err);
   1.190 +		}
   1.191 +	DP_OUT();
   1.192 +	}
   1.193 +	
   1.194 +// -----------------------------------------------------------------------------
   1.195 +// CDevAudio::PostOpen
   1.196 +// -----------------------------------------------------------------------------
   1.197 +//
   1.198 +TInt CDevAudio::PostOpen()
   1.199 +	{
   1.200 +	DP_CONTEXT(CDevAudio::PostOpen *CD1*, CtxDevSound, DPLOCAL);
   1.201 +	DP_IN();
   1.202 +	ASSERT(iPreOpenState==EPreOpenStateIdle);
   1.203 +	TInt err = KErrNone;
   1.204 +	
   1.205 +	if(iPreOpenState == EPreOpenStateIdle)
   1.206 +		{
   1.207 +		err = iAdaptationInfo->RequestMaxGain(KUidAudioDecoder);
   1.208 +		if (err == KErrNone)
   1.209 +			{
   1.210 +			iPreOpenState = EPreOpenStateRequestingMaxVolume;
   1.211 +			}
   1.212 +		}
   1.213 +	
   1.214 +	DP0_RET(err, "%d");
   1.215 +	}
   1.216 +	
   1.217 +
   1.218 +TBool CDevAudio::IsResumeSupported()
   1.219 +	{
   1.220 +	DP_CONTEXT(CDevAudio::IsResumeSupported *CD1*, CtxDevSound, DPLOCAL);
   1.221 +	DP_IN();
   1.222 +
   1.223 +	TUid codecType(KNullUid);
   1.224 +	if(iMode == EMMFStatePlaying || iMode == EMMFStateTonePlaying)
   1.225 +		{
   1.226 +		codecType = KUidAudioDecoder;
   1.227 +		}
   1.228 +	else if (iMode == EMMFStateRecording)
   1.229 +		{
   1.230 +		codecType = KUidAudioEncoder;
   1.231 +		}
   1.232 +	TBool supported = iAdaptationInfo->IsResumeSupported(codecType, iFormat);
   1.233 +
   1.234 +	DP0_RET(supported, "%d");
   1.235 +	}
   1.236 +
   1.237 +
   1.238 +// -----------------------------------------------------------------------------
   1.239 +// CDevAudio::RequestMaxGainComplete
   1.240 +// -----------------------------------------------------------------------------
   1.241 +//
   1.242 +void CDevAudio::RequestMaxGainComplete (TUid __DEBUG_ONLY(aCodecType), TInt aError, TInt aResult)
   1.243 +	{
   1.244 +	DP_CONTEXT(CDevAudio::RequestMaxGainComplete *CD1*, CtxDevSound, DPLOCAL);
   1.245 +	DP_IN();
   1.246 +	ASSERT(iPreOpenState==EPreOpenStateRequestingMaxVolume && aCodecType==KUidAudioDecoder||
   1.247 +			iPreOpenState==EPreOpenStateRequestingMaxGain && aCodecType==KUidAudioEncoder);
   1.248 +
   1.249 +	TInt err = aError;
   1.250 +	TBool asyncComplete = EFalse;
   1.251 +	
   1.252 +	if (err == KErrNone)
   1.253 +		{
   1.254 +		if (iPreOpenState==EPreOpenStateRequestingMaxVolume)
   1.255 +			{
   1.256 +			iDevSoundMaxVolume = aResult;
   1.257 +						
   1.258 +			err = SetDevSoundVolume((iDevSoundMaxVolume+1)/2, asyncComplete);
   1.259 +
   1.260 +			__ASSERT_DEBUG(asyncComplete==EFalse, User::Invariant());
   1.261 +			
   1.262 +			if(err == KErrNone)
   1.263 +				{
   1.264 +				// first request - so request max gain
   1.265 +				err = iAdaptationInfo->RequestMaxGain(KUidAudioEncoder);
   1.266 +				if (err == KErrNone)
   1.267 +					{
   1.268 +					iPreOpenState = EPreOpenStateRequestingMaxGain;
   1.269 +					}
   1.270 +				}
   1.271 +			}
   1.272 +		else if(iPreOpenState==EPreOpenStateRequestingMaxGain)
   1.273 +			{
   1.274 +			iDevSoundMaxGain = aResult;
   1.275 +			
   1.276 +			err = SetDevSoundGain((iDevSoundMaxGain+1)/2, asyncComplete);
   1.277 +
   1.278 +			__ASSERT_DEBUG(asyncComplete==EFalse, User::Invariant());
   1.279 +			
   1.280 +			if(err == KErrNone)
   1.281 +				{
   1.282 +				// second request - complete whatever - Ready for Formats
   1.283 +				err = iAdaptationInfo->RequestSupportedFormats(KUidAudioDecoder, iSupportedInputFormats);
   1.284 +				if (err == KErrNone)
   1.285 +					{
   1.286 +					iPreOpenState = EPreOpenStateRequestingInputFormats;
   1.287 +					}
   1.288 +				}
   1.289 +			}
   1.290 +		}
   1.291 +
   1.292 +	if (err!=KErrNone)
   1.293 +		{
   1.294 +		iPreOpenState = EPreOpenStateIdle;
   1.295 +		iAdaptationObserver.AsynchronousOperationComplete(err, ETrue);
   1.296 +		}
   1.297 +	
   1.298 +	DP_OUT();
   1.299 +	}
   1.300 +
   1.301 +// -----------------------------------------------------------------------------
   1.302 +// CDevAudio::RequestSupportedFormatsComplete
   1.303 +// -----------------------------------------------------------------------------
   1.304 +//
   1.305 +void CDevAudio::RequestSupportedFormatsComplete(TUid __DEBUG_ONLY(aCodecType), TInt aError)
   1.306 +	{
   1.307 +	DP_CONTEXT(CDevAudio::RequestSupportedFormatsComplete *CD1*, CtxDevSound, DPLOCAL);
   1.308 +	DP_IN();
   1.309 +	ASSERT(iPreOpenState==EPreOpenStateRequestingInputFormats && aCodecType==KUidAudioDecoder||
   1.310 +			iPreOpenState==EPreOpenStateRequestingOutputFormats && aCodecType==KUidAudioEncoder);
   1.311 +
   1.312 +	TInt err = aError;
   1.313 +
   1.314 +	if (err == KErrNone)
   1.315 +		{
   1.316 +		if (iPreOpenState==EPreOpenStateRequestingInputFormats)
   1.317 +			{
   1.318 +			// first request - so request output formats
   1.319 +			err = iAdaptationInfo->RequestSupportedFormats(KUidAudioEncoder, iSupportedOutputFormats);
   1.320 +			if (err == KErrNone)
   1.321 +				{
   1.322 +				iPreOpenState = EPreOpenStateRequestingOutputFormats;
   1.323 +				}
   1.324 +			}
   1.325 +		else
   1.326 +			{
   1.327 +			ASSERT(iPreOpenState==EPreOpenStateRequestingOutputFormats);
   1.328 +			// second request - complete whatever
   1.329 +			iPreOpenState = EPreOpenStateIdle;
   1.330 +			iAdaptationObserver.AsynchronousOperationComplete(aError, ETrue);
   1.331 +			}
   1.332 +		}
   1.333 +
   1.334 +	if (err!=KErrNone)
   1.335 +		{
   1.336 +		iPreOpenState = EPreOpenStateIdle;
   1.337 +		iAdaptationObserver.AsynchronousOperationComplete(err, ETrue);
   1.338 +		}
   1.339 +	DP_OUT();
   1.340 +	}
   1.341 +
   1.342 +
   1.343 +
   1.344 +// -----------------------------------------------------------------------------
   1.345 +// CDevAudio::Initialize
   1.346 +// -----------------------------------------------------------------------------
   1.347 +//
   1.348 +TInt CDevAudio::Initialize(TUid aFormat, TMMFState aMode)
   1.349 +	{
   1.350 +	DP_CONTEXT(CDevAudio::Initialize*CD1*, CtxDevSound, DPLOCAL);
   1.351 +	DP_IN();
   1.352 +	TInt err(KErrNone);
   1.353 +
   1.354 +	if(iActiveState != EDevSoundAdaptorCreated_Uninitialised &&
   1.355 +		iActiveState != EDevSoundAdaptorInitialised_Initialised && 
   1.356 +		iActiveState != EDevSoundAdaptorInitialised_Idle &&
   1.357 +		iActiveState != EDevSoundAdaptorUnitialised_Uninitialised )
   1.358 +		{
   1.359 +		DP0_RET(KErrNotReady, "%d");
   1.360 +		}
   1.361 +
   1.362 +	// Reinitialization 
   1.363 +	if (iActiveState == EDevSoundAdaptorInitialised_Initialised || 
   1.364 +		iActiveState == EDevSoundAdaptorInitialised_Idle)
   1.365 +		{
   1.366 +		iReinitializing = ETrue;
   1.367 +		iTargetFormat = aFormat;
   1.368 +		iTargetMode = aMode;
   1.369 +		if(iActiveState == EDevSoundAdaptorInitialised_Idle)
   1.370 +			{
   1.371 +			err = iAudioStream->Unload();
   1.372 +			if(err == KErrNone)
   1.373 +				{
   1.374 +				err = CommitAudioContext();
   1.375 +				}
   1.376 +			if(err == KErrNone)
   1.377 +				{
   1.378 +				iActiveState = EDevSoundAdaptorUnloading;
   1.379 +				}
   1.380 +			}
   1.381 +		else
   1.382 +			{
   1.383 +			err = iCurrentAudioControl->Uninitialize();
   1.384 +			}
   1.385 +		DP0_RET(err, "%d");
   1.386 +		}
   1.387 +
   1.388 +	// Redo partial initialization after pre-emption clash event in
   1.389 +	// EDevSoundAdaptorRemovingProcessingUnits state
   1.390 +	if (iActiveState == EDevSoundAdaptorUnitialised_Uninitialised &&
   1.391 +			iPreviousState == EDevSoundAdaptorRemovingProcessingUnits)
   1.392 +		{
   1.393 +		err = iCurrentAudioControl->RemoveProcessingUnits();
   1.394 +		DP0_RET(err, "%d");
   1.395 +		}
   1.396 +
   1.397 +	// Delete pUnits if already created
   1.398 +	if (iAudioSource)
   1.399 +		{
   1.400 +		iAudioContext->DeleteAudioProcessingUnit(iAudioSource);
   1.401 +		iAudioSource = NULL;
   1.402 +		}
   1.403 +
   1.404 +	if (iAudioSink)
   1.405 +		{
   1.406 +		iAudioContext->DeleteAudioProcessingUnit(iAudioSink);
   1.407 +		iAudioSink = NULL;
   1.408 +		}
   1.409 +
   1.410 +	if (iAudioCodec)
   1.411 +		{
   1.412 +		iAudioContext->DeleteAudioProcessingUnit(iAudioCodec);
   1.413 +		iAudioCodec = NULL;
   1.414 +		}
   1.415 +
   1.416 +	//	Create pUnits and select proper DevSound Adaptor Helper
   1.417 +	if (aMode == EMMFStatePlaying)
   1.418 +		{
   1.419 +		// create correct type sink&source&codec
   1.420 +		err = CreateAudioProcessingUnits(KUidMmfBufferSource, KUidAudioDeviceSink, KUidAudioDecoder);
   1.421 +		if (err == KErrNone)
   1.422 +			{
   1.423 +			// Now just the playcontrol should receive the only one receiving events from 
   1.424 +			// AudioContext
   1.425 +			iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
   1.426 +			iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevPlayControl);
   1.427 +			err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
   1.428 +			}
   1.429 +		if ((err != KErrNone) && (err != KErrAlreadyExists))
   1.430 +			{
   1.431 +			DeleteAudioProcessingUnits();
   1.432 +			}
   1.433 +		}
   1.434 +		
   1.435 +	else if (aMode == EMMFStateRecording)
   1.436 +		{
   1.437 +		// create correct type sink&source&codec
   1.438 +		err = CreateAudioProcessingUnits(KUidAudioDeviceSource, KUidMmfBufferSink, KUidAudioEncoder);
   1.439 +		if (err == KErrNone)
   1.440 +			{
   1.441 +			iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
   1.442 +			iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevRecordControl);
   1.443 +			err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
   1.444 +			}
   1.445 +		if ((err != KErrNone) && (err != KErrAlreadyExists))
   1.446 +			{
   1.447 +			DeleteAudioProcessingUnits();
   1.448 +			}
   1.449 +		}
   1.450 +	else if (aMode == EMMFStateTonePlaying)
   1.451 +		{
   1.452 +		// create correct type sink&source&codec
   1.453 +		err = CreateAudioProcessingUnits(KUidMmfBufferSource, KUidAudioDeviceSink, KUidAudioDecoder);
   1.454 +		if (err == KErrNone)
   1.455 +			{
   1.456 +			iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
   1.457 +			iCurrentAudioControl =  static_cast<CDevAudioControl*>(iDevToneControl);
   1.458 +			err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
   1.459 +			}
   1.460 +	if ((err != KErrNone) && (err != KErrAlreadyExists))
   1.461 +			{
   1.462 +			DeleteAudioProcessingUnits();
   1.463 +			}
   1.464 +		}
   1.465 +	else if (aMode == EMMFStateIdle)
   1.466 +		{
   1.467 +		// Unsure about this
   1.468 +		iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
   1.469 +		iCurrentAudioControl =  static_cast<CDevAudioControl*>(iDevGenControl);
   1.470 +		err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
   1.471 +		}
   1.472 +	else
   1.473 +		{
   1.474 +		iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevGenControl);
   1.475 +		err = KErrNotSupported;
   1.476 +		}
   1.477 +
   1.478 +	if (err == KErrNone)
   1.479 +		{
   1.480 +		err = iCurrentAudioControl->Initialize(aFormat);	
   1.481 +		}
   1.482 +	
   1.483 +	if(err == KErrNone)
   1.484 +		{
   1.485 +		iMode = aMode;
   1.486 +		iFormat = aFormat;
   1.487 +		}
   1.488 +
   1.489 +	DP0_RET(err, "%d");
   1.490 +	}
   1.491 +
   1.492 +// -----------------------------------------------------------------------------
   1.493 +// CDevAudio::CancelInitialize
   1.494 +// -----------------------------------------------------------------------------
   1.495 +//
   1.496 +TInt CDevAudio::CancelInitialize()
   1.497 +	{
   1.498 +	DP_CONTEXT(CDevAudio::CancelInitialize *CD1*, CtxDevSound, DPLOCAL);
   1.499 +	DP_IN();
   1.500 +	TInt err(KErrNone);
   1.501 +
   1.502 +	// Redo partial cancelling of initialization after pre-emption clash event in
   1.503 +	// EDevSoundAdaptorRemovingProcessingUnits state.
   1.504 +	if (iActiveState == EDevSoundAdaptorUnitialised_Uninitialised &&
   1.505 +			iPreviousState == EDevSoundAdaptorRemovingProcessingUnits)
   1.506 +		{
   1.507 +		err = iCurrentAudioControl->RemoveProcessingUnits();
   1.508 +		DP0_RET(err, "%d");
   1.509 +		}
   1.510 +	else if(iActiveState != EDevSoundAdaptorInitialised_Initialised)
   1.511 +		{
   1.512 +		DP0_RET(KErrNotReady, "%d");
   1.513 +		}
   1.514 +
   1.515 +	err = iCurrentAudioControl->Uninitialize();
   1.516 +	
   1.517 +	DP0_RET(err, "%d");
   1.518 +	}
   1.519 +
   1.520 +// -----------------------------------------------------------------------------
   1.521 +// CDevAudio::GetAudioControl
   1.522 +// -----------------------------------------------------------------------------
   1.523 +//
   1.524 +CDevAudioControl* CDevAudio::GetAudioControl()
   1.525 +	{
   1.526 +	DP_CONTEXT(CDevAudio::GetAudioControl *CD1*, CtxDevSound, DPLOCAL);
   1.527 +	DP_IN();
   1.528 +	DP_OUT();
   1.529 +	return iCurrentAudioControl;
   1.530 +	}
   1.531 +
   1.532 +// -----------------------------------------------------------------------------
   1.533 +// CDevAudio::SetPrioritySettings
   1.534 +// -----------------------------------------------------------------------------
   1.535 +//
   1.536 +TInt CDevAudio::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
   1.537 +	{
   1.538 +	DP_CONTEXT(CDevAudio::SetPrioritySettings *CD1*, CtxDevSound, DPLOCAL);
   1.539 +	DP_IN();
   1.540 +	iPrioritySettings.iPriority = aPrioritySettings.iPriority;
   1.541 +	iPrioritySettings.iPref = aPrioritySettings.iPref;
   1.542 +	iPriorityFlag = ETrue;
   1.543 +	DP2(DLINFO, "Priority = 0x%x Preference = 0x%x", iPrioritySettings.iPriority,iPrioritySettings.iPref);
   1.544 +	DP0_RET(0, "%d");
   1.545 +	}
   1.546 +
   1.547 +// -----------------------------------------------------------------------------
   1.548 +// CDevAudio::GetPrioritySettings
   1.549 +// -----------------------------------------------------------------------------
   1.550 +//
   1.551 +void CDevAudio::GetPrioritySettings(TAudioTypeSettings& aPrioritySettings)
   1.552 +	{
   1.553 +	aPrioritySettings = iPrioritySettings;
   1.554 +	}
   1.555 +// -----------------------------------------------------------------------------
   1.556 +// CDevAudio::IsPrioritySet
   1.557 +// -----------------------------------------------------------------------------
   1.558 +//
   1.559 +TBool CDevAudio::IsPrioritySet()
   1.560 +	{
   1.561 +	return iPriorityFlag;
   1.562 +	}
   1.563 +
   1.564 +// -----------------------------------------------------------------------------
   1.565 +// CDevAudio::SetClientConfig
   1.566 +// -----------------------------------------------------------------------------
   1.567 +//
   1.568 +TInt CDevAudio::SetClientConfig(const TProcessId& aProcessId)
   1.569 +	{
   1.570 +	DP_CONTEXT(CDevAudio::SetClientConfig *CD1*, CtxDevSound, DPLOCAL);
   1.571 +	DP_IN();
   1.572 +	// TODO: Check if the TClientContextSettings atributte go back since 
   1.573 +	// if not there is no way to send the vendor id
   1.574 +	TClientContextSettings context;
   1.575 +	context.iProcessId = aProcessId;
   1.576 +	TInt err = iAudioContext->SetClientSettings(context);
   1.577 +	if (err != KErrNone)
   1.578 +		{
   1.579 +		DP1(DLERR, "Error %d setting client context!",err);
   1.580 +		}
   1.581 +	DP0_RET(err, "%d");
   1.582 +	}
   1.583 +
   1.584 +TInt CDevAudio::SetClientConfig(const TProcessId& aActualProcessId, const TProcessId& aProcessId)
   1.585 +	{
   1.586 +	DP_CONTEXT(CDevAudio::SetClientConfig *CD1*, CtxDevSound, DPLOCAL);
   1.587 +	DP_IN();
   1.588 +	
   1.589 +	MContextSetEffectiveClient* setEffectiveClient
   1.590 +        = static_cast<MContextSetEffectiveClient*>(iAudioContext->Interface(KSetClientInfoUid));
   1.591 +	
   1.592 +	TInt err;
   1.593 +	
   1.594 +	if (!setEffectiveClient)
   1.595 +	    {
   1.596 +        DP0(DLINFO, "MContextSetEffectiveClient not supported, revert to old behaviour of just passing actual client info");
   1.597 +        err = SetClientConfig(aActualProcessId);
   1.598 +	    }
   1.599 +	else
   1.600 +	    {
   1.601 +        TClientContextSettings context;
   1.602 +        context.iProcessId = aProcessId;
   1.603 +        err = iAudioContext->SetClientSettings(context);
   1.604 +        if (err != KErrNone)
   1.605 +            {
   1.606 +            DP1(DLERR, "Error %d setting client context!",err);
   1.607 +            }
   1.608 +        if (!err)
   1.609 +            {
   1.610 +            err = setEffectiveClient->SetEffectiveClientInfo(aActualProcessId);
   1.611 +            if (err != KErrNone)
   1.612 +                {
   1.613 +                DP1(DLERR, "Error %d setting effective client context!",err);
   1.614 +                }
   1.615 +            }
   1.616 +	    }
   1.617 +
   1.618 +	DP0_RET(err, "%d");
   1.619 +	}
   1.620 +
   1.621 +
   1.622 +void CDevAudio::ContextEvent(TUid /*aEvent*/, TInt /*aError*/)
   1.623 +	{
   1.624 +	DP_CONTEXT(CDevAudio::ContextEvent *CD1*, CtxDevSound, DPLOCAL);
   1.625 +	DP_IN();
   1.626 +	DP_OUT();
   1.627 +	}
   1.628 +
   1.629 +// -----------------------------------------------------------------------------
   1.630 +// CDevAudio::ActiveState
   1.631 +// -----------------------------------------------------------------------------
   1.632 +//
   1.633 +TDevSoundAdaptorState CDevAudio::ActiveState() const
   1.634 +	{
   1.635 +	DP_CONTEXT(CDevAudio::ActiveState *CD1*, CtxDevSound, DPLOCAL);
   1.636 +	DP_IN();
   1.637 +	DP0_RET(iActiveState, "%d");
   1.638 +	}
   1.639 +
   1.640 +// -----------------------------------------------------------------------------
   1.641 +// CDevAudio::ActiveState
   1.642 +// -----------------------------------------------------------------------------
   1.643 +//
   1.644 +TDevSoundAdaptorState CDevAudio::PreviousState() const
   1.645 +	{
   1.646 +	DP_CONTEXT(CDevAudio::PreviousState *CD1*, CtxDevSound, DPLOCAL);
   1.647 +	DP_IN();
   1.648 +	DP0_RET(iPreviousState, "%d");
   1.649 +	}
   1.650 +
   1.651 +// -----------------------------------------------------------------------------
   1.652 +// CDevAudio::SetActiveState
   1.653 +// -----------------------------------------------------------------------------
   1.654 +//
   1.655 +void CDevAudio::SetActiveState(TDevSoundAdaptorState aAdaptorState)
   1.656 +	{
   1.657 +	DP_CONTEXT(CDevAudio::SetActiveState *CD1*, CtxDevSound, DPLOCAL);
   1.658 +	DP_IN();
   1.659 +	iActiveState = aAdaptorState;
   1.660 +	DP_OUT();
   1.661 +	}
   1.662 +
   1.663 +// -----------------------------------------------------------------------------
   1.664 +// CDevAudio::SetPreviousState
   1.665 +// -----------------------------------------------------------------------------
   1.666 +//
   1.667 +void CDevAudio::SetPreviousState(TDevSoundAdaptorState aAdaptorState)
   1.668 +	{
   1.669 +	DP_CONTEXT(CDevAudio::SetPreviousState *CD1*, CtxDevSound, DPLOCAL);
   1.670 +	DP_IN();
   1.671 +	iPreviousState = aAdaptorState;
   1.672 +	DP_OUT();
   1.673 +	}
   1.674 +
   1.675 +// -----------------------------------------------------------------------------
   1.676 +// CDevAudio::SetDevSoundVolume
   1.677 +// -----------------------------------------------------------------------------
   1.678 +//
   1.679 +TInt CDevAudio::SetDevSoundVolume(TInt aVolume, TBool& aAsyncComplete)
   1.680 +	{
   1.681 +	DP_CONTEXT(CDevAudio::SetDevSoundVolume *CD1*, CtxDevSound, DPLOCAL);
   1.682 +	DP_IN();
   1.683 +
   1.684 +	// Values are clipped between 0 and MaxGain. 
   1.685 +	// because MAudioGainControl expects this to be done
   1.686 +	TInt volume = aVolume;
   1.687 +	if (volume < 0)
   1.688 +		{
   1.689 +		volume = 0;
   1.690 +		}
   1.691 +	else if (volume > iDevSoundMaxVolume)
   1.692 +		{
   1.693 +		volume = iDevSoundMaxVolume;
   1.694 +		}
   1.695 +	iDevSoundVolume = volume;
   1.696 +	
   1.697 +	TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
   1.698 +
   1.699 +	DP0_RET(error, "%d");
   1.700 +	}
   1.701 +
   1.702 +
   1.703 +// -----------------------------------------------------------------------------
   1.704 +// CDevAudio::SetDevSoundGain
   1.705 +// -----------------------------------------------------------------------------
   1.706 +//
   1.707 +TInt CDevAudio::SetDevSoundGain(TInt aGain, TBool& aAsyncComplete)
   1.708 +	{
   1.709 +	DP_CONTEXT(CDevAudio::SetDevSoundGain *CD1*, CtxDevSound, DPLOCAL);
   1.710 +	DP_IN();
   1.711 +
   1.712 +	// Values are clipped between 0 and MaxGain. 
   1.713 +	// because MAudioGainControl expects this to be done
   1.714 +	TInt gain = aGain;
   1.715 +	if (gain < 0)
   1.716 +		{
   1.717 +		gain = 0;
   1.718 +		}
   1.719 +	else if (gain > iDevSoundMaxGain)
   1.720 +		{
   1.721 +		gain = iDevSoundMaxGain;
   1.722 +		}
   1.723 +	iDevSoundGain = gain;
   1.724 +
   1.725 +	TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
   1.726 +
   1.727 +	DP0_RET(error, "%d");
   1.728 +	}
   1.729 +
   1.730 +// -----------------------------------------------------------------------------
   1.731 +// CDevAudio::SetDevSoundPlayBalance
   1.732 +// -----------------------------------------------------------------------------
   1.733 +//
   1.734 +TInt CDevAudio::SetDevSoundPlayBalance(TInt aLeftBalance, TInt aRightBalance, TBool& aAsyncComplete)
   1.735 +	{
   1.736 +	DP_CONTEXT(CDevAudio::SetDevSoundPlayBalance *CD1*, CtxDevSound, DPLOCAL);
   1.737 +	DP_IN();
   1.738 +	
   1.739 +	// Clipping values
   1.740 +	TInt left = aLeftBalance;
   1.741 +	if (left < 0)
   1.742 +		{
   1.743 +		left = 0;
   1.744 +		}
   1.745 +	else if (left > KMaxBalance)
   1.746 +		{
   1.747 +		left = KMaxBalance;
   1.748 +		}
   1.749 +	TInt right = aRightBalance;
   1.750 +	if (right < 0)
   1.751 +		{
   1.752 +		right = 0;
   1.753 +		}
   1.754 +	else if (right > KMaxBalance)
   1.755 +		{
   1.756 +		right = KMaxBalance;
   1.757 +		}
   1.758 +	iDevSoundPlayBalance[KLeftChannel] = left;
   1.759 +	iDevSoundPlayBalance[KRightChannel] = right;
   1.760 +
   1.761 +	TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
   1.762 +
   1.763 +	DP0_RET(error, "%d");
   1.764 +	}
   1.765 +
   1.766 +// -----------------------------------------------------------------------------
   1.767 +// CDevAudio::SetDevSoundRecordBalance
   1.768 +// -----------------------------------------------------------------------------
   1.769 +//
   1.770 +TInt CDevAudio::SetDevSoundRecordBalance(TInt aLeftBalance, TInt aRightBalance, TBool& aAsyncComplete)
   1.771 +	{
   1.772 +	DP_CONTEXT(CDevAudio::SetDevSoundRecordBalance *CD1*, CtxDevSound, DPLOCAL);
   1.773 +	DP_IN();
   1.774 +
   1.775 +	// Clipping values	
   1.776 +	TInt left = aLeftBalance;
   1.777 +	if (left < 0)
   1.778 +		{
   1.779 +		left = 0;
   1.780 +		}
   1.781 +	else if (left > KMaxBalance)
   1.782 +		{
   1.783 +		left = KMaxBalance;
   1.784 +		}
   1.785 +	TInt right = aRightBalance;
   1.786 +	if (right < 0)
   1.787 +		{
   1.788 +		right = 0;
   1.789 +		}
   1.790 +	else if (right > KMaxBalance)
   1.791 +		{
   1.792 +		right = KMaxBalance;
   1.793 +		}
   1.794 +	iDevSoundRecordBalance[KLeftChannel] = left;
   1.795 +	iDevSoundRecordBalance[KRightChannel] = right;
   1.796 +
   1.797 +	TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
   1.798 +
   1.799 +	DP0_RET(error, "%d");
   1.800 +	}
   1.801 +
   1.802 +
   1.803 +// -----------------------------------------------------------------------------
   1.804 +// CDevAudio::SetVolumeRamp
   1.805 +// -----------------------------------------------------------------------------
   1.806 +//
   1.807 +TInt CDevAudio::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
   1.808 +	{
   1.809 +	DP_CONTEXT(CDevAudioControl::SetVolumeRamp *CD1*, CtxDevSound, DPLOCAL);
   1.810 +	DP_IN();
   1.811 +
   1.812 +	iRampDuration = aRampDuration;
   1.813 +	
   1.814 +	DP0_RET(KErrNone,"%d");
   1.815 +	}
   1.816 +
   1.817 +// -----------------------------------------------------------------------------
   1.818 +// CDevAudio::RequestGainAndBalance
   1.819 +// -----------------------------------------------------------------------------
   1.820 +//
   1.821 +TInt CDevAudio::RequestGainAndBalance(CDevAudioControl* aCallingControl)
   1.822 +	{
   1.823 +	DP_CONTEXT(CDevAudio::RequestGainAndBalance *CD1*, CtxDevSound, DPLOCAL);
   1.824 +	DP_IN();
   1.825 +	
   1.826 +	TInt error = KErrNone;
   1.827 +	if (aCallingControl != iCurrentAudioControl)
   1.828 +		{
   1.829 +		error = KErrNotReady;
   1.830 +		}
   1.831 +	else
   1.832 +		{
   1.833 +		TBool dummy;
   1.834 +		error = SetGainAndBalance(ETrue, dummy);
   1.835 +		}
   1.836 +	DP0_RET(error, "%d");
   1.837 +	}
   1.838 +	
   1.839 +// -----------------------------------------------------------------------------
   1.840 +// CDevAudio::SetGainAndBalance
   1.841 +// -----------------------------------------------------------------------------
   1.842 +//
   1.843 +TInt CDevAudio::SetGainAndBalance(TBool aBecomingActive, TBool& aAsyncComplete)
   1.844 +	{
   1.845 +	DP_CONTEXT(CDevAudio::SetGainAndBalance *CD1*, CtxDevSound, DPLOCAL);
   1.846 +	DP_IN();
   1.847 +	
   1.848 +	TInt error = KErrNone;
   1.849 +	aAsyncComplete = EFalse; // let's assume this - makes logic easier below
   1.850 +	// Apply cached settings. 
   1.851 +	// If aBecomingActive is true it indicates this call is doing before the MAudioStream::Activate() transition, 
   1.852 +	// so if required will apply volume ramp and won't itself generate a Commit() call. 
   1.853 +	// Otherwise, when Active, the calls made here will generate a Commit() 
   1.854 +	// and aAsyncComplete is returned true unless the SetGain() call fails
   1.855 +	if (aBecomingActive || iActiveState == EDevSoundAdaptorActive_Active) 
   1.856 +		{
   1.857 +		if (iCurrentAudioControl==iDevRecordControl)
   1.858 +			{
   1.859 +			// TODO assumes we are not mid Commit cycle
   1.860 +			// we are recing, need to change current volume at A3F layer
   1.861 +			error = iCurrentAudioControl->SetGains(iDevSoundGain, iDevSoundMaxGain, iDevSoundRecordBalance, 0, aBecomingActive);
   1.862 +			if (error==KErrNone)
   1.863 +				{
   1.864 +				aAsyncComplete = ETrue;
   1.865 +				}
   1.866 +			}
   1.867 +		else if (iCurrentAudioControl==iDevPlayControl || iCurrentAudioControl==iDevToneControl)
   1.868 +			{
   1.869 +			// TODO assumes we are not mid Commit cycle
   1.870 +			// we are playing, need to change current volume at A3F layer
   1.871 +			error = iCurrentAudioControl->SetGains(iDevSoundVolume, iDevSoundMaxVolume, iDevSoundPlayBalance, iRampDuration, aBecomingActive);
   1.872 +			if (error==KErrNone)
   1.873 +				{
   1.874 +				aAsyncComplete = ETrue;
   1.875 +				}
   1.876 +			}
   1.877 +		
   1.878 +		} 
   1.879 +
   1.880 +		
   1.881 +	DP0_RET(error, "%d");	
   1.882 +	}
   1.883 +
   1.884 +// -----------------------------------------------------------------------------
   1.885 +// CDevAudio::GetDevSoundPlayBalance
   1.886 +// -----------------------------------------------------------------------------
   1.887 +//
   1.888 +void CDevAudio::GetDevSoundPlayBalance(TInt& aLeftBalance, TInt& aRightBalance)
   1.889 +	{
   1.890 +	DP_CONTEXT(CDevAudio::GetDevSoundPlayBalance *CD1*, CtxDevSound, DPLOCAL);
   1.891 +	DP_IN();
   1.892 +	aLeftBalance = iDevSoundPlayBalance[KLeftChannel];
   1.893 +	aRightBalance = iDevSoundPlayBalance[KRightChannel];
   1.894 +	DP_OUT();
   1.895 +	}
   1.896 +	
   1.897 +
   1.898 +// -----------------------------------------------------------------------------
   1.899 +// CDevAudio::GetDevSoundRecordBalance
   1.900 +// -----------------------------------------------------------------------------
   1.901 +//
   1.902 +void CDevAudio::GetDevSoundRecordBalance(TInt& aLeftBalance, TInt& aRightBalance)
   1.903 +	{
   1.904 +	DP_CONTEXT(CDevAudio::GetDevSoundRecordBalance *CD1*, CtxDevSound, DPLOCAL);
   1.905 +	DP_IN();
   1.906 +	aLeftBalance = iDevSoundRecordBalance[KLeftChannel];
   1.907 +	aRightBalance = iDevSoundRecordBalance[KRightChannel];
   1.908 +	DP_OUT();
   1.909 +	}
   1.910 +
   1.911 +// -----------------------------------------------------------------------------
   1.912 +// CDevAudio::DevSoundSupportedDataTypesL
   1.913 +// -----------------------------------------------------------------------------
   1.914 +//
   1.915 +void CDevAudio::DevSoundSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes, TUint aDataType)
   1.916 +	{
   1.917 +	DP_CONTEXT(CDevAudio::DevSoundSupportedDataTypesL *CD1*, CtxDevSound, DPLOCAL);
   1.918 +	DP_IN();
   1.919 +	
   1.920 +	//Clear any existing data
   1.921 +	aSupportedDataTypes.Reset();
   1.922 +	
   1.923 +	if(aDataType == KDataForPlay)
   1.924 +		{
   1.925 +		ConvertToFourCcL(aSupportedDataTypes, iSupportedInputFormats);
   1.926 +		}
   1.927 +	else if(aDataType == KDataForRecord)
   1.928 +		{
   1.929 +		ConvertToFourCcL(aSupportedDataTypes, iSupportedOutputFormats);
   1.930 +		}
   1.931 +	
   1.932 +	DP_OUT();
   1.933 +	}
   1.934 +	
   1.935 +// -----------------------------------------------------------------------------
   1.936 +// CDevAudio::ConvertToFourCcL
   1.937 +// -----------------------------------------------------------------------------
   1.938 +//
   1.939 +void CDevAudio::ConvertToFourCcL(RArray<TFourCC>& aSupportedDataTypes, RArray<TUid>& aSupportedFormats)
   1.940 +	{
   1.941 +	DP_CONTEXT(CDevAudio::ConvertToFourCcL *CD1*, CtxDevSound, DPLOCAL);
   1.942 +	DP_IN();
   1.943 +	
   1.944 +	if(aSupportedFormats.Count() > 0)
   1.945 +		{
   1.946 +		TFourCC fourCC;
   1.947 +		
   1.948 +		for(TInt element=0; element<aSupportedFormats.Count(); element++)
   1.949 +			{		
   1.950 +			User::LeaveIfError(const_cast<CFourCCConvertor&>(iGlobalProperties->GetFourCCConvertor()).FormatToFourCC(aSupportedFormats[element],fourCC));
   1.951 +			aSupportedDataTypes.AppendL(fourCC);	
   1.952 +			}
   1.953 +		}
   1.954 +	DP_OUT();
   1.955 +	}
   1.956 +
   1.957 +
   1.958 +// -----------------------------------------------------------------------------
   1.959 +// CDevAudio::CreateAudioProcessingUnits
   1.960 +// -----------------------------------------------------------------------------
   1.961 +//
   1.962 +TInt CDevAudio::CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec)
   1.963 +	{
   1.964 +	DP_CONTEXT(CDevAudio::CreateAudioProcessingUnits *CD1*, CtxDevSound, DPLOCAL);
   1.965 +	DP_IN();
   1.966 +	TInt err = iAudioContext->CreateAudioProcessingUnit(aSource, iAudioSource);
   1.967 +	if(err != KErrNone)
   1.968 +		{
   1.969 +		DP0_RET(err,"Audio source creation failed!");
   1.970 +		}
   1.971 +	err = iAudioContext->CreateAudioProcessingUnit(aSink, iAudioSink);
   1.972 +	if(err != KErrNone)
   1.973 +		{
   1.974 +		DP0_RET(err,"Audio sink creation failed!");
   1.975 +		}
   1.976 +	err = iAudioContext->CreateAudioProcessingUnit(aCodec, iAudioCodec);
   1.977 +	if(err != KErrNone)
   1.978 +		{
   1.979 +		DP0_RET(err,"Audio codec creation failed!");
   1.980 +		}
   1.981 +
   1.982 +	DP0_RET(err,"");
   1.983 +	}
   1.984 +
   1.985 +// -----------------------------------------------------------------------------
   1.986 +// CDevAudio::DeleteAudioProcessingUnits
   1.987 +// -----------------------------------------------------------------------------
   1.988 +//
   1.989 +void CDevAudio::DeleteAudioProcessingUnits()
   1.990 +	{
   1.991 +	DP_CONTEXT(CDevAudio::DeleteAudioProcessingUnits *CD1*, CtxDevSound, DPLOCAL);
   1.992 +	DP_IN();
   1.993 +	if (iAudioSource)
   1.994 +		{
   1.995 +		iAudioContext->DeleteAudioProcessingUnit(iAudioSource);
   1.996 +		iAudioSource = NULL;
   1.997 +		}
   1.998 +	if (iAudioSink)
   1.999 +		{
  1.1000 +		iAudioContext->DeleteAudioProcessingUnit(iAudioSink);
  1.1001 +		iAudioSink = NULL;
  1.1002 +		}
  1.1003 +	if (iAudioCodec)
  1.1004 +		{
  1.1005 +		iAudioContext->DeleteAudioProcessingUnit(iAudioCodec);
  1.1006 +		iAudioCodec = NULL;
  1.1007 +		}
  1.1008 +	DP_OUT();
  1.1009 +	}
  1.1010 +
  1.1011 +TInt CDevAudio::CommitAudioContext()
  1.1012 +	{
  1.1013 +	DP_CONTEXT(CDevAudio::CommitAudioContext *CD1*, CtxDevSound, DPLOCAL);
  1.1014 +	DP_IN();
  1.1015 +
  1.1016 +	//If we are in mid state then Panic as DevSound server-side session (CMMFDevSoundSession) is not blocking properly
  1.1017 +	__ASSERT_DEBUG(!IsMidState(iActiveState), Panic(EValidStateBeforeCommit));
  1.1018 +
  1.1019 +	TInt err = KErrNone;
  1.1020 +	iPreviousState = iActiveState;
  1.1021 +	err = iAudioContext->Commit();
  1.1022 +
  1.1023 +	DP0_RET(err,"%d");
  1.1024 +	}
  1.1025 +
  1.1026 +TBool CDevAudio::IsMidState(TDevSoundAdaptorState aAdaptorState)
  1.1027 +	{
  1.1028 +	DP_CONTEXT(CDevAudio::IsMidState *CD1*, CtxDevSound, DPLOCAL);
  1.1029 +	DP_IN();
  1.1030 +	if (aAdaptorState == EDevSoundAdaptorRemovingProcessingUnits || aAdaptorState == EDevSoundAdaptorUninitialising ||
  1.1031 +			aAdaptorState == EDevSoundAdaptorInitialising || aAdaptorState == EDevSoundAdaptorLoading ||
  1.1032 +			aAdaptorState == EDevSoundAdaptorUnloading || aAdaptorState == EDevSoundAdaptorStopping ||
  1.1033 +			aAdaptorState == EDevSoundAdaptorActivating || aAdaptorState == EDevSoundAdaptorPausing)
  1.1034 +		{
  1.1035 +		DP0_RET(ETrue,"%d");
  1.1036 +		}
  1.1037 +	DP0_RET(EFalse,"%d");
  1.1038 +	}
  1.1039 +
  1.1040 +// -----------------------------------------------------------------------------
  1.1041 +// From MA3FDevSoundAutoPauseResume
  1.1042 +// CDevAudio::RegisterAsClient
  1.1043 +// -----------------------------------------------------------------------------
  1.1044 +//
  1.1045 +TInt CDevAudio::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
  1.1046 +	{
  1.1047 +	DP_CONTEXT(CDevAudio::RegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
  1.1048 +	DP_IN();
  1.1049 +	TInt err = KErrNotSupported;
  1.1050 +	MA3FDevSoundAutoPauseResume* iAPR =  static_cast<MA3FDevSoundAutoPauseResume*>(iAudioContext->Interface(KUIdAudioResourceNotification));
  1.1051 +	if(iAPR)
  1.1052 +		{
  1.1053 +		err = iAPR->RegisterAsClient(aEventType, aNotificationRegistrationData, this);
  1.1054 +		}
  1.1055 +	DP0_RET(err, "%d");	
  1.1056 +	}
  1.1057 +	
  1.1058 +
  1.1059 +// -----------------------------------------------------------------------------
  1.1060 +// CDevAudio::CancelRegisterAsClient
  1.1061 +// -----------------------------------------------------------------------------
  1.1062 +//
  1.1063 +TInt CDevAudio::CancelRegisterAsClient(TUid aEventType)
  1.1064 +	{
  1.1065 +	DP_CONTEXT(CDevAudio::CancelRegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
  1.1066 +	DP_IN();
  1.1067 +	TInt err = KErrNotSupported;
  1.1068 +	MA3FDevSoundAutoPauseResume* iAPR =  static_cast<MA3FDevSoundAutoPauseResume*>(iAudioContext->Interface(KUIdAudioResourceNotification));
  1.1069 +	if(iAPR)
  1.1070 +		{
  1.1071 +		err = iAPR->CancelRegisterAsClient(aEventType);
  1.1072 +		}
  1.1073 +	DP0_RET(err, "%d");	
  1.1074 +	}
  1.1075 +
  1.1076 +
  1.1077 +// -----------------------------------------------------------------------------
  1.1078 +// CDevAudio::WillResumePlay
  1.1079 +// -----------------------------------------------------------------------------
  1.1080 +//
  1.1081 +TInt CDevAudio::WillResumePlay()
  1.1082 +	{
  1.1083 +	DP_CONTEXT(CDevAudio::WillResumePlay *CD1*, CtxDevSound, DPLOCAL);
  1.1084 +	DP_IN();
  1.1085 +	TInt err = KErrNotSupported;
  1.1086 +	MA3FDevSoundAutoPauseResume* iAPR =  static_cast<MA3FDevSoundAutoPauseResume*>(iAudioContext->Interface(KUIdAudioResourceNotification));
  1.1087 +	if(iAPR)
  1.1088 +		{
  1.1089 +		err = iAPR->WillResumePlay();
  1.1090 +		}
  1.1091 +	DP0_RET(err, "%d");	
  1.1092 +	}
  1.1093 +
  1.1094 +
  1.1095 +// -----------------------------------------------------------------------------
  1.1096 +// CDevAudio::NotifyResume
  1.1097 +// -----------------------------------------------------------------------------
  1.1098 +//
  1.1099 +void CDevAudio::NotifyResume()
  1.1100 +	{
  1.1101 +	DP_CONTEXT(CDevAudio::NotifyResume *CD1*, CtxDevSound, DPLOCAL);
  1.1102 +	DP_IN();
  1.1103 +	iAdaptationObserver.CallbackFromAdaptorReceived(KCallbackAutoPauseResume, KErrNone);
  1.1104 +	DP_OUT();
  1.1105 +	}
  1.1106 +
  1.1107 +void CDevAudio::Panic(TMMFDevAudioPanicCodes aCode)
  1.1108 +	{
  1.1109 +	User::Panic(KMMFDevAudioPanicCategory, aCode);
  1.1110 +	}
  1.1111 +
  1.1112 +// End of file