os/mm/mmlibs/mmfw/inc/mmf/server/MmfAudioInput.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __MMF_AUDIOINPUT_H__
sl@0
    17
#define __MMF_AUDIOINPUT_H__
sl@0
    18
sl@0
    19
// Standard EPOC32 includes required by this header file
sl@0
    20
#include <e32base.h>
sl@0
    21
#include <e32std.h>
sl@0
    22
sl@0
    23
// Public Media Server includes
sl@0
    24
#include <mmf/common/mmfpaniccodes.h>
sl@0
    25
sl@0
    26
//DevSound
sl@0
    27
#include <mmf/server/sounddevice.h>
sl@0
    28
sl@0
    29
/** 
sl@0
    30
@publishedAll
sl@0
    31
@deprecated
sl@0
    32
*/
sl@0
    33
const TUint KAudioInputDefaultFrameSize = 0x1000;  //4K
sl@0
    34
//#define KAudioInputCanResample		//uncomment this to allow Audio Input to sample rate convert 
sl@0
    35
sl@0
    36
sl@0
    37
void Panic(TInt aPanicCode);
sl@0
    38
sl@0
    39
sl@0
    40
/**
sl@0
    41
@publishedAll
sl@0
    42
@released
sl@0
    43
sl@0
    44
Interface class to allow dynamic linkage to CMMFAudioInput.
sl@0
    45
*/
sl@0
    46
class MMMFAudioInput : public MDataSource
sl@0
    47
	{
sl@0
    48
public:
sl@0
    49
sl@0
    50
	//factory function
sl@0
    51
	inline static MMMFAudioInput* NewAudioInputL(TUid aImplementationUid, const TDesC8& aInitData);
sl@0
    52
sl@0
    53
	//interface
sl@0
    54
	/**
sl@0
    55
	Returns the sound device.
sl@0
    56
sl@0
    57
	@return A reference to a CMMFDevSound objector. Accessor function exposing public CMMFDevsound methods.
sl@0
    58
	*/
sl@0
    59
	virtual CMMFDevSound& SoundDevice() = 0;
sl@0
    60
sl@0
    61
	/**
sl@0
    62
	Returns the number of bytes played.
sl@0
    63
sl@0
    64
	@return	The number of bytes played. If 16-bit divide this number returned by 2 to get word length.
sl@0
    65
	*/
sl@0
    66
	virtual TInt BytesPlayed() = 0;
sl@0
    67
sl@0
    68
	/**
sl@0
    69
	@deprecated
sl@0
    70
sl@0
    71
	Gets audio from hardware device abstracted MMFDevsound (not used).
sl@0
    72
sl@0
    73
	@param  aBuffer
sl@0
    74
	        The data to read in from a Hardware Device
sl@0
    75
	@param  aConsumer
sl@0
    76
	        The MDataSink consuming the data contained in aBuffer.
sl@0
    77
	*/
sl@0
    78
	virtual void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer) = 0;
sl@0
    79
protected:
sl@0
    80
	//constructor
sl@0
    81
	/**
sl@0
    82
	Protected constructor.
sl@0
    83
	*/
sl@0
    84
	inline MMMFAudioInput() : MDataSource(KUidMmfAudioInput) {};
sl@0
    85
	};
sl@0
    86
sl@0
    87
/**
sl@0
    88
Allocates and constructs an audio input object. 
sl@0
    89
sl@0
    90
Calls MDataSource::NewSourceL().
sl@0
    91
sl@0
    92
@param  aImplementationUid
sl@0
    93
		The Implementation UID.
sl@0
    94
@param  aInitData
sl@0
    95
		The initialisation data.
sl@0
    96
sl@0
    97
@return A new audio input object.
sl@0
    98
*/
sl@0
    99
inline MMMFAudioInput* MMMFAudioInput::NewAudioInputL( TUid aImplementationUid,  const TDesC8& aInitData )
sl@0
   100
	{
sl@0
   101
	//make sure the cast will be ok by checking the uid is what we expect
sl@0
   102
	__ASSERT_ALWAYS(aImplementationUid==KUidMmfAudioInput, Panic(EMMFAudioInputPanicBadUID));
sl@0
   103
	MMMFAudioInput* retPtr = STATIC_CAST(MMMFAudioInput*, MDataSource::NewSourceL(aImplementationUid, aInitData));
sl@0
   104
	return retPtr;
sl@0
   105
	}
sl@0
   106
sl@0
   107
/**
sl@0
   108
@publishedAll
sl@0
   109
@released
sl@0
   110
sl@0
   111
Concrete data source to provide microphone support.
sl@0
   112
sl@0
   113
Intended to be used by controller plugin developers for source plugins. Uses CMMFDevSound to access
sl@0
   114
hardware.
sl@0
   115
*/
sl@0
   116
class CMMFAudioInput : public CBase, public MMMFAudioInput, public MDevSoundObserver
sl@0
   117
sl@0
   118
	{
sl@0
   119
public:
sl@0
   120
sl@0
   121
	static MDataSource* NewSourceL();
sl@0
   122
	virtual ~CMMFAudioInput();
sl@0
   123
	void ConstructL();
sl@0
   124
sl@0
   125
	//MDataSource mixin implementations
sl@0
   126
	virtual TFourCC SourceDataTypeCode(TMediaId aMediaId);
sl@0
   127
	virtual void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer,TMediaId aMediaId);//called by a MDataSink to request buffer fill
sl@0
   128
	virtual void BufferEmptiedL(CMMFBuffer* aBuffer); //called by MDataSink to pass back emptied buffer to the source
sl@0
   129
	virtual TBool CanCreateSourceBuffer();
sl@0
   130
	virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId);
sl@0
   131
sl@0
   132
	inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer);
sl@0
   133
sl@0
   134
	virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference);
sl@0
   135
sl@0
   136
	inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference);
sl@0
   137
	virtual TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler);
sl@0
   138
	virtual void SourceThreadLogoff();
sl@0
   139
	virtual void SourcePrimeL();
sl@0
   140
	virtual void SourceStopL();
sl@0
   141
	virtual void SourcePlayL();
sl@0
   142
	virtual void SourcePauseL();
sl@0
   143
	virtual void SetSourcePrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
sl@0
   144
sl@0
   145
	virtual void NegotiateSourceL(MDataSink& aSink);
sl@0
   146
sl@0
   147
	// MMMFAudioInput mixin implementations
sl@0
   148
	TInt BytesPlayed();
sl@0
   149
	void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer); //called by a FillBufferL if using HW codec
sl@0
   150
	CMMFDevSound& SoundDevice();
sl@0
   151
	virtual TInt SetSourceDataTypeCode(TFourCC aSourceFourCC, TMediaId aMediaId);
sl@0
   152
sl@0
   153
	void LoadL();
sl@0
   154
sl@0
   155
	//The following DataType() methods and iBufferStatus should not be used.
sl@0
   156
	//They are provided to maintain BC/SC with 7.0s
sl@0
   157
	virtual void SetDataTypeL(TFourCC aAudioType);
sl@0
   158
	virtual TFourCC DataType() const;
sl@0
   159
	/**
sl@0
   160
	Buffer completion status.
sl@0
   161
	*/
sl@0
   162
	TRequestStatus iBufferStatus;
sl@0
   163
sl@0
   164
protected:
sl@0
   165
	virtual void ConstructSourceL( const TDesC8& aInitData ) ;
sl@0
   166
sl@0
   167
private:
sl@0
   168
	inline CMMFAudioInput() {}
sl@0
   169
sl@0
   170
	MAsyncEventHandler* iEventHandler;
sl@0
   171
	CMMFDevSound* iMMFDevSound;	//this is now private to stop stuff "grabbing it"
sl@0
   172
	
sl@0
   173
	//MDevSoundObserver mixin implementations
sl@0
   174
	virtual void InitializeComplete(TInt aError);
sl@0
   175
	virtual void ToneFinished(TInt aError);
sl@0
   176
	virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
sl@0
   177
	virtual void PlayError(TInt aError); 
sl@0
   178
	virtual void BufferToBeEmptied(CMMFBuffer* aBuffer); 
sl@0
   179
	virtual void RecordError(TInt aError); 
sl@0
   180
	virtual void ConvertError(TInt aError);
sl@0
   181
	virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
sl@0
   182
	virtual void SendEventToClient(const TMMFEvent& /*aEvent*/);
sl@0
   183
sl@0
   184
	void ConfigDevSoundL();
sl@0
   185
	
sl@0
   186
private:
sl@0
   187
	
sl@0
   188
	enum TCodec
sl@0
   189
		{
sl@0
   190
		EUseARMCodec=0,
sl@0
   191
		EUseHWCodec
sl@0
   192
		};
sl@0
   193
sl@0
   194
	enum TState
sl@0
   195
		{
sl@0
   196
		EIdle=0,
sl@0
   197
		EPaused,
sl@0
   198
		EDevSoundReady,
sl@0
   199
		EBufferEmpty
sl@0
   200
		};
sl@0
   201
sl@0
   202
	enum TError
sl@0
   203
		{
sl@0
   204
		ECantCreateBuffer,
sl@0
   205
		EEmptyBuffer,
sl@0
   206
		EDevSoundNotLoaded,
sl@0
   207
		EUnknown
sl@0
   208
		}; 
sl@0
   209
	
sl@0
   210
sl@0
   211
	MDataSink* iConsumer;
sl@0
   212
	TState iState;
sl@0
   213
sl@0
   214
	TBool iFirstBufferRequested;
sl@0
   215
	TBool iFirstBufferRead;
sl@0
   216
sl@0
   217
	TBool iDevSoundLoaded;
sl@0
   218
	TBool iStopped;
sl@0
   219
sl@0
   220
	TError iError;
sl@0
   221
	TInt iMMFDevsoundError;
sl@0
   222
	TMMFPrioritySettings iPrioritySettings;
sl@0
   223
sl@0
   224
	TUint iSinkSampleRate;
sl@0
   225
	TUint iSinkChannels;
sl@0
   226
	TFourCC iSinkFourCC;
sl@0
   227
	TFourCC iDataTypeCode;
sl@0
   228
	CMMFBuffer* iDevSoundBuf;
sl@0
   229
sl@0
   230
	TBool iPausePending;
sl@0
   231
	TInt iInitializeState;	
sl@0
   232
 	CActiveSchedulerWait* iActiveSchedulerWait;
sl@0
   233
	};
sl@0
   234
sl@0
   235
/**
sl@0
   236
Intended for synchronous usage (returns buffer specific to a Media Type).
sl@0
   237
sl@0
   238
@param	aMediaId
sl@0
   239
        The Media ID.
sl@0
   240
@param	aSinkBuffer
sl@0
   241
        Not Used.
sl@0
   242
sl@0
   243
@return A pointer to the CMMFBuffer source buffer.
sl@0
   244
*/
sl@0
   245
inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/)
sl@0
   246
{
sl@0
   247
	return CreateSourceBufferL(aMediaId);
sl@0
   248
}
sl@0
   249
sl@0
   250
/**
sl@0
   251
Creates a source buffer.
sl@0
   252
sl@0
   253
Intended for asynchronous usage (returns buffer specific to a Media Type).
sl@0
   254
sl@0
   255
@param  aMediaId
sl@0
   256
        The Media ID.
sl@0
   257
@param  aSinkBuffer
sl@0
   258
        Not used.
sl@0
   259
@param	aReference
sl@0
   260
        A boolean indicating if MDataSource owns the buffer. If EFalse the the caller owns the 
sl@0
   261
        buffer.
sl@0
   262
sl@0
   263
@return The source buffer.
sl@0
   264
*/
sl@0
   265
inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/, TBool &aReference)
sl@0
   266
{
sl@0
   267
	return CreateSourceBufferL(aMediaId, aReference);
sl@0
   268
}
sl@0
   269
sl@0
   270
#endif