os/mm/mmdevicefw/mdf/src/audio/mdasoundadapter/mdasoundadapterbody.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-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 MDASOUNDADAPTERBODY_H
sl@0
    17
#define MDASOUNDADAPTERBODY_H
sl@0
    18
sl@0
    19
#include "mdasoundadapter.h"
sl@0
    20
#include <d32soundsc.h>
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <e32std.h>
sl@0
    23
sl@0
    24
/** 
sl@0
    25
Panic category and codes for the mdasoundadapter
sl@0
    26
*/
sl@0
    27
_LIT(KSoundAdapterPanicCategory, "mdasoundadapter");
sl@0
    28
enum TSoundAdapterPanicCodes
sl@0
    29
	{
sl@0
    30
	EDeviceNotOpened,
sl@0
    31
	EPanicPartialBufferConverterNotSupported,
sl@0
    32
	EBadState,
sl@0
    33
	ENoClientPlayRequest,
sl@0
    34
	EFifoEmpty,
sl@0
    35
	EFifoFull
sl@0
    36
	};
sl@0
    37
	
sl@0
    38
//Structure used to map samples per second to the corresponding enums in RSoundSc
sl@0
    39
struct TSampleRateEnumTable
sl@0
    40
  	{
sl@0
    41
	TInt iRate;
sl@0
    42
	TSoundRate iRateEnum;
sl@0
    43
	TUint iRateConstant;
sl@0
    44
	};
sl@0
    45
sl@0
    46
//Table that maps given samples per second to the corresponding enums in RSoundSc
sl@0
    47
const TSampleRateEnumTable KRateEnumLookup[] =
sl@0
    48
								 {
sl@0
    49
									{48000,ESoundRate48000Hz,KSoundRate48000Hz},
sl@0
    50
			                   		{44100,ESoundRate44100Hz,KSoundRate44100Hz},
sl@0
    51
				                  	{32000,ESoundRate32000Hz,KSoundRate32000Hz},
sl@0
    52
									{24000,ESoundRate24000Hz,KSoundRate24000Hz},
sl@0
    53
				                  	{22050,ESoundRate22050Hz,KSoundRate22050Hz},
sl@0
    54
				                  	{16000,ESoundRate16000Hz,KSoundRate16000Hz},
sl@0
    55
				                  	{12000,ESoundRate12000Hz,KSoundRate12000Hz},
sl@0
    56
				                  	{11025,ESoundRate11025Hz,KSoundRate11025Hz},
sl@0
    57
				                  	{8000, ESoundRate8000Hz, KSoundRate8000Hz}
sl@0
    58
                   				 };
sl@0
    59
//Structure used to map linear value of the volume to the decibel value.
sl@0
    60
struct TLinearToDbTable
sl@0
    61
	{
sl@0
    62
	TInt iLiniearValue;
sl@0
    63
	TInt iDBValue;
sl@0
    64
	};
sl@0
    65
sl@0
    66
sl@0
    67
//Table that maps given linear value of volume to the corresponding decibel value.
sl@0
    68
const TLinearToDbTable KLinerToDbConstantLookup[] =
sl@0
    69
						{
sl@0
    70
							{0,0},
sl@0
    71
							{1,158},
sl@0
    72
							{2,170},
sl@0
    73
							{3,177},
sl@0
    74
							{4,182},
sl@0
    75
							{5,186},
sl@0
    76
							{6,189},
sl@0
    77
							{7,192},
sl@0
    78
							{8,194},
sl@0
    79
							{9,196},
sl@0
    80
							{10,198},
sl@0
    81
							{11,200},
sl@0
    82
							{12,201},
sl@0
    83
							{13,203},
sl@0
    84
							{14,204},
sl@0
    85
							{15,205},
sl@0
    86
							{16,206},
sl@0
    87
							{17,207},
sl@0
    88
							{18,208},
sl@0
    89
							{19,209},
sl@0
    90
							{20,210},
sl@0
    91
							{21,211},
sl@0
    92
							{22,212},
sl@0
    93
							{23,213},
sl@0
    94
							{24,213},
sl@0
    95
							{25,214},
sl@0
    96
							{26,215},
sl@0
    97
							{27,215},
sl@0
    98
							{28,216},
sl@0
    99
							{29,217},
sl@0
   100
							{30,217},
sl@0
   101
							{31,218},
sl@0
   102
							{32,218},
sl@0
   103
							{33,219},
sl@0
   104
							{34,219},
sl@0
   105
							{35,220},
sl@0
   106
							{36,220},
sl@0
   107
							{37,221},
sl@0
   108
							{38,221},
sl@0
   109
							{39,222},
sl@0
   110
							{40,222},
sl@0
   111
							{41,223},
sl@0
   112
							{42,223},
sl@0
   113
							{43,224},
sl@0
   114
							{44,224},
sl@0
   115
							{45,224},
sl@0
   116
							{46,225},
sl@0
   117
							{47,225},
sl@0
   118
							{48,225},
sl@0
   119
							{49,226},
sl@0
   120
							{50,226},
sl@0
   121
							{51,226},
sl@0
   122
							{52,227},
sl@0
   123
							{53,227},
sl@0
   124
							{54,227},
sl@0
   125
							{55,228},
sl@0
   126
							{56,228},
sl@0
   127
							{57,228},
sl@0
   128
							{58,229},
sl@0
   129
							{59,229},
sl@0
   130
							{60,229},
sl@0
   131
							{61,230},
sl@0
   132
							{62,230},
sl@0
   133
							{63,230},
sl@0
   134
							{64,230},
sl@0
   135
							{65,231},
sl@0
   136
							{66,231},
sl@0
   137
							{67,231},
sl@0
   138
							{68,231},
sl@0
   139
							{69,232},
sl@0
   140
							{70,232},
sl@0
   141
							{71,232},
sl@0
   142
							{72,232},
sl@0
   143
							{73,233},
sl@0
   144
							{74,233},
sl@0
   145
							{75,233},
sl@0
   146
							{76,233},
sl@0
   147
							{77,234},
sl@0
   148
							{78,234},
sl@0
   149
							{79,234},
sl@0
   150
							{80,234},
sl@0
   151
							{81,235},
sl@0
   152
							{82,235},
sl@0
   153
							{83,235},
sl@0
   154
							{84,235},
sl@0
   155
							{85,235},
sl@0
   156
							{86,236},
sl@0
   157
							{87,236},
sl@0
   158
							{88,236},
sl@0
   159
							{89,236},
sl@0
   160
							{90,236},
sl@0
   161
							{91,237},
sl@0
   162
							{92,237},
sl@0
   163
							{93,237},
sl@0
   164
							{94,237},
sl@0
   165
							{95,237},
sl@0
   166
							{96,237},
sl@0
   167
							{97,238},
sl@0
   168
							{98,238},
sl@0
   169
							{99,238},
sl@0
   170
							{100,238},
sl@0
   171
							{101,238},
sl@0
   172
							{102,239},
sl@0
   173
							{103,239},
sl@0
   174
							{104,239},
sl@0
   175
							{105,239},
sl@0
   176
							{106,239},
sl@0
   177
							{107,239},
sl@0
   178
							{108,240},
sl@0
   179
							{109,240},
sl@0
   180
							{110,240},
sl@0
   181
							{111,240},
sl@0
   182
							{112,240},
sl@0
   183
							{113,240},
sl@0
   184
							{114,240},
sl@0
   185
							{115,241},
sl@0
   186
							{116,241},
sl@0
   187
							{117,241},
sl@0
   188
							{118,241},
sl@0
   189
							{119,241},
sl@0
   190
							{120,241},
sl@0
   191
							{121,241},
sl@0
   192
							{122,242},
sl@0
   193
							{123,242},
sl@0
   194
							{124,242},
sl@0
   195
							{125,242},
sl@0
   196
							{126,242},
sl@0
   197
							{127,242},
sl@0
   198
							{128,242},
sl@0
   199
							{129,243},
sl@0
   200
							{130,243},
sl@0
   201
							{131,243},
sl@0
   202
							{132,243},
sl@0
   203
							{133,243},
sl@0
   204
							{134,243},
sl@0
   205
							{135,243},
sl@0
   206
							{136,244},
sl@0
   207
							{137,244},
sl@0
   208
							{138,244},
sl@0
   209
							{139,244},
sl@0
   210
							{140,244},
sl@0
   211
							{141,244},
sl@0
   212
							{142,244},
sl@0
   213
							{143,244},
sl@0
   214
							{144,245},
sl@0
   215
							{145,245},
sl@0
   216
							{146,245},
sl@0
   217
							{147,245},
sl@0
   218
							{148,245},
sl@0
   219
							{149,245},
sl@0
   220
							{150,245},
sl@0
   221
							{151,245},
sl@0
   222
							{152,245},
sl@0
   223
							{153,246},
sl@0
   224
							{154,246},
sl@0
   225
							{155,246},
sl@0
   226
							{156,246},
sl@0
   227
							{157,246},
sl@0
   228
							{158,246},
sl@0
   229
							{159,246},
sl@0
   230
							{160,246},
sl@0
   231
							{161,246},
sl@0
   232
							{162,247},
sl@0
   233
							{163,247},
sl@0
   234
							{164,247},
sl@0
   235
							{165,247},
sl@0
   236
							{166,247},
sl@0
   237
							{167,247},
sl@0
   238
							{168,247},
sl@0
   239
							{169,247},
sl@0
   240
							{170,247},
sl@0
   241
							{171,247},
sl@0
   242
							{172,248},
sl@0
   243
							{173,248},
sl@0
   244
							{174,248},
sl@0
   245
							{175,248},
sl@0
   246
							{176,248},
sl@0
   247
							{177,248},
sl@0
   248
							{178,248},
sl@0
   249
							{179,248},
sl@0
   250
							{180,248},
sl@0
   251
							{181,248},
sl@0
   252
							{182,249},
sl@0
   253
							{183,249},
sl@0
   254
							{184,249},
sl@0
   255
							{185,249},
sl@0
   256
							{186,249},
sl@0
   257
							{187,249},
sl@0
   258
							{188,249},
sl@0
   259
							{189,249},
sl@0
   260
							{190,249},
sl@0
   261
							{191,249},
sl@0
   262
							{192,250},
sl@0
   263
							{193,250},
sl@0
   264
							{194,250},
sl@0
   265
							{195,250},
sl@0
   266
							{196,250},
sl@0
   267
							{197,250},
sl@0
   268
							{198,250},
sl@0
   269
							{199,250},
sl@0
   270
							{200,250},
sl@0
   271
							{201,250},
sl@0
   272
							{202,250},
sl@0
   273
							{203,250},
sl@0
   274
							{204,251},
sl@0
   275
							{205,251},
sl@0
   276
							{206,251},
sl@0
   277
							{207,251},
sl@0
   278
							{208,251},
sl@0
   279
							{209,251},
sl@0
   280
							{210,251},
sl@0
   281
							{211,251},
sl@0
   282
							{212,251},
sl@0
   283
							{213,251},
sl@0
   284
							{214,251},
sl@0
   285
							{215,251},
sl@0
   286
							{216,252},
sl@0
   287
							{217,252},
sl@0
   288
							{218,252},
sl@0
   289
							{219,252},
sl@0
   290
							{220,252},
sl@0
   291
							{221,252},
sl@0
   292
							{222,252},
sl@0
   293
							{223,252},
sl@0
   294
							{224,252},
sl@0
   295
							{225,252},
sl@0
   296
							{226,252},
sl@0
   297
							{227,252},
sl@0
   298
							{228,252},
sl@0
   299
							{229,253},
sl@0
   300
							{230,253},
sl@0
   301
							{231,253},
sl@0
   302
							{232,253},
sl@0
   303
							{233,253},
sl@0
   304
							{234,253},
sl@0
   305
							{235,253},
sl@0
   306
							{236,253},
sl@0
   307
							{237,253},
sl@0
   308
							{238,253},
sl@0
   309
							{239,253},
sl@0
   310
							{240,253},
sl@0
   311
							{241,253},
sl@0
   312
							{242,254},
sl@0
   313
							{243,254},
sl@0
   314
							{244,254},
sl@0
   315
							{245,254},
sl@0
   316
							{246,254},
sl@0
   317
							{247,254},
sl@0
   318
							{248,254},
sl@0
   319
							{249,254},
sl@0
   320
							{250,254},
sl@0
   321
							{251,254},
sl@0
   322
							{252,254},
sl@0
   323
							{253,254},
sl@0
   324
							{254,254},
sl@0
   325
							{255,254}
sl@0
   326
						};
sl@0
   327
sl@0
   328
// Total Number of sample rates
sl@0
   329
const TUint KNumSampleRates = 9;
sl@0
   330
// Number of shared chunk buffers used for playing
sl@0
   331
// Each buffer is permanently mapped, via an index number, to a particular buffer in the chunk
sl@0
   332
// The esoundsc.ldd can only handle a max of 8 pending play requests, therefore no point in having
sl@0
   333
// more than 8 play buffers...
sl@0
   334
const TUint KPlaySharedChunkBuffers = 8;
sl@0
   335
// Size of RSoundSc play buffers
sl@0
   336
const TUint KPlaySharedChunkBufferSize = 4096;
sl@0
   337
sl@0
   338
//Number of shared chunk buffers used for recording
sl@0
   339
const TUint KRecordMaxSharedChunkBuffers = 8;
sl@0
   340
// Size of RSoundSc record buffers
sl@0
   341
const TUint KRecordSharedChunkBufferSize = 4096;
sl@0
   342
sl@0
   343
//Shared chunk driver does not support max. buffer size. 16K is given in order to simulate the old driver behavior.
sl@0
   344
const TUint KMaxBufferSize = 0x4000;
sl@0
   345
sl@0
   346
class TPlaySharedChunkBufConfig : public TSharedChunkBufConfigBase
sl@0
   347
	{
sl@0
   348
public:
sl@0
   349
	TInt iBufferOffsetList[KPlaySharedChunkBuffers];
sl@0
   350
	};
sl@0
   351
sl@0
   352
class TRecordSharedChunkBufConfig : public TSharedChunkBufConfigBase
sl@0
   353
	{
sl@0
   354
public:
sl@0
   355
	TInt iBufferOffsetList[KRecordMaxSharedChunkBuffers];
sl@0
   356
	};
sl@0
   357
	
sl@0
   358
class CChannelAndSampleRateConverter; // forward dec
sl@0
   359
sl@0
   360
GLDEF_C void Panic(TSoundAdapterPanicCodes aPanicCode);//forward declaration
sl@0
   361
sl@0
   362
// RFifo class which manages a fifo of up to COUNT items of type T
sl@0
   363
template<typename T, TUint32 COUNT> class RFifo
sl@0
   364
	{
sl@0
   365
public:
sl@0
   366
	RFifo()
sl@0
   367
		: iWriteIndex(0), iReadIndex(0)
sl@0
   368
		{}
sl@0
   369
	TBool IsEmpty() const
sl@0
   370
		{
sl@0
   371
		return iWriteIndex == iReadIndex;
sl@0
   372
		}
sl@0
   373
	TBool IsFull() const
sl@0
   374
		{
sl@0
   375
		// Full if writing one more item would make iWriteIndex equal to iReadIndex
sl@0
   376
		TUint32 next = NextIndex(iWriteIndex);
sl@0
   377
		return next == iReadIndex;
sl@0
   378
		}
sl@0
   379
	/// Push item into FIFO. Does not take ownership. Will PANIC with EFifoFull if full.
sl@0
   380
	void Push(const T &aItem)
sl@0
   381
		{
sl@0
   382
		if(IsFull())
sl@0
   383
			{
sl@0
   384
			Panic(EFifoFull);
sl@0
   385
			}
sl@0
   386
		iFifo[iWriteIndex] = aItem;
sl@0
   387
		iWriteIndex = NextIndex(iWriteIndex);
sl@0
   388
		}
sl@0
   389
    /// Pop item from FIFO. Will PANIC with EFifoEmpty if empty 
sl@0
   390
	T Pop()
sl@0
   391
		{
sl@0
   392
		if(IsEmpty())
sl@0
   393
			{
sl@0
   394
			Panic(EFifoEmpty);
sl@0
   395
			}
sl@0
   396
		TUint32 tmp = iReadIndex;
sl@0
   397
		iReadIndex = NextIndex(iReadIndex);
sl@0
   398
		return iFifo[tmp];
sl@0
   399
		}
sl@0
   400
sl@0
   401
    /// Peek first item from FIFO. Will PANIC with EFifoEmpty if empty 
sl@0
   402
	T Peek()
sl@0
   403
		{
sl@0
   404
		if(IsEmpty())
sl@0
   405
			{
sl@0
   406
			Panic(EFifoEmpty);
sl@0
   407
			}
sl@0
   408
		return iFifo[iReadIndex];
sl@0
   409
		}
sl@0
   410
	TUint Length() const
sl@0
   411
		{
sl@0
   412
		TUint len;
sl@0
   413
		if(iWriteIndex >= iReadIndex)
sl@0
   414
			{
sl@0
   415
			len = iWriteIndex - iReadIndex;
sl@0
   416
			}
sl@0
   417
		else
sl@0
   418
			{
sl@0
   419
			len =  COUNT+1 - (iReadIndex - iWriteIndex);
sl@0
   420
			}
sl@0
   421
		return len;
sl@0
   422
		}
sl@0
   423
private:
sl@0
   424
	TUint32 NextIndex(TUint32 aIndex) const
sl@0
   425
		{
sl@0
   426
		++aIndex;
sl@0
   427
		aIndex %= (COUNT+1);
sl@0
   428
		return aIndex;
sl@0
   429
		}
sl@0
   430
	T iFifo[COUNT+1];
sl@0
   431
	TUint32 iWriteIndex;
sl@0
   432
	TUint32 iReadIndex;
sl@0
   433
	};
sl@0
   434
sl@0
   435
sl@0
   436
sl@0
   437
//Body class for the adapter
sl@0
   438
NONSHARABLE_CLASS( RMdaDevSound::CBody ): public CBase
sl@0
   439
	{
sl@0
   440
public:
sl@0
   441
	//This class handles the play/record completions from the new sound driver
sl@0
   442
	NONSHARABLE_CLASS( CPlayer ) : public CActive
sl@0
   443
		{
sl@0
   444
	public:
sl@0
   445
		explicit CPlayer(TInt aPriority, RMdaDevSound::CBody& aParent, TInt aIndex);
sl@0
   446
		~CPlayer();
sl@0
   447
		void RunL();
sl@0
   448
		TInt RunError(TInt aError);
sl@0
   449
		void DoCancel();
sl@0
   450
		void PlayData(TUint aChunkOffset, TInt aLength);
sl@0
   451
sl@0
   452
		TUint GetPlayerIndex() const;
sl@0
   453
sl@0
   454
	private:		
sl@0
   455
		RMdaDevSound::CBody& iParent;
sl@0
   456
		const TUint iIndex; // index of this object in parent
sl@0
   457
		
sl@0
   458
		TInt iBufferOffset;
sl@0
   459
		TInt iBufferLength;
sl@0
   460
		};
sl@0
   461
sl@0
   462
	
sl@0
   463
	NONSHARABLE_CLASS( CRecorder ) : public CActive
sl@0
   464
		{
sl@0
   465
	public:
sl@0
   466
		explicit CRecorder(TInt aPriority, RMdaDevSound::CBody& aParent);
sl@0
   467
		~CRecorder();
sl@0
   468
		void RunL();
sl@0
   469
		TInt RunError(TInt aError);
sl@0
   470
		void DoCancel();
sl@0
   471
		void RecordData(TInt& aLength);
sl@0
   472
sl@0
   473
	private:		
sl@0
   474
		RMdaDevSound::CBody& iParent;
sl@0
   475
sl@0
   476
		TInt iBufferOffset;
sl@0
   477
		TInt iBufferLength;
sl@0
   478
		};
sl@0
   479
	
sl@0
   480
	enum TStateEnum
sl@0
   481
		{
sl@0
   482
		ENotReady,
sl@0
   483
		EStopped,
sl@0
   484
		ERecording,
sl@0
   485
		ERecordingPausedInHw,
sl@0
   486
		ERecordingPausedInSw,
sl@0
   487
		EPlaying,
sl@0
   488
		EPlayingPausedInHw, // ie. Play request pending on h/w and paused
sl@0
   489
		EPlayingPausedInSw, // ie. Driver not playing or paused
sl@0
   490
		EPlayingUnderrun
sl@0
   491
		};
sl@0
   492
sl@0
   493
	NONSHARABLE_CLASS( TState )
sl@0
   494
		{
sl@0
   495
		public:
sl@0
   496
			TState(TStateEnum aState) : iState(aState) {}
sl@0
   497
			const TText8 *Name() const;
sl@0
   498
			TState &operator=(TStateEnum aNewState);
sl@0
   499
			operator TStateEnum() const { return iState; }
sl@0
   500
		private:
sl@0
   501
			TStateEnum iState;
sl@0
   502
		};
sl@0
   503
		
sl@0
   504
	class TFormatData
sl@0
   505
		{
sl@0
   506
	public:
sl@0
   507
		inline TFormatData():
sl@0
   508
			iSampleRate(8000), iRequestedChannels(1) // default
sl@0
   509
			{
sl@0
   510
			}
sl@0
   511
	public:
sl@0
   512
		CChannelAndSampleRateConverter* iConverter;
sl@0
   513
		TInt iSampleRate;
sl@0
   514
		TInt iActualRate;
sl@0
   515
		TInt iRequestedChannels;
sl@0
   516
		TInt iActualChannels;			
sl@0
   517
		};
sl@0
   518
		
sl@0
   519
public:
sl@0
   520
	~CBody();
sl@0
   521
	static CBody* NewL();
sl@0
   522
	TInt Open(TInt aUnit=KNullUnit);
sl@0
   523
	TVersion VersionRequired() const;
sl@0
   524
	TInt IsMdaSound();
sl@0
   525
	void PlayFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported);
sl@0
   526
	void GetPlayFormat(TCurrentSoundFormatBuf& aFormat);
sl@0
   527
	TInt SetPlayFormat(const TCurrentSoundFormatBuf& aFormat);
sl@0
   528
	TInt PlayVolume();
sl@0
   529
	void SetPlayVolume(TInt aVolume);
sl@0
   530
	void SetVolume(TInt aLogarithmicVolume);
sl@0
   531
	void CancelPlayData();
sl@0
   532
	void RecordFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported);
sl@0
   533
	void GetRecordFormat(TCurrentSoundFormatBuf& aFormat);
sl@0
   534
	TInt SetRecordFormat(const TCurrentSoundFormatBuf& aFormat);
sl@0
   535
	TInt RecordLevel();
sl@0
   536
	void SetRecordLevel(TInt aLevel);
sl@0
   537
	void CancelRecordData();
sl@0
   538
	void FlushRecordBuffer();
sl@0
   539
	TInt BytesPlayed();
sl@0
   540
	void ResetBytesPlayed();
sl@0
   541
	void PausePlayBuffer();
sl@0
   542
	void ResumePlaying();
sl@0
   543
	void PauseRecordBuffer();
sl@0
   544
	void ResumeRecording();
sl@0
   545
	TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTimePlayed);
sl@0
   546
	void Close();
sl@0
   547
	TInt Handle();
sl@0
   548
	void PlayData(TRequestStatus& aStatus,const TDesC8& aData);
sl@0
   549
	void RecordData(TRequestStatus& aStatus,TDes8& aData);
sl@0
   550
	void NotifyRecordError(TRequestStatus& aStatus);
sl@0
   551
	void NotifyPlayError(TRequestStatus& aStatus);
sl@0
   552
	void CancelNotifyPlayError();
sl@0
   553
	void CancelNotifyRecordError();
sl@0
   554
	void FlushPlayBuffer();
sl@0
   555
	//internal methods added to reduce the code
sl@0
   556
	void FormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported, RSoundSc& aDevice);
sl@0
   557
	void GetFormat(TCurrentSoundFormatBuf& aFormat, RSoundSc& aDevice, const TFormatData &aFormatData);
sl@0
   558
	TInt SetFormat(const TCurrentSoundFormatBuf& aFormat, RSoundSc& aDevice, TFormatData &aFormatData);
sl@0
   559
	
sl@0
   560
	//for players
sl@0
   561
	void SoundDeviceError(TInt aError);
sl@0
   562
	RSoundSc& PlaySoundDevice();
sl@0
   563
	RSoundSc& RecordSoundDevice();
sl@0
   564
	const TState &State() const;
sl@0
   565
	void BufferFilled(TInt aError);
sl@0
   566
sl@0
   567
	// Called whenever a player becomes inactive.
sl@0
   568
	// This includes driver request ok, driver request failed, CPlayer:::RunError invoked.
sl@0
   569
	void PlayRequestHasCompleted(CPlayer *aPlayer, TInt aStatus, TBool aDueToCancelCommand);
sl@0
   570
sl@0
   571
private:
sl@0
   572
	CBody();
sl@0
   573
	void ConstructL();
sl@0
   574
	
sl@0
   575
	TInt NegotiateFormat(const TCurrentSoundFormatBuf& aFormat, RSoundSc& aDevice, TFormatData &aFormatData);
sl@0
   576
sl@0
   577
	void StartPlayersAndUpdateState();
sl@0
   578
	void StartRecordRequest();
sl@0
   579
sl@0
   580
	const char *StateName() const;
sl@0
   581
sl@0
   582
	TBool InRecordMode() const;
sl@0
   583
	TBool InPlayMode() const;
sl@0
   584
sl@0
   585
	TUint32 CurrentTimeInMsec() const;
sl@0
   586
	TUint64 BytesPlayed64();
sl@0
   587
sl@0
   588
private:
sl@0
   589
	RSoundSc iPlaySoundDevice;
sl@0
   590
	RChunk iPlayChunk;//handle to the shared chunk
sl@0
   591
	RSoundSc iRecordSoundDevice;
sl@0
   592
	RChunk iRecordChunk;//handle to the shared chunk
sl@0
   593
	TState iState;
sl@0
   594
sl@0
   595
	//Playing Properties
sl@0
   596
	TPlaySharedChunkBufConfig iPlayBufferConfig;
sl@0
   597
	TInt iDeviceBufferLength;
sl@0
   598
	
sl@0
   599
	//Stores the status of CDataPathPlayer
sl@0
   600
	TRequestStatus* iClientPlayStatus;
sl@0
   601
	TPtrC8 iClientPlayData;
sl@0
   602
	//Stores the status of CSoundDevPlayErrorReceiver
sl@0
   603
	TRequestStatus* iClientPlayErrorStatus;
sl@0
   604
	RBuf8 iConvertedPlayData;
sl@0
   605
	RBuf8 iSavedTrailingData;
sl@0
   606
sl@0
   607
	CPlayer* iPlayers[KPlaySharedChunkBuffers];
sl@0
   608
	RFifo<CPlayer *, KPlaySharedChunkBuffers> iFreePlayers;
sl@0
   609
	RFifo<TUint32, KPlaySharedChunkBuffers> iActivePlayRequestSizes;
sl@0
   610
	
sl@0
   611
	TInt iRequestMinSize;
sl@0
   612
	TUint iRequestMinMask;
sl@0
   613
	
sl@0
   614
	//Recording Properties
sl@0
   615
	TRecordSharedChunkBufConfig iRecordBufferConfig;
sl@0
   616
	TInt iBufferOffset;
sl@0
   617
	TInt iBufferLength;
sl@0
   618
sl@0
   619
	//Stores the status of CDataPathRecorder
sl@0
   620
	TRequestStatus* iClientRecordStatus;
sl@0
   621
	//Stores the status of CSoundDevRecordErrorReceiver
sl@0
   622
	TRequestStatus* iClientRecordErrorStatus;
sl@0
   623
	TDes8* iClientRecordData;//stores the data pointer from datapath recorder
sl@0
   624
	RBuf8 iBufferedRecordData; // Used if RSoundSc returns more data than current client request requires.
sl@0
   625
sl@0
   626
	CRecorder* iRecorder; // We only need one recorder. The driver will buffer data for us.
sl@0
   627
sl@0
   628
	TBool iUnderFlowReportedSinceLastPlayOrRecordRequest;
sl@0
   629
	
sl@0
   630
	TUint64 iBytesPlayed;
sl@0
   631
	TUint32 iNTickPeriodInUsec;
sl@0
   632
	TUint32 iStartTime; // Time when previous driver PlayData completed (or first was issued) in msec
sl@0
   633
	TUint32 iPauseTime; // Time when pause started in msec
sl@0
   634
	TUint64 iPausedBytesPlayed;
sl@0
   635
sl@0
   636
	TFormatData iPlayFormatData;
sl@0
   637
	TFormatData iRecordFormatData;
sl@0
   638
	};
sl@0
   639
#endif