sl@0: // Copyright (c) 2002-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: #ifndef MMFCLIENTAUDIOOUTPUTSTREAM_H sl@0: #define MMFCLIENTAUDIOOUTPUTSTREAM_H sl@0: sl@0: #include sl@0: #include sl@0: sl@0: template sl@0: class CMMFFifo; sl@0: class CMMFBuffer; sl@0: class MMdaAudioOutputStreamCallback; sl@0: class TMdaPackage; sl@0: class MMMFAudioResourceNotificationCallback; sl@0: sl@0: class CMMFMdaAudioOutputStream; sl@0: NONSHARABLE_CLASS( CMMFMdaAudioOutputStream ): public CBase, sl@0: public MDevSoundObserver sl@0: { sl@0: enum TIsOpenState sl@0: { sl@0: EIsNotOpen, sl@0: EIsOpening, // Open() called but not responded to sl@0: EIsOpen, // Open callback made and successfully opened sl@0: }; sl@0: public: sl@0: static CMMFMdaAudioOutputStream* NewL(MMdaAudioOutputStreamCallback& aCallback); sl@0: static CMMFMdaAudioOutputStream* NewL(MMdaAudioOutputStreamCallback& aCallback, TInt aPriority, TInt aPref); sl@0: virtual ~CMMFMdaAudioOutputStream(); sl@0: // sl@0: void SetAudioPropertiesL(TInt aSampleRate, TInt aChannels); sl@0: void Open(TMdaPackage* aSettings); sl@0: void SetVolume(const TInt aVolume); sl@0: TInt Volume(); sl@0: TInt MaxVolume(); sl@0: void SetBalanceL(TInt aBalance = KMMFBalanceCenter); sl@0: TInt GetBalanceL() const; sl@0: void SetPriority(TInt aPriority, TInt aPref); sl@0: void WriteL(const TDesC8& aData); sl@0: void Stop(); sl@0: TInt Pause(); sl@0: TInt Resume(); sl@0: const TTimeIntervalMicroSeconds& Position(); sl@0: TInt GetBytes(); sl@0: void SetDataTypeL(TFourCC aAudioType); sl@0: TFourCC DataType() const; sl@0: TInt RegisterAudioResourceNotification(MMMFAudioResourceNotificationCallback& aCallback,TUid aNotificationEventUid,const TDesC8& aNotificationRegistrationData = KNullDesC8); sl@0: TInt CancelRegisterAudioResourceNotification(TUid aNotificationEventId); sl@0: TInt WillResumePlay(); sl@0: TAny* CustomInterface(TUid aInterfaceId); sl@0: TInt KeepOpenAtEnd(); sl@0: TInt RequestStop(); sl@0: public: sl@0: // from MDevSoundObserver sl@0: virtual void InitializeComplete(TInt aError); sl@0: virtual void ToneFinished(TInt aError); sl@0: virtual void BufferToBeFilled(CMMFBuffer* aBuffer); sl@0: virtual void PlayError(TInt aError); sl@0: virtual void BufferToBeEmptied(CMMFBuffer* aBuffer); sl@0: virtual void RecordError(TInt aError); sl@0: virtual void ConvertError(TInt aError); sl@0: virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg); sl@0: virtual void SendEventToClient(const TMMFEvent& aEvent); sl@0: sl@0: private: sl@0: void RealSetAudioPropertiesL(TInt aSampleRate, TInt aChannels); sl@0: sl@0: private: sl@0: // class to allow asynchronous user callbacks sl@0: class CActiveCallback : public CActive sl@0: { sl@0: public: sl@0: ~CActiveCallback(); sl@0: CActiveCallback(MMdaAudioOutputStreamCallback& aCallback); sl@0: void Signal(const TInt aReason); sl@0: protected: sl@0: virtual void RunL(); sl@0: virtual void DoCancel(); sl@0: private: sl@0: MMdaAudioOutputStreamCallback& iCallback; sl@0: }; sl@0: private: sl@0: CMMFMdaAudioOutputStream(MMdaAudioOutputStreamCallback& aCallback); sl@0: void ConstructL(TInt aPriority, TInt aPref); sl@0: void StartPlayL(); sl@0: enum TState { EStopped, EPlaying, EStopping, EPaused}; sl@0: void EmptyFifo(TInt aError); sl@0: void StartShutDownTimer(); sl@0: static TInt ShutDownTimerComplete(TAny* aSamplesPlayed); sl@0: void DoShutDownTimerComplete(); sl@0: private: sl@0: MMdaAudioOutputStreamCallback& iCallback; sl@0: MMMFAudioResourceNotificationCallback* iAudioResourceNotificationCallBack; sl@0: CMMFFifo* iFifo; sl@0: TInt iFifoItemPos; sl@0: CMMFDevSound* iDevSound; sl@0: TState iState; sl@0: TTimeIntervalMicroSeconds iPosition; sl@0: CActiveCallback* iActiveCallback; sl@0: TUid iEventHolder; sl@0: TBuf8<256> iNotificationDataHolder; sl@0: // only for testing sl@0: friend class CTestStepUnitMMFAudClient; sl@0: CMMFBuffer* iBuffer; sl@0: TFourCC iDataTypeCode; sl@0: TIsOpenState iIsOpenState; sl@0: TBool iValuesCached; sl@0: TInt iSampleRate; sl@0: TInt iChannels; sl@0: TInt iVolume; sl@0: TBool iInitCallFrmSetDataType;//Flag to indicate that InitializeL is called from SetDataTypeL. sl@0: TInt iInitializeState; sl@0: CActiveSchedulerWait* iActiveSchedulerWait; sl@0: TBool iKeepOpenAtEnd; sl@0: CPeriodic* iShutDownTimer; sl@0: TInt iCurrentSamplesPlayed; sl@0: TBool iDevSoundIgnoresUnderflow; sl@0: }; sl@0: sl@0: #endif