mmlibs/mmfw/src/Client/Audio/mmfclientaudioinputstream.h
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 
       
    17 #ifndef MMFCLIENTAUDIOINPUTSTREAM_H
       
    18 #define MMFCLIENTAUDIOINPUTSTREAM_H
       
    19 
       
    20 #include <mmf/server/sounddevice.h>
       
    21 #include <mmf/common/mmfstandardcustomcommands.h>
       
    22 #include <mda/common/audio.h>
       
    23 
       
    24 template<class T>
       
    25 class CMMFFifo;
       
    26 class CMMFBuffer;
       
    27 class MMdaAudioInputStreamCallback;
       
    28 class TMdaPackage;
       
    29 
       
    30 class CMMFMdaAudioInputStream;
       
    31 NONSHARABLE_CLASS( CMMFMdaAudioInputStream ): public CBase, 
       
    32 											  public MDevSoundObserver
       
    33 	{
       
    34 	enum TIsOpenState
       
    35 		{
       
    36 		EIsNotOpen,
       
    37 		EIsOpening,  // Open() called but not responded to
       
    38 		EIsOpen,     // Open callback made and successfully opened
       
    39 		};
       
    40 public:
       
    41 	static CMMFMdaAudioInputStream* NewL(MMdaAudioInputStreamCallback& aCallback);
       
    42 	static CMMFMdaAudioInputStream* NewL(MMdaAudioInputStreamCallback& aCallback, TInt aPriority, TInt aPref);
       
    43 	~CMMFMdaAudioInputStream();
       
    44 
       
    45 	void SetAudioPropertiesL(TInt aSampleRate, TInt aChannels);
       
    46 	void Open(TMdaPackage* aSettings);
       
    47 	void SetGain(TInt aGain);
       
    48 	TInt Gain() const;
       
    49 	TInt MaxGain() const;
       
    50 	void SetBalanceL(TInt aBalance = KMMFBalanceCenter);
       
    51 	TInt GetBalanceL() const;
       
    52 	void SetPriority(TInt aPriority, TInt aPref);
       
    53 	void ReadL(TDes8& aData);
       
    54 	void Stop();
       
    55 	const TTimeIntervalMicroSeconds& Position();
       
    56 	TInt GetBytes();
       
    57 	void SetDataTypeL(TFourCC aAudioType);
       
    58 	TFourCC DataType() const;
       
    59 	void GetSupportedBitRatesL(RArray<TInt>& aSupportedBitRates);
       
    60 	TInt BitRateL() const;
       
    61 	void SetBitRateL(TInt aBitRate);
       
    62 	TAny* CustomInterface(TUid aInterfaceId);
       
    63 	void SetSingleBufferMode(TBool aSingleMode);
       
    64 	void RequestStop();
       
    65 	void ShutDown();
       
    66 
       
    67 public:		
       
    68 	// from MDevSoundObserver
       
    69 	void InitializeComplete(TInt aError);
       
    70 	void ToneFinished(TInt aError); 
       
    71 	void BufferToBeFilled(CMMFBuffer* aBuffer);
       
    72 	void PlayError(TInt aError); 
       
    73 	void BufferToBeEmptied(CMMFBuffer* aBuffer); 
       
    74 	void RecordError(TInt aError); 
       
    75 	void ConvertError(TInt aError);
       
    76 	void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
       
    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(MMdaAudioInputStreamCallback& aCallback);
       
    87 		~CActiveCallback();
       
    88 		void Signal(const TInt aReason);
       
    89 	protected:
       
    90 		void RunL();
       
    91 		void DoCancel();
       
    92 	private:
       
    93 		MMdaAudioInputStreamCallback& iCallback;
       
    94 		};
       
    95 private:
       
    96 	enum TState { EStopped, ERecording, EStopping };
       
    97 private:
       
    98 	CMMFMdaAudioInputStream(MMdaAudioInputStreamCallback& aCallback);
       
    99 	void ConstructL(TInt aPriority, TInt aPref);
       
   100 	TInt Read(TDes8& aData);
       
   101 private:
       
   102 	MMdaAudioInputStreamCallback&		iCallback;
       
   103 	TTimeIntervalMicroSeconds			iPosition;
       
   104 	CMMFDevSound*						iDevSound;
       
   105 	CMMFFifo<TDes8>*					iFifo;
       
   106 	TBool								iSingleBuffer;
       
   107 	TPtr8								iStorageItem;
       
   108 	TPtr8								iBufferPtr;
       
   109 	TInt								iState;
       
   110 	CActiveCallback*					iActiveCallback;
       
   111 	TInt								iBytesRecorded;//tracks bytes supplied by devsound
       
   112 	TFourCC								iDataTypeCode;
       
   113 	TIsOpenState						iIsOpenState;
       
   114 	TMdaAudioDataSettings				iSettings;
       
   115 	TBool								iAudioDataStored;
       
   116 	// only for testing
       
   117 	friend class						CTestStepUnitMMFAudClient;
       
   118 	TBool								iInitCallFrmSetDataType;//Flag to indicate that InitializeL is called from SetDataTypeL.
       
   119 	TInt								iInitializeState;
       
   120 	CActiveSchedulerWait*				iActiveSchedulerWait;
       
   121 	}; 
       
   122 
       
   123 #endif