sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\multimedia\t_camera_api.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_camera_display.h" sl@0: #include "t_camera_bitmap.h" sl@0: #include "d_mmcsc.h" sl@0: sl@0: _LIT(KTstLddFileName,"D_MMCSC.LDD"); sl@0: _LIT(KCamLddFileName,"ECAMERASC.LDD"); sl@0: sl@0: #ifdef __WINSCW__ sl@0: _LIT(KCamPddFileName,"_TEMPLATE_CAMERASC.PDD"); sl@0: #else sl@0: _LIT(KCamPddFileName,"CAMERASC.PDD"); sl@0: #endif sl@0: sl@0: sl@0: _LIT(KCamFreePddExtension,".*"); sl@0: sl@0: _LIT(KFrameSize, "%dx%d"); sl@0: _LIT(KSensor, "d:\\Sensor_"); sl@0: _LIT(KUnderscore, "_"); sl@0: _LIT(KBmp, ".bmp"); sl@0: _LIT(KJpeg, ".jpg"); sl@0: _LIT(KSpeedTaggedJpeg, ".stj"); sl@0: sl@0: LOCAL_D TCameraCapsV02* CameraCaps; sl@0: LOCAL_D TInt CapsSize; sl@0: LOCAL_D TAny* CapsBufPtr; sl@0: RTest Test(_L("T_CAMERA_API")); sl@0: sl@0: const TInt KNumVideoFramesToAllocate=6; sl@0: const TInt KNumVideoFramesToCapture=(KNumVideoFramesToAllocate-2); sl@0: const TInt KHeapSize=0x4000; sl@0: const TInt KUnit0=0; sl@0: sl@0: enum TSecThreadTestId sl@0: { sl@0: ESecThreadTestOpen, sl@0: ESecThreadTestDuplicateHandle, sl@0: ESecThreadReuseHandle sl@0: }; sl@0: sl@0: struct SSecondaryThreadInfo sl@0: { sl@0: TSecThreadTestId iTestId; sl@0: TInt iExpectedRetVal; sl@0: TThreadId iThreadId; sl@0: TInt iDrvHandle; sl@0: TInt iCameraModuleIndex; sl@0: }; sl@0: sl@0: LOCAL_C TInt secondaryThread(TAny* aTestInfo) sl@0: { sl@0: RTest stest(_L("Secondary test camera thread")); sl@0: stest.Title(); sl@0: sl@0: stest.Start(_L("Check which test to perform")); sl@0: SSecondaryThreadInfo sti =*((SSecondaryThreadInfo*)aTestInfo); sl@0: sl@0: TInt r; sl@0: switch(sti.iTestId) sl@0: { sl@0: case ESecThreadTestOpen: sl@0: { sl@0: stest.Next(_L("Open channel test")); sl@0: RDevCameraSc cam; sl@0: r=cam.Open(sti.iCameraModuleIndex); sl@0: stest(r==sti.iExpectedRetVal); sl@0: cam.Close(); sl@0: break; sl@0: } sl@0: case ESecThreadTestDuplicateHandle: sl@0: { sl@0: stest.Next(_L("Duplicate channel handle test")); sl@0: sl@0: // Get a reference to the main thread - which created the handle sl@0: RThread thread; sl@0: r=thread.Open(sti.iThreadId); sl@0: stest(r==KErrNone); sl@0: sl@0: // Duplicate the driver handle passed from the other thread - for this thread sl@0: RDevCameraSc cam; sl@0: cam.SetHandle(sti.iDrvHandle); sl@0: r=cam.Duplicate(thread); sl@0: stest(r==sti.iExpectedRetVal); sl@0: cam.Close(); sl@0: thread.Close(); sl@0: break; sl@0: } sl@0: case ESecThreadReuseHandle: sl@0: { sl@0: stest.Next(_L("Re-use channel test")); sl@0: RDevCameraSc* camPtr=(RDevCameraSc*)sti.iDrvHandle; sl@0: TCameraConfigV02Buf camConfBuf; sl@0: camPtr->GetCamConfig(ECamCaptureModeImage, camConfBuf); // This should cause a panic. sl@0: break; sl@0: } sl@0: default: sl@0: break; sl@0: } sl@0: sl@0: stest.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Test for defect DEF135950. */ sl@0: LOCAL_C void DoCamDynamicSettingsTests(RDevCameraSc& aCam, RTest& aTest) sl@0: { sl@0: aTest.Next(_L("DYNAMIC SETTINGS TESTS")); sl@0: sl@0: aTest.Next(_L("Get the Caps size. Should be non-zero")); sl@0: TInt capsSize = aCam.CapsSize(); sl@0: aTest(capsSize>0); sl@0: sl@0: aTest.Next(_L("Get the Capabilities (driver owned copy).")); sl@0: TPtrC8 driverCopy = aCam.Caps(); sl@0: aTest(driverCopy.Ptr() != NULL); sl@0: aTest(driverCopy.Length()>0); sl@0: sl@0: aTest.Next(_L("Test failure (buffer too small).")); sl@0: TAny* capsBufPtr = User::Alloc(capsSize-1); sl@0: aTest(capsBufPtr != NULL); sl@0: TPtr8 smallBuf((TUint8*) capsBufPtr, capsSize-1, capsSize-1); sl@0: aTest(KErrArgument==aCam.Caps(smallBuf)); sl@0: User::Free(capsBufPtr); sl@0: sl@0: aTest.Next(_L("Get the Capabilities (client owned copy).")); sl@0: capsBufPtr = User::Alloc(capsSize); sl@0: aTest(capsBufPtr != NULL); sl@0: TPtr8 clientCopy((TUint8*) capsBufPtr, capsSize, capsSize); sl@0: aTest(KErrNone==aCam.Caps(clientCopy)); sl@0: aTest(clientCopy.Ptr() != NULL); sl@0: aTest(clientCopy.Length()>0); sl@0: sl@0: aTest.Next(_L("Obtain the range for Dynamic Settings from both copies (should be the same).")); sl@0: sl@0: TDynamicRange &driverRangeBrightness = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness]; sl@0: TDynamicRange &clientRangeBrightness = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness]; sl@0: sl@0: aTest(driverRangeBrightness.iMin == 0); sl@0: aTest(driverRangeBrightness.iMax == 6); sl@0: aTest(driverRangeBrightness.iMin == clientRangeBrightness.iMin); sl@0: aTest(driverRangeBrightness.iMax == clientRangeBrightness.iMax); sl@0: sl@0: TDynamicRange &driverRangeContrast = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeContrast]; sl@0: TDynamicRange &clientRangeContrast = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeContrast]; sl@0: sl@0: aTest(driverRangeContrast.iMin == 0); sl@0: aTest(driverRangeContrast.iMax == 6); sl@0: aTest(driverRangeContrast.iMin == clientRangeContrast.iMin); sl@0: aTest(driverRangeContrast.iMax == clientRangeContrast.iMax); sl@0: sl@0: TDynamicRange &driverRangeColorEffect = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect]; sl@0: TDynamicRange &clientRangeColorEffect = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect]; sl@0: sl@0: aTest(driverRangeColorEffect.iMin == 0); sl@0: aTest(driverRangeColorEffect.iMax == 7); // TBC::OV3640 set to 7, template driver set to 0x0040 (enum) sl@0: aTest(driverRangeColorEffect.iMin == clientRangeColorEffect.iMin); sl@0: aTest(driverRangeColorEffect.iMax == clientRangeColorEffect.iMax); sl@0: sl@0: aTest.Next(_L("Test for invalid Min range.")); sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMin-1)==KErrArgument); sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMin-1)==KErrArgument); sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMin-1)==KErrArgument); sl@0: sl@0: aTest.Next(_L("Test for invalid Max range.")); sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMax+1)==KErrArgument); sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMax+1)==KErrArgument); sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMax+1)==KErrArgument); sl@0: sl@0: aTest.Next(_L("Test all valid settings as reported by range - Brightness")); sl@0: for (TUint i=driverRangeBrightness.iMin; i <= driverRangeBrightness.iMax; ++i) sl@0: { sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, i)==KErrNone); sl@0: } sl@0: sl@0: aTest.Next(_L("Test all valid settings as reported by range - Contrast")); sl@0: for (TUint j=driverRangeContrast.iMin; j <= driverRangeContrast.iMax; ++j) sl@0: { sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, j)==KErrNone); sl@0: } sl@0: sl@0: aTest.Next(_L("Test all valid settings as reported by range - ColorEffect")); sl@0: for (TUint k=driverRangeColorEffect.iMin; k <= driverRangeColorEffect.iMax; ++k) sl@0: { sl@0: aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, k)==KErrNone); sl@0: } sl@0: sl@0: User::Free(capsBufPtr); sl@0: } sl@0: sl@0: /** Test for defect DEF135949. */ sl@0: LOCAL_C void DoCamBufferOffsetTests(RDevCameraSc& aCam, RTest& aTest, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate) sl@0: { sl@0: TInt r; sl@0: sl@0: aTest.Next(_L("BUFFER ID OFFSET TESTS")); sl@0: aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight); sl@0: sl@0: // Configure Image Capture sl@0: aTest.Next(_L("Get the camera config of Image mode")); sl@0: TCameraConfigV02Buf camConfBuf; sl@0: aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: TCameraConfigV02 &camConf=camConfBuf(); sl@0: sl@0: camConf.iFrameSize=aFrameSize; sl@0: camConf.iPixelFormat=aPixelFormat; sl@0: camConf.iFrameRate=aFrameRate; sl@0: sl@0: // Set the Image configuration. sl@0: aTest.Next(_L("Set the Get the camera config of Image mode")); sl@0: r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf); sl@0: aTest(r==KErrNone); sl@0: aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: sl@0: // Create an Image chunk handle. sl@0: aTest.Next(_L("Create the Image chunk")); sl@0: RChunk imgChunkImage; sl@0: TInt numBuffers=KNumVideoFramesToAllocate; sl@0: r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,imgChunkImage); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the Image buffer config")); sl@0: TMmSharedChunkBufConfig bufferConfig; sl@0: TPckg bufferConfigBuf(bufferConfig); sl@0: aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: // Configure Video Capture sl@0: aTest.Next(_L("Get the camera config of Video mode")); sl@0: aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf); sl@0: camConf=camConfBuf(); sl@0: sl@0: camConf.iFrameSize=aFrameSize; sl@0: camConf.iPixelFormat=aPixelFormat; sl@0: camConf.iFrameRate=aFrameRate; sl@0: sl@0: // Set the video configuration. sl@0: aTest.Next(_L("Set the Get the camera config of Video mode")); sl@0: r=aCam.SetCamConfig(ECamCaptureModeVideo,camConfBuf); sl@0: aTest(r==KErrNone); sl@0: aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: sl@0: // Create an Video chunk handle. sl@0: aTest.Next(_L("Create the Video chunk")); sl@0: RChunk chunkVideo; sl@0: numBuffers=KNumVideoFramesToAllocate; sl@0: r=aCam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the Video buffer config")); sl@0: aCam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: // Test that stop still returns an error. sl@0: r=aCam.Stop(); sl@0: aTest(r==KErrGeneral); sl@0: sl@0: // Set the current capture mode to image sl@0: aTest.Next(_L("Set the camera in Image mode and capture a buffer, then requesting the buffer offset.")); sl@0: r=aCam.SetCaptureMode(ECamCaptureModeImage); sl@0: aTest(r==KErrNone); sl@0: sl@0: // Start the camera sl@0: r=aCam.Start(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Issue a capture request")); sl@0: TRequestStatus rs1; sl@0: aCam.NotifyNewImage(rs1); sl@0: User::WaitForRequest(rs1); sl@0: TInt retId=rs1.Int(); sl@0: TInt retOffset=-1; sl@0: aTest(retId>=0); sl@0: aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset); sl@0: aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: sl@0: // Change capture mode sl@0: aTest.Next(_L("Set the capture mode to Video.")); sl@0: r=aCam.SetCaptureMode(ECamCaptureModeVideo); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Request again the offset for the buffer in Image mode.")); sl@0: aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset); sl@0: aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: sl@0: // Stop the camera. sl@0: r=aCam.Stop(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Close the chunk")); sl@0: r=aCam.ChunkClose(ECamCaptureModeImage); sl@0: aTest(r==KErrNone); sl@0: r=aCam.ChunkClose(ECamCaptureModeVideo); sl@0: aTest(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void DoCamOpenCapTests(RTest& aTest,TInt aCameraSensorIndex) sl@0: { sl@0: TInt r; sl@0: sl@0: // Open the camera driver to obtain the basic capabilities for use throughout the tests and sl@0: // then close it again so that it may be confirmed that opening multiple times is ok sl@0: aTest.Next(_L("CHANNEL OPEN AND CAPABILITIES TESTS")); sl@0: RDevCameraSc cam; sl@0: aTest.Next(_L("Open a channel on the camera driver")); sl@0: r=cam.Open(aCameraSensorIndex); sl@0: aTest(r==KErrNone); sl@0: sl@0: // Make sure that the driver can handle attempts to start it before it has been configured sl@0: aTest.Next(_L("Try to start/stop camera before its configured")); sl@0: r=cam.Start(); sl@0: aTest(r==KErrNotReady); sl@0: r=cam.Stop(); sl@0: aTest(r==KErrGeneral); sl@0: sl@0: aTest.Next(_L("Read the capabilities structure size of this device")); sl@0: CapsSize=cam.CapsSize(); sl@0: aTest.Next(_L("Read and display the capabilities of this device")); sl@0: CapsBufPtr = User::Alloc(CapsSize); sl@0: TPtr8 capsPtr( (TUint8*)CapsBufPtr, CapsSize, CapsSize ); sl@0: r=cam.Caps(capsPtr); sl@0: aTest(r==KErrNone); sl@0: CameraCaps = (TCameraCapsV02*) capsPtr.Ptr(); sl@0: PrintCamModes(CameraCaps,aTest); sl@0: sl@0: TAny* frameSizeCapsBuf; sl@0: SDevCamPixelFormat* pixelFormat; sl@0: TBuf<80> buf; sl@0: SDevCamFrameSize* frameSize; sl@0: TPtr8 frameSizeCapsPtr(0,0,0); sl@0: TUint fsCount, pfCount, theCount = 0; sl@0: sl@0: /* IMAGE */ sl@0: /* Use pixel formats from 0 to CapsBuf->iNumImagePixelFormats */ sl@0: buf.Zero(); sl@0: buf.Append(KCaptureModeImage); sl@0: buf.Append(_L("\r\n")); sl@0: aTest.Printf(buf); sl@0: pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1); sl@0: for (pfCount = theCount; pfCount < CameraCaps->iNumImagePixelFormats; pfCount++) sl@0: { sl@0: buf.Zero(); sl@0: AppendPixelFormat(buf, pixelFormat->iPixelFormat); sl@0: aTest.Printf(buf); sl@0: frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize)); sl@0: new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize)); sl@0: r=cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizeCapsPtr); sl@0: aTest(r==KErrNone); sl@0: frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr(); sl@0: for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++) sl@0: { sl@0: aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight); sl@0: frameSize++; sl@0: } sl@0: aTest.Printf(_L("\n")); sl@0: User::Free(frameSizeCapsBuf); sl@0: pixelFormat++; sl@0: } sl@0: sl@0: /* VIDEO */ sl@0: buf.Zero(); sl@0: buf.Append(KCaptureModeVideo); sl@0: buf.Append(_L("\r\n")); sl@0: aTest.Printf(buf); sl@0: pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1); sl@0: pixelFormat += CameraCaps->iNumImagePixelFormats; sl@0: theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats; sl@0: for (pfCount = CameraCaps->iNumImagePixelFormats; pfCount < theCount; pfCount++) sl@0: { sl@0: buf.Zero(); sl@0: AppendPixelFormat(buf, pixelFormat->iPixelFormat); sl@0: aTest.Printf(buf); sl@0: frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize)); sl@0: new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize)); sl@0: r=cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizeCapsPtr); sl@0: aTest(r==KErrNone); sl@0: frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr(); sl@0: for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++) sl@0: { sl@0: aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight); sl@0: frameSize++; sl@0: } sl@0: aTest.Printf(_L("\n")); sl@0: User::Free(frameSizeCapsBuf); sl@0: pixelFormat++; sl@0: } sl@0: sl@0: /* VIEW FINDER */ sl@0: buf.Zero(); sl@0: buf.Append(KCaptureModeViewFinder); sl@0: buf.Append(_L("\r\n")); sl@0: aTest.Printf(buf); sl@0: pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1); sl@0: pixelFormat += (CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats); sl@0: theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats + CameraCaps->iNumViewFinderPixelFormats; sl@0: for (pfCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats; pfCount < theCount; pfCount++) sl@0: { sl@0: buf.Zero(); sl@0: AppendPixelFormat(buf, pixelFormat->iPixelFormat); sl@0: aTest.Printf(buf); sl@0: frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize)); sl@0: new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize)); sl@0: r=cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizeCapsPtr); sl@0: aTest(r==KErrNone); sl@0: frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr(); sl@0: for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++) sl@0: { sl@0: aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight); sl@0: frameSize++; sl@0: } sl@0: aTest.Printf(_L("\n")); sl@0: User::Free(frameSizeCapsBuf); sl@0: pixelFormat++; sl@0: } sl@0: sl@0: aTest.Next(_L("Try opening the same unit a second time.")); sl@0: RDevCameraSc cam2; sl@0: r=cam2.Open(aCameraSensorIndex); sl@0: aTest(r==KErrInUse); sl@0: sl@0: aTest.Next(_L("Open a channel from the 2nd thread without closing the 1st")); sl@0: RThread thread; sl@0: TRequestStatus stat; sl@0: SSecondaryThreadInfo sti; sl@0: sl@0: // Setup the 2nd thread to open a channel on the same unit sl@0: sti.iTestId=ESecThreadTestOpen; sl@0: sti.iExpectedRetVal=KErrInUse; sl@0: sti.iCameraModuleIndex=aCameraSensorIndex; sl@0: r=thread.Create(_L("Thread"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); sl@0: Test(r==KErrNone); sl@0: thread.Logon(stat); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: Test(stat.Int()==KErrNone); sl@0: Test(thread.ExitType()==EExitKill); sl@0: thread.Close(); sl@0: User::After(10000); // Wait 10ms sl@0: sl@0: aTest.Next(_L("Open a channel from the 2nd thread having closed the 1st")); sl@0: cam.Close(); // Close the 1st channel sl@0: sti.iTestId=ESecThreadTestOpen; sl@0: sti.iExpectedRetVal=KErrNone; sl@0: r=thread.Create(_L("Thread02"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); sl@0: Test(r==KErrNone); sl@0: thread.Logon(stat); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: Test(stat.Int()==KErrNone); sl@0: Test(thread.ExitType()==EExitKill); sl@0: thread.Close(); sl@0: User::After(10000); // Wait 10ms sl@0: sl@0: aTest.Next(_L("Re-open channel and duplicate it from 2nd thread")); sl@0: r=cam.Open(aCameraSensorIndex); // Re-open the channel sl@0: aTest(r==KErrNone); sl@0: sti.iTestId=ESecThreadTestDuplicateHandle; sl@0: sti.iExpectedRetVal=KErrAccessDenied; sl@0: sti.iThreadId=RThread().Id(); // Get the ID of this thread sl@0: sti.iDrvHandle=cam.Handle(); // Pass the channel handle sl@0: sl@0: r=thread.Create(_L("Thread03"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread sl@0: Test(r==KErrNone); sl@0: thread.Logon(stat); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: Test(stat.Int()==KErrNone); sl@0: Test(thread.ExitType()==EExitKill); sl@0: thread.Close(); sl@0: User::After(10000); // Wait 10ms sl@0: sl@0: aTest.Next(_L("Re-use the same channel from 2nd thread")); sl@0: sti.iTestId=ESecThreadReuseHandle; sl@0: sti.iDrvHandle=(TInt)&cam; // Pass a pointer to the channel sl@0: r=thread.Create(_L("Thread04"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread sl@0: Test(r==KErrNone); sl@0: thread.Logon(stat); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: TExitCategoryName exitCategoryName = thread.ExitCategory(); sl@0: Test.Printf(_L("Thread exit info: Cat:%S, Reason:%x, Type:%d\r\n"),&exitCategoryName,thread.ExitReason(),thread.ExitType()); sl@0: Test(thread.ExitType()==EExitPanic); // Secondary thread is expected to panic sl@0: Test(stat.Int()==KErrNone); sl@0: thread.Close(); sl@0: User::After(10000); // Wait 10ms sl@0: sl@0: cam.Close(); sl@0: } sl@0: sl@0: LOCAL_C void DoCamConfigTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize) sl@0: { sl@0: TInt r; sl@0: sl@0: aTest.Next(_L("GETTING & SETTING CONFIG TESTS")); sl@0: aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight); sl@0: sl@0: aTest.Next(_L("Read and display the default camera config for requested capture mode")); sl@0: TCameraConfigV02Buf camConfBuf; sl@0: aCam.GetCamConfig(aCaptureMode, camConfBuf); sl@0: TCameraConfigV02 &camConf=camConfBuf(); sl@0: PrintCamConf(camConf,aTest); sl@0: sl@0: aTest.Next(_L("Read and display the default buffer config for requested capture mode")); sl@0: TMmSharedChunkBufConfig bufferConfig; sl@0: TPckg bufferConfigBuf(bufferConfig); sl@0: aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: aTest.Next(_L("Setup the config - creating a chunk")); sl@0: camConf.iFrameSize=aFrameSize; sl@0: camConf.iPixelFormat=aPixelFormat; sl@0: camConf.iFrameRate=aFrameSize.iMaxFrameRate; sl@0: r=aCam.SetCamConfig(aCaptureMode, camConfBuf); sl@0: aTest(r==KErrNone); sl@0: RChunk chunk; sl@0: r=aCam.SetBufConfigChunkCreate(aCaptureMode, KNumVideoFramesToAllocate, chunk); sl@0: aTest(r==KErrNone); sl@0: aCam.GetCamConfig(aCaptureMode, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: sl@0: aTest.Next(_L("Read and display the resulting buffer config")); sl@0: aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: aTest.Next(_L("Close the chunk created")); sl@0: chunk.Close(); sl@0: sl@0: aTest.Next(_L("Open a channel on the test driver")); sl@0: RMmCreateSc tstDrv; sl@0: r=tstDrv.Open(); // Opening the channel results in the creation of a shared chunk. sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Get a handle on its shared chunk")); sl@0: r=tstDrv.GetChunkHandle(chunk); // Get a handle on the shared chunk created by the test driver sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the buffer config")); sl@0: TMmSharedChunkBufConfig bufferConfigTest; sl@0: TPckg bufferConfigBufTest(bufferConfigTest); sl@0: sl@0: // Get info on the buffers within the shared chunk sl@0: aTest.Next(_L("Get info. on the shared chunk")); sl@0: r=tstDrv.GetBufInfo(bufferConfigBufTest); sl@0: aTest(r==KErrNone); sl@0: sl@0: PrintBufferConf(bufferConfigTest,aTest); sl@0: aTest.Next(_L("Setup the config - supplying a chunk")); sl@0: r=aCam.SetBufConfigChunkOpen(aCaptureMode, bufferConfigBufTest, chunk); sl@0: aTest(r==KErrNone); sl@0: aCam.GetCamConfig(aCaptureMode, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: aCam.GetBufferConfig(aCaptureMode, bufferConfigBufTest); sl@0: PrintBufferConf(bufferConfigTest,aTest); sl@0: sl@0: aTest.Next(_L("Close the chunk driver and the 2nd chunk")); sl@0: tstDrv.Close(); sl@0: chunk.Close(); sl@0: } sl@0: sl@0: LOCAL_C void DoCamVideoCaptureTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate) sl@0: { sl@0: TInt r; sl@0: sl@0: aTest.Next(_L("VIDEO CAPTURE TESTS")); sl@0: aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight); sl@0: sl@0: // Configure Video or Viewfinder Capture sl@0: TCameraConfigV02Buf camConfBuf; sl@0: aCam.GetCamConfig(aCaptureMode, camConfBuf); sl@0: TCameraConfigV02 &camConf=camConfBuf(); sl@0: sl@0: camConf.iFrameSize=aFrameSize; sl@0: camConf.iPixelFormat=aPixelFormat; sl@0: camConf.iFrameRate=aFrameRate; sl@0: sl@0: // Set the camera configuration. sl@0: r=aCam.SetCamConfig(aCaptureMode,camConfBuf); sl@0: aTest(r==KErrNone); sl@0: aCam.GetCamConfig(aCaptureMode, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: sl@0: // Create a chunk handle and trigger the buffer creation. sl@0: aTest.Next(_L("Setup the config - creating a chunk")); sl@0: RChunk chunkVideo; sl@0: TInt numBuffers=KNumVideoFramesToAllocate; sl@0: r=aCam.SetBufConfigChunkCreate(aCaptureMode,numBuffers,chunkVideo); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the resulting buffer config")); sl@0: TMmSharedChunkBufConfig bufferConfig; sl@0: TPckg bufferConfigBufVideo(bufferConfig); sl@0: aCam.GetBufferConfig(aCaptureMode, bufferConfigBufVideo); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: // Request and print the camera and buffer configurations for all three capture modes sl@0: aTest.Next(_L("Read and display the camera configs")); sl@0: aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: aCam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: sl@0: // Create and configure a display handler sl@0: TCamDisplayHandler dispHand; sl@0: r=dispHand.Init(); sl@0: aTest(r==KErrNone); sl@0: sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: r=dispHand.SetConfig(aFrameSize,aPixelFormat); sl@0: aTest(r==KErrNone); sl@0: } sl@0: sl@0: // Test that stop still returns an error. sl@0: r=aCam.Stop(); sl@0: aTest(r==KErrGeneral); sl@0: sl@0: // Set the current capture mode sl@0: r=aCam.SetCaptureMode(aCaptureMode); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Start the camera in video mode")); sl@0: r=aCam.Start(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Issue capture requests")); sl@0: aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture); sl@0: // Issue new image requests immediately. We'll have to wait while the sl@0: // camera captures the images. sl@0: TRequestStatus rs[KNumVideoFramesToCapture]; sl@0: TInt i; sl@0: for (i=0 ; i=0); sl@0: aTest.Printf(_L("Getting buffer offset for... %d\n"), i); sl@0: aCam.BufferIdToOffset(aCaptureMode,retId,retOffset); sl@0: aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset); sl@0: aTest(retOffset>=0); sl@0: } sl@0: sl@0: TUint8* imgBase; sl@0: sl@0: // Display each image received for 333ms sl@0: for (i=0 ; i=0); sl@0: aCam.BufferIdToOffset(aCaptureMode,retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: imgBase=chunkVideo.Base()+retOffset; sl@0: r=dispHand.Process(imgBase); sl@0: sl@0: #ifdef __WINSCW__ sl@0: aTest(r==KErrNotSupported); sl@0: #else sl@0: aTest(r==KErrNone); sl@0: #endif sl@0: sl@0: User::After(333000); // 0.33sec sl@0: } sl@0: } sl@0: sl@0: aTest.Next(_L("Free the buffers")); sl@0: for (i=0 ; i=0); sl@0: aCam.BufferIdToOffset(aCaptureMode,retId,retOffset); sl@0: aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset); sl@0: aTest(retOffset>=0); sl@0: } sl@0: sl@0: aTest.Next(_L("Stop the camera.")); sl@0: r=aCam.Stop(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Start it again.")); sl@0: r=aCam.Start(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Continuously display for 10 secs")); sl@0: RTimer tim; sl@0: tim.CreateLocal(); sl@0: TRequestStatus timStatus; sl@0: const TUint KTimeOut=10000000; // 10 seconds sl@0: tim.After(timStatus,KTimeOut); sl@0: aTest(timStatus==KRequestPending); sl@0: aCam.NotifyNewImage(rs[0]); sl@0: aCam.NotifyNewImage(rs[1]); sl@0: FOREVER sl@0: { sl@0: User::WaitForAnyRequest(); sl@0: if (timStatus!=KRequestPending) sl@0: { sl@0: aCam.NotifyNewImageCancel(); sl@0: User::WaitForRequest(rs[0]); sl@0: User::WaitForRequest(rs[1]); sl@0: break; sl@0: } sl@0: else if (rs[0]!=KRequestPending) sl@0: { sl@0: retId=rs[0].Int(); sl@0: aTest(retId>=0); sl@0: aCam.BufferIdToOffset(aCaptureMode,retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: imgBase=chunkVideo.Base()+retOffset; sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: r=dispHand.Process(imgBase); sl@0: sl@0: #ifdef __WINSCW__ sl@0: aTest(r==KErrNotSupported); sl@0: #else sl@0: aTest(r==KErrNone); sl@0: #endif sl@0: sl@0: } sl@0: r=aCam.ReleaseBuffer(retId); sl@0: aTest(r==KErrNone); sl@0: aCam.NotifyNewImage(rs[0]); sl@0: } sl@0: else if (rs[1]!=KRequestPending) sl@0: { sl@0: retId=rs[1].Int(); sl@0: aTest(retId>=0); sl@0: aCam.BufferIdToOffset(aCaptureMode,retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: imgBase=chunkVideo.Base()+retOffset; sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: r=dispHand.Process(imgBase); sl@0: sl@0: #ifdef __WINSCW__ sl@0: aTest(r==KErrNotSupported); sl@0: #else sl@0: aTest(r==KErrNone); sl@0: #endif sl@0: sl@0: } sl@0: r=aCam.ReleaseBuffer(retId); sl@0: aTest(r==KErrNone); sl@0: aCam.NotifyNewImage(rs[1]); sl@0: } sl@0: else sl@0: aTest(0); sl@0: } sl@0: sl@0: tim.Close(); sl@0: sl@0: aTest.Next(_L("Stop the camera.")); sl@0: r=aCam.Stop(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Close the chunk")); sl@0: r=aCam.ChunkClose(aCaptureMode); sl@0: } sl@0: sl@0: LOCAL_C void DoCamImageCaptureTests(RDevCameraSc& aCam, RTest& aTest, TInt aCameraSensorIndex, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate) sl@0: { sl@0: TInt r; sl@0: sl@0: aTest.Next(_L("IMAGE CAPTURE TESTS")); sl@0: aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight); sl@0: sl@0: // Configure Image Capture sl@0: TCameraConfigV02Buf camConfBuf; sl@0: aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: TCameraConfigV02 &camConf=camConfBuf(); sl@0: sl@0: camConf.iFrameSize=aFrameSize; sl@0: camConf.iPixelFormat=aPixelFormat; sl@0: camConf.iFrameRate=aFrameRate; sl@0: sl@0: // Set the camera configuration. sl@0: r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf); sl@0: aTest(r==KErrNone); sl@0: aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: PrintCamConf(camConf,aTest); sl@0: sl@0: // Create a chunk handle and trigger the buffer creation. sl@0: aTest.Next(_L("Setup the config - creating a chunk")); sl@0: RChunk chunkImage; sl@0: TInt numBuffers=KNumVideoFramesToAllocate; sl@0: r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the resulting buffer config")); sl@0: TMmSharedChunkBufConfig bufferConfig; sl@0: TPckg bufferConfigBufImage(bufferConfig); sl@0: aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: // Create and configure a display handler sl@0: TCamDisplayHandler dispHand; sl@0: r=dispHand.Init(); sl@0: aTest(r==KErrNone); sl@0: sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: r=dispHand.SetConfig(aFrameSize,aPixelFormat); sl@0: aTest(r==KErrNone); sl@0: } sl@0: sl@0: // Test that stop still returns an error. sl@0: r=aCam.Stop(); sl@0: aTest(r==KErrGeneral); sl@0: sl@0: // Set the current capture mode sl@0: r=aCam.SetCaptureMode(ECamCaptureModeImage); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Start the camera in image capture mode")); sl@0: r=aCam.Start(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Issue a capture request")); sl@0: TRequestStatus rs1; sl@0: aCam.NotifyNewImage(rs1); sl@0: User::WaitForRequest(rs1); sl@0: TInt retId=rs1.Int(); sl@0: TInt retOffset=-1; sl@0: aTest(retId>=0); sl@0: aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset); sl@0: aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: sl@0: TUint8* imgBase; sl@0: imgBase=chunkImage.Base()+retOffset; sl@0: sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: // Display the image received for 1s sl@0: r=dispHand.Process(imgBase); sl@0: sl@0: #ifdef __WINSCW__ sl@0: aTest(r==KErrNotSupported); sl@0: #else sl@0: aTest(r==KErrNone); sl@0: #endif sl@0: sl@0: User::After(1000000); // 1 sec sl@0: } sl@0: sl@0: // Save the to do MMC card with a filename to indicate its size. If no MMC card is present sl@0: // then we will just display a warning rather than fail as this is an optional manual step sl@0: TBuf<100> fileName(KSensor); sl@0: fileName.AppendNum(aCameraSensorIndex); sl@0: fileName.Append(KUnderscore); sl@0: fileName.AppendFormat(KFrameSize, aFrameSize.iWidth, aFrameSize.iHeight); sl@0: fileName.Append(KUnderscore); sl@0: AppendPixelFormat(fileName, aPixelFormat.iPixelFormat); sl@0: sl@0: TBool wrote = ETrue; sl@0: RBitmap bitmap; sl@0: sl@0: if ((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) || (aPixelFormat.iPixelFormat == EUidPixelFormatSpeedTaggedJPEG)) sl@0: { sl@0: fileName.Append((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) ? KJpeg : KSpeedTaggedJpeg); sl@0: r=bitmap.WriteBuffer(fileName, imgBase, (aFrameSize.iWidth * aFrameSize.iHeight * aPixelFormat.iPixelWidthInBytes)); sl@0: } sl@0: else if ((aPixelFormat.iPixelFormat == EUidPixelFormatYUV_422Interleaved) || (aPixelFormat.iPixelFormat == EUidPixelFormatRGB_565)) sl@0: { sl@0: fileName.Append(KBmp); sl@0: r=bitmap.WriteBMP(fileName, imgBase, aPixelFormat, aFrameSize.iWidth, aFrameSize.iHeight); sl@0: } sl@0: else sl@0: { sl@0: wrote = EFalse; sl@0: } sl@0: sl@0: if (wrote) sl@0: { sl@0: if (r==KErrNone) sl@0: { sl@0: aTest.Printf(_L("Wrote image to %S\n"),&fileName); sl@0: } sl@0: else sl@0: { sl@0: aTest.Printf(_L("Warning: Unable to write %S (error = %d)\r\n"),&fileName,r); sl@0: } sl@0: } sl@0: sl@0: aTest.Next(_L("Free the buffer")); sl@0: r=aCam.ReleaseBuffer(retId); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Issue two consecutive capture requests")); sl@0: TRequestStatus rs2; sl@0: aCam.NotifyNewImage(rs1); sl@0: aCam.NotifyNewImage(rs2); sl@0: sl@0: User::WaitForRequest(rs1); sl@0: retId=rs1.Int(); sl@0: aTest(retId>=0); sl@0: aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset); sl@0: aTest.Printf(_L("Buffer0 offset: %d(%xH)\r\n"),retOffset,retOffset); sl@0: aTest(retOffset>=0); sl@0: sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: // Display the image received for 1s sl@0: imgBase=chunkImage.Base()+retOffset; sl@0: r=dispHand.Process(imgBase); sl@0: sl@0: #ifdef __WINSCW__ sl@0: aTest(r==KErrNotSupported); sl@0: #else sl@0: aTest(r==KErrNone); sl@0: #endif sl@0: sl@0: User::After(1000000); // 1 sec sl@0: } sl@0: sl@0: r=aCam.ReleaseBuffer(retId); sl@0: aTest(r==KErrNone); sl@0: sl@0: User::WaitForRequest(rs2); sl@0: retId=rs2.Int(); sl@0: aTest(retId>=0); sl@0: aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset); sl@0: aTest.Printf(_L("Buffer1 offset: %d(%xH)\r\n"),retOffset,retOffset); sl@0: aTest(retOffset>=0); sl@0: sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: // Display the image received for 1s sl@0: imgBase=chunkImage.Base()+retOffset; sl@0: r=dispHand.Process(imgBase); sl@0: sl@0: #ifdef __WINSCW__ sl@0: aTest(r==KErrNotSupported); sl@0: #else sl@0: aTest(r==KErrNone); sl@0: #endif sl@0: sl@0: User::After(1000000); // 1 sec sl@0: } sl@0: sl@0: r=aCam.ReleaseBuffer(retId); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Issue four more separate capture requests")); sl@0: for (TInt i=0 ; i<4 ; i++) sl@0: { sl@0: aCam.NotifyNewImage(rs1); sl@0: User::WaitForRequest(rs1); sl@0: retId=rs1.Int(); sl@0: aTest(retId>=0); sl@0: aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset); sl@0: aTest.Printf(_L("Buffer%d offset: %d(%xH)\r\n"),i,retOffset,retOffset); sl@0: aTest(retOffset>=0); sl@0: sl@0: if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG) sl@0: { sl@0: // Display the image received for 1s sl@0: imgBase=chunkImage.Base()+retOffset; sl@0: r=dispHand.Process(imgBase); sl@0: sl@0: #ifdef __WINSCW__ sl@0: aTest(r==KErrNotSupported); sl@0: #else sl@0: aTest(r==KErrNone); sl@0: #endif sl@0: sl@0: User::After(1000000); // 1 sec sl@0: } sl@0: } sl@0: sl@0: r=aCam.ReleaseBuffer(retId); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Stop the camera.")); sl@0: r=aCam.Stop(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Close the chunk")); sl@0: r=aCam.ChunkClose(ECamCaptureModeImage); sl@0: aTest(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void DoCamCancelTests(RTest& aTest, TInt aCameraSensorIndex) sl@0: { sl@0: TInt bufferSize, r; sl@0: SDevCamFrameSize* frameSizes; sl@0: TCameraConfigV02Buf camConfBuf; sl@0: sl@0: aTest.Next(_L("CAPTURE CANCEL TESTS")); sl@0: sl@0: RDevCameraSc cam; sl@0: aTest.Next(_L("Open a channel on the camera driver")); sl@0: r=cam.Open(aCameraSensorIndex); sl@0: aTest(r==KErrNone); sl@0: sl@0: TInt numBuffers=KNumVideoFramesToAllocate; sl@0: SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1); sl@0: sl@0: // Test Image Capture, if supported sl@0: if (CameraCaps->iNumImagePixelFormats) sl@0: { sl@0: // If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0 sl@0: Test(pixelFormat->iNumFrameSizes > 0); sl@0: frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes]; sl@0: Test(frameSizes != NULL); sl@0: bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes); sl@0: TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize); sl@0: r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf); sl@0: Test(r == KErrNone); sl@0: sl@0: cam.GetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: sl@0: camConfBuf().iFrameSize=frameSizes[0]; sl@0: camConfBuf().iPixelFormat=*pixelFormat; sl@0: camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate; sl@0: sl@0: // Set the camera configuration. sl@0: r=cam.SetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: aTest(r==KErrNone); sl@0: cam.GetCamConfig(ECamCaptureModeImage, camConfBuf); sl@0: PrintCamConf(camConfBuf(), aTest); sl@0: sl@0: // Create a chunk handle and trigger the buffer creation. sl@0: RChunk chunkImage; sl@0: aTest.Next(_L("Setup the config - creating a chunk for image capture")); sl@0: r=cam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the resulting buffer config")); sl@0: TMmSharedChunkBufConfig bufferConfig; sl@0: TPckg bufferConfigBufImage(bufferConfig); sl@0: cam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: // Set the current capture mode sl@0: r=cam.SetCaptureMode(ECamCaptureModeImage); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Start the camera in image capture mode.")); sl@0: r=cam.Start(); sl@0: aTest(r==KErrNone); sl@0: sl@0: TRequestStatus rs[KNumVideoFramesToCapture]; sl@0: TInt retId, retOffset; sl@0: sl@0: aTest.Next(_L("Issue a request and then cancel it")); sl@0: cam.NotifyNewImage(rs[0]); sl@0: cam.NotifyNewImageCancel(); sl@0: User::WaitForRequest(rs[0]); sl@0: retId=rs[0].Int(); sl@0: aTest(retId==KErrCancel || retId>=0); sl@0: if (retId>=0) sl@0: { sl@0: cam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset); sl@0: aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: cam.ReleaseBuffer(retId); sl@0: } sl@0: sl@0: aTest.Next(_L("Stop the camera.")); sl@0: r=cam.Stop(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Close the Image chunk")); sl@0: chunkImage.Close(); sl@0: sl@0: delete [] frameSizes; sl@0: } sl@0: sl@0: // Skip past the image pixel formats sl@0: pixelFormat += CameraCaps->iNumImagePixelFormats; sl@0: sl@0: // Test Video Capture, if supported sl@0: if (CameraCaps->iNumVideoPixelFormats) sl@0: { sl@0: // If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0 sl@0: Test(pixelFormat->iNumFrameSizes > 0); sl@0: frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes]; sl@0: Test(frameSizes != NULL); sl@0: bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes); sl@0: TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize); sl@0: r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf); sl@0: Test(r == KErrNone); sl@0: sl@0: cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf); sl@0: sl@0: camConfBuf().iFrameSize=frameSizes[0]; sl@0: camConfBuf().iPixelFormat=*pixelFormat; sl@0: camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate; sl@0: sl@0: // Set the camera configuration. sl@0: r=cam.SetCamConfig(ECamCaptureModeVideo, camConfBuf); sl@0: aTest(r==KErrNone); sl@0: cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf); sl@0: PrintCamConf(camConfBuf(), aTest); sl@0: sl@0: // Create a chunk handle and trigger the buffer creation. sl@0: RChunk chunkVideo; sl@0: aTest.Next(_L("Setup the config - creating a chunk for video capture")); sl@0: r=cam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the resulting buffer config")); sl@0: TMmSharedChunkBufConfig bufferConfig; sl@0: TPckg bufferConfigBufVideo(bufferConfig); sl@0: cam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBufVideo); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: // Set the current capture mode sl@0: r=cam.SetCaptureMode(ECamCaptureModeVideo); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Start the camera in video mode")); sl@0: r=cam.Start(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Issue capture requests and globally cancel them all")); sl@0: aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture); sl@0: TRequestStatus rs[KNumVideoFramesToCapture]; sl@0: TInt i; sl@0: for (i=0 ; i=0); sl@0: if (retId>=0) sl@0: { sl@0: cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset); sl@0: aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: cam.ReleaseBuffer(retId); sl@0: } sl@0: } sl@0: sl@0: aTest.Next(_L("Issue capture requests and individually cancel them all")); sl@0: aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture); sl@0: sl@0: for (i=0 ; i=0); sl@0: if (retId>=0) sl@0: { sl@0: cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset); sl@0: aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset); sl@0: aTest(retOffset>=0); sl@0: cam.ReleaseBuffer(retId); sl@0: } sl@0: } sl@0: sl@0: aTest.Next(_L("Stop the camera.")); sl@0: r=cam.Stop(); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Close the Video chunk")); sl@0: chunkVideo.Close(); sl@0: sl@0: delete [] frameSizes; sl@0: } sl@0: sl@0: // Skip past the video pixel formats sl@0: pixelFormat += CameraCaps->iNumVideoPixelFormats; sl@0: sl@0: // Test Viewfinder Capture, if supported sl@0: if (CameraCaps->iNumViewFinderPixelFormats) sl@0: { sl@0: // If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0 sl@0: Test(pixelFormat->iNumFrameSizes > 0); sl@0: frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes]; sl@0: Test(frameSizes != NULL); sl@0: bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes); sl@0: TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize); sl@0: r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf); sl@0: Test(r == KErrNone); sl@0: sl@0: cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf); sl@0: sl@0: camConfBuf().iFrameSize=frameSizes[0]; sl@0: camConfBuf().iPixelFormat=*pixelFormat; sl@0: camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate; sl@0: sl@0: // Set the camera configuration. sl@0: r=cam.SetCamConfig(ECamCaptureModeViewFinder, camConfBuf); sl@0: aTest(r==KErrNone); sl@0: cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf); sl@0: PrintCamConf(camConfBuf(), aTest); sl@0: sl@0: // Create a chunk handle and trigger the buffer creation. sl@0: RChunk chunkViewFinder; sl@0: aTest.Next(_L("Setup the config - creating a chunk for viewfinder capture")); sl@0: r=cam.SetBufConfigChunkCreate(ECamCaptureModeViewFinder,numBuffers,chunkViewFinder); sl@0: aTest(r==KErrNone); sl@0: sl@0: aTest.Next(_L("Read and display the resulting buffer config")); sl@0: TMmSharedChunkBufConfig bufferConfig; sl@0: TPckg bufferConfigBufViewFinder(bufferConfig); sl@0: cam.GetBufferConfig(ECamCaptureModeViewFinder, bufferConfigBufViewFinder); sl@0: PrintBufferConf(bufferConfig,aTest); sl@0: sl@0: aTest.Next(_L("Close the Viewfinder chunk")); sl@0: chunkViewFinder.Close(); sl@0: sl@0: delete [] frameSizes; sl@0: } sl@0: sl@0: aTest.Next(_L("Close the drivers")); sl@0: cam.Close(); sl@0: } sl@0: sl@0: void CameraTests(TInt aCameraSensorIndex) sl@0: { sl@0: TUint index, size; sl@0: Test.Printf(_L("Testing unit number: %d\r\n"),aCameraSensorIndex); sl@0: sl@0: // Perform some basic opening and multithreaded tests. We don't want just in time debugging during sl@0: // these tests sl@0: TBool justInTime=User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: DoCamOpenCapTests(Test,aCameraSensorIndex); sl@0: User::SetJustInTime(justInTime); sl@0: sl@0: // Test request handling sl@0: DoCamCancelTests(Test, aCameraSensorIndex); sl@0: sl@0: // Re-open the camera driver for use below and to ensure that it can deal with being re-opened (it sl@0: // has already been opened and closed by DoCamOpenCapTests()) sl@0: RDevCameraSc cam; sl@0: Test.Next(_L("Open a channel on the camera driver")); sl@0: TInt r=cam.Open(aCameraSensorIndex); sl@0: Test(r==KErrNone); sl@0: sl@0: // Test Dynamic Settings, e.g. Brightness, Contrast, etc. sl@0: DoCamDynamicSettingsTests(cam, Test); sl@0: sl@0: // Go through all supported image, video and viewfinder pixel formats and perform configuration sl@0: // and capture tests on them all, for all supported frame sizes and frame rates sl@0: TInt bufferSize; sl@0: SDevCamFrameSize* frameSizes; sl@0: TBool imageConfigTestsDone=EFalse, videoConfigTestsDone=EFalse, viewFinderConfigTestsDone=EFalse; sl@0: SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1); sl@0: sl@0: for (index = 0; index < CameraCaps->iNumImagePixelFormats; ++index) sl@0: { sl@0: // If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0 sl@0: Test(pixelFormat->iNumFrameSizes > 0); sl@0: Test.Printf(_L("Image pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes); sl@0: frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes]; sl@0: Test(frameSizes!=NULL); sl@0: bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes); sl@0: TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize); sl@0: r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf); sl@0: Test(r == KErrNone); sl@0: sl@0: // Test camera configuration for image capture. This is only done once for the sake of sl@0: // test expediency sl@0: if (!imageConfigTestsDone) sl@0: { sl@0: imageConfigTestsDone = ETrue; sl@0: DoCamConfigTests(cam, Test, ECamCaptureModeImage, *pixelFormat, frameSizes[0]); sl@0: } sl@0: sl@0: // Test image capture mode sl@0: for (size = 0; size < pixelFormat->iNumFrameSizes; ++size) sl@0: { sl@0: DoCamImageCaptureTests(cam, Test, aCameraSensorIndex, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate); sl@0: } sl@0: sl@0: // Test buffer offset sl@0: for (size = 0; size < pixelFormat->iNumFrameSizes; ++size) sl@0: { sl@0: DoCamBufferOffsetTests(cam, Test, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate); sl@0: } sl@0: sl@0: delete [] frameSizes; sl@0: ++pixelFormat; sl@0: } sl@0: sl@0: for (index = 0; index < CameraCaps->iNumVideoPixelFormats; ++index) sl@0: { sl@0: // If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0 sl@0: Test(pixelFormat->iNumFrameSizes > 0); sl@0: Test.Printf(_L("Video pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes); sl@0: frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes]; sl@0: Test(frameSizes!=NULL); sl@0: bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes); sl@0: TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize); sl@0: r = cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizesBuf); sl@0: Test(r == KErrNone); sl@0: sl@0: // Test camera configuration for video capture. This is only done once for the sake of sl@0: // test expediency sl@0: if (!videoConfigTestsDone) sl@0: { sl@0: videoConfigTestsDone=ETrue; sl@0: DoCamConfigTests(cam, Test, ECamCaptureModeVideo, *pixelFormat, frameSizes[0]); sl@0: } sl@0: sl@0: // Test video capture mode sl@0: for (size = 0; size < pixelFormat->iNumFrameSizes; ++size) sl@0: { sl@0: DoCamVideoCaptureTests(cam, Test, ECamCaptureModeVideo, *pixelFormat,frameSizes[size], frameSizes[size].iMaxFrameRate); sl@0: } sl@0: delete [] frameSizes; sl@0: ++pixelFormat; sl@0: } sl@0: sl@0: for (index = 0; index < CameraCaps->iNumViewFinderPixelFormats; ++index) sl@0: { sl@0: // If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0 sl@0: Test(pixelFormat->iNumFrameSizes > 0); sl@0: Test.Printf(_L("Viewfinder pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes); sl@0: frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes]; sl@0: Test(frameSizes!=NULL); sl@0: bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes); sl@0: TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize); sl@0: r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf); sl@0: Test(r == KErrNone); sl@0: sl@0: // Test camera configuration for view finder capture. This is only done once for the sake of sl@0: // test expediency sl@0: if (!viewFinderConfigTestsDone) sl@0: { sl@0: viewFinderConfigTestsDone=ETrue; sl@0: DoCamConfigTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[0]); sl@0: } sl@0: sl@0: // Test view finder capture mode sl@0: for (size = 0; size < pixelFormat->iNumFrameSizes; ++size) sl@0: { sl@0: DoCamVideoCaptureTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate); sl@0: } sl@0: delete [] frameSizes; sl@0: ++pixelFormat; sl@0: } sl@0: cam.Close(); sl@0: sl@0: // And free the global capabilities buffer that was allocated in DoCamOpenCapTests() sl@0: User::Free(CapsBufPtr); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: Test.Title(); sl@0: Test.Start(_L("Camera module API test")); sl@0: sl@0: Test.Next(_L("Loading CAMERA PDD")); sl@0: TInt r=User::LoadPhysicalDevice(KCamPddFileName); sl@0: Test.Printf(_L("Returned %d\r\n"),r); sl@0: sl@0: if (r==KErrNotFound) sl@0: { sl@0: Test.Printf(_L("Shared chunk camera driver not supported - test skipped\r\n")); sl@0: Test.End(); sl@0: Test.Close(); sl@0: __UHEAP_MARKEND; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: Test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: Test.Next(_L("Loading CAMERA LDD")); sl@0: r=User::LoadLogicalDevice(KCamLddFileName); sl@0: Test.Printf(_L("Returned %d\r\n"),r); sl@0: Test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: Test.Next(_L("Loading D_MMCSC LDD")); sl@0: r=User::LoadLogicalDevice(KTstLddFileName); sl@0: Test.Printf(_L("Returned %d\r\n"),r); sl@0: Test(r==KErrNone||r==KErrAlreadyExists); sl@0: sl@0: __KHEAP_MARK; sl@0: sl@0: if (User::CommandLineLength()>0) sl@0: { sl@0: TBuf<0x100> cmd; sl@0: TInt moduleIndex = KUnit0; sl@0: User::CommandLine(cmd); sl@0: Test(cmd.Length()>0); sl@0: if (cmd[0]>='0' && cmd[0]<='9') sl@0: moduleIndex=(TInt)(cmd[0]-'0'); sl@0: CameraTests(moduleIndex); sl@0: } sl@0: else // If no command line arguments are passed we perform tests on the module 0 and 1 sl@0: { sl@0: CameraTests(0); sl@0: } sl@0: sl@0: __KHEAP_MARKEND; sl@0: sl@0: // Free the PDDs and LDDs sl@0: Test.Next(_L("Freeing ECAMERASC LDD")); sl@0: r=User::FreeLogicalDevice(KDevCameraScName); sl@0: Test(r==KErrNone); sl@0: sl@0: Test.Next(_L("Freeing CAMERASC PDD")); sl@0: TFindPhysicalDevice fDr; sl@0: TFullName drivName; sl@0: TName searchName; sl@0: searchName.Append(KDevCameraScName); sl@0: searchName.Append(KCamFreePddExtension); sl@0: fDr.Find(searchName); sl@0: r=fDr.Next(drivName); sl@0: Test(r==KErrNone); sl@0: r=User::FreePhysicalDevice(drivName); sl@0: Test(r==KErrNone); sl@0: sl@0: Test.Next(_L("Freeing D_MMCSC LDD")); sl@0: r=User::FreeLogicalDevice(KDevMmCScName); sl@0: Test(r==KErrNone); sl@0: sl@0: Test.End(); sl@0: Test.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: return(KErrNone); sl@0: }