mmlibs/mmfw/src/Client/Audio/mmfclientaudiooutputstream.h
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef MMFCLIENTAUDIOOUTPUTSTREAM_H
       
    17 #define MMFCLIENTAUDIOOUTPUTSTREAM_H
       
    18 
       
    19 #include <mmf/server/sounddevice.h>
       
    20 #include <mmf/common/mmfstandardcustomcommands.h>
       
    21 
       
    22 template<class T>
       
    23 class CMMFFifo;
       
    24 class CMMFBuffer;
       
    25 class MMdaAudioOutputStreamCallback;
       
    26 class TMdaPackage;
       
    27 class MMMFAudioResourceNotificationCallback;
       
    28 
       
    29 class CMMFMdaAudioOutputStream;
       
    30 NONSHARABLE_CLASS( CMMFMdaAudioOutputStream ): public CBase,
       
    31 								 			   public MDevSoundObserver
       
    32 	{
       
    33 	enum TIsOpenState
       
    34 		{
       
    35 		EIsNotOpen,
       
    36 		EIsOpening,  // Open() called but not responded to
       
    37 		EIsOpen,     // Open callback made and successfully opened
       
    38 		};
       
    39 public:
       
    40 	static CMMFMdaAudioOutputStream* NewL(MMdaAudioOutputStreamCallback& aCallback);
       
    41 	static CMMFMdaAudioOutputStream* NewL(MMdaAudioOutputStreamCallback& aCallback, TInt aPriority, TInt aPref);
       
    42 	virtual ~CMMFMdaAudioOutputStream();
       
    43 //
       
    44 	void SetAudioPropertiesL(TInt aSampleRate, TInt aChannels);
       
    45 	void Open(TMdaPackage* aSettings);
       
    46 	void SetVolume(const TInt aVolume);
       
    47 	TInt Volume();
       
    48 	TInt MaxVolume();
       
    49 	void SetBalanceL(TInt aBalance = KMMFBalanceCenter);
       
    50 	TInt GetBalanceL() const;
       
    51 	void SetPriority(TInt aPriority, TInt aPref);
       
    52 	void WriteL(const TDesC8& aData);
       
    53 	void Stop();
       
    54 	TInt Pause();
       
    55 	TInt Resume();
       
    56 	const TTimeIntervalMicroSeconds& Position();
       
    57 	TInt GetBytes();
       
    58 	void SetDataTypeL(TFourCC aAudioType);
       
    59 	TFourCC DataType() const;
       
    60 	TInt RegisterAudioResourceNotification(MMMFAudioResourceNotificationCallback& aCallback,TUid aNotificationEventUid,const TDesC8& aNotificationRegistrationData = KNullDesC8);
       
    61 	TInt CancelRegisterAudioResourceNotification(TUid aNotificationEventId);
       
    62 	TInt WillResumePlay();
       
    63 	TAny* CustomInterface(TUid aInterfaceId);
       
    64 	TInt KeepOpenAtEnd();
       
    65 	TInt RequestStop();
       
    66 public:		
       
    67 	// from MDevSoundObserver
       
    68 	virtual void InitializeComplete(TInt aError);
       
    69 	virtual void ToneFinished(TInt aError); 
       
    70 	virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
       
    71 	virtual void PlayError(TInt aError); 
       
    72 	virtual void BufferToBeEmptied(CMMFBuffer* aBuffer); 
       
    73 	virtual void RecordError(TInt aError); 
       
    74 	virtual void ConvertError(TInt aError);
       
    75 	virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
       
    76 	virtual void SendEventToClient(const TMMFEvent& aEvent);
       
    77 	
       
    78 private:
       
    79 	void RealSetAudioPropertiesL(TInt aSampleRate, TInt aChannels);
       
    80 
       
    81 private:
       
    82 	// class to allow asynchronous user callbacks
       
    83 	class CActiveCallback : public CActive
       
    84 		{
       
    85 	public:
       
    86 		~CActiveCallback();
       
    87 		CActiveCallback(MMdaAudioOutputStreamCallback& aCallback);
       
    88 		void Signal(const TInt aReason);
       
    89 	protected:
       
    90 		virtual void RunL();
       
    91 		virtual void DoCancel();
       
    92 	private:
       
    93 		MMdaAudioOutputStreamCallback& iCallback;
       
    94 		};
       
    95 private:
       
    96 	CMMFMdaAudioOutputStream(MMdaAudioOutputStreamCallback& aCallback);
       
    97 	void ConstructL(TInt aPriority, TInt aPref);
       
    98 	void StartPlayL();
       
    99 	enum TState { EStopped, EPlaying, EStopping, EPaused};
       
   100 	void EmptyFifo(TInt aError);
       
   101 	void StartShutDownTimer();
       
   102 	static TInt ShutDownTimerComplete(TAny* aSamplesPlayed);
       
   103 	void DoShutDownTimerComplete();
       
   104 private:
       
   105 	MMdaAudioOutputStreamCallback&		iCallback;
       
   106 	MMMFAudioResourceNotificationCallback* iAudioResourceNotificationCallBack;
       
   107 	CMMFFifo<const TDesC8>*				iFifo;
       
   108 	TInt								iFifoItemPos;
       
   109 	CMMFDevSound*						iDevSound;
       
   110 	TState								iState;
       
   111 	TTimeIntervalMicroSeconds			iPosition;
       
   112 	CActiveCallback*					iActiveCallback;
       
   113 	TUid 								iEventHolder;
       
   114 	TBuf8<256> 						iNotificationDataHolder;
       
   115 	// only for testing
       
   116 	friend class						CTestStepUnitMMFAudClient;
       
   117 	CMMFBuffer*							iBuffer;
       
   118 	TFourCC								iDataTypeCode;
       
   119 	TIsOpenState						iIsOpenState;
       
   120 	TBool								iValuesCached;
       
   121 	TInt								iSampleRate;
       
   122 	TInt								iChannels;
       
   123 	TInt								iVolume;
       
   124 	TBool								iInitCallFrmSetDataType;//Flag to indicate that InitializeL is called from SetDataTypeL.
       
   125 	TInt								iInitializeState;
       
   126 	CActiveSchedulerWait*				iActiveSchedulerWait;
       
   127 	TBool								iKeepOpenAtEnd;
       
   128 	CPeriodic*							iShutDownTimer;
       
   129 	TInt								iCurrentSamplesPlayed;
       
   130 	TBool 								iDevSoundIgnoresUnderflow;
       
   131 	}; 
       
   132 
       
   133 #endif