sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #ifndef CDEVAUDIO_H sl@0: #define CDEVAUDIO_H sl@0: sl@0: #include sl@0: sl@0: #include "mmfdevsoundadaptationbody.h" sl@0: #include sl@0: #include sl@0: #include "mdevsoundadaptationinfoobserver.h" sl@0: sl@0: #include sl@0: #include sl@0: sl@0: sl@0: // CLASS FORWARD sl@0: class CDevAudioControl; sl@0: class CDevPlayControl; sl@0: class CDevRecordControl; sl@0: class CDevToneControl; sl@0: class CDevGenControl; sl@0: class CAudioContextFactory; sl@0: class CA3FDevSoundAdaptationInfo; sl@0: class MAudioContext; sl@0: class MAudioStream; sl@0: class MGlobalProperties; sl@0: sl@0: /** sl@0: Panic category and codes that CDevAudio raises on the client sl@0: */ sl@0: _LIT(KMMFDevAudioPanicCategory, "CDevAudio"); sl@0: sl@0: enum TMMFDevAudioPanicCodes sl@0: { sl@0: EValidStateBeforeCommit =1 sl@0: }; sl@0: sl@0: enum TDevSoundAdaptorState sl@0: { sl@0: EDevSoundAdaptorCreated_Uninitialised, sl@0: EDevSoundAdaptorRemovingProcessingUnits, sl@0: EDevSoundAdaptorUnitialised_Uninitialised, sl@0: EDevSoundAdaptorUninitialising, sl@0: EDevSoundAdaptorInitialising, sl@0: EDevSoundAdaptorInitialised_Initialised, sl@0: EDevSoundAdaptorLoading, sl@0: EDevSoundAdaptorUnloading, sl@0: EDevSoundAdaptorInitialised_Idle, sl@0: EDevSoundAdaptorGoingActive, sl@0: EDevSoundAdaptorPreempted, sl@0: EDevSoundAdaptorBeingPreempted, sl@0: EDevSoundAdaptorStopping, sl@0: EDevSoundAdaptorActivating, sl@0: EDevSoundAdaptorActive_Active, sl@0: EDevSoundAdaptorPausing, sl@0: EDevSoundAdaptorPaused_Primed sl@0: }; sl@0: sl@0: /** sl@0: * CDevAudio. sl@0: * sl@0: * ?description sl@0: * sl@0: * @lib mmfdevsoundadaptation.lib sl@0: * @since sl@0: */ sl@0: NONSHARABLE_CLASS(CDevAudio) : public CBase, sl@0: public MAudioContextObserver, sl@0: public MA3FDevSoundAdaptationInfoObserver, sl@0: public MA3FDevSoundAutoPauseResumeObserver sl@0: { sl@0: friend class CDevAudioControl; sl@0: friend class CDevPlayControl; sl@0: friend class CDevRecordControl; sl@0: friend class CDevToneControl; sl@0: friend class CDevGenControl; sl@0: friend class CDevCommonControl; sl@0: sl@0: public: sl@0: sl@0: ~CDevAudio(); sl@0: sl@0: static CDevAudio* NewL(MDevSoundAdaptationObserver& aDevSoundObserver, sl@0: MGlobalProperties& aGlobalProperties); sl@0: sl@0: void ConstructL(MGlobalProperties& aGlobalProperties); sl@0: sl@0: // 2nd phase async construct - will callback to aDevSoundObserver sl@0: TInt PostOpen(); sl@0: sl@0: /** sl@0: * Sets control operating mode (playing/recording...) sl@0: * @since sl@0: * @param aMode new control mode sl@0: * @param aFormat codec format sl@0: * @return error code sl@0: */ sl@0: TInt Initialize(TUid aFormat, TMMFState aMode); sl@0: sl@0: /** sl@0: * Cancels Initialization sl@0: * @since sl@0: * @return error code sl@0: */ sl@0: TInt CancelInitialize(); sl@0: sl@0: /** sl@0: * Returns pointer to audio control instance for current operating mode sl@0: * @since sl@0: * @param aAudioControl on return, contains pointer to audio control sl@0: * @return error code sl@0: */ sl@0: CDevAudioControl* GetAudioControl(); sl@0: sl@0: /** sl@0: * Defines the priority settings that should be used for this instance. sl@0: * @since sl@0: * @param const TMMFPrioritySettings &aPrioritySettings A class type sl@0: * representing the client's priority, priority preference and sl@0: * state sl@0: * @return Err sl@0: */ sl@0: TInt SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings); sl@0: sl@0: /** sl@0: * Sets client configuration sl@0: * @since sl@0: * @param aProcessId DevSound's client process sl@0: * @param aActualProcessId DevSound's effective/actual client (supplied by SetClientThreadInfo) sl@0: */ sl@0: TInt SetClientConfig(const TProcessId& aProcessId); sl@0: TInt SetClientConfig(const TProcessId& aActualProcessId, const TProcessId& aProcessId); sl@0: sl@0: sl@0: /** sl@0: * Retrieve the current A3F state sl@0: * @since sl@0: * @return the current A3F state. See TAudioState sl@0: */ sl@0: TDevSoundAdaptorState ActiveState() const; sl@0: sl@0: /** sl@0: * Retrieve the previous DevSound adaptor state sl@0: * @return void sl@0: */ sl@0: TDevSoundAdaptorState PreviousState() const; sl@0: sl@0: /** sl@0: * Set the current DevSound adaptor state sl@0: * @return void sl@0: */ sl@0: void SetActiveState(TDevSoundAdaptorState aAdaptorState); sl@0: sl@0: /** sl@0: * Set the previous DevSound adaptor state sl@0: * @return void sl@0: */ sl@0: void SetPreviousState(TDevSoundAdaptorState aAdaptorState); sl@0: sl@0: /** sl@0: * SetVolume for DevSound sl@0: */ sl@0: TInt SetDevSoundVolume(TInt aVolume, TBool& aAsyncCompletion); sl@0: sl@0: /** sl@0: * SetGain for DevSound sl@0: */ sl@0: TInt SetDevSoundGain(TInt aGain, TBool& aAsyncCompletion); sl@0: sl@0: /** sl@0: * SetPlayBalance for DevSound sl@0: */ sl@0: TInt SetDevSoundPlayBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion); sl@0: sl@0: /** sl@0: * SetPlayBalance for DevSound sl@0: */ sl@0: TInt SetDevSoundRecordBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion); sl@0: sl@0: /** sl@0: * SetVolumeRamp for DevSound sl@0: */ sl@0: TInt SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); sl@0: sl@0: /** sl@0: * MaxVolume for DevSound sl@0: */ sl@0: TInt DevSoundMaxVolume() const; sl@0: /** sl@0: * MaxGain for DevSound sl@0: */ sl@0: TInt DevSoundMaxGain() const; sl@0: /** sl@0: * Volume setting sl@0: */ sl@0: TInt DevSoundVolume() const; sl@0: /** sl@0: * Gain setting sl@0: */ sl@0: TInt DevSoundGain() const; sl@0: sl@0: /** sl@0: * GetPlayBalance for DevSound sl@0: */ sl@0: void GetDevSoundPlayBalance(TInt& aLeftPercentage, TInt& aRightPercentage); sl@0: sl@0: /** sl@0: * GetRecordBalance for DevSound sl@0: */ sl@0: void GetDevSoundRecordBalance(TInt& aLeftPercentage, TInt& aRightPercentage); sl@0: sl@0: /** sl@0: * GetSupportedDataTypes for DevSound sl@0: */ sl@0: void DevSoundSupportedDataTypesL(RArray& aSupportedDataTypes, TUint aDataType); sl@0: sl@0: /** sl@0: * Call from control - generates appropriate SetGainAndBalance() call sl@0: */ sl@0: TInt RequestGainAndBalance(CDevAudioControl* aCallingControl); sl@0: sl@0: // From base class MAudioContextObserver sl@0: /** sl@0: * Callback to context observer to show progression through Commit() and pre-emption cycles sl@0: * sl@0: * @param aEvent a Uid giving the specific event. sl@0: * @param aError an error code. KErrNone if successful, otherwise one of the system wide error codes. sl@0: */ sl@0: virtual void ContextEvent(TUid aEvent, TInt aError); sl@0: sl@0: // from MA3FDevSoundAdaptationInfoObserver sl@0: void RequestMaxGainComplete (TUid aCodecType, TInt aError, TInt aResult); sl@0: void RequestSupportedFormatsComplete(TUid aCodecType, TInt aError); sl@0: sl@0: /** sl@0: * Queries if the low layers does support resume operation. sl@0: * @since sl@0: * @return TBool ETrue if Resume is supported sl@0: * EFalse otherwise sl@0: */ sl@0: TBool IsResumeSupported(); sl@0: sl@0: void ConvertToFourCcL(RArray& aSupportedDataTypes, RArray& iSupportedFormats); sl@0: sl@0: //from MA3FDevSoundAutoPauseResume sl@0: TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData); sl@0: TInt CancelRegisterAsClient(TUid aEventType); sl@0: TInt WillResumePlay(); sl@0: sl@0: //from MA3FDevSoundAutoPauseResumeObserver sl@0: virtual void NotifyResume(); sl@0: sl@0: /** sl@0: * GetPrioritySettings for DevSound sl@0: */ sl@0: void GetPrioritySettings(TAudioTypeSettings& astorage); sl@0: sl@0: TBool IsPrioritySet(); sl@0: sl@0: //Panic function sl@0: void Panic(TMMFDevAudioPanicCodes aCode); sl@0: sl@0: protected: sl@0: sl@0: CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver); sl@0: sl@0: // If active, apply devsound volume and balance changes sl@0: TInt SetGainAndBalance(TBool aCallBack, TBool& aAsyncCompletion); sl@0: sl@0: // Helper methods sl@0: TInt CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec); sl@0: void DeleteAudioProcessingUnits(); sl@0: sl@0: TInt CommitAudioContext(); sl@0: TBool IsMidState(TDevSoundAdaptorState aAdaptorState); sl@0: sl@0: /* sl@0: * most of member data is protected for DevAudioControl access sl@0: */ sl@0: protected: // data sl@0: sl@0: /** sl@0: * adaptation observer - used to indicate async callbacks etc sl@0: */ sl@0: MDevSoundAdaptationObserver& iAdaptationObserver; sl@0: sl@0: /** sl@0: * Pointer to audio context factory - context creation sl@0: * Own. sl@0: */ sl@0: CAudioContextFactory *iAudioContextFactory; sl@0: sl@0: /** sl@0: * Pointer to audio context. sl@0: * Not own. sl@0: */ sl@0: MAudioContext *iAudioContext; sl@0: sl@0: /** sl@0: * Pointer to audio stream. sl@0: * Not own. sl@0: */ sl@0: MAudioStream *iAudioStream; sl@0: sl@0: /** sl@0: * Pointer to audio source. sl@0: * Not own. sl@0: */ sl@0: MAudioProcessingUnit* iAudioSource; sl@0: sl@0: /** sl@0: * Pointer to audio codec. sl@0: * Not own. sl@0: */ sl@0: MAudioProcessingUnit* iAudioCodec; sl@0: sl@0: /** sl@0: * Pointer to audio gain control sl@0: * Not own. sl@0: */ sl@0: MAudioProcessingUnit* iGainControl; sl@0: sl@0: /** sl@0: * Pointer to audio sink sl@0: * Not own. sl@0: */ sl@0: MAudioProcessingUnit* iAudioSink; sl@0: sl@0: /** sl@0: * Mode to which this DevAudio is initialized in sl@0: */ sl@0: TMMFState iMode; sl@0: sl@0: TUid iFormat; sl@0: sl@0: /** sl@0: * Active DevSound Adaptor state sl@0: */ sl@0: TDevSoundAdaptorState iActiveState; sl@0: sl@0: /** sl@0: * Previous DevSound Adaptor state sl@0: */ sl@0: TDevSoundAdaptorState iPreviousState; sl@0: sl@0: TAudioState iActiveStreamState; sl@0: sl@0: TBool iReinitializing; sl@0: TBool iClosing; sl@0: TBool iStop; sl@0: TUid iTargetFormat; sl@0: TMMFState iTargetMode; sl@0: sl@0: TInt iDevSoundMaxGain; sl@0: TInt iDevSoundMaxVolume; sl@0: TInt iDevSoundGain; sl@0: TInt iDevSoundVolume; sl@0: TInt iDevSoundPlayBalance[2]; sl@0: TInt iDevSoundRecordBalance[2]; sl@0: TTimeIntervalMicroSeconds iRampDuration; sl@0: private: sl@0: enum TPreOpenState sl@0: { sl@0: EPreOpenStateIdle, sl@0: EPreOpenStateRequestingMaxVolume, sl@0: EPreOpenStateRequestingMaxGain, sl@0: EPreOpenStateRequestingInputFormats, sl@0: EPreOpenStateRequestingOutputFormats, sl@0: }; sl@0: sl@0: TPreOpenState iPreOpenState; sl@0: sl@0: RArray iSupportedInputFormats; sl@0: RArray iSupportedOutputFormats; sl@0: sl@0: CA3FDevSoundAdaptationInfo* iAdaptationInfo; sl@0: sl@0: CDevPlayControl* iDevPlayControl; sl@0: CDevRecordControl* iDevRecordControl; sl@0: CDevToneControl* iDevToneControl; sl@0: CDevGenControl* iDevGenControl; sl@0: sl@0: /** sl@0: * Points to whichever control is active sl@0: * Not own. sl@0: */ sl@0: CDevAudioControl* iCurrentAudioControl; sl@0: sl@0: // Pointer to global properties sl@0: // Not owned. sl@0: MGlobalProperties* iGlobalProperties; sl@0: sl@0: TAudioTypeSettings iPrioritySettings; sl@0: TBool iPriorityFlag; sl@0: sl@0: }; sl@0: sl@0: inline TInt CDevAudio::DevSoundMaxVolume() const sl@0: { sl@0: return iDevSoundMaxVolume; sl@0: } sl@0: sl@0: inline TInt CDevAudio::DevSoundMaxGain() const sl@0: { sl@0: return iDevSoundMaxGain; sl@0: } sl@0: sl@0: inline TInt CDevAudio::DevSoundVolume() const sl@0: { sl@0: return iDevSoundVolume; sl@0: } sl@0: sl@0: inline TInt CDevAudio::DevSoundGain() const sl@0: { sl@0: return iDevSoundGain; sl@0: } sl@0: sl@0: #endif // CDEVAUDIO_H