⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mymotiondetectcamappui.cpp

📁 How to control the camera of cellphone.
💻 CPP
字号:
/*
 ============================================================================
 Name		: CMyMotionDetectCamAppUi from MyMotionDetectCamAppUi.h
 Author	  : 
 Version	 :
 Copyright   : 
 
 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2008.

 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
 The use of the software is subject to the terms of the end-user license 
 agreement which accompanies or is included with the software. The software is 
 provided "as is" and Sony Ericsson specifically disclaim any warranty or 
 condition whatsoever regarding merchantability or fitness for a specific 
 purpose, title or non-infringement. No warranty of any kind is made in 
 relation to the condition, suitability, availability, accuracy, reliability, 
 merchantability and/or non-infringement of the software provided herein.


Description : CMyMotionDetectCamAppUi implementation
============================================================================
*/

#include "MyMotionDetectCamAppUi.h"
#include "MyMotionDetectCam.hrh"
#include <QikCommand.h>


/**
 2nd stage construction of the App UI.
 Create view and add it to the framework.
 The framework will take over the ownership.
 */
void CMyMotionDetectCamAppUi::ConstructL()
	{
	// Calls ConstructL that initiate the standard values.
	CQikAppUi::ConstructL();
	
	// Create the view and add it to the framework
	CMyMotionDetectCamView* appView = CMyMotionDetectCamView::NewLC(*this);
	AddViewL(*appView);
	CleanupStack::Pop(appView);
	
	iBaseView = appView;
	// Make sure a camera is available
    if(CCamera::CamerasAvailable()<=0)
    	{
		User::Leave(KErrNotSupported);
		}
	// Create the object representing the camera
    iCam = CCamera::NewL(*this, 0);
	}

/**
Destructor
 */
CMyMotionDetectCamAppUi::~CMyMotionDetectCamAppUi()
	{
	// Release the camera
	if(iCam)
		{
		iCam->StopVideoCapture();
		iCam->PowerOff();
		iCam->Release();
		}
	// Destroy the object
	delete iCam;
	}

/**
Handle commands
 */
void CMyMotionDetectCamAppUi::HandleCommandL(CQikCommand& aCommand)
	{
	switch (aCommand.Id())
		{
		case EMyMotionDetectCamStartStopCmd:
			{
			// Stop is active, start otherwise
			if(iState==EActive)
				{
				Reset();
				iState=EIdle;
				}
			else
				{
				iCam->Reserve();
				iState=EActive;
				}
			break;
			}
		default:
			CQikAppUi::HandleCommandL(aCommand);
			break;
		}
	}

/**
Called when the app is about to gain or lose foreground
 */
void CMyMotionDetectCamAppUi::HandleForegroundEventL(TBool aForeground)
	{
	if(!aForeground && iState==EActive)
		{
		// Putting the capture on hold since the computation is very resource intensive
		Reset();
		iState=EOnHold;
		}
	else if(aForeground && iState==EOnHold)
		{
		// Resuming if capture was active when leaving the applciation
		iCam->Reserve();
		iState=EActive;	
		}
	}
	
/**
Release the camera and update the view to show that capture is inactive
 */	
void CMyMotionDetectCamAppUi::Reset()
	{
	iCam->StopVideoCapture();
	iCam->PowerOff();
	iCam->Release();
	iBaseView->DestroyBitmaps();
	iBaseView->DrawNow();
	}

/*-----------------------------------------------------------------------*/
//
//		MCameraObserver
//
/*-----------------------------------------------------------------------*/


/**
Callback for CCamera::Reserve()
 */	
void CMyMotionDetectCamAppUi::ReserveComplete(TInt aError)
{
	if(aError!=KErrNone)
		{
		// Reset state and show error
		iState=EIdle;
		CEikonEnv::Static()->ResolveError(aError);
		}
	else
		{
		// Camera is successfully reserved. Power the camera on.
		iCam->PowerOn();
		}
}

/**
Callback for CCamera::PowerOn()
 */	
void CMyMotionDetectCamAppUi::PowerOnComplete(TInt aError)
{
	if(aError==KErrNone)
		{
		// Camera powered on successfully. Get camera info
		TCameraInfo info;
		iCam->CameraInfo(info);
		TInt index=0;
		TSize size;
		
		TRAP(aError, 
		// Create view bitmaps and get the bitmap size
		TSize acceptedSize=iBaseView->CreateBitmapsL();
		while(index<info.iNumVideoFrameSizesSupported)
			{
			// Find a video frame size that matches the view bitmap size
			iCam->EnumerateVideoFrameSizes(size, index, CCamera::EFormatYUV420SemiPlanar);	
			if(acceptedSize==size)
				{
				// A correct size found. Prepare for video capture in YUV420 semi planar format, the size determined by the view, minimum frame rate, 2 frame buffers, and maximum frame size.
				iCam->PrepareVideoCaptureL(CCamera::EFormatYUV420SemiPlanar, index, info.iNumVideoFrameRatesSupported-1, 2, info.iMaxFramesPerBufferSupported); 
				// Start video capture
				iCam->StartVideoCapture();	
				return;
				}
			index++;
			}
		);
		}
	// Error during power on, or could not start video capture. Reset and show error.
	Reset();
	iState=EIdle;
	CEikonEnv::Static()->ResolveError(aError==KErrNone ? KErrNotSupported : aError);
}

/**
Periodic callback for CCamera::StartViewFinderBitmapsL(). Not used is this example.
 */
void CMyMotionDetectCamAppUi::ViewFinderFrameReady(CFbsBitmap &aFrame){}

/**
Callback for CCamera::CaptureImage(). Not used in this example.
 */
void CMyMotionDetectCamAppUi::ImageReady(CFbsBitmap *aBitmap, HBufC8 *aData, TInt aError){}

/**
Periodic callback for CCamera::StartVideoCapture()
 */
void CMyMotionDetectCamAppUi::FrameBufferReady(MFrameBuffer *aFrameBuffer, TInt aError)
{
	if(aError!=KErrNone)
		{
		// Error during capture. Reset and show error.
		Reset();
		iState=EIdle;
		CEikonEnv::Static()->ResolveError(aError);		
		}
	else
		{
		// Update the view with the first frame in the frame buffer
		TRAP_IGNORE(iBaseView->UpdateBitmaps(*aFrameBuffer->DataL(0)));
		}
	// Release the frame buffer so it can be reused by the CCamera.
	aFrameBuffer->Release();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -