1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/a3fdevsound/src/devsoundadaptor/cdevaudio.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,436 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +#ifndef CDEVAUDIO_H
1.24 +#define CDEVAUDIO_H
1.25 +
1.26 +#include <e32base.h>
1.27 +
1.28 +#include "mmfdevsoundadaptationbody.h"
1.29 +#include <a3f/maudiocontextobserver.h>
1.30 +#include <a3f/maudiostreamobserver.h>
1.31 +#include "mdevsoundadaptationinfoobserver.h"
1.32 +
1.33 +#include <a3f/a3f_trace_utils.h>
1.34 +#include <a3f/a3fdevsoundaudiopauseresume.h>
1.35 +
1.36 +
1.37 +// CLASS FORWARD
1.38 +class CDevAudioControl;
1.39 +class CDevPlayControl;
1.40 +class CDevRecordControl;
1.41 +class CDevToneControl;
1.42 +class CDevGenControl;
1.43 +class CAudioContextFactory;
1.44 +class CA3FDevSoundAdaptationInfo;
1.45 +class MAudioContext;
1.46 +class MAudioStream;
1.47 +class MGlobalProperties;
1.48 +
1.49 +/**
1.50 +Panic category and codes that CDevAudio raises on the client
1.51 +*/
1.52 +_LIT(KMMFDevAudioPanicCategory, "CDevAudio");
1.53 +
1.54 +enum TMMFDevAudioPanicCodes
1.55 + {
1.56 + EValidStateBeforeCommit =1
1.57 + };
1.58 +
1.59 +enum TDevSoundAdaptorState
1.60 + {
1.61 + EDevSoundAdaptorCreated_Uninitialised,
1.62 + EDevSoundAdaptorRemovingProcessingUnits,
1.63 + EDevSoundAdaptorUnitialised_Uninitialised,
1.64 + EDevSoundAdaptorUninitialising,
1.65 + EDevSoundAdaptorInitialising,
1.66 + EDevSoundAdaptorInitialised_Initialised,
1.67 + EDevSoundAdaptorLoading,
1.68 + EDevSoundAdaptorUnloading,
1.69 + EDevSoundAdaptorInitialised_Idle,
1.70 + EDevSoundAdaptorGoingActive,
1.71 + EDevSoundAdaptorPreempted,
1.72 + EDevSoundAdaptorBeingPreempted,
1.73 + EDevSoundAdaptorStopping,
1.74 + EDevSoundAdaptorActivating,
1.75 + EDevSoundAdaptorActive_Active,
1.76 + EDevSoundAdaptorPausing,
1.77 + EDevSoundAdaptorPaused_Primed
1.78 + };
1.79 +
1.80 +/**
1.81 + * CDevAudio.
1.82 + *
1.83 + * ?description
1.84 + *
1.85 + * @lib mmfdevsoundadaptation.lib
1.86 + * @since
1.87 + */
1.88 +NONSHARABLE_CLASS(CDevAudio) : public CBase,
1.89 + public MAudioContextObserver,
1.90 + public MA3FDevSoundAdaptationInfoObserver,
1.91 + public MA3FDevSoundAutoPauseResumeObserver
1.92 + {
1.93 + friend class CDevAudioControl;
1.94 + friend class CDevPlayControl;
1.95 + friend class CDevRecordControl;
1.96 + friend class CDevToneControl;
1.97 + friend class CDevGenControl;
1.98 + friend class CDevCommonControl;
1.99 +
1.100 +public:
1.101 +
1.102 + ~CDevAudio();
1.103 +
1.104 + static CDevAudio* NewL(MDevSoundAdaptationObserver& aDevSoundObserver,
1.105 + MGlobalProperties& aGlobalProperties);
1.106 +
1.107 + void ConstructL(MGlobalProperties& aGlobalProperties);
1.108 +
1.109 + // 2nd phase async construct - will callback to aDevSoundObserver
1.110 + TInt PostOpen();
1.111 +
1.112 + /**
1.113 + * Sets control operating mode (playing/recording...)
1.114 + * @since
1.115 + * @param aMode new control mode
1.116 + * @param aFormat codec format
1.117 + * @return error code
1.118 + */
1.119 + TInt Initialize(TUid aFormat, TMMFState aMode);
1.120 +
1.121 + /**
1.122 + * Cancels Initialization
1.123 + * @since
1.124 + * @return error code
1.125 + */
1.126 + TInt CancelInitialize();
1.127 +
1.128 + /**
1.129 + * Returns pointer to audio control instance for current operating mode
1.130 + * @since
1.131 + * @param aAudioControl on return, contains pointer to audio control
1.132 + * @return error code
1.133 + */
1.134 + CDevAudioControl* GetAudioControl();
1.135 +
1.136 + /**
1.137 + * Defines the priority settings that should be used for this instance.
1.138 + * @since
1.139 + * @param const TMMFPrioritySettings &aPrioritySettings A class type
1.140 + * representing the client's priority, priority preference and
1.141 + * state
1.142 + * @return Err
1.143 + */
1.144 + TInt SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
1.145 +
1.146 + /**
1.147 + * Sets client configuration
1.148 + * @since
1.149 + * @param aProcessId DevSound's client process
1.150 + * @param aActualProcessId DevSound's effective/actual client (supplied by SetClientThreadInfo)
1.151 + */
1.152 + TInt SetClientConfig(const TProcessId& aProcessId);
1.153 + TInt SetClientConfig(const TProcessId& aActualProcessId, const TProcessId& aProcessId);
1.154 +
1.155 +
1.156 + /**
1.157 + * Retrieve the current A3F state
1.158 + * @since
1.159 + * @return the current A3F state. See TAudioState
1.160 + */
1.161 + TDevSoundAdaptorState ActiveState() const;
1.162 +
1.163 + /**
1.164 + * Retrieve the previous DevSound adaptor state
1.165 + * @return void
1.166 + */
1.167 + TDevSoundAdaptorState PreviousState() const;
1.168 +
1.169 + /**
1.170 + * Set the current DevSound adaptor state
1.171 + * @return void
1.172 + */
1.173 + void SetActiveState(TDevSoundAdaptorState aAdaptorState);
1.174 +
1.175 + /**
1.176 + * Set the previous DevSound adaptor state
1.177 + * @return void
1.178 + */
1.179 + void SetPreviousState(TDevSoundAdaptorState aAdaptorState);
1.180 +
1.181 + /**
1.182 + * SetVolume for DevSound
1.183 + */
1.184 + TInt SetDevSoundVolume(TInt aVolume, TBool& aAsyncCompletion);
1.185 +
1.186 + /**
1.187 + * SetGain for DevSound
1.188 + */
1.189 + TInt SetDevSoundGain(TInt aGain, TBool& aAsyncCompletion);
1.190 +
1.191 + /**
1.192 + * SetPlayBalance for DevSound
1.193 + */
1.194 + TInt SetDevSoundPlayBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion);
1.195 +
1.196 + /**
1.197 + * SetPlayBalance for DevSound
1.198 + */
1.199 + TInt SetDevSoundRecordBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion);
1.200 +
1.201 + /**
1.202 + * SetVolumeRamp for DevSound
1.203 + */
1.204 + TInt SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
1.205 +
1.206 + /**
1.207 + * MaxVolume for DevSound
1.208 + */
1.209 + TInt DevSoundMaxVolume() const;
1.210 + /**
1.211 + * MaxGain for DevSound
1.212 + */
1.213 + TInt DevSoundMaxGain() const;
1.214 + /**
1.215 + * Volume setting
1.216 + */
1.217 + TInt DevSoundVolume() const;
1.218 + /**
1.219 + * Gain setting
1.220 + */
1.221 + TInt DevSoundGain() const;
1.222 +
1.223 + /**
1.224 + * GetPlayBalance for DevSound
1.225 + */
1.226 + void GetDevSoundPlayBalance(TInt& aLeftPercentage, TInt& aRightPercentage);
1.227 +
1.228 + /**
1.229 + * GetRecordBalance for DevSound
1.230 + */
1.231 + void GetDevSoundRecordBalance(TInt& aLeftPercentage, TInt& aRightPercentage);
1.232 +
1.233 + /**
1.234 + * GetSupportedDataTypes for DevSound
1.235 + */
1.236 + void DevSoundSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes, TUint aDataType);
1.237 +
1.238 + /**
1.239 + * Call from control - generates appropriate SetGainAndBalance() call
1.240 + */
1.241 + TInt RequestGainAndBalance(CDevAudioControl* aCallingControl);
1.242 +
1.243 + // From base class MAudioContextObserver
1.244 + /**
1.245 + * Callback to context observer to show progression through Commit() and pre-emption cycles
1.246 + *
1.247 + * @param aEvent a Uid giving the specific event.
1.248 + * @param aError an error code. KErrNone if successful, otherwise one of the system wide error codes.
1.249 + */
1.250 + virtual void ContextEvent(TUid aEvent, TInt aError);
1.251 +
1.252 + // from MA3FDevSoundAdaptationInfoObserver
1.253 + void RequestMaxGainComplete (TUid aCodecType, TInt aError, TInt aResult);
1.254 + void RequestSupportedFormatsComplete(TUid aCodecType, TInt aError);
1.255 +
1.256 + /**
1.257 + * Queries if the low layers does support resume operation.
1.258 + * @since
1.259 + * @return TBool ETrue if Resume is supported
1.260 + * EFalse otherwise
1.261 + */
1.262 + TBool IsResumeSupported();
1.263 +
1.264 + void ConvertToFourCcL(RArray<TFourCC>& aSupportedDataTypes, RArray<TUid>& iSupportedFormats);
1.265 +
1.266 + //from MA3FDevSoundAutoPauseResume
1.267 + TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData);
1.268 + TInt CancelRegisterAsClient(TUid aEventType);
1.269 + TInt WillResumePlay();
1.270 +
1.271 + //from MA3FDevSoundAutoPauseResumeObserver
1.272 + virtual void NotifyResume();
1.273 +
1.274 + /**
1.275 + * GetPrioritySettings for DevSound
1.276 + */
1.277 + void GetPrioritySettings(TAudioTypeSettings& astorage);
1.278 +
1.279 + TBool IsPrioritySet();
1.280 +
1.281 + //Panic function
1.282 + void Panic(TMMFDevAudioPanicCodes aCode);
1.283 +
1.284 +protected:
1.285 +
1.286 + CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver);
1.287 +
1.288 + // If active, apply devsound volume and balance changes
1.289 + TInt SetGainAndBalance(TBool aCallBack, TBool& aAsyncCompletion);
1.290 +
1.291 + // Helper methods
1.292 + TInt CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec);
1.293 + void DeleteAudioProcessingUnits();
1.294 +
1.295 + TInt CommitAudioContext();
1.296 + TBool IsMidState(TDevSoundAdaptorState aAdaptorState);
1.297 +
1.298 +/*
1.299 +* most of member data is protected for DevAudioControl access
1.300 +*/
1.301 +protected: // data
1.302 +
1.303 + /**
1.304 + * adaptation observer - used to indicate async callbacks etc
1.305 + */
1.306 + MDevSoundAdaptationObserver& iAdaptationObserver;
1.307 +
1.308 + /**
1.309 + * Pointer to audio context factory - context creation
1.310 + * Own.
1.311 + */
1.312 + CAudioContextFactory *iAudioContextFactory;
1.313 +
1.314 + /**
1.315 + * Pointer to audio context.
1.316 + * Not own.
1.317 + */
1.318 + MAudioContext *iAudioContext;
1.319 +
1.320 + /**
1.321 + * Pointer to audio stream.
1.322 + * Not own.
1.323 + */
1.324 + MAudioStream *iAudioStream;
1.325 +
1.326 + /**
1.327 + * Pointer to audio source.
1.328 + * Not own.
1.329 + */
1.330 + MAudioProcessingUnit* iAudioSource;
1.331 +
1.332 + /**
1.333 + * Pointer to audio codec.
1.334 + * Not own.
1.335 + */
1.336 + MAudioProcessingUnit* iAudioCodec;
1.337 +
1.338 + /**
1.339 + * Pointer to audio gain control
1.340 + * Not own.
1.341 + */
1.342 + MAudioProcessingUnit* iGainControl;
1.343 +
1.344 + /**
1.345 + * Pointer to audio sink
1.346 + * Not own.
1.347 + */
1.348 + MAudioProcessingUnit* iAudioSink;
1.349 +
1.350 + /**
1.351 + * Mode to which this DevAudio is initialized in
1.352 + */
1.353 + TMMFState iMode;
1.354 +
1.355 + TUid iFormat;
1.356 +
1.357 + /**
1.358 + * Active DevSound Adaptor state
1.359 + */
1.360 + TDevSoundAdaptorState iActiveState;
1.361 +
1.362 + /**
1.363 + * Previous DevSound Adaptor state
1.364 + */
1.365 + TDevSoundAdaptorState iPreviousState;
1.366 +
1.367 + TAudioState iActiveStreamState;
1.368 +
1.369 + TBool iReinitializing;
1.370 + TBool iClosing;
1.371 + TBool iStop;
1.372 + TUid iTargetFormat;
1.373 + TMMFState iTargetMode;
1.374 +
1.375 + TInt iDevSoundMaxGain;
1.376 + TInt iDevSoundMaxVolume;
1.377 + TInt iDevSoundGain;
1.378 + TInt iDevSoundVolume;
1.379 + TInt iDevSoundPlayBalance[2];
1.380 + TInt iDevSoundRecordBalance[2];
1.381 + TTimeIntervalMicroSeconds iRampDuration;
1.382 +private:
1.383 + enum TPreOpenState
1.384 + {
1.385 + EPreOpenStateIdle,
1.386 + EPreOpenStateRequestingMaxVolume,
1.387 + EPreOpenStateRequestingMaxGain,
1.388 + EPreOpenStateRequestingInputFormats,
1.389 + EPreOpenStateRequestingOutputFormats,
1.390 + };
1.391 +
1.392 + TPreOpenState iPreOpenState;
1.393 +
1.394 + RArray<TUid> iSupportedInputFormats;
1.395 + RArray<TUid> iSupportedOutputFormats;
1.396 +
1.397 + CA3FDevSoundAdaptationInfo* iAdaptationInfo;
1.398 +
1.399 + CDevPlayControl* iDevPlayControl;
1.400 + CDevRecordControl* iDevRecordControl;
1.401 + CDevToneControl* iDevToneControl;
1.402 + CDevGenControl* iDevGenControl;
1.403 +
1.404 + /**
1.405 + * Points to whichever control is active
1.406 + * Not own.
1.407 + */
1.408 + CDevAudioControl* iCurrentAudioControl;
1.409 +
1.410 + // Pointer to global properties
1.411 + // Not owned.
1.412 + MGlobalProperties* iGlobalProperties;
1.413 +
1.414 + TAudioTypeSettings iPrioritySettings;
1.415 + TBool iPriorityFlag;
1.416 +
1.417 + };
1.418 +
1.419 +inline TInt CDevAudio::DevSoundMaxVolume() const
1.420 + {
1.421 + return iDevSoundMaxVolume;
1.422 + }
1.423 +
1.424 +inline TInt CDevAudio::DevSoundMaxGain() const
1.425 + {
1.426 + return iDevSoundMaxGain;
1.427 + }
1.428 +
1.429 +inline TInt CDevAudio::DevSoundVolume() const
1.430 + {
1.431 + return iDevSoundVolume;
1.432 + }
1.433 +
1.434 +inline TInt CDevAudio::DevSoundGain() const
1.435 + {
1.436 + return iDevSoundGain;
1.437 + }
1.438 +
1.439 +#endif // CDEVAUDIO_H