1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "ProcProcessAO.h" |
|
22 #include "AudCommon.h" |
|
23 #include "AudPanic.h" |
|
24 #include "audconstants.h" |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 TBool CProcProcess::StartSyncProcessingL(const CAudSong* aSong, TBool aGetTimeEstimation) |
|
30 { |
|
31 |
|
32 iSong = aSong; |
|
33 |
|
34 if (iEncoder != 0) |
|
35 { |
|
36 delete iEncoder; |
|
37 iEncoder = 0; |
|
38 } |
|
39 iEncoder = CProcEncoder::NewL(); |
|
40 iEncoder->InitL(iSong->OutputFileProperties().iAudioType, |
|
41 iSong->OutputFileProperties().iSamplingRate, |
|
42 iSong->OutputFileProperties().iChannelMode, |
|
43 iSong->OutputFileProperties().iBitrate ); |
|
44 |
|
45 |
|
46 if (iAMRBuf) |
|
47 { |
|
48 delete iAMRBuf; |
|
49 iAMRBuf = 0; |
|
50 |
|
51 } |
|
52 // buffer for extra AMR-frames |
|
53 iAMRBuf = HBufC8::NewL(KAedMaxAMRFrameLength); |
|
54 |
|
55 if (iDecBuffer) |
|
56 { |
|
57 delete iDecBuffer; |
|
58 iDecBuffer = 0; |
|
59 |
|
60 } |
|
61 |
|
62 iDecBuffer = HBufC8::NewL(KAedMaxFeedBufferSize); |
|
63 |
|
64 TInt rawFrameSize = KAedSizeAMRBuffer; |
|
65 if (aSong->OutputFileProperties().iSamplingRate == KAedSampleRate8kHz) |
|
66 { |
|
67 rawFrameSize = KAedSizeAMRBuffer; |
|
68 } |
|
69 else |
|
70 { |
|
71 rawFrameSize = KAedSizeAACBuffer; |
|
72 if ( aSong->OutputFileProperties().iChannelMode == EAudStereo ) |
|
73 { |
|
74 rawFrameSize *= 2; |
|
75 } |
|
76 } |
|
77 |
|
78 |
|
79 CAudProcessorImpl* processorImpl = CAudProcessorImpl::NewLC(); |
|
80 |
|
81 processorImpl->ProcessSongL(aSong, rawFrameSize, aGetTimeEstimation); |
|
82 |
|
83 CleanupStack::Pop(processorImpl); |
|
84 iProcessorImpl = processorImpl; |
|
85 |
|
86 |
|
87 return ETrue; |
|
88 |
|
89 } |
|
90 |
|
91 TBool CProcProcess::ProcessSyncPieceL(HBufC8*& aFrame, TInt& aProgress, |
|
92 TTimeIntervalMicroSeconds& aDuration) |
|
93 { |
|
94 |
|
95 // first check if we have frames left from the previous encoding |
|
96 |
|
97 if (iAMRBuf->Length() > 0) |
|
98 { |
|
99 // we do have some frames left |
|
100 |
|
101 TInt frLen = ProcTools::GetNextAMRFrameLength(iAMRBuf, 0); |
|
102 |
|
103 if (frLen > iAMRBuf->Length()) |
|
104 { |
|
105 // something has gone wrong, we don't have a proper AMR frame in the buffer |
|
106 User::Leave(KErrGeneral); |
|
107 } |
|
108 |
|
109 aFrame = HBufC8::NewL(frLen); |
|
110 aFrame->Des().Append(iAMRBuf->Left(frLen)); |
|
111 iAMRBuf->Des().Delete(0, frLen); |
|
112 |
|
113 aDuration = KAedAMRFrameDuration; |
|
114 iProgress = aProgress; |
|
115 |
|
116 return EFalse; |
|
117 } |
|
118 |
|
119 iDecBuffer->Des().Delete(0, iDecBuffer->Size()); |
|
120 |
|
121 HBufC8* frame = 0; |
|
122 |
|
123 TBool rawFrame = EFalse; |
|
124 |
|
125 TInt outDurationMilli = 0; |
|
126 |
|
127 TBool ret = iProcessorImpl->ProcessSyncPieceL(frame, aProgress, aDuration, rawFrame); |
|
128 iProgress = aProgress; |
|
129 |
|
130 if (!rawFrame) |
|
131 { |
|
132 |
|
133 // frame already in compressed domain, no need for encoding |
|
134 if (ret || frame == 0) |
|
135 { |
|
136 |
|
137 iTimeEstimate = iProcessorImpl->GetFinalTimeEstimate(); |
|
138 |
|
139 aFrame = frame; |
|
140 // no more frames left -> processing ready |
|
141 delete iProcessorImpl; |
|
142 iProcessorImpl = 0; |
|
143 delete iDecBuffer; |
|
144 iDecBuffer = 0; |
|
145 return ETrue; |
|
146 } |
|
147 else |
|
148 { |
|
149 aFrame = frame; |
|
150 return EFalse; |
|
151 } |
|
152 |
|
153 } |
|
154 else |
|
155 { |
|
156 // frame needs to be encoded |
|
157 if (ret || frame == 0) |
|
158 { |
|
159 |
|
160 iTimeEstimate = iProcessorImpl->GetFinalTimeEstimate(); |
|
161 // no more frames left -> processing ready |
|
162 delete iProcessorImpl; |
|
163 iProcessorImpl = 0; |
|
164 delete iDecBuffer; |
|
165 iDecBuffer = 0; |
|
166 return ETrue; |
|
167 } |
|
168 |
|
169 |
|
170 // feed encoder until we have something in the output buffer |
|
171 |
|
172 |
|
173 iEncoder->FillEncBufferL(*frame, iDecBuffer, outDurationMilli); |
|
174 |
|
175 delete frame; |
|
176 frame = 0; |
|
177 |
|
178 while (iDecBuffer->Size() == 0) |
|
179 { |
|
180 |
|
181 // we need more input for encoder |
|
182 |
|
183 TTimeIntervalMicroSeconds dur; |
|
184 ret = iProcessorImpl->ProcessSyncPieceL(frame, aProgress, dur, rawFrame); |
|
185 |
|
186 if (!ret) |
|
187 { |
|
188 |
|
189 } |
|
190 else |
|
191 { |
|
192 |
|
193 // no more frames left -> processing ready |
|
194 |
|
195 |
|
196 iTimeEstimate = iProcessorImpl->GetFinalTimeEstimate(); |
|
197 delete iProcessorImpl; |
|
198 iProcessorImpl = 0; |
|
199 delete iDecBuffer; |
|
200 iDecBuffer = 0; |
|
201 return ETrue; |
|
202 } |
|
203 |
|
204 |
|
205 |
|
206 iProgress = aProgress; |
|
207 |
|
208 if (ret) |
|
209 { |
|
210 |
|
211 // no more frames left -> processing ready |
|
212 |
|
213 iTimeEstimate = iProcessorImpl->GetFinalTimeEstimate(); |
|
214 delete iProcessorImpl; |
|
215 iProcessorImpl = 0; |
|
216 delete iDecBuffer; |
|
217 iDecBuffer = 0; |
|
218 return ETrue; |
|
219 } |
|
220 |
|
221 if (!rawFrame) |
|
222 { |
|
223 |
|
224 // we got encoded frame -> return it |
|
225 aFrame = frame; |
|
226 return EFalse; |
|
227 } |
|
228 |
|
229 // we should now have a raw frame in aFrame -> feed the encoder |
|
230 |
|
231 aDuration = aDuration.Int64() + dur.Int64(); |
|
232 |
|
233 iEncoder->FillEncBufferL(*frame, iDecBuffer, outDurationMilli); |
|
234 delete frame; |
|
235 frame = 0; |
|
236 |
|
237 } |
|
238 |
|
239 } |
|
240 |
|
241 // read the encoded frame to aFrame |
|
242 |
|
243 TInt frameLen = 0; |
|
244 if (iEncoder->DestAudType() == EAudAMR) |
|
245 { |
|
246 frameLen = ProcTools::GetNextAMRFrameLength(iDecBuffer, 0); |
|
247 } |
|
248 |
|
249 if (frameLen < iDecBuffer->Length() && iEncoder->DestAudType() == EAudAMR) |
|
250 { |
|
251 |
|
252 // we got more than one AMR frame, return the first now |
|
253 // and the second when this function is called next time |
|
254 aFrame = HBufC8::NewL(frameLen); |
|
255 aFrame->Des().Append(iDecBuffer->Des().Left(frameLen)); |
|
256 |
|
257 if ( (iDecBuffer->Length() + iAMRBuf->Length() - frameLen) > iAMRBuf->Des().MaxLength()) |
|
258 { |
|
259 // if the temporary storage is too small, we need more space for it |
|
260 iAMRBuf = iAMRBuf->ReAlloc(iDecBuffer->Length() + iAMRBuf->Length() - frameLen); |
|
261 } |
|
262 |
|
263 iAMRBuf->Des().Append(iDecBuffer->Right(iDecBuffer->Length() - frameLen)); |
|
264 |
|
265 } |
|
266 else |
|
267 { |
|
268 |
|
269 aFrame = HBufC8::NewL(iDecBuffer->Size()); |
|
270 aFrame->Des().Append(iDecBuffer->Des()); |
|
271 |
|
272 } |
|
273 |
|
274 iDecBuffer->Des().Delete(0, iDecBuffer->Size()); |
|
275 |
|
276 aDuration = outDurationMilli*1000; |
|
277 |
|
278 return EFalse; |
|
279 |
|
280 } |
|
281 |
|
282 TInt64 CProcProcess::GetFinalTimeEstimate() const |
|
283 { |
|
284 |
|
285 return iTimeEstimate; |
|
286 |
|
287 } |
|
288 |
|
289 |
|
290 CProcProcess* CProcProcess::NewL() |
|
291 { |
|
292 |
|
293 |
|
294 CProcProcess* self = new (ELeave) CProcProcess(); |
|
295 CleanupStack::PushL(self); |
|
296 self->ConstructL(); |
|
297 CleanupStack::Pop(self); |
|
298 return self; |
|
299 } |
|
300 |
|
301 CProcProcess::~CProcProcess() |
|
302 { |
|
303 |
|
304 if (iProcessorImpl != 0) |
|
305 { |
|
306 delete iProcessorImpl; |
|
307 iProcessorImpl = 0; |
|
308 } |
|
309 |
|
310 delete iEncoder; |
|
311 |
|
312 delete iDecBuffer; |
|
313 iDecBuffer = 0; |
|
314 |
|
315 delete iAMRBuf; |
|
316 |
|
317 |
|
318 } |
|
319 |
|
320 |
|
321 void CProcProcess::ConstructL() |
|
322 { |
|
323 |
|
324 |
|
325 } |
|
326 |
|
327 CProcProcess::CProcProcess() : iProcessorImpl(0), iSong(0) |
|
328 { |
|
329 |
|
330 } |
|
331 |
|
332 |
|