sl@0: // Copyright (c) 2003-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 __MMFSWCODECRECORDDATAPATH_H__
sl@0: #define __MMFSWCODECRECORDDATAPATH_H__
sl@0: 
sl@0: #include "mmfSwCodecDataPath.h"
sl@0: #include <mmf/server/mmfswcodecwrapper.h>
sl@0: #include "mmfswaudioinput.h"
sl@0: 
sl@0: class CMMFSwCodecRecordDataPath; //fwd ref
sl@0: class MSetVbrFlagCustomInterface;	// fwd ref
sl@0: 
sl@0: /**
sl@0:  *  Derived class for record datapath internal to the Sw codec wrapper
sl@0:  *  @internalComponent
sl@0:  */
sl@0: class CMMFSwCodecRecordDataPath : public CMMFSwCodecDataPath,
sl@0: 								  public MSetVbrFlagCustomInterface,
sl@0: 								  public MAudioInputObserver,
sl@0: 								  public MSwSetParamInterface,
sl@0: 								  public MSwInfoInterface
sl@0: 	{
sl@0: 	enum TRecordState
sl@0: 	    {
sl@0: 	    ERecordStateCreated,                       // note order here is important - see State(), RecordOrPause() etc
sl@0:         ERecordStateFailed,
sl@0: 	    ERecordStateRecording,
sl@0:         ERecordStateSendingBuffer,
sl@0:         ERecordStateSendingPartialBuffer,
sl@0:         ERecordStateEmptiedPartialBuffer,
sl@0:         ERecordStateRecordingPaused,
sl@0:         ERecordStateSendingBufferPaused,
sl@0:         ERecordStateSendingPartialBufferPaused,
sl@0:         ERecordStateEmptiedPartialBufferPaused,
sl@0: 	    };
sl@0: public:
sl@0: 	static CMMFSwCodecRecordDataPath* NewL();
sl@0: 	virtual ~CMMFSwCodecRecordDataPath();
sl@0: 
sl@0: 	//From CMMFSwCodecDataPath
sl@0: 	TInt SetObserver(MMMFHwDeviceObserver &aHwObserver);
sl@0: 	TInt AddCodec(CMMFSwCodec& aCodec);
sl@0: 	TInt Start(); //record
sl@0: 	void Stop();
sl@0: 	void Pause();
sl@0: 	void BufferFilledL(CMMFDataBuffer& aBuffer);
sl@0: 	void BufferEmptiedL(const CMMFDataBuffer& aBuffer);
sl@0: 	void SoundDeviceException(TInt aError);
sl@0: 	RMdaDevSound& Device();
sl@0: 	TUint RecordedBytesCount();
sl@0: 	TAny* CustomInterface(TUid aInterfaceId);
sl@0: 	TSwCodecDataPathState State() const;
sl@0: 	//From MSetVbrFlagCustomInterface
sl@0: 	void SetVbrFlag();
sl@0: 	//From MAudioInputObserver
sl@0: 	void InputBufferAvailable(const TDesC8& aBuffer);
sl@0: 	void InputFinished();
sl@0: 	void InputError(TInt aError);
sl@0: 	//From MSwSetParamInerface
sl@0: 	TInt SetSampleRate(TInt aSampleRate);
sl@0: 	TInt SetNumChannels(TInt aNumChannels);
sl@0: 	TInt SetGain(TInt aGain);
sl@0: 	TInt GetBufferSizes(TInt& aMinSize, TInt& aMaxSize);
sl@0: 	//From MSwInfoInterface
sl@0: 	TInt GetSupportedSampleRates(RArray<TInt>& aSupportedSampleRates);
sl@0: 
sl@0: private:
sl@0: 	CMMFSwCodecRecordDataPath();
sl@0: 	void ConstructL();
sl@0: 	void ProcessBufferL(TBool aLastBuffer);
sl@0: 	TInt EmptyBufferL();
sl@0: 
sl@0: 	TBool RecordOrPause() const;
sl@0: 	TBool IsPaused() const;
sl@0: 
sl@0: 	void RequestCallback();
sl@0: 	TInt DoCallback();
sl@0: 	static TInt Callback(TAny* aPtr);
sl@0: 
sl@0: 	static const TRecordState KResumePauseTable[];
sl@0: 
sl@0: private:
sl@0: 	MAudioInput* iAudioInput;
sl@0: 	CMMFDataBuffer* iCodecBuffer;
sl@0: 	const TDesC8*	iInputData;	  // not owned - cache of past data
sl@0: 	TPtr8			iShadowData;  // need TPtr8
sl@0: 	TInt 			iInputOffset; // track how much data we've processed from audio input
sl@0: 	CMMFPtrBuffer* 	iInputBuffer; // select from iInputData
sl@0: 	CMMFDataBuffer* iSinkBuffer;  // not owned - pointer to buffer to send to client
sl@0: 	CAsyncCallBack*	iAsyncCallback;
sl@0: 	TInt  iSampleRate;
sl@0: 	TInt  iNumChannels;
sl@0: 	TInt  iGain;
sl@0: 	TUint iSinkBufferSize;
sl@0: 	TUint iAudioInputBufferSize;
sl@0: 	TUint iRecordedBytesCount;
sl@0: 	TBool iVbrFlag;
sl@0: 	TRecordState iState;
sl@0:     TBool iInputHasFinished; // extension to iState, if we've received InputFinished we don't want to call BufferAck() but signal complete
sl@0: 	RMdaDevSound iDummyDevSound; // TODO - remove when Device() is removed.
sl@0: 	};
sl@0: 
sl@0: #endif
sl@0: