|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Audio Stream Test Component |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "InputStreamer.h" |
|
19 |
|
20 const TInt CInputStreamer::KRecorderActionStop = 3; |
|
21 const TInt CInputStreamer::KSchedulerStop = 4; |
|
22 |
|
23 CInputStreamer::CInputStreamer(CStifLogger *aLogger) |
|
24 : CStreamerBase(aLogger) , iAlreadyClosed(EFalse) , iRecording(EFalse) |
|
25 { |
|
26 } |
|
27 |
|
28 void CInputStreamer::ConstructL() |
|
29 { |
|
30 iMdaAudioInputStream = CMdaAudioInputStream::NewL(*this); |
|
31 } |
|
32 |
|
33 CInputStreamer* CInputStreamer::NewL(CStifLogger *aLogger, TInt aId) |
|
34 { |
|
35 CInputStreamer *_self = NewLC(aLogger, aId); |
|
36 CleanupStack::Pop(_self); |
|
37 return _self; |
|
38 } |
|
39 |
|
40 CInputStreamer* CInputStreamer::NewLC(CStifLogger *aLogger, TInt aId) |
|
41 { |
|
42 CInputStreamer *_self = new(ELeave)CInputStreamer(aLogger); |
|
43 CleanupStack::PushL(_self); |
|
44 _self->ConstructL(); |
|
45 _self->SetId(aId); |
|
46 return _self; |
|
47 } |
|
48 |
|
49 void CInputStreamer::ConstructL(TInt aPriority, TMdaPriorityPreference aPref) |
|
50 { |
|
51 iMdaAudioInputStream = CMdaAudioInputStream::NewL(*this, aPriority, aPref); |
|
52 } |
|
53 |
|
54 CInputStreamer* CInputStreamer::NewL(TInt aPriority, TMdaPriorityPreference aPref, |
|
55 CStifLogger *aLogger, TInt aId) |
|
56 { |
|
57 CInputStreamer *_self = NewLC(aPriority, aPref, aLogger, aId); |
|
58 CleanupStack::Pop(_self); |
|
59 return _self; |
|
60 } |
|
61 |
|
62 CInputStreamer* CInputStreamer::NewLC(TInt aPriority, TMdaPriorityPreference aPref, |
|
63 CStifLogger *aLogger, TInt aId) |
|
64 { |
|
65 CInputStreamer *_self = new(ELeave)CInputStreamer(aLogger); |
|
66 CleanupStack::PushL(_self); |
|
67 _self->ConstructL(aPriority, aPref); |
|
68 _self->SetId(aId); |
|
69 return _self; |
|
70 } |
|
71 |
|
72 |
|
73 CInputStreamer::~CInputStreamer() |
|
74 { |
|
75 |
|
76 delete iMdaAudioInputStream; |
|
77 delete iSettings; |
|
78 TInt Before = iBuffers.Count(); |
|
79 iBuffers.ResetAndDestroy(); |
|
80 iBuffers.Close(); |
|
81 iLogger->Log(_L("%d) Items in buffer (%d), there were (%d)") , iId, iBuffers.Count() , Before); |
|
82 iMdaAudioInputStream = NULL; |
|
83 } |
|
84 |
|
85 void CInputStreamer::SetAudioPropertiesL(TInt aSampleRate, TInt aChannels) |
|
86 { |
|
87 iLogger->Log(_L("%d) CInputStreamer::SetAudioPropertiesL(rate=%d, chan=%d)") , iId, aSampleRate, aChannels); |
|
88 iMdaAudioInputStream->SetAudioPropertiesL(aSampleRate, aChannels); |
|
89 } |
|
90 |
|
91 void CInputStreamer::SetPriority(TInt aPriority, TMdaPriorityPreference aPref) |
|
92 { |
|
93 iLogger->Log(_L("%d) CInputStreamer::SetPriority(%d, %d)") , iId, aPriority, aPref); |
|
94 iMdaAudioInputStream->SetPriority(aPriority, aPref); |
|
95 } |
|
96 |
|
97 TInt CInputStreamer::GetBalanceL() |
|
98 { |
|
99 TInt retVal = iMdaAudioInputStream->GetBalanceL(); |
|
100 iLogger->Log(_L("%d) CInputStreamer::GetBalanceL() , result=(%d)") , iId, retVal); |
|
101 return retVal; |
|
102 } |
|
103 |
|
104 void CInputStreamer::SetBalanceL(TInt aBalance) |
|
105 { |
|
106 iLogger->Log(_L("%d) CInputStreamer::SetBalanceL(%d)") , iId, aBalance); |
|
107 iMdaAudioInputStream->SetBalanceL(aBalance); |
|
108 } |
|
109 |
|
110 void CInputStreamer::SetGain(const TInt aNewGain) { iMdaAudioInputStream->SetGain(aNewGain); } |
|
111 TInt CInputStreamer::GetMaxGain() { return iMdaAudioInputStream->MaxGain(); } |
|
112 TInt CInputStreamer::GetGain() { return iMdaAudioInputStream->Gain(); } |
|
113 |
|
114 void CInputStreamer::Stop() |
|
115 { |
|
116 iLogger->Log(_L("%d) CInputStreamer::Stop()") , iId); |
|
117 iRecording=EFalse; |
|
118 iState=EStopped; |
|
119 iMdaAudioInputStream->Stop(); |
|
120 } |
|
121 |
|
122 TFourCC CInputStreamer::GetDataType() |
|
123 { |
|
124 TFourCC retVal = iMdaAudioInputStream->DataType(); |
|
125 iLogger->Log(_L("%d) CInputStreamer::GetDataType() , result=(%d)") , iId, retVal.FourCC()); |
|
126 return retVal; |
|
127 } |
|
128 |
|
129 void CInputStreamer::SetDataTypeL(TFourCC aDataType) |
|
130 { |
|
131 iLogger->Log(_L("%d) CInputStreamer::SetDataTypeL(%d)") , iId, aDataType.FourCC()); |
|
132 iMdaAudioInputStream->SetDataTypeL(aDataType); |
|
133 } |
|
134 |
|
135 void CInputStreamer::GetSupportedBitRatesL(RArray<TInt>& aSupportedBitRates) |
|
136 { |
|
137 iMdaAudioInputStream->GetSupportedBitRatesL(aSupportedBitRates); |
|
138 } |
|
139 |
|
140 TInt CInputStreamer::BitRateL() |
|
141 { |
|
142 TInt retVal = iMdaAudioInputStream->BitRateL(); |
|
143 iLogger->Log(_L("%d) CInputStreamer::BitRateL() , result=(%d)") , iId, retVal); |
|
144 return retVal; |
|
145 } |
|
146 |
|
147 void CInputStreamer::SetBitRateL(TInt aBitRate) |
|
148 { |
|
149 iLogger->Log(_L("%d) CInputStreamer::SetBitRateL(%d)") , iId, aBitRate); |
|
150 iMdaAudioInputStream->SetBitRateL(aBitRate); |
|
151 } |
|
152 |
|
153 RPointerArray<TDes8> &CInputStreamer::GetBuffers() |
|
154 { |
|
155 return iBuffers; |
|
156 } |
|
157 |
|
158 void CInputStreamer::StartRecording() |
|
159 { |
|
160 iLogger->Log(_L("CInputStreamer::StartRecording()") ); |
|
161 iMdaAudioInputStream->Open(iSettings); |
|
162 } |
|
163 |
|
164 void CInputStreamer::Exit(TInt aExitCode) |
|
165 { |
|
166 iLogger->Log(_L("%d) CInputStreamer::Exit(%d)"), iId, aExitCode); |
|
167 iFinalError = aExitCode; |
|
168 if (!iAlreadyClosed) |
|
169 { |
|
170 iAlreadyClosed=ETrue; |
|
171 CActiveScheduler::Stop(); |
|
172 iLogger->Log(_L("%d) Stop Active Scheduler"), iId); |
|
173 } |
|
174 } |
|
175 |
|
176 void CInputStreamer::SetSettings(TMdaPackage *aSettings) |
|
177 { |
|
178 iSettings=aSettings; |
|
179 } |
|
180 |
|
181 void CInputStreamer::MaiscOpenComplete(TInt aError) |
|
182 { |
|
183 iLogger->Log(_L("%d) CInputStreamer::MaiscOpenComplete(%d)") , iId, aError); |
|
184 iLogger->Log(_L("Error=(%d)") , aError); |
|
185 if (aError || iExitAfterOpen) |
|
186 { |
|
187 Exit(aError); |
|
188 return; |
|
189 } |
|
190 |
|
191 iState=ERecording; |
|
192 if (iState == EClosed) |
|
193 { |
|
194 iState = EFirstOpenSuccessful; |
|
195 } |
|
196 else |
|
197 { |
|
198 iState = EOpen; |
|
199 } |
|
200 iLogger->Log(_L("%d) MaiscOpenComplete: Bytes (%d), Position (%d)") , iId, iMdaAudioInputStream->GetBytes() , |
|
201 iMdaAudioInputStream->Position() ); |
|
202 iRecording=ETrue; |
|
203 |
|
204 ++iCurrentBuffer; |
|
205 TDes8 *tmp = new(ELeave)TBuf8<KBufferSize>; |
|
206 tmp->SetMax(); |
|
207 CleanupStack::PushL(tmp); |
|
208 |
|
209 if (iBuffers.Append(tmp)) { iLogger->Log(_L("Error appending in openComplete")); } |
|
210 CleanupStack::Pop(tmp); |
|
211 iLogger->Log(_L("%d) CInputStreamer::MaiscOpenComplete(), adding buffer #(%d)") , iId, iCurrentBuffer); |
|
212 iMdaAudioInputStream->ReadL( *iBuffers[iBuffers.Count()-1] ); |
|
213 |
|
214 } |
|
215 |
|
216 void CInputStreamer::MaiscBufferCopied(TInt aError, const TDesC8 &aBuffer) |
|
217 { |
|
218 iLogger->Log(_L("%d) CInputStreamer::MaiscBufferCopied(%d)") , iId, aError); |
|
219 iLogger->Log(_L(" Buffer's length=(%d)") , aBuffer.Length() ); |
|
220 iLogger->Log(_L("Error=(%d)") , aError); |
|
221 |
|
222 if (aError) |
|
223 { |
|
224 iRecording=EFalse; |
|
225 if (iState == EStopped) |
|
226 Exit(KErrNone); |
|
227 else |
|
228 Exit(aError); |
|
229 //TODO: remove previous line when the MaiscRecordComplete callback gets called correctly |
|
230 return; |
|
231 } |
|
232 |
|
233 iLogger->Log(_L("%d) MaiscBufferCopied: Bytes (%d), Position (%d)") , iId, iMdaAudioInputStream->GetBytes() , |
|
234 iMdaAudioInputStream->Position() ); |
|
235 ++iCurrentBuffer; |
|
236 TDes8 *tmp = new(ELeave)TBuf8<KBufferSize>; |
|
237 tmp->SetMax(); |
|
238 CleanupStack::PushL(tmp); |
|
239 |
|
240 if (iBuffers.Append(tmp)) { iLogger->Log(_L("Error appending in openComplete")); } |
|
241 CleanupStack::Pop(tmp); |
|
242 |
|
243 iLogger->Log(_L("%d) CInputStreamer::MaiscBufferCopied(), Reading buffer #(%d)") , iId, iCurrentBuffer); |
|
244 iMdaAudioInputStream->ReadL( *iBuffers[iBuffers.Count()-1] ); |
|
245 } |
|
246 |
|
247 void CInputStreamer::MaiscRecordComplete(TInt aError) |
|
248 { |
|
249 iLogger->Log(_L("%d) MaiscRecordComplete: Bytes (%d), Position (%d)") , iId, iMdaAudioInputStream->GetBytes() , |
|
250 iMdaAudioInputStream->Position() ); |
|
251 iLogger->Log(_L("%d) CInputStreamer::MaiscRecordComplete(%d)") , iId, aError); |
|
252 iLogger->Log(_L("Error=(%d)") , aError); |
|
253 iRecording=EFalse; |
|
254 Exit(aError); |
|
255 return; |
|
256 } |
|
257 |
|
258 // Callback from MEventTarget |
|
259 TInt CInputStreamer::ExecuteL(CParameters *aParams) |
|
260 { |
|
261 switch (aParams->iAction) |
|
262 { |
|
263 case KRecorderActionStop: |
|
264 Stop(); |
|
265 break; |
|
266 case KSchedulerStop: |
|
267 CActiveScheduler::Stop(); |
|
268 break; |
|
269 } |
|
270 return EFalse; |
|
271 } |
|
272 |