Update contrib.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // mmfswaudioinputpriv.h
18 #ifndef SWAUDIOINPUTPRIV_H
19 #define SWAUDIOINPUTPRIV_H
22 #include "mmfswaudioinput.h"
23 #include <d32soundsc.h>
27 #define KNumRecorders (2) // 2 for double buffering, 4 quadruple etc
31 KPanicBadTotalQueueLength=1, // once constructed, total queue length should be KNumRecorders
32 KPanicBadTotalQueueLength2, // during construction or delation, total queue length should be <= KNumRecorders
33 KPanicBadBusyQueueLength, // Busy queue should never exceed length of 1
34 EPanicBusyRecorderNotActive, // If in the busy queue, should be active
35 EPanicNonBusyRecorderActive, // opposite
38 //Total Number of sample rates
39 class CChannelAndSampleRateConverter; // forward dec
41 class TRecordSharedChunkBufConfig : public TSharedChunkBufConfigBase
44 TInt iBufferOffsetList[3];
47 NONSHARABLE_CLASS(CAudioInput) : public CBase,
49 public MAIParamInterface
51 NONSHARABLE_CLASS( CRecorder ) : public CActive
54 CRecorder(CAudioInput& aParent, TInt aIndex);
60 void ReleaseBuffer(TBool aDoAnyway=EFalse);
62 TBool BufferHeld() const;
65 TInt StatusOrOffset() const;
67 TSglQueLink iLink; // used to form queues. Treat as private.
84 iSampleRate(8000), iRequestedChannels(1) // default
90 TInt iRequestedChannels;
95 static CAudioInput* NewL(MAudioInputObserver& aObserver);
100 TInt Initialize(const TAudioInputParams& aParams);
108 TAny* Interface(TUid aInterfaceUid);
110 // from MAIParamInterface
111 TInt SetGain(TInt aGain);
112 TInt GetBufferSizes(TInt& aMinSize, TInt& aMaxSize);
113 TInt GetSupportedSampleRates(RArray<TInt>& aSupportedSampleRates);
115 RSoundSc& RecordSoundDevice();
116 void BufferArrives(CRecorder* aRecorder);
117 void BufferError(CRecorder* aRecorder, TInt aError);
118 TInt SetFormat(const TAudioInputParams& aFormat);
119 TInt NegotiateFormat(const TAudioInputParams& aFormat, TFormatData &aFormatData);
120 TInt GetSupportedSampleRates(RArray<TInt>& aSupportedSampleRates, RSoundSc& aSoundDevice);
123 CAudioInput(MAudioInputObserver& aObserver);
127 static TInt Callback(TAny* aPtr);
128 void AsyncCallbackL();
129 void RequestCallback();
131 void CancelRecorders();
132 void CancelPendingRecorders();
133 void CancelBusyRecorder();
135 void InternalFlush();
136 void RecordAllIdle();
138 void UseBuffer(CRecorder* aRecorder);
139 void HandleBufferAck();
141 void CheckFullInvariant();
142 void CheckInvariant(TBool aKnownConstructed=ETrue);
145 void CheckActiveRecorders();
146 void CheckActiveRecorders(TSglQue<CRecorder>& aQueue, TBool aExpected, TInt aPanicCode);
149 static TInt QLength(TSglQue<CRecorder>& aQueue);
150 CRecorder* QPop(TSglQue<CRecorder>& aQueue);
151 TBool QPop(CRecorder*& aRecorder, TSglQue<CRecorder>& aQueue);
153 inline TInt BufferLength() const { return iBufferLength; } // TODO required?
156 MAudioInputObserver& iObserver;
163 EStateRecordWaitAck2,
166 enum TRunningState // when in RecordWait2 or RecordWaitAck2
168 ERStateRunning, // recording
169 ERStatePaused, // paused state
170 ERStateFinishing, // look to do InputFinished() on next tick
171 ERStateFinished, // InputFinished() sent
172 ERStateFailed, // InputError() sent
176 TRunningState iRState;
177 TRecordSharedChunkBufConfig iRecordBufferConfig;
178 RSoundSc iRecordSoundDevice;
180 CRecorder* iRecorders[KNumRecorders];
181 CAsyncCallBack* iAsyncCallBack;
182 TInt iBufferLength; // this is the length of buffers we request
183 CChannelAndSampleRateConverter* iConverter;
184 TPtrC8 iBufPtr; // this is usually the descriptor sent to the observer
185 RBuf8 iConvBuff; // extra buffer from when we use a converter
187 TSglQue<CRecorder> iIdleQueue; // just sitting there
188 TSglQue<CRecorder> iRecordingQueue; // record operation outstanding
189 TSglQue<CRecorder> iPendingQueue; // buffer has been recorded, waiting to be processed
190 TSglQue<CRecorder> iBusyQueue; // mid InputAvailable()/BufferAck() cycle. Length <= 1
193 inline TBool CAudioInput::QPop(CRecorder*& aRecorder, TSglQue<CRecorder>& aQueue)
194 // overload of QPop(), since "while (recorder = QPop(...))" etc gives warnings
195 // This allows "while (QPop(recorder, ...))" instead
197 CRecorder* recorder = QPop(aQueue);
200 aRecorder = recorder;
206 #endif // SWAUDIOINPUTPRIV_H