ICamera Snapshot Help! | developer.brewmp.com ICamera Snapshot Help! | developer.brewmp.com

Developer

ICamera Snapshot Help!

Forums:

Hi,

I am trying to take a snapshot right now but whenever I try to take a snapshot, my phone hangs.

I am following these steps but I am not sure if my step is correct. :confused:
1. SetMediaData()
2. SetVideoEncode()
3. SetSize()
4. ICAMERA_RecordSnapshot()

As I run the program, my phone stops right after SetVideoEncode().
Please give me some guidance and let me know what I am missing here.

Thanks in advance.

static int CamTest_SnapShot_Process(CamTest* pMe)
{
int nRet = 0;

// stop preview mode
ICAMERA_Stop(pMe->m_pICamera);

// we're now in ready mode
DBGPRINTF("WE STOP THE CAMERA AND READY TO TAKE A SNAPSHOT\n");

// 1. SetMediaData()
pMe->m_Md.clsData = MMD_FILE_NAME;
pMe->m_Md.pData = (void *)"test.jpg";

if ((nRet = ICAMERA_SetMediaData(pMe->m_pICamera, &pMe->m_Md, pMe->cpszMIME)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetMediaData returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("WE PASS ICAMERA_SetMediaData() RET[%d]\n", nRet);

// 2. SetVideoEncode()
if ((nRet = ICAMERA_SetVideoEncode(pMe->m_pICamera, AEECLSID_JPEG, 0)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetVideoEncode returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("WE PASS ICAMERA_SetVideoEncode() RET[%d]\n", nRet);

// 3. SetSize()
pMe->m_sizePreview.cx = XSNAPSHOT - 4;
pMe->m_sizePreview.cy = YSNAPSHOT - 4;
if ((nRet = ICAMERA_SetSize(pMe->m_pICamera, &pMe->m_sizePreview)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetSize returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("ICAMERA_SetSize returns SUCCESS[%d]\n", nRet);

// Finally snapshot!!!
if ((nRet = ICAMERA_RecordSnapshot(pMe->m_pICamera)) != SUCCESS)
{
DBGPRINTF("ICAMERA_RecordSnapshot returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("ICAMERA_RecordSnapshot returns SUCCESS[%d]\n", nRet);

return SUCCESS;

Ilho,
Can you place your code to take the snapshot in the callback function of the camera. I assume you are calling ICAMERA_Stop() to stop the preview mode. Try placing the code to take a snapshot in the call back function when you get the CAM_STATUS_DONE msg for CAM_CMD_START and CAM_MODE_PREVIEW.
Also you can try setting pMe->m_Md.dwSize = 0;
Whats the value of pMe->cpszMIME ?
Regards

Ilho,
Can you place your code to take the snapshot in the callback function of the camera. I assume you are calling ICAMERA_Stop() to stop the preview mode. Try placing the code to take a snapshot in the call back function when you get the CAM_STATUS_DONE msg for CAM_CMD_START and CAM_MODE_PREVIEW.
Also you can try setting pMe->m_Md.dwSize = 0;
Whats the value of pMe->cpszMIME ?
Regards

Hi brewers, r@I and yeilho,
I think you have the good steps because I implemented the same thing. But i did this for MediaSetData :
ICAMERA_SetMediaData(ctrl->m_pICamera, &(ctrl->m_sMediaData), MT_JPG);
My problem is a little different than yours... All that part of the ICamera works, and I tried to add the zoom with ICamera_SetZoom.
When I´m in the preview mode, It works perfectly (I can zoom forward and backward) but when I call this sequence of commands to Record the snapshot, my image is saved but in the normal size (without the zoom...). The phone I use is a Mototrola 710.
Is there anyone with the same issue?
Thanx, guys.
niboi

Hi brewers, r@I and yeilho,
I think you have the good steps because I implemented the same thing. But i did this for MediaSetData :
ICAMERA_SetMediaData(ctrl->m_pICamera, &(ctrl->m_sMediaData), MT_JPG);
My problem is a little different than yours... All that part of the ICamera works, and I tried to add the zoom with ICamera_SetZoom.
When I´m in the preview mode, It works perfectly (I can zoom forward and backward) but when I call this sequence of commands to Record the snapshot, my image is saved but in the normal size (without the zoom...). The phone I use is a Mototrola 710.
Is there anyone with the same issue?
Thanx, guys.
niboi

Hi :D ,
I worked on the program again and I was able to get it done.
I think that the problem was the time gap in camera mode changes.
Amount of time was not enough to change the camera mode from preview status to ready status.
So I changed my code as follows.
1. I stop the camera.
2. Wait for the notification.
3. Take a snapshot when I receive the ready notification
static void CamTest_Stop(CamTest* pMe)
{
// Stop preview mode; We're now in ready mode
ICAMERA_Stop(pMe->m_pICamera);
pMe->m_Status = READY_FLAG;

static int CamTest_SnapShot_Process(CamTest* pMe)
{
int nRet = 0;
AEESize as;
// 1. SetMediaData()
pMe->m_Md.clsData = MMD_FILE_NAME;
pMe->m_Md.pData = (void *)"/test.jpg";
pMe->m_Md.dwSize = 0;
//if ((nRet = ICAMERA_SetMediaData(pMe->m_pICamera, &pMe->m_Md, pMe->cpszMIME)) != SUCCESS)
if ((nRet = ICAMERA_SetMediaData(pMe->m_pICamera, &pMe->m_Md, MT_JPEG)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetMediaData returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("WE PASS ICAMERA_SetMediaData() RET[%d]\n", nRet);
//File_Creation(pMe);
// 2. SetSize()
as.cx = XSNAPSHOT - 4;
as.cy = YSNAPSHOT - 4;
if ((nRet = ICAMERA_SetSize(pMe->m_pICamera, &as)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetSize returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("ICAMERA_SetSize returns SUCCESS[%d]\n", nRet);
// 3. SetVideoEncode()
if ((nRet = ICAMERA_SetVideoEncode(pMe->m_pICamera, AEECLSID_JPEG, 0)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetVideoEncode returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("WE PASS ICAMERA_SetVideoEncode() RET[%d]\n", nRet);
// Finally snapshot!!!
if ((nRet = ICAMERA_RecordSnapshot(pMe->m_pICamera)) != SUCCESS)
{
DBGPRINTF("ICAMERA_RecordSnapshot returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("ICAMERA_RecordSnapshot returns SUCCESS[%d]\n", nRet);
return SUCCESS;

// part of my notification code
static void CamTest_CameraNotify(void *pUser, AEECameraNotify *pn)
{
switch (pn->nStatus)
{
case CAM_STATUS_DONE:
// Cam is ready so we take a snapshot
if(pn->nCmd == CAM_CMD_START && pn->nSubCmd == CAM_MODE_PREVIEW)
{
if (pMe->m_Status & READY_FLAG)
{
DBGPRINTF("PROCEED TO SNAPSHOT PROCESS!\n");
CamTest_SnapShot_Process(pMe);
}
else
{
DBGPRINTF("CAMERA IS NOT READY!\n");
}
}
if (pn->nCmd == CAM_CMD_START && pn->nSubCmd == CAM_STATUS_DONE)
{
DBGPRINTF("Raw Frame recorded\n");
}
if (pn->nCmd == CAM_CMD_ENCODESNAPSHOT)
//if (pn->nCmd == CAM_CMD_ENCODESNAPSHOT && pn->nSubCmd == CAM_MODE_SNAPSHOT)
{
DBGPRINTF("----------->> Frame encoded\n");
// frame has been encoded so we get back to Preview mode
StartCameraInPreviewMode(pMe);
}
break;
}

Anyhow, I think that development in brew is not well-structured. The document is not so good and the sameple codes have bugs here and there.
I spend most of time not coming up with effiecient algorithms but figuring out how to do simple procedure such as above.
If you guys could post the code when you solves certain problems, it will help many of us.
Please also let me know if there is any bugs in above code.
Have a good one!
ilho

Hi :D ,
I worked on the program again and I was able to get it done.
I think that the problem was the time gap in camera mode changes.
Amount of time was not enough to change the camera mode from preview status to ready status.
So I changed my code as follows.
1. I stop the camera.
2. Wait for the notification.
3. Take a snapshot when I receive the ready notification
static void CamTest_Stop(CamTest* pMe)
{
// Stop preview mode; We're now in ready mode
ICAMERA_Stop(pMe->m_pICamera);
pMe->m_Status = READY_FLAG;

static int CamTest_SnapShot_Process(CamTest* pMe)
{
int nRet = 0;
AEESize as;
// 1. SetMediaData()
pMe->m_Md.clsData = MMD_FILE_NAME;
pMe->m_Md.pData = (void *)"/test.jpg";
pMe->m_Md.dwSize = 0;
//if ((nRet = ICAMERA_SetMediaData(pMe->m_pICamera, &pMe->m_Md, pMe->cpszMIME)) != SUCCESS)
if ((nRet = ICAMERA_SetMediaData(pMe->m_pICamera, &pMe->m_Md, MT_JPEG)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetMediaData returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("WE PASS ICAMERA_SetMediaData() RET[%d]\n", nRet);
//File_Creation(pMe);
// 2. SetSize()
as.cx = XSNAPSHOT - 4;
as.cy = YSNAPSHOT - 4;
if ((nRet = ICAMERA_SetSize(pMe->m_pICamera, &as)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetSize returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("ICAMERA_SetSize returns SUCCESS[%d]\n", nRet);
// 3. SetVideoEncode()
if ((nRet = ICAMERA_SetVideoEncode(pMe->m_pICamera, AEECLSID_JPEG, 0)) != SUCCESS)
{
DBGPRINTF("ICAMERA_SetVideoEncode returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("WE PASS ICAMERA_SetVideoEncode() RET[%d]\n", nRet);
// Finally snapshot!!!
if ((nRet = ICAMERA_RecordSnapshot(pMe->m_pICamera)) != SUCCESS)
{
DBGPRINTF("ICAMERA_RecordSnapshot returns FALSE[%d]\n", nRet);
return FALSE;
}
DBGPRINTF("ICAMERA_RecordSnapshot returns SUCCESS[%d]\n", nRet);
return SUCCESS;

// part of my notification code
static void CamTest_CameraNotify(void *pUser, AEECameraNotify *pn)
{
switch (pn->nStatus)
{
case CAM_STATUS_DONE:
// Cam is ready so we take a snapshot
if(pn->nCmd == CAM_CMD_START && pn->nSubCmd == CAM_MODE_PREVIEW)
{
if (pMe->m_Status & READY_FLAG)
{
DBGPRINTF("PROCEED TO SNAPSHOT PROCESS!\n");
CamTest_SnapShot_Process(pMe);
}
else
{
DBGPRINTF("CAMERA IS NOT READY!\n");
}
}
if (pn->nCmd == CAM_CMD_START && pn->nSubCmd == CAM_STATUS_DONE)
{
DBGPRINTF("Raw Frame recorded\n");
}
if (pn->nCmd == CAM_CMD_ENCODESNAPSHOT)
//if (pn->nCmd == CAM_CMD_ENCODESNAPSHOT && pn->nSubCmd == CAM_MODE_SNAPSHOT)
{
DBGPRINTF("----------->> Frame encoded\n");
// frame has been encoded so we get back to Preview mode
StartCameraInPreviewMode(pMe);
}
break;
}

Anyhow, I think that development in brew is not well-structured. The document is not so good and the sameple codes have bugs here and there.
I spend most of time not coming up with effiecient algorithms but figuring out how to do simple procedure such as above.
If you guys could post the code when you solves certain problems, it will help many of us.
Please also let me know if there is any bugs in above code.
Have a good one!
ilho

Hi Ilho,
Please tell me where should we call the ICAMERA_Stop() method. Iam not able to stop the preview mode and get the snap shot taken. Iam implementing RecordSnapShot in the camera call back function, but when to stop the camera preview mode and when to call RecordSnapshot , iam not getting.
Please help me out.
thanks,
Narenderan

Hi Ilho,
Please tell me where should we call the ICAMERA_Stop() method. Iam not able to stop the preview mode and get the snap shot taken. Iam implementing RecordSnapShot in the camera call back function, but when to stop the camera preview mode and when to call RecordSnapshot , iam not getting.
Please help me out.
thanks,
Narenderan

Call ICAMERA_Stop() in the Callback when status is CAM_STATUS_FRAME. Then in the call back function when status is CAM_STATUS_DONE, call the RecordSnapshot method.

Call ICAMERA_Stop() in the Callback when status is CAM_STATUS_FRAME. Then in the call back function when status is CAM_STATUS_DONE, call the RecordSnapshot method.

Hi,
Do we need to check about any camera events in the HandleEvent? or we will check all the events like CAM_MODE_SNAPSHOT, CAM_STATUS_DONE, in camera call back function only.?
Thanks
NAren

Hi,
Do we need to check about any camera events in the HandleEvent? or we will check all the events like CAM_MODE_SNAPSHOT, CAM_STATUS_DONE, in camera call back function only.?
Thanks
NAren