|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <barsc.h> |
|
17 #include <barsread.h> |
|
18 #include <bautils.h> |
|
19 #include <imageconversion.h> |
|
20 #include <101F7BF5_extra.rsg> |
|
21 |
|
22 #include "TestAsyncCodec.h" |
|
23 #include "TestAsyncConvert.h" |
|
24 |
|
25 #include "TestPanic.h" |
|
26 #include "TestDecs.h" |
|
27 #include "TestUids.hrh" |
|
28 |
|
29 //_LIT(KTestPanicCategory, "TestAsyncConvertPlugin"); // EABI warning removal |
|
30 |
|
31 const TInt KDummyFileSize = 100; |
|
32 const TInt KDummyHeaderSize = 10; |
|
33 const TInt KDummyDataSize = KDummyFileSize - KDummyHeaderSize; |
|
34 |
|
35 |
|
36 //******************************************** |
|
37 // CTestAsyncDecoder. |
|
38 //******************************************** |
|
39 CTestAsyncDecoder* CTestAsyncDecoder::NewL() |
|
40 { |
|
41 CTestAsyncDecoder* self = new(ELeave) CTestAsyncDecoder(); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 CTestAsyncDecoder::CTestAsyncDecoder() |
|
49 { |
|
50 } |
|
51 |
|
52 void CTestAsyncDecoder::ConstructL() |
|
53 { |
|
54 } |
|
55 |
|
56 CTestAsyncDecoder::~CTestAsyncDecoder() |
|
57 { |
|
58 delete iScheduler; |
|
59 |
|
60 CImageDecoderPlugin::Cleanup(); |
|
61 } |
|
62 |
|
63 void CTestAsyncDecoder::ImageType(TInt aFrameNumber, TUid& aImageType, TUid& aImageSubType) const |
|
64 { |
|
65 __ASSERT_ALWAYS(aFrameNumber == 0, Panic(EFrameNumberOutOfRange)); |
|
66 aImageType = KImageTypeTestUid; |
|
67 aImageSubType = KImageSubTypeTestUid; |
|
68 } |
|
69 |
|
70 void CTestAsyncDecoder::ScanDataL() |
|
71 { |
|
72 |
|
73 SetDataLength(10); |
|
74 |
|
75 |
|
76 if (!iReadHeaders) |
|
77 { |
|
78 TPtrC8 bufferDes; |
|
79 ReadDataL(0, bufferDes, (KDummyHeaderSize)); |
|
80 if (bufferDes.Length() < KDummyHeaderSize) |
|
81 User::Leave(KErrUnderflow); |
|
82 |
|
83 iReadHeaders = ETrue; |
|
84 SetDataLength(KDummyDataSize); |
|
85 |
|
86 |
|
87 iDecodeIterations = 0; |
|
88 |
|
89 // create the codec |
|
90 delete iImageReadCodec; |
|
91 iImageReadCodec = NULL; |
|
92 iImageReadCodec = CTestAsyncReadCodec::NewL(*this); |
|
93 SetImageReadCodec(iImageReadCodec); |
|
94 |
|
95 // create the async decoder |
|
96 delete iScheduler; |
|
97 iScheduler = NULL; |
|
98 iScheduler = new (ELeave) CAsyncScheduler(*this); |
|
99 |
|
100 // create a dummy TFrameInfo |
|
101 TFrameInfo imageInfo; |
|
102 imageInfo = ImageInfo(); |
|
103 imageInfo.iFrameSizeInTwips.iWidth = 0; |
|
104 imageInfo.iFrameSizeInTwips.iHeight = 0; |
|
105 imageInfo.iFrameCoordsInPixels.SetRect(TPoint(0, 0), TPoint(256, 256)); |
|
106 imageInfo.iOverallSizeInPixels = TSize(256, 256); |
|
107 imageInfo.iBitsPerPixel = 24; |
|
108 imageInfo.iDelay = 0; |
|
109 imageInfo.iFlags = TFrameInfo::ECanDither; |
|
110 imageInfo.iFrameDisplayMode = EColor16M; |
|
111 SetImageInfo(imageInfo); |
|
112 |
|
113 SetStartPosition(KDummyHeaderSize); |
|
114 |
|
115 ReadFrameHeadersL(); |
|
116 } |
|
117 |
|
118 } |
|
119 |
|
120 CFrameInfoStrings* CTestAsyncDecoder::FrameInfoStringsL(RFs& aFs, TInt aFrameNumber) |
|
121 { |
|
122 if (aFrameNumber!=0) |
|
123 User::Leave(KErrArgument); |
|
124 |
|
125 const TUid testCodecDllUid = {KTestDecoderDllUidValue}; |
|
126 |
|
127 RResourceFile resourceFile; |
|
128 OpenExtraResourceFileLC(aFs,testCodecDllUid,resourceFile); |
|
129 |
|
130 HBufC8* resourceInfo = resourceFile.AllocReadLC(THEDECODERINFO); |
|
131 TResourceReader resourceReader; |
|
132 resourceReader.SetBuffer(resourceInfo); |
|
133 |
|
134 TBuf<128> info; |
|
135 TBuf<128> templte; |
|
136 |
|
137 CFrameInfoStrings* frameInfoStrings = CFrameInfoStrings::NewLC(); |
|
138 |
|
139 info = resourceReader.ReadTPtrC(); |
|
140 frameInfoStrings->SetDecoderL(info); |
|
141 |
|
142 info = resourceReader.ReadTPtrC(); |
|
143 frameInfoStrings->SetFormatL(info); |
|
144 |
|
145 templte = resourceReader.ReadTPtrC(); |
|
146 const TFrameInfo& frameInfo = FrameInfo(aFrameNumber); |
|
147 const TSize& size = frameInfo.iOverallSizeInPixels; |
|
148 info.Format(templte, size.iWidth, size.iHeight); |
|
149 frameInfoStrings->SetDimensionsL(info); |
|
150 |
|
151 templte = resourceReader.ReadTPtrC(); |
|
152 iMaxValue = 10; |
|
153 info.Format(templte, iMaxValue); |
|
154 frameInfoStrings->SetDepthL(info); |
|
155 |
|
156 // leave details blank |
|
157 |
|
158 CleanupStack::Pop(frameInfoStrings); |
|
159 CleanupStack::PopAndDestroy(2); // resourceInfo + resourceFile |
|
160 return frameInfoStrings; |
|
161 } |
|
162 |
|
163 void CTestAsyncDecoder::DoConvert() |
|
164 { |
|
165 const TInt KDecodeIterations = 10; |
|
166 |
|
167 TRAPD(errCode, PrepareForProcessFrameL()); |
|
168 |
|
169 if (errCode!=KErrNone) |
|
170 { |
|
171 RequestComplete(errCode); |
|
172 return; |
|
173 } |
|
174 |
|
175 if (iError != KErrNone) |
|
176 { |
|
177 RequestComplete(iError); |
|
178 } |
|
179 // need to get more data from client app ? |
|
180 else if (SourceData().Length() < KDummyDataSize) |
|
181 { |
|
182 RequestComplete(KErrUnderflow); |
|
183 } |
|
184 else if (iDecodeIterations++ > KDecodeIterations) |
|
185 { |
|
186 RequestComplete(iError); |
|
187 } |
|
188 else |
|
189 { |
|
190 iDecodeState = EDecodeInit; |
|
191 iScheduler->Start(); |
|
192 SetSelfPending(); |
|
193 } |
|
194 } |
|
195 |
|
196 TInt CTestAsyncDecoder::NumberOfImageComments() const |
|
197 { |
|
198 return 1; |
|
199 } |
|
200 |
|
201 HBufC* CTestAsyncDecoder::ImageCommentL(TInt /*aCommentNumber*/) const |
|
202 { |
|
203 HBufC* imageComment = HBufC::NewL(20); |
|
204 TPtr ptr(imageComment->Des()); |
|
205 ptr.Copy(_L("Test Image Comment 1")); |
|
206 return imageComment; |
|
207 } |
|
208 |
|
209 TInt CTestAsyncDecoder::NumberOfFrameComments(TInt /*aFrameNumber*/) const |
|
210 { |
|
211 return 1; |
|
212 } |
|
213 |
|
214 HBufC* CTestAsyncDecoder::FrameCommentL(TInt /*aFrameNumber*/, TInt /*aCommentNumber*/) const |
|
215 { |
|
216 HBufC* frameComment = HBufC::NewL(20); |
|
217 TPtr ptr(frameComment->Des()); |
|
218 ptr.Copy(_L("Test Frame Comment 1")); |
|
219 return frameComment; |
|
220 } |
|
221 |
|
222 void CTestAsyncDecoder::ProcessFrameComplete(TInt aError) |
|
223 { |
|
224 iError = aError; |
|
225 iDecodeState = EDecodeFinished; |
|
226 iScheduler->Start(); |
|
227 } |
|
228 |
|
229 void CTestAsyncDecoder::MasoProcessL(TInt aError) |
|
230 { |
|
231 iError = aError; |
|
232 |
|
233 if (aError != KErrNone) |
|
234 { |
|
235 SelfComplete(iError); |
|
236 return; |
|
237 } |
|
238 |
|
239 switch(iDecodeState) |
|
240 { |
|
241 case EDecodeInit: |
|
242 iDecodeState = EDecodeInProgress; |
|
243 iScheduler->Start(); |
|
244 break; |
|
245 |
|
246 case EDecodeInProgress: |
|
247 TRAP(iError, iImageReadCodec->ProcessFrameL(SourceData())); |
|
248 if (iError != KErrNone) |
|
249 { |
|
250 SelfComplete(iError); |
|
251 break; |
|
252 } |
|
253 // now wait for async callback to ProcessFrameComplete... |
|
254 break; |
|
255 |
|
256 case EDecodeFinished: |
|
257 SelfComplete(iError); |
|
258 break; |
|
259 } |
|
260 |
|
261 } |
|
262 |
|
263 void CTestAsyncDecoder::Cleanup() |
|
264 { |
|
265 // cancel the state machine |
|
266 if (iScheduler) |
|
267 iScheduler->Cancel(); |
|
268 |
|
269 CImageDecoderPlugin::Cleanup(); |
|
270 } |
|
271 |
|
272 |
|
273 //******************************************** |
|
274 // CTestAsyncEncoder. |
|
275 //******************************************** |
|
276 CTestAsyncEncoder* CTestAsyncEncoder::NewL() |
|
277 { |
|
278 CTestAsyncEncoder* self = new(ELeave) CTestAsyncEncoder(); |
|
279 CleanupStack::PushL(self); |
|
280 self->ConstructL(); |
|
281 CleanupStack::Pop(self); |
|
282 return self; |
|
283 } |
|
284 |
|
285 CTestAsyncEncoder::CTestAsyncEncoder() |
|
286 { |
|
287 } |
|
288 |
|
289 void CTestAsyncEncoder::ConstructL() |
|
290 { |
|
291 } |
|
292 |
|
293 CTestAsyncEncoder::~CTestAsyncEncoder() |
|
294 { |
|
295 delete iScheduler; |
|
296 |
|
297 CImageEncoderPlugin::Cleanup(); |
|
298 } |
|
299 |
|
300 void CTestAsyncEncoder::DoConvert() |
|
301 { |
|
302 const TInt KEncodeIterations = 10; |
|
303 |
|
304 /* |
|
305 TRAPD(errCode, PrepareForProcessFrameL()); |
|
306 |
|
307 if (errCode!=KErrNone) |
|
308 { |
|
309 RequestComplete(errCode); |
|
310 return; |
|
311 } |
|
312 */ |
|
313 if (iError != KErrNone) |
|
314 { |
|
315 RequestComplete(iError); |
|
316 } |
|
317 |
|
318 if (iEncodeIterations++ > KEncodeIterations) |
|
319 { |
|
320 RequestComplete(iError); |
|
321 } |
|
322 else |
|
323 { |
|
324 iEncodeState = EEncodeInit; |
|
325 iScheduler->Start(); |
|
326 SetSelfPending(); |
|
327 } |
|
328 } |
|
329 |
|
330 void CTestAsyncEncoder::PrepareEncoderL(const CFrameImageData* /*aFrameImageData*/) |
|
331 { |
|
332 // create the codec |
|
333 delete iImageWriteCodec; |
|
334 iImageWriteCodec = NULL; |
|
335 iImageWriteCodec = CTestAsyncWriteCodec::NewL(*this); |
|
336 SetImageWriteCodec(iImageWriteCodec); |
|
337 |
|
338 // create the scheduler |
|
339 delete iScheduler; |
|
340 iScheduler = NULL; |
|
341 iScheduler = new (ELeave) CAsyncScheduler(*this); |
|
342 |
|
343 } |
|
344 |
|
345 void CTestAsyncEncoder::UpdateHeaderL() |
|
346 { |
|
347 } |
|
348 |
|
349 void CTestAsyncEncoder::ProcessFrameComplete(TInt aError) |
|
350 { |
|
351 iError = aError; |
|
352 iEncodeState = EEncodeFinished; |
|
353 iScheduler->Start(); |
|
354 } |
|
355 |
|
356 void CTestAsyncEncoder::MasoProcessL(TInt aError) |
|
357 { |
|
358 iError = aError; |
|
359 |
|
360 if (aError != KErrNone) |
|
361 { |
|
362 SelfComplete(iError); |
|
363 return; |
|
364 } |
|
365 |
|
366 switch(iEncodeState) |
|
367 { |
|
368 case EEncodeInit: |
|
369 iEncodeState = EEncodeInProgress; |
|
370 iScheduler->Start(); |
|
371 break; |
|
372 |
|
373 case EEncodeInProgress: |
|
374 TRAP(iError, iImageWriteCodec->ProcessFrameL(DestinationData())); |
|
375 if (iError != KErrNone) |
|
376 { |
|
377 SelfComplete(iError); |
|
378 break; |
|
379 } |
|
380 // now wait for async callback to ProcessFrameComplete... |
|
381 break; |
|
382 |
|
383 case EEncodeFinished: |
|
384 SelfComplete(iError); |
|
385 break; |
|
386 } |
|
387 |
|
388 } |
|
389 |
|
390 void CTestAsyncEncoder::Cleanup() |
|
391 { |
|
392 // cancel the state machine |
|
393 if (iScheduler) |
|
394 iScheduler->Cancel(); |
|
395 |
|
396 CImageEncoderPlugin::Cleanup(); |
|
397 } |
|
398 |
|
399 |
|
400 // CAsyncScheduler |
|
401 CAsyncScheduler::CAsyncScheduler(MAsyncSchedulerObserver& aSchedulerObserver) : |
|
402 CActive(CActive::EPriorityIdle), iSchedulerObserver(aSchedulerObserver) |
|
403 { |
|
404 CActiveScheduler::Add(this); |
|
405 } |
|
406 |
|
407 |
|
408 void CAsyncScheduler::Start() |
|
409 { |
|
410 SetActive(); |
|
411 TRequestStatus* status = &iStatus; |
|
412 User::RequestComplete(status, KErrNone); |
|
413 } |
|
414 |
|
415 void CAsyncScheduler::RunL() |
|
416 { |
|
417 TInt error = iStatus.Int(); |
|
418 |
|
419 iSchedulerObserver.MasoProcessL(error); |
|
420 } |
|
421 |
|
422 |