Tuesday, August 02, 2005

ICAMERA_Pause() and ICAMERA_Resume()

Last week I was playing around with an applet that required me to pause the camera while it was in preview mode on a key press. Sounds simple enough !!!

To Pause the Camera

1) Check if the camera is in preview mode.

if(SUCCESS != ICAMERA_GetMode(pMe->m_pCamera, &lMode, &bPaused))
return;
if (CAM_MODE_PREVIEW == lMode && !bPaused)

{
//Pause the Camera
ICAMERA_Pause(pMe->m_pCamera);
}


2) The above call should return the status of CAM_STATUS_PAUSE in the callback
Function of the camera control. The AEECameraNotify structure will contain the following values.

nStatus = CAM_STATUS_PAUSE
nCmd = CAM_CMD_START
nSubCmd = CAM_MODE_PREVIEW


Do any thing that you want to do while the camera is paused here.


To Resume the Camera

1) The resume call will place the camera back in the preview mode. The process is similar to the call to the Pause function.

if(SUCCESS != ICAMERA_GetMode(pMe->m_pCamera, &lMode, &bPaused))
return;
if(CAM_MODE_PREVIEW == lMode && bPaused) //check for pause
{
//Resume the Camera
ICAMERA_Resume(pMe->m_pCamera);
}


2) The above call returns the status CAM_STATUS_RESUME in the callback function of the camera control. The AEECameraNotify structure will contain the following values.

nStatus = CAM_STATUS_RESUME
nCmd = CAM_CMD_START
nSubCmd = CAM_MODE_PREVIEW

Once you receive this callback, the applet should automatically start receiving the callbacks with CAM_STATUS_FRAME.

Handling Suspend (EVT_SUSPEND) and Resume (EVT_RESUME) Events.

Conventional wisdom dictates stopping the camera altogether and releasing the reference to the ICamera interface when your applet receives a EVT_SUSPEND event.

NEVER NEVER NEVER let your applet release the reference to the ICamera interface when the camera is in paused state. When you receive the EVT_SUSPEND event make sure the camera is not in the paused state, if it is then put in a call to ICAMERA_Resume(). Do not know if this is a bug or a feature (J) in the ICamera but once you put the camera in the pause state and release the reference, you need to restart the device to be able to use the camera again.

case EVT_SUSPEND:
if(SUCCESS == ICAMERA_GetMode(pMe->m_pCamera, &lMode, &bPaused))
{

if(CAM_MODE_PREVIEW == lMode && bPaused)
{
ICAMERA_Resume(pMe->m_pCamera);
}
}
//you could call ICamera_Stop(), but it works without it.
ICAMERA_Release(pMe->m_pCamera);
pMe->m_pCamera = NULL;
//Always a good idea to null it out.
return TRUE;

No comments:

Post a Comment