Update contrib.
1 // Copyright (c) 2006-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 the License "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 // e32test\multimedia\t_camera_api.cpp
19 #include <d32camerasc.h>
21 #include <e32def_private.h>
22 #include "t_camera_display.h"
23 #include "t_camera_bitmap.h"
26 _LIT(KTstLddFileName,"D_MMCSC.LDD");
27 _LIT(KCamLddFileName,"ECAMERASC.LDD");
30 _LIT(KCamPddFileName,"_TEMPLATE_CAMERASC.PDD");
32 _LIT(KCamPddFileName,"CAMERASC.PDD");
36 _LIT(KCamFreePddExtension,".*");
38 _LIT(KFrameSize, "%dx%d");
39 _LIT(KSensor, "d:\\Sensor_");
40 _LIT(KUnderscore, "_");
43 _LIT(KSpeedTaggedJpeg, ".stj");
45 LOCAL_D TCameraCapsV02* CameraCaps;
46 LOCAL_D TInt CapsSize;
47 LOCAL_D TAny* CapsBufPtr;
48 RTest Test(_L("T_CAMERA_API"));
50 const TInt KNumVideoFramesToAllocate=6;
51 const TInt KNumVideoFramesToCapture=(KNumVideoFramesToAllocate-2);
52 const TInt KHeapSize=0x4000;
58 ESecThreadTestDuplicateHandle,
62 struct SSecondaryThreadInfo
64 TSecThreadTestId iTestId;
68 TInt iCameraModuleIndex;
71 LOCAL_C TInt secondaryThread(TAny* aTestInfo)
73 RTest stest(_L("Secondary test camera thread"));
76 stest.Start(_L("Check which test to perform"));
77 SSecondaryThreadInfo sti =*((SSecondaryThreadInfo*)aTestInfo);
82 case ESecThreadTestOpen:
84 stest.Next(_L("Open channel test"));
86 r=cam.Open(sti.iCameraModuleIndex);
87 stest(r==sti.iExpectedRetVal);
91 case ESecThreadTestDuplicateHandle:
93 stest.Next(_L("Duplicate channel handle test"));
95 // Get a reference to the main thread - which created the handle
97 r=thread.Open(sti.iThreadId);
100 // Duplicate the driver handle passed from the other thread - for this thread
102 cam.SetHandle(sti.iDrvHandle);
103 r=cam.Duplicate(thread);
104 stest(r==sti.iExpectedRetVal);
109 case ESecThreadReuseHandle:
111 stest.Next(_L("Re-use channel test"));
112 RDevCameraSc* camPtr=(RDevCameraSc*)sti.iDrvHandle;
113 TCameraConfigV02Buf camConfBuf;
114 camPtr->GetCamConfig(ECamCaptureModeImage, camConfBuf); // This should cause a panic.
125 /** Test for defect DEF135950. */
126 LOCAL_C void DoCamDynamicSettingsTests(RDevCameraSc& aCam, RTest& aTest)
128 aTest.Next(_L("DYNAMIC SETTINGS TESTS"));
130 aTest.Next(_L("Get the Caps size. Should be non-zero"));
131 TInt capsSize = aCam.CapsSize();
134 aTest.Next(_L("Get the Capabilities (driver owned copy)."));
135 TPtrC8 driverCopy = aCam.Caps();
136 aTest(driverCopy.Ptr() != NULL);
137 aTest(driverCopy.Length()>0);
139 aTest.Next(_L("Test failure (buffer too small)."));
140 TAny* capsBufPtr = User::Alloc(capsSize-1);
141 aTest(capsBufPtr != NULL);
142 TPtr8 smallBuf((TUint8*) capsBufPtr, capsSize-1, capsSize-1);
143 aTest(KErrArgument==aCam.Caps(smallBuf));
144 User::Free(capsBufPtr);
146 aTest.Next(_L("Get the Capabilities (client owned copy)."));
147 capsBufPtr = User::Alloc(capsSize);
148 aTest(capsBufPtr != NULL);
149 TPtr8 clientCopy((TUint8*) capsBufPtr, capsSize, capsSize);
150 aTest(KErrNone==aCam.Caps(clientCopy));
151 aTest(clientCopy.Ptr() != NULL);
152 aTest(clientCopy.Length()>0);
154 aTest.Next(_L("Obtain the range for Dynamic Settings from both copies (should be the same)."));
156 TDynamicRange &driverRangeBrightness = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness];
157 TDynamicRange &clientRangeBrightness = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness];
159 aTest(driverRangeBrightness.iMin == 0);
160 aTest(driverRangeBrightness.iMax == 6);
161 aTest(driverRangeBrightness.iMin == clientRangeBrightness.iMin);
162 aTest(driverRangeBrightness.iMax == clientRangeBrightness.iMax);
164 TDynamicRange &driverRangeContrast = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeContrast];
165 TDynamicRange &clientRangeContrast = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeContrast];
167 aTest(driverRangeContrast.iMin == 0);
168 aTest(driverRangeContrast.iMax == 6);
169 aTest(driverRangeContrast.iMin == clientRangeContrast.iMin);
170 aTest(driverRangeContrast.iMax == clientRangeContrast.iMax);
172 TDynamicRange &driverRangeColorEffect = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect];
173 TDynamicRange &clientRangeColorEffect = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect];
175 aTest(driverRangeColorEffect.iMin == 0);
176 aTest(driverRangeColorEffect.iMax == 7); // TBC::OV3640 set to 7, template driver set to 0x0040 (enum)
177 aTest(driverRangeColorEffect.iMin == clientRangeColorEffect.iMin);
178 aTest(driverRangeColorEffect.iMax == clientRangeColorEffect.iMax);
180 aTest.Next(_L("Test for invalid Min range."));
181 aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMin-1)==KErrArgument);
182 aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMin-1)==KErrArgument);
183 aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMin-1)==KErrArgument);
185 aTest.Next(_L("Test for invalid Max range."));
186 aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMax+1)==KErrArgument);
187 aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMax+1)==KErrArgument);
188 aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMax+1)==KErrArgument);
190 aTest.Next(_L("Test all valid settings as reported by range - Brightness"));
191 for (TUint i=driverRangeBrightness.iMin; i <= driverRangeBrightness.iMax; ++i)
193 aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, i)==KErrNone);
196 aTest.Next(_L("Test all valid settings as reported by range - Contrast"));
197 for (TUint j=driverRangeContrast.iMin; j <= driverRangeContrast.iMax; ++j)
199 aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, j)==KErrNone);
202 aTest.Next(_L("Test all valid settings as reported by range - ColorEffect"));
203 for (TUint k=driverRangeColorEffect.iMin; k <= driverRangeColorEffect.iMax; ++k)
205 aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, k)==KErrNone);
208 User::Free(capsBufPtr);
211 /** Test for defect DEF135949. */
212 LOCAL_C void DoCamBufferOffsetTests(RDevCameraSc& aCam, RTest& aTest, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
216 aTest.Next(_L("BUFFER ID OFFSET TESTS"));
217 aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
219 // Configure Image Capture
220 aTest.Next(_L("Get the camera config of Image mode"));
221 TCameraConfigV02Buf camConfBuf;
222 aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
223 TCameraConfigV02 &camConf=camConfBuf();
225 camConf.iFrameSize=aFrameSize;
226 camConf.iPixelFormat=aPixelFormat;
227 camConf.iFrameRate=aFrameRate;
229 // Set the Image configuration.
230 aTest.Next(_L("Set the Get the camera config of Image mode"));
231 r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf);
233 aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
234 PrintCamConf(camConf,aTest);
236 // Create an Image chunk handle.
237 aTest.Next(_L("Create the Image chunk"));
238 RChunk imgChunkImage;
239 TInt numBuffers=KNumVideoFramesToAllocate;
240 r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,imgChunkImage);
243 aTest.Next(_L("Read and display the Image buffer config"));
244 TMmSharedChunkBufConfig bufferConfig;
245 TPckg<TMmSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
246 aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBuf);
247 PrintBufferConf(bufferConfig,aTest);
249 // Configure Video Capture
250 aTest.Next(_L("Get the camera config of Video mode"));
251 aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
252 camConf=camConfBuf();
254 camConf.iFrameSize=aFrameSize;
255 camConf.iPixelFormat=aPixelFormat;
256 camConf.iFrameRate=aFrameRate;
258 // Set the video configuration.
259 aTest.Next(_L("Set the Get the camera config of Video mode"));
260 r=aCam.SetCamConfig(ECamCaptureModeVideo,camConfBuf);
262 aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
263 PrintCamConf(camConf,aTest);
265 // Create an Video chunk handle.
266 aTest.Next(_L("Create the Video chunk"));
268 numBuffers=KNumVideoFramesToAllocate;
269 r=aCam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo);
272 aTest.Next(_L("Read and display the Video buffer config"));
273 aCam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBuf);
274 PrintBufferConf(bufferConfig,aTest);
276 // Test that stop still returns an error.
278 aTest(r==KErrGeneral);
280 // Set the current capture mode to image
281 aTest.Next(_L("Set the camera in Image mode and capture a buffer, then requesting the buffer offset."));
282 r=aCam.SetCaptureMode(ECamCaptureModeImage);
289 aTest.Next(_L("Issue a capture request"));
291 aCam.NotifyNewImage(rs1);
292 User::WaitForRequest(rs1);
293 TInt retId=rs1.Int();
296 aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
297 aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
300 // Change capture mode
301 aTest.Next(_L("Set the capture mode to Video."));
302 r=aCam.SetCaptureMode(ECamCaptureModeVideo);
305 aTest.Next(_L("Request again the offset for the buffer in Image mode."));
306 aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
307 aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
314 aTest.Next(_L("Close the chunk"));
315 r=aCam.ChunkClose(ECamCaptureModeImage);
317 r=aCam.ChunkClose(ECamCaptureModeVideo);
322 LOCAL_C void DoCamOpenCapTests(RTest& aTest,TInt aCameraSensorIndex)
326 // Open the camera driver to obtain the basic capabilities for use throughout the tests and
327 // then close it again so that it may be confirmed that opening multiple times is ok
328 aTest.Next(_L("CHANNEL OPEN AND CAPABILITIES TESTS"));
330 aTest.Next(_L("Open a channel on the camera driver"));
331 r=cam.Open(aCameraSensorIndex);
334 // Make sure that the driver can handle attempts to start it before it has been configured
335 aTest.Next(_L("Try to start/stop camera before its configured"));
337 aTest(r==KErrNotReady);
339 aTest(r==KErrGeneral);
341 aTest.Next(_L("Read the capabilities structure size of this device"));
342 CapsSize=cam.CapsSize();
343 aTest.Next(_L("Read and display the capabilities of this device"));
344 CapsBufPtr = User::Alloc(CapsSize);
345 TPtr8 capsPtr( (TUint8*)CapsBufPtr, CapsSize, CapsSize );
348 CameraCaps = (TCameraCapsV02*) capsPtr.Ptr();
349 PrintCamModes(CameraCaps,aTest);
351 TAny* frameSizeCapsBuf;
352 SDevCamPixelFormat* pixelFormat;
354 SDevCamFrameSize* frameSize;
355 TPtr8 frameSizeCapsPtr(0,0,0);
356 TUint fsCount, pfCount, theCount = 0;
359 /* Use pixel formats from 0 to CapsBuf->iNumImagePixelFormats */
361 buf.Append(KCaptureModeImage);
362 buf.Append(_L("\r\n"));
364 pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
365 for (pfCount = theCount; pfCount < CameraCaps->iNumImagePixelFormats; pfCount++)
368 AppendPixelFormat(buf, pixelFormat->iPixelFormat);
370 frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
371 new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
372 r=cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizeCapsPtr);
374 frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
375 for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
377 aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
380 aTest.Printf(_L("\n"));
381 User::Free(frameSizeCapsBuf);
387 buf.Append(KCaptureModeVideo);
388 buf.Append(_L("\r\n"));
390 pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
391 pixelFormat += CameraCaps->iNumImagePixelFormats;
392 theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats;
393 for (pfCount = CameraCaps->iNumImagePixelFormats; pfCount < theCount; pfCount++)
396 AppendPixelFormat(buf, pixelFormat->iPixelFormat);
398 frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
399 new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
400 r=cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizeCapsPtr);
402 frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
403 for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
405 aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
408 aTest.Printf(_L("\n"));
409 User::Free(frameSizeCapsBuf);
415 buf.Append(KCaptureModeViewFinder);
416 buf.Append(_L("\r\n"));
418 pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
419 pixelFormat += (CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats);
420 theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats + CameraCaps->iNumViewFinderPixelFormats;
421 for (pfCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats; pfCount < theCount; pfCount++)
424 AppendPixelFormat(buf, pixelFormat->iPixelFormat);
426 frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
427 new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
428 r=cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizeCapsPtr);
430 frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
431 for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
433 aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
436 aTest.Printf(_L("\n"));
437 User::Free(frameSizeCapsBuf);
441 aTest.Next(_L("Try opening the same unit a second time."));
443 r=cam2.Open(aCameraSensorIndex);
446 aTest.Next(_L("Open a channel from the 2nd thread without closing the 1st"));
449 SSecondaryThreadInfo sti;
451 // Setup the 2nd thread to open a channel on the same unit
452 sti.iTestId=ESecThreadTestOpen;
453 sti.iExpectedRetVal=KErrInUse;
454 sti.iCameraModuleIndex=aCameraSensorIndex;
455 r=thread.Create(_L("Thread"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti);
459 User::WaitForRequest(stat);
460 Test(stat.Int()==KErrNone);
461 Test(thread.ExitType()==EExitKill);
463 User::After(10000); // Wait 10ms
465 aTest.Next(_L("Open a channel from the 2nd thread having closed the 1st"));
466 cam.Close(); // Close the 1st channel
467 sti.iTestId=ESecThreadTestOpen;
468 sti.iExpectedRetVal=KErrNone;
469 r=thread.Create(_L("Thread02"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti);
473 User::WaitForRequest(stat);
474 Test(stat.Int()==KErrNone);
475 Test(thread.ExitType()==EExitKill);
477 User::After(10000); // Wait 10ms
479 aTest.Next(_L("Re-open channel and duplicate it from 2nd thread"));
480 r=cam.Open(aCameraSensorIndex); // Re-open the channel
482 sti.iTestId=ESecThreadTestDuplicateHandle;
483 sti.iExpectedRetVal=KErrAccessDenied;
484 sti.iThreadId=RThread().Id(); // Get the ID of this thread
485 sti.iDrvHandle=cam.Handle(); // Pass the channel handle
487 r=thread.Create(_L("Thread03"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
491 User::WaitForRequest(stat);
492 Test(stat.Int()==KErrNone);
493 Test(thread.ExitType()==EExitKill);
495 User::After(10000); // Wait 10ms
497 aTest.Next(_L("Re-use the same channel from 2nd thread"));
498 sti.iTestId=ESecThreadReuseHandle;
499 sti.iDrvHandle=(TInt)&cam; // Pass a pointer to the channel
500 r=thread.Create(_L("Thread04"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
504 User::WaitForRequest(stat);
505 TExitCategoryName exitCategoryName = thread.ExitCategory();
506 Test.Printf(_L("Thread exit info: Cat:%S, Reason:%x, Type:%d\r\n"),&exitCategoryName,thread.ExitReason(),thread.ExitType());
507 Test(thread.ExitType()==EExitPanic); // Secondary thread is expected to panic
508 Test(stat.Int()==KErrNone);
510 User::After(10000); // Wait 10ms
515 LOCAL_C void DoCamConfigTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize)
519 aTest.Next(_L("GETTING & SETTING CONFIG TESTS"));
520 aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
522 aTest.Next(_L("Read and display the default camera config for requested capture mode"));
523 TCameraConfigV02Buf camConfBuf;
524 aCam.GetCamConfig(aCaptureMode, camConfBuf);
525 TCameraConfigV02 &camConf=camConfBuf();
526 PrintCamConf(camConf,aTest);
528 aTest.Next(_L("Read and display the default buffer config for requested capture mode"));
529 TMmSharedChunkBufConfig bufferConfig;
530 TPckg<TMmSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
531 aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf);
532 PrintBufferConf(bufferConfig,aTest);
534 aTest.Next(_L("Setup the config - creating a chunk"));
535 camConf.iFrameSize=aFrameSize;
536 camConf.iPixelFormat=aPixelFormat;
537 camConf.iFrameRate=aFrameSize.iMaxFrameRate;
538 r=aCam.SetCamConfig(aCaptureMode, camConfBuf);
541 r=aCam.SetBufConfigChunkCreate(aCaptureMode, KNumVideoFramesToAllocate, chunk);
543 aCam.GetCamConfig(aCaptureMode, camConfBuf);
544 PrintCamConf(camConf,aTest);
546 aTest.Next(_L("Read and display the resulting buffer config"));
547 aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf);
548 PrintBufferConf(bufferConfig,aTest);
550 aTest.Next(_L("Close the chunk created"));
553 aTest.Next(_L("Open a channel on the test driver"));
555 r=tstDrv.Open(); // Opening the channel results in the creation of a shared chunk.
558 aTest.Next(_L("Get a handle on its shared chunk"));
559 r=tstDrv.GetChunkHandle(chunk); // Get a handle on the shared chunk created by the test driver
562 aTest.Next(_L("Read and display the buffer config"));
563 TMmSharedChunkBufConfig bufferConfigTest;
564 TPckg<TMmSharedChunkBufConfig> bufferConfigBufTest(bufferConfigTest);
566 // Get info on the buffers within the shared chunk
567 aTest.Next(_L("Get info. on the shared chunk"));
568 r=tstDrv.GetBufInfo(bufferConfigBufTest);
571 PrintBufferConf(bufferConfigTest,aTest);
572 aTest.Next(_L("Setup the config - supplying a chunk"));
573 r=aCam.SetBufConfigChunkOpen(aCaptureMode, bufferConfigBufTest, chunk);
575 aCam.GetCamConfig(aCaptureMode, camConfBuf);
576 PrintCamConf(camConf,aTest);
577 aCam.GetBufferConfig(aCaptureMode, bufferConfigBufTest);
578 PrintBufferConf(bufferConfigTest,aTest);
580 aTest.Next(_L("Close the chunk driver and the 2nd chunk"));
585 LOCAL_C void DoCamVideoCaptureTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
589 aTest.Next(_L("VIDEO CAPTURE TESTS"));
590 aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
592 // Configure Video or Viewfinder Capture
593 TCameraConfigV02Buf camConfBuf;
594 aCam.GetCamConfig(aCaptureMode, camConfBuf);
595 TCameraConfigV02 &camConf=camConfBuf();
597 camConf.iFrameSize=aFrameSize;
598 camConf.iPixelFormat=aPixelFormat;
599 camConf.iFrameRate=aFrameRate;
601 // Set the camera configuration.
602 r=aCam.SetCamConfig(aCaptureMode,camConfBuf);
604 aCam.GetCamConfig(aCaptureMode, camConfBuf);
605 PrintCamConf(camConf,aTest);
607 // Create a chunk handle and trigger the buffer creation.
608 aTest.Next(_L("Setup the config - creating a chunk"));
610 TInt numBuffers=KNumVideoFramesToAllocate;
611 r=aCam.SetBufConfigChunkCreate(aCaptureMode,numBuffers,chunkVideo);
614 aTest.Next(_L("Read and display the resulting buffer config"));
615 TMmSharedChunkBufConfig bufferConfig;
616 TPckg<TMmSharedChunkBufConfig> bufferConfigBufVideo(bufferConfig);
617 aCam.GetBufferConfig(aCaptureMode, bufferConfigBufVideo);
618 PrintBufferConf(bufferConfig,aTest);
620 // Request and print the camera and buffer configurations for all three capture modes
621 aTest.Next(_L("Read and display the camera configs"));
622 aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
623 PrintCamConf(camConf,aTest);
624 aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
625 PrintCamConf(camConf,aTest);
626 aCam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
627 PrintCamConf(camConf,aTest);
629 // Create and configure a display handler
630 TCamDisplayHandler dispHand;
634 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
636 r=dispHand.SetConfig(aFrameSize,aPixelFormat);
640 // Test that stop still returns an error.
642 aTest(r==KErrGeneral);
644 // Set the current capture mode
645 r=aCam.SetCaptureMode(aCaptureMode);
648 aTest.Next(_L("Start the camera in video mode"));
652 aTest.Next(_L("Issue capture requests"));
653 aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
654 // Issue new image requests immediately. We'll have to wait while the
655 // camera captures the images.
656 TRequestStatus rs[KNumVideoFramesToCapture];
658 for (i=0 ; i<KNumVideoFramesToCapture; i++)
660 aTest.Printf(_L("Requesting new image... %d\n"), i);
661 aCam.NotifyNewImage(rs[i]);
662 aTest.Printf(_L("Requested new image... %d\n"), i);
667 for (i=0 ; i<KNumVideoFramesToCapture; i++)
669 aTest.Printf(_L("Waiting for... %d\n"), i);
670 User::WaitForRequest(rs[i]);
673 aTest.Printf(_L("Getting buffer offset for... %d\n"), i);
674 aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
675 aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset);
681 // Display each image received for 333ms
682 for (i=0 ; i<KNumVideoFramesToCapture; i++)
684 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
688 aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
690 imgBase=chunkVideo.Base()+retOffset;
691 r=dispHand.Process(imgBase);
694 aTest(r==KErrNotSupported);
699 User::After(333000); // 0.33sec
703 aTest.Next(_L("Free the buffers"));
704 for (i=0 ; i<KNumVideoFramesToCapture; i++)
706 aTest.Printf(_L("Releasing %d(i:%d) "),rs[i].Int(), i);
707 r=aCam.ReleaseBuffer(rs[i].Int());
708 aTest.Printf(_L("buffer(%d), r=%d\n"),rs[i].Int(),r);
712 aTest.Next(_L("Issue more capture requests"));
713 // Wait a bit more so camera has images ready as soon as we issue the requests
714 User::After(500000); // 0.5sec
716 aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
717 for (i=0 ; i<KNumVideoFramesToCapture; i++)
718 aCam.NotifyNewImage(rs[i]);
720 for (i=0 ; i<KNumVideoFramesToCapture; i++)
722 User::WaitForRequest(rs[i]);
725 aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
726 aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset);
730 aTest.Next(_L("Stop the camera."));
734 aTest.Next(_L("Start it again."));
738 aTest.Next(_L("Continuously display for 10 secs"));
741 TRequestStatus timStatus;
742 const TUint KTimeOut=10000000; // 10 seconds
743 tim.After(timStatus,KTimeOut);
744 aTest(timStatus==KRequestPending);
745 aCam.NotifyNewImage(rs[0]);
746 aCam.NotifyNewImage(rs[1]);
749 User::WaitForAnyRequest();
750 if (timStatus!=KRequestPending)
752 aCam.NotifyNewImageCancel();
753 User::WaitForRequest(rs[0]);
754 User::WaitForRequest(rs[1]);
757 else if (rs[0]!=KRequestPending)
761 aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
763 imgBase=chunkVideo.Base()+retOffset;
764 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
766 r=dispHand.Process(imgBase);
769 aTest(r==KErrNotSupported);
775 r=aCam.ReleaseBuffer(retId);
777 aCam.NotifyNewImage(rs[0]);
779 else if (rs[1]!=KRequestPending)
783 aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
785 imgBase=chunkVideo.Base()+retOffset;
786 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
788 r=dispHand.Process(imgBase);
791 aTest(r==KErrNotSupported);
797 r=aCam.ReleaseBuffer(retId);
799 aCam.NotifyNewImage(rs[1]);
807 aTest.Next(_L("Stop the camera."));
811 aTest.Next(_L("Close the chunk"));
812 r=aCam.ChunkClose(aCaptureMode);
815 LOCAL_C void DoCamImageCaptureTests(RDevCameraSc& aCam, RTest& aTest, TInt aCameraSensorIndex, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
819 aTest.Next(_L("IMAGE CAPTURE TESTS"));
820 aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
822 // Configure Image Capture
823 TCameraConfigV02Buf camConfBuf;
824 aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
825 TCameraConfigV02 &camConf=camConfBuf();
827 camConf.iFrameSize=aFrameSize;
828 camConf.iPixelFormat=aPixelFormat;
829 camConf.iFrameRate=aFrameRate;
831 // Set the camera configuration.
832 r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf);
834 aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
835 PrintCamConf(camConf,aTest);
837 // Create a chunk handle and trigger the buffer creation.
838 aTest.Next(_L("Setup the config - creating a chunk"));
840 TInt numBuffers=KNumVideoFramesToAllocate;
841 r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage);
844 aTest.Next(_L("Read and display the resulting buffer config"));
845 TMmSharedChunkBufConfig bufferConfig;
846 TPckg<TMmSharedChunkBufConfig> bufferConfigBufImage(bufferConfig);
847 aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage);
848 PrintBufferConf(bufferConfig,aTest);
850 // Create and configure a display handler
851 TCamDisplayHandler dispHand;
855 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
857 r=dispHand.SetConfig(aFrameSize,aPixelFormat);
861 // Test that stop still returns an error.
863 aTest(r==KErrGeneral);
865 // Set the current capture mode
866 r=aCam.SetCaptureMode(ECamCaptureModeImage);
869 aTest.Next(_L("Start the camera in image capture mode"));
873 aTest.Next(_L("Issue a capture request"));
875 aCam.NotifyNewImage(rs1);
876 User::WaitForRequest(rs1);
877 TInt retId=rs1.Int();
880 aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
881 aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
885 imgBase=chunkImage.Base()+retOffset;
887 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
889 // Display the image received for 1s
890 r=dispHand.Process(imgBase);
893 aTest(r==KErrNotSupported);
898 User::After(1000000); // 1 sec
901 // Save the to do MMC card with a filename to indicate its size. If no MMC card is present
902 // then we will just display a warning rather than fail as this is an optional manual step
903 TBuf<100> fileName(KSensor);
904 fileName.AppendNum(aCameraSensorIndex);
905 fileName.Append(KUnderscore);
906 fileName.AppendFormat(KFrameSize, aFrameSize.iWidth, aFrameSize.iHeight);
907 fileName.Append(KUnderscore);
908 AppendPixelFormat(fileName, aPixelFormat.iPixelFormat);
913 if ((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) || (aPixelFormat.iPixelFormat == EUidPixelFormatSpeedTaggedJPEG))
915 fileName.Append((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) ? KJpeg : KSpeedTaggedJpeg);
916 r=bitmap.WriteBuffer(fileName, imgBase, (aFrameSize.iWidth * aFrameSize.iHeight * aPixelFormat.iPixelWidthInBytes));
918 else if ((aPixelFormat.iPixelFormat == EUidPixelFormatYUV_422Interleaved) || (aPixelFormat.iPixelFormat == EUidPixelFormatRGB_565))
920 fileName.Append(KBmp);
921 r=bitmap.WriteBMP(fileName, imgBase, aPixelFormat, aFrameSize.iWidth, aFrameSize.iHeight);
932 aTest.Printf(_L("Wrote image to %S\n"),&fileName);
936 aTest.Printf(_L("Warning: Unable to write %S (error = %d)\r\n"),&fileName,r);
940 aTest.Next(_L("Free the buffer"));
941 r=aCam.ReleaseBuffer(retId);
944 aTest.Next(_L("Issue two consecutive capture requests"));
946 aCam.NotifyNewImage(rs1);
947 aCam.NotifyNewImage(rs2);
949 User::WaitForRequest(rs1);
952 aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
953 aTest.Printf(_L("Buffer0 offset: %d(%xH)\r\n"),retOffset,retOffset);
956 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
958 // Display the image received for 1s
959 imgBase=chunkImage.Base()+retOffset;
960 r=dispHand.Process(imgBase);
963 aTest(r==KErrNotSupported);
968 User::After(1000000); // 1 sec
971 r=aCam.ReleaseBuffer(retId);
974 User::WaitForRequest(rs2);
977 aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
978 aTest.Printf(_L("Buffer1 offset: %d(%xH)\r\n"),retOffset,retOffset);
981 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
983 // Display the image received for 1s
984 imgBase=chunkImage.Base()+retOffset;
985 r=dispHand.Process(imgBase);
988 aTest(r==KErrNotSupported);
993 User::After(1000000); // 1 sec
996 r=aCam.ReleaseBuffer(retId);
999 aTest.Next(_L("Issue four more separate capture requests"));
1000 for (TInt i=0 ; i<4 ; i++)
1002 aCam.NotifyNewImage(rs1);
1003 User::WaitForRequest(rs1);
1006 aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
1007 aTest.Printf(_L("Buffer%d offset: %d(%xH)\r\n"),i,retOffset,retOffset);
1008 aTest(retOffset>=0);
1010 if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
1012 // Display the image received for 1s
1013 imgBase=chunkImage.Base()+retOffset;
1014 r=dispHand.Process(imgBase);
1017 aTest(r==KErrNotSupported);
1022 User::After(1000000); // 1 sec
1026 r=aCam.ReleaseBuffer(retId);
1029 aTest.Next(_L("Stop the camera."));
1033 aTest.Next(_L("Close the chunk"));
1034 r=aCam.ChunkClose(ECamCaptureModeImage);
1038 LOCAL_C void DoCamCancelTests(RTest& aTest, TInt aCameraSensorIndex)
1041 SDevCamFrameSize* frameSizes;
1042 TCameraConfigV02Buf camConfBuf;
1044 aTest.Next(_L("CAPTURE CANCEL TESTS"));
1047 aTest.Next(_L("Open a channel on the camera driver"));
1048 r=cam.Open(aCameraSensorIndex);
1051 TInt numBuffers=KNumVideoFramesToAllocate;
1052 SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
1054 // Test Image Capture, if supported
1055 if (CameraCaps->iNumImagePixelFormats)
1057 // If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
1058 Test(pixelFormat->iNumFrameSizes > 0);
1059 frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
1060 Test(frameSizes != NULL);
1061 bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
1062 TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
1063 r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
1064 Test(r == KErrNone);
1066 cam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
1068 camConfBuf().iFrameSize=frameSizes[0];
1069 camConfBuf().iPixelFormat=*pixelFormat;
1070 camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
1072 // Set the camera configuration.
1073 r=cam.SetCamConfig(ECamCaptureModeImage, camConfBuf);
1075 cam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
1076 PrintCamConf(camConfBuf(), aTest);
1078 // Create a chunk handle and trigger the buffer creation.
1080 aTest.Next(_L("Setup the config - creating a chunk for image capture"));
1081 r=cam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage);
1084 aTest.Next(_L("Read and display the resulting buffer config"));
1085 TMmSharedChunkBufConfig bufferConfig;
1086 TPckg<TMmSharedChunkBufConfig> bufferConfigBufImage(bufferConfig);
1087 cam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage);
1088 PrintBufferConf(bufferConfig,aTest);
1090 // Set the current capture mode
1091 r=cam.SetCaptureMode(ECamCaptureModeImage);
1094 aTest.Next(_L("Start the camera in image capture mode."));
1098 TRequestStatus rs[KNumVideoFramesToCapture];
1099 TInt retId, retOffset;
1101 aTest.Next(_L("Issue a request and then cancel it"));
1102 cam.NotifyNewImage(rs[0]);
1103 cam.NotifyNewImageCancel();
1104 User::WaitForRequest(rs[0]);
1106 aTest(retId==KErrCancel || retId>=0);
1109 cam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
1110 aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
1111 aTest(retOffset>=0);
1112 cam.ReleaseBuffer(retId);
1115 aTest.Next(_L("Stop the camera."));
1119 aTest.Next(_L("Close the Image chunk"));
1122 delete [] frameSizes;
1125 // Skip past the image pixel formats
1126 pixelFormat += CameraCaps->iNumImagePixelFormats;
1128 // Test Video Capture, if supported
1129 if (CameraCaps->iNumVideoPixelFormats)
1131 // If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
1132 Test(pixelFormat->iNumFrameSizes > 0);
1133 frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
1134 Test(frameSizes != NULL);
1135 bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
1136 TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
1137 r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
1138 Test(r == KErrNone);
1140 cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
1142 camConfBuf().iFrameSize=frameSizes[0];
1143 camConfBuf().iPixelFormat=*pixelFormat;
1144 camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
1146 // Set the camera configuration.
1147 r=cam.SetCamConfig(ECamCaptureModeVideo, camConfBuf);
1149 cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
1150 PrintCamConf(camConfBuf(), aTest);
1152 // Create a chunk handle and trigger the buffer creation.
1154 aTest.Next(_L("Setup the config - creating a chunk for video capture"));
1155 r=cam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo);
1158 aTest.Next(_L("Read and display the resulting buffer config"));
1159 TMmSharedChunkBufConfig bufferConfig;
1160 TPckg<TMmSharedChunkBufConfig> bufferConfigBufVideo(bufferConfig);
1161 cam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBufVideo);
1162 PrintBufferConf(bufferConfig,aTest);
1164 // Set the current capture mode
1165 r=cam.SetCaptureMode(ECamCaptureModeVideo);
1168 aTest.Next(_L("Start the camera in video mode"));
1172 aTest.Next(_L("Issue capture requests and globally cancel them all"));
1173 aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
1174 TRequestStatus rs[KNumVideoFramesToCapture];
1176 for (i=0 ; i<KNumVideoFramesToCapture; i++)
1177 cam.NotifyNewImage(rs[i]);
1179 cam.NotifyNewImageCancel();
1181 TInt retOffset = -2;
1183 for (i=0 ; i<KNumVideoFramesToCapture; i++)
1185 User::WaitForRequest(rs[i]);
1187 aTest(retId==KErrCancel || retId>=0);
1190 cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset);
1191 aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
1192 aTest(retOffset>=0);
1193 cam.ReleaseBuffer(retId);
1197 aTest.Next(_L("Issue capture requests and individually cancel them all"));
1198 aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
1200 for (i=0 ; i<KNumVideoFramesToCapture; i++)
1201 cam.NotifyNewImage(rs[i]);
1203 for (i=0 ; i<KNumVideoFramesToCapture; i++)
1204 cam.NotifyNewImageCancel(rs[i]);
1206 for (i=0 ; i<KNumVideoFramesToCapture; i++)
1208 User::WaitForRequest(rs[i]);
1210 aTest(retId==KErrCancel || retId>=0);
1213 cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset);
1214 aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
1215 aTest(retOffset>=0);
1216 cam.ReleaseBuffer(retId);
1220 aTest.Next(_L("Stop the camera."));
1224 aTest.Next(_L("Close the Video chunk"));
1227 delete [] frameSizes;
1230 // Skip past the video pixel formats
1231 pixelFormat += CameraCaps->iNumVideoPixelFormats;
1233 // Test Viewfinder Capture, if supported
1234 if (CameraCaps->iNumViewFinderPixelFormats)
1236 // If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
1237 Test(pixelFormat->iNumFrameSizes > 0);
1238 frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
1239 Test(frameSizes != NULL);
1240 bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
1241 TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
1242 r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf);
1243 Test(r == KErrNone);
1245 cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
1247 camConfBuf().iFrameSize=frameSizes[0];
1248 camConfBuf().iPixelFormat=*pixelFormat;
1249 camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
1251 // Set the camera configuration.
1252 r=cam.SetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
1254 cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
1255 PrintCamConf(camConfBuf(), aTest);
1257 // Create a chunk handle and trigger the buffer creation.
1258 RChunk chunkViewFinder;
1259 aTest.Next(_L("Setup the config - creating a chunk for viewfinder capture"));
1260 r=cam.SetBufConfigChunkCreate(ECamCaptureModeViewFinder,numBuffers,chunkViewFinder);
1263 aTest.Next(_L("Read and display the resulting buffer config"));
1264 TMmSharedChunkBufConfig bufferConfig;
1265 TPckg<TMmSharedChunkBufConfig> bufferConfigBufViewFinder(bufferConfig);
1266 cam.GetBufferConfig(ECamCaptureModeViewFinder, bufferConfigBufViewFinder);
1267 PrintBufferConf(bufferConfig,aTest);
1269 aTest.Next(_L("Close the Viewfinder chunk"));
1270 chunkViewFinder.Close();
1272 delete [] frameSizes;
1275 aTest.Next(_L("Close the drivers"));
1279 void CameraTests(TInt aCameraSensorIndex)
1282 Test.Printf(_L("Testing unit number: %d\r\n"),aCameraSensorIndex);
1284 // Perform some basic opening and multithreaded tests. We don't want just in time debugging during
1286 TBool justInTime=User::JustInTime();
1287 User::SetJustInTime(EFalse);
1288 DoCamOpenCapTests(Test,aCameraSensorIndex);
1289 User::SetJustInTime(justInTime);
1291 // Test request handling
1292 DoCamCancelTests(Test, aCameraSensorIndex);
1294 // Re-open the camera driver for use below and to ensure that it can deal with being re-opened (it
1295 // has already been opened and closed by DoCamOpenCapTests())
1297 Test.Next(_L("Open a channel on the camera driver"));
1298 TInt r=cam.Open(aCameraSensorIndex);
1301 // Test Dynamic Settings, e.g. Brightness, Contrast, etc.
1302 DoCamDynamicSettingsTests(cam, Test);
1304 // Go through all supported image, video and viewfinder pixel formats and perform configuration
1305 // and capture tests on them all, for all supported frame sizes and frame rates
1307 SDevCamFrameSize* frameSizes;
1308 TBool imageConfigTestsDone=EFalse, videoConfigTestsDone=EFalse, viewFinderConfigTestsDone=EFalse;
1309 SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
1311 for (index = 0; index < CameraCaps->iNumImagePixelFormats; ++index)
1313 // If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
1314 Test(pixelFormat->iNumFrameSizes > 0);
1315 Test.Printf(_L("Image pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
1316 frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
1317 Test(frameSizes!=NULL);
1318 bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
1319 TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
1320 r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
1321 Test(r == KErrNone);
1323 // Test camera configuration for image capture. This is only done once for the sake of
1325 if (!imageConfigTestsDone)
1327 imageConfigTestsDone = ETrue;
1328 DoCamConfigTests(cam, Test, ECamCaptureModeImage, *pixelFormat, frameSizes[0]);
1331 // Test image capture mode
1332 for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
1334 DoCamImageCaptureTests(cam, Test, aCameraSensorIndex, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
1337 // Test buffer offset
1338 for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
1340 DoCamBufferOffsetTests(cam, Test, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
1343 delete [] frameSizes;
1347 for (index = 0; index < CameraCaps->iNumVideoPixelFormats; ++index)
1349 // If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
1350 Test(pixelFormat->iNumFrameSizes > 0);
1351 Test.Printf(_L("Video pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
1352 frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
1353 Test(frameSizes!=NULL);
1354 bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
1355 TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
1356 r = cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizesBuf);
1357 Test(r == KErrNone);
1359 // Test camera configuration for video capture. This is only done once for the sake of
1361 if (!videoConfigTestsDone)
1363 videoConfigTestsDone=ETrue;
1364 DoCamConfigTests(cam, Test, ECamCaptureModeVideo, *pixelFormat, frameSizes[0]);
1367 // Test video capture mode
1368 for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
1370 DoCamVideoCaptureTests(cam, Test, ECamCaptureModeVideo, *pixelFormat,frameSizes[size], frameSizes[size].iMaxFrameRate);
1372 delete [] frameSizes;
1376 for (index = 0; index < CameraCaps->iNumViewFinderPixelFormats; ++index)
1378 // If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
1379 Test(pixelFormat->iNumFrameSizes > 0);
1380 Test.Printf(_L("Viewfinder pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
1381 frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
1382 Test(frameSizes!=NULL);
1383 bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
1384 TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
1385 r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf);
1386 Test(r == KErrNone);
1388 // Test camera configuration for view finder capture. This is only done once for the sake of
1390 if (!viewFinderConfigTestsDone)
1392 viewFinderConfigTestsDone=ETrue;
1393 DoCamConfigTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[0]);
1396 // Test view finder capture mode
1397 for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
1399 DoCamVideoCaptureTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
1401 delete [] frameSizes;
1406 // And free the global capabilities buffer that was allocated in DoCamOpenCapTests()
1407 User::Free(CapsBufPtr);
1410 GLDEF_C TInt E32Main()
1415 Test.Start(_L("Camera module API test"));
1417 Test.Next(_L("Loading CAMERA PDD"));
1418 TInt r=User::LoadPhysicalDevice(KCamPddFileName);
1419 Test.Printf(_L("Returned %d\r\n"),r);
1421 if (r==KErrNotFound)
1423 Test.Printf(_L("Shared chunk camera driver not supported - test skipped\r\n"));
1430 Test(r==KErrNone || r==KErrAlreadyExists);
1432 Test.Next(_L("Loading CAMERA LDD"));
1433 r=User::LoadLogicalDevice(KCamLddFileName);
1434 Test.Printf(_L("Returned %d\r\n"),r);
1435 Test(r==KErrNone || r==KErrAlreadyExists);
1437 Test.Next(_L("Loading D_MMCSC LDD"));
1438 r=User::LoadLogicalDevice(KTstLddFileName);
1439 Test.Printf(_L("Returned %d\r\n"),r);
1440 Test(r==KErrNone||r==KErrAlreadyExists);
1444 if (User::CommandLineLength()>0)
1447 TInt moduleIndex = KUnit0;
1448 User::CommandLine(cmd);
1449 Test(cmd.Length()>0);
1450 if (cmd[0]>='0' && cmd[0]<='9')
1451 moduleIndex=(TInt)(cmd[0]-'0');
1452 CameraTests(moduleIndex);
1454 else // If no command line arguments are passed we perform tests on the module 0 and 1
1461 // Free the PDDs and LDDs
1462 Test.Next(_L("Freeing ECAMERASC LDD"));
1463 r=User::FreeLogicalDevice(KDevCameraScName);
1466 Test.Next(_L("Freeing CAMERASC PDD"));
1467 TFindPhysicalDevice fDr;
1470 searchName.Append(KDevCameraScName);
1471 searchName.Append(KCamFreePddExtension);
1472 fDr.Find(searchName);
1473 r=fDr.Next(drivName);
1475 r=User::FreePhysicalDevice(drivName);
1478 Test.Next(_L("Freeing D_MMCSC LDD"));
1479 r=User::FreeLogicalDevice(KDevMmCScName);