#include "StdAfx.h"
|
#include "MulticamControl.h"
|
#include "Global_Define.h"
|
#include "FrameBufferController.h"
|
|
#define DEFAULT_GRAB_FRAME_HEIGHT 1024
|
|
//==========================================================================================================================================================================
|
// Grabber Multicam
|
CGrabberMulticam::CGrabberMulticam()
|
{
|
m_nEndFrameIdx = m_nStartFrameIdx = 0;
|
m_nSetBufferIdx = 0;
|
m_nScanIndex = 0;
|
m_nBoardID = 0;
|
|
#if OFFLINE_KEY == 0
|
m_hGrabChannel = 0;
|
#endif
|
|
m_nAllocatedGrabBufSize = 0;
|
m_isGrabbing = FALSE;
|
m_isLiveGrab = FALSE;
|
m_pFrameBuffer = NULL;
|
}
|
|
CGrabberMulticam::~CGrabberMulticam()
|
{
|
if(m_pFrameBuffer != NULL)
|
delete m_pFrameBuffer;
|
m_pFrameBuffer = NULL;
|
}
|
|
BOOL CGrabberMulticam::Initialize(void *pParam, int *pErrorCode,int iBoard)
|
{
|
_GRABBER_INIT_PARAM_ *pParameter = (_GRABBER_INIT_PARAM_ *)pParam;
|
|
if(NULL != pParameter)
|
{
|
m_Param = *pParameter;
|
m_nBoardID = iBoard;
|
|
CString strDCF;
|
strDCF = pParameter->cDCFPath;
|
|
if(OpenMulticam() != 0)
|
{
|
g_pLog->DisplayMessage(_T("Open Multicam Fail! : %d"), m_nBoardID);
|
return FALSE;
|
}
|
if(InitMulticam(strDCF,iBoard,m_Param.nConnectPort) == FALSE)
|
{
|
g_pLog->DisplayMessage(_T("Init Multicam Fail! : %d"), m_nBoardID);
|
return FALSE;
|
}
|
|
// 4/13 MiniLED
|
GrabLiveStart();
|
Sleep(1000);
|
GrabScanStop();
|
}
|
else
|
return FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CGrabberMulticam::InitializeBuffer(void *pParam)
|
{
|
_GRABBER_INIT_PARAM_ *pParameter = (_GRABBER_INIT_PARAM_ *)pParam;
|
|
BOOL bRet = TRUE;
|
if(NULL != pParameter)
|
{
|
m_Param = *pParameter;
|
|
bRet = CreateGrabBuffer(m_Param.nScanCount,m_Param.nGrabBufCount,m_Param.nFrameWidth,m_Param.nFrameHeight);
|
}
|
|
return bRet;
|
}
|
|
BOOL CGrabberMulticam::Deinitialize(void)
|
{
|
DeleteMulticam();
|
|
return TRUE;
|
}
|
|
BOOL CGrabberMulticam::GrabLiveStart(int nExposure)
|
{
|
if (IsGrabbing())
|
{
|
g_pLog->DisplayMessage(_T("Start Live Acq : IsGrabbing -> Stop Acq %d"), m_nEndFrameIdx);
|
GrabScanStop();
|
Sleep(100);
|
}
|
|
m_nStartFrameIdx = 0;
|
m_nEndFrameIdx = 0;
|
m_nSetBufferIdx = -1;
|
m_nScanIndex = 0;
|
|
#if OFFLINE_KEY == 0
|
MCSTATUS driver_status = 0;
|
|
// driver_status |= McSetParamInt(m_hGrabChannel, MC_Expose_us , nExposure);
|
// driver_status |= McSetParamInt(m_hGrabChannel, MC_Period_us , nExposure/2);
|
// driver_status |= McSetParamInt(m_hGrabChannel, MC_LineRateMode,MC_LineRateMode_PERIOD);
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_Expose_us, nExposure);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_Period_us, nExposure);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_LineRateMode, MC_LineRateMode_PERIOD);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ChannelState, MC_ChannelState_ACTIVE);
|
|
g_pLog->DisplayMessage(_T("GrabLiveStart MCSTATUS : %#x"), driver_status);
|
#endif
|
|
m_isGrabbing = TRUE;
|
m_isLiveGrab = TRUE;
|
g_pLog->DisplayMessage(_T("Start Live Acq"));
|
|
return TRUE;
|
}
|
|
BOOL CGrabberMulticam::GrabScanStart(int iScan, BOOL bFreeRun, int nPeriod, int nExposure, BOOL bAuto)
|
{
|
if (IsGrabbing())
|
{
|
g_pLog->DisplayMessage(_T("Start Acq : IsGrabbing -> Stop Acq %d"), m_nEndFrameIdx);
|
GrabScanStop();
|
Sleep(100);
|
}
|
|
m_nStartFrameIdx = 0;
|
m_nEndFrameIdx = 0;
|
m_nSetBufferIdx = -1;
|
m_nScanIndex = iScan;
|
|
if(bAuto == TRUE)
|
{
|
#if OFFLINE_KEY == 0
|
MCSTATUS driver_status = 0;
|
|
if(bFreeRun == FALSE)
|
{
|
/* Start the processing. The processing function is called for every frame grabbed. */
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_Expose_us, nExposure);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_Period_us, nExposure+1);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_LineRateMode, MC_LineRateMode_PULSE);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ChannelState, MC_ChannelState_ACTIVE);
|
}
|
else
|
{
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_Expose_us, nExposure);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_Period_us, nPeriod);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_LineRateMode, MC_LineRateMode_PERIOD);
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ChannelState, MC_ChannelState_ACTIVE);
|
}
|
|
g_pLog->DisplayMessage(_T("GrabScanStart MCSTATUS : %#x"), driver_status);
|
#endif
|
m_isGrabbing = TRUE;
|
m_isLiveGrab = FALSE;
|
}
|
else
|
{
|
SimulationGrab(iScan);
|
}
|
|
g_pLog->DisplayMessage(_T("Start Acq : %d"), iScan);
|
|
return TRUE;
|
}
|
|
void CGrabberMulticam::SimulationGrab(int iScan)
|
{
|
if(m_pFrameBuffer == NULL)
|
return;
|
|
int nFrameCnt = m_pFrameBuffer->GetFrameCount();
|
|
m_nEndFrameIdx = nFrameCnt;
|
m_nSetBufferIdx = nFrameCnt -1;
|
|
for(int i=0;i<nFrameCnt;i++)
|
{
|
SetInsertFrame(iScan,i);
|
}
|
}
|
|
BOOL CGrabberMulticam::GrabScanStop(void)
|
{
|
g_pLog->DisplayMessage(_T("%d StopAcq : Scan %d, Grab %d, End %d"), m_nBoardID,m_nScanIndex,m_nSetBufferIdx, m_nEndFrameIdx);
|
#if OFFLINE_KEY == 0
|
MCSTATUS driver_status = 0;
|
|
/* Stop the sequence acquisition. */
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ChannelState, MC_ChannelState_IDLE);
|
g_pLog->DisplayMessage(_T("GrabScanStop MCSTATUS : %#x"), driver_status);
|
#endif
|
m_isGrabbing = FALSE;
|
m_isLiveGrab = FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CGrabberMulticam::IsGrabbing(void)
|
{
|
return m_isGrabbing;
|
}
|
|
int CGrabberMulticam::IsAcqFrame(int nFrameNo, int nThreadIdx)
|
{
|
return m_nSetBufferIdx - nFrameNo;
|
}
|
|
LPBYTE CGrabberMulticam::GetFrameHeaderLine(int iScan,int nLine, BOOL* bSuccess)
|
{
|
if(m_pFrameBuffer == NULL)
|
return NULL;
|
|
return m_pFrameBuffer->GetFrameHeaderLine(iScan,nLine);
|
}
|
|
LPBYTE CGrabberMulticam::GetFrameHeader(int iScan,int nFrameNo, BOOL* bRet)
|
{
|
if(m_pFrameBuffer == NULL)
|
return NULL;
|
|
return m_pFrameBuffer->GetFrameBuferHeader(iScan,nFrameNo);
|
}
|
|
BOOL CGrabberMulticam::GetSmallImage(int iScan,LPBYTE lpIn, int nXStart, int nYStart, int nXSize, int nYSize, BOOL bMustMapping)
|
{
|
int nBufSizeX = m_Param.nFrameWidth;
|
int nBufSizeY = m_Param.nFrameHeight;
|
|
if (nXStart < 0 || nYStart < 0)
|
return FALSE;
|
if (nXStart + nXSize > nBufSizeX)
|
return FALSE;
|
if (nYStart + nYSize > nBufSizeY* GetEndFrameIdx())
|
return FALSE;
|
|
// 矫累 橇饭烙 锅龋客 场 橇饭烙 锅龋.
|
int nStartFrameNo = nYStart / nBufSizeY;
|
int nEndFrameNo = (nYStart + nYSize) / nBufSizeY;
|
LPBYTE lpHeadAddr = GetFrameHeader(iScan,nStartFrameNo);
|
if (!lpHeadAddr)
|
{
|
return FALSE;
|
}
|
LPBYTE lpStart = lpHeadAddr + (nYStart % nBufSizeY) * nBufSizeX + nXStart;
|
|
int nLine = 0;
|
for (int i = 0; i < nYSize; i++)
|
{
|
memcpy(lpIn + i * nXSize, lpStart + nLine * nBufSizeX, nXSize);
|
if (nStartFrameNo <= nEndFrameNo && (nYStart + i + 1) % nBufSizeY == 0)
|
{
|
// 捞固瘤甫 蝶郴具窍绰 康开捞 MemFrameNo 版拌俊 吧媚乐绰 版快 贸府.
|
lpHeadAddr = GetFrameHeader(iScan,++nStartFrameNo);
|
lpStart = lpHeadAddr + nXStart;
|
nLine = 0;
|
}
|
else
|
nLine++;
|
}
|
|
return TRUE;
|
}
|
|
void CGrabberMulticam::SetSimulFrame(int nFrame)
|
{
|
//if(nFrame == 0)
|
//{
|
// for(int i = 0; i < g_pBase->m_nProcessMargin; i++)
|
// SetSimulBuffer(i, m_nScanIndex % 2 == 1);
|
//}
|
|
//m_nEndFrameIdx = CHKMIN(GetGrabFrameNo(m_nScanIndex), nFrame + g_pBase->m_nProcessMargin + 1);
|
//SetSimulBuffer(m_nEndFrameIdx - 1, m_nScanIndex % 2 == 1);
|
|
//if(GetParents() != NULL)
|
// GetParents()->PostMessage(UM_IMAGE_GRAB, m_nEndFrameIdx - 1,NULL);
|
}
|
|
#if OFFLINE_KEY == 0
|
void MCAPI CGrabberMulticam::ProcessCallbackFunc(PMCSIGNALINFO signal_info)
|
{
|
if(GetThreadPriority(GetCurrentThread()) != THREAD_PRIORITY_HIGHEST)
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
|
if (signal_info && signal_info->Context)
|
{
|
CGrabberMulticam* pThis = (CGrabberMulticam*)(signal_info->Context);
|
if (pThis==NULL)
|
return;
|
|
pThis->Processing(signal_info);
|
}
|
}
|
|
BOOL CGrabberMulticam::Processing(PMCSIGNALINFO signal_info)
|
{
|
if(signal_info->Signal != MC_SIG_SURFACE_PROCESSING)
|
return TRUE;
|
if(m_pFrameBuffer == NULL)
|
return FALSE;
|
|
PVOID pGrabBuffer = NULL;
|
int read_bytes = 0;
|
MCSTATUS driver_status = 0;
|
|
int nImgSize = m_Param.nFrameWidth*m_Param.nFrameHeight;
|
int nCurFrame = -1;
|
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_SurfaceIndex, &nCurFrame);
|
|
driver_status |= McGetParamPtr(signal_info->SignalInfo, MC_SurfaceAddr, &pGrabBuffer);
|
|
driver_status |= McGetParamInt(signal_info->SignalInfo, MC_FillCount, &read_bytes);
|
|
g_pLog->DisplayMessage(_T("Processing MCSTATUS : %#x"), driver_status);
|
|
if ((driver_status != 0) || (read_bytes < nImgSize))
|
return FALSE;
|
|
if (pGrabBuffer==NULL)
|
return FALSE;
|
|
int nImageSizeX = 0;
|
int nImageSizeY = 0;
|
|
if(McGetParamInt(signal_info->SignalInfo, MC_SurfaceSizeX, &nImageSizeX) != MC_OK)
|
{
|
g_pLog->DisplayMessage(_T("GrabLink X Size Error : %d"),nImageSizeX);
|
return FALSE;
|
}
|
|
if(McGetParamInt(signal_info->SignalInfo, MC_SurfaceSizeY, (PINT32) &nImageSizeY) != MC_OK)
|
{
|
g_pLog->DisplayMessage(_T("GrabLink Y Size Error : %d"),nImageSizeY);
|
return FALSE;
|
}
|
|
if(nImageSizeX<=0 || nImageSizeY<=0 )
|
{
|
g_pLog->DisplayMessage(_T("GrabLink Size Error : %d,%d"),nImageSizeX,nImageSizeY);
|
return FALSE;
|
}
|
|
if(m_pFrameBuffer->GetFrameWidth() != nImageSizeX || m_pFrameBuffer->GetFrameHeight() != nImageSizeY)
|
{
|
g_pLog->DisplayMessage(_T("GrabLink Size MissMatching Error : %d,%d"),nImageSizeX,nImageSizeY);
|
return FALSE;
|
}
|
|
if(m_isLiveGrab == TRUE) // Live Grab 矫.
|
{
|
m_nSetBufferIdx = 0;
|
|
if(m_pFrameBuffer->SetFrameBuffer(0,m_nSetBufferIdx,(LPBYTE)pGrabBuffer) == FALSE)
|
{
|
GrabScanStop();
|
g_pLog->DisplayMessage(_T("Set Live Frame Buffer Stop Grab[%d][%d]"), 0, m_nSetBufferIdx);
|
return TRUE;
|
}
|
|
return TRUE;
|
}
|
|
m_nEndFrameIdx++; //Count
|
m_nSetBufferIdx++; //index
|
|
int nCameraIdx = m_Param.nCameraIdx;
|
if (m_nEndFrameIdx > g_pStatus->GetGrabFrameCount(nCameraIdx, m_nScanIndex))
|
{
|
GrabScanStop();
|
g_pStatus->SetGrabEnd(nCameraIdx, m_nScanIndex);
|
g_pLog->DisplayMessage(_T("%d Over Grab Count : Stop Grab[%d][%d] - %d"), m_nBoardID, m_nScanIndex, m_nEndFrameIdx,g_pStatus->GetGrabFrameCount(nCameraIdx, m_nScanIndex));
|
return TRUE;
|
}
|
|
if (m_nSetBufferIdx > m_pFrameBuffer->GetFrameCount())
|
{
|
GrabScanStop();
|
g_pStatus->SetGrabEnd(nCameraIdx, m_nScanIndex);
|
g_pLog->DisplayMessage(_T("%d Over Grab Buffer Stop Grab[%d][%d] - %d"), m_nBoardID, m_nScanIndex, m_nEndFrameIdx,m_pFrameBuffer->GetFrameCount());
|
return TRUE;
|
}
|
|
if(m_pFrameBuffer->SetFrameBuffer(m_nScanIndex,m_nSetBufferIdx,(LPBYTE)pGrabBuffer) == FALSE)
|
{
|
GrabScanStop();
|
g_pLog->DisplayMessage(_T("%d Set Frame Buffer Error Stop Grab[%d][%d]"),m_nBoardID, m_nScanIndex, m_nSetBufferIdx);
|
return TRUE;
|
}
|
|
// if(m_nBoardID == 0)
|
// {
|
// g_pLog->DisplayMessage(_T("Grab Index : %d,%d"),m_nScanIndex,m_nSetBufferIdx);
|
// }
|
SetInsertFrame(m_nScanIndex,m_nSetBufferIdx);
|
|
return TRUE;
|
}
|
#endif
|
|
int CGrabberMulticam::OpenMulticam(void)
|
{
|
#if OFFLINE_KEY == 0
|
MCSTATUS driver_status = 0;
|
|
driver_status |= McOpenDriver(NULL);
|
|
driver_status |= McSetParamInt(MC_CONFIGURATION, MC_ErrorHandling, MC_ErrorHandling_NONE);
|
|
driver_status |= McSetParamStr(MC_CONFIGURATION, MC_ErrorLog, "error.log");
|
|
g_pLog->DisplayMessage(_T("OpenMulticam MCSTATUS : %#x"), driver_status);
|
return (int)driver_status;
|
#else
|
return 0;
|
#endif
|
}
|
|
void CGrabberMulticam::DeleteMulticam()
|
{
|
#if OFFLINE_KEY == 0
|
McSetParamInt(m_hGrabChannel, MC_ChannelState, MC_ChannelState_IDLE);
|
|
McDelete(m_hGrabChannel);
|
|
McCloseDriver ();
|
#endif
|
}
|
|
BOOL CGrabberMulticam::InitMulticam(CString strCamfile,int nChannel, int nPort)
|
{
|
#if OFFLINE_KEY == 0
|
MCSTATUS driver_status = 0;
|
|
driver_status |= McCreate(MC_CHANNEL, &m_hGrabChannel);
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_DriverIndex, nChannel);
|
|
driver_status |= McSetParamStr(m_hGrabChannel, MC_Connector, "M"); // FULL : M , DUALBASE : (A, B)
|
|
char port_number[10] = {0,};
|
sprintf(port_number, "COM%d", nPort);
|
|
McSetParamStr((MC_BOARD + (nPort-8)), MC_SerialControlA, port_number);
|
|
char cCamfile[1024];
|
|
ZeroMemory(cCamfile,sizeof(char)*1024);
|
|
CString strCam = strCamfile;
|
|
#ifdef _UNICODE
|
int nSize = WideCharToMultiByte(CP_ACP, 0, strCam.GetBuffer(), -1, NULL, 0, NULL,NULL);
|
WideCharToMultiByte(CP_ACP, 0, strCam.GetBuffer(), -1, cCamfile, nSize, NULL, NULL);
|
#else
|
sprintf_s(cCamfile,sizeof(char)*255,"%s",(LPSTR)(LPCTSTR)strCamfile);
|
#endif
|
|
driver_status |= McSetParamStr(m_hGrabChannel, MC_CamFile, cCamfile); // Choose the video standard strCamFile
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ColorFormat, MC_ColorFormat_Y8); // Choose the pixel color format
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_AcquisitionMode, MC_AcquisitionMode_WEB); // Set the acquisition mode
|
|
int nImgHeight = m_Param.nFrameHeight;
|
|
if(nImgHeight <= 1)
|
nImgHeight = DEFAULT_GRAB_FRAME_HEIGHT;
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_PageLength_Ln, nImgHeight);
|
|
int expose_value;
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_Expose_us, &expose_value);
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_Expose_us, 1);
|
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_Expose_us, &expose_value);
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_TrigMode, MC_TrigMode_IMMEDIATE); // Choose the way the first acquisition is triggered
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_NextTrigMode, MC_NextTrigMode_REPEAT); // Choose the triggering mode for subsequent acquisitions
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_SeqLength_Ln, MC_INDETERMINATE); // Choose the number of images to acquire
|
|
int image_size_x_value, image_size_y_value;
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_ImageSizeX, &image_size_x_value);
|
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_ImageSizeY, &image_size_y_value);
|
|
if(nImgHeight != image_size_y_value)
|
{
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ImageSizeY, nImgHeight);
|
image_size_y_value = 0;
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_ImageSizeY, &image_size_y_value);
|
}
|
|
int nImgWidth = m_Param.nFrameWidth;
|
if(nImgWidth != image_size_x_value)
|
{
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ImageSizeX, nImgWidth);
|
image_size_x_value = 0;
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_ImageSizeX, &image_size_x_value);
|
}
|
|
int buffer_pitch_value;
|
driver_status |= McGetParamInt(m_hGrabChannel, MC_BufferPitch, &buffer_pitch_value);
|
|
///// Time out 5 檬....
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_AcqTimeout_ms, -1);
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_SurfaceCount, 25);
|
|
// Enable MultiCam signals
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_SignalEnable + MC_SIG_SURFACE_PROCESSING, MC_SignalEnable_ON);
|
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_SignalEnable + MC_SIG_ACQUISITION_FAILURE, MC_SignalEnable_ON);
|
|
if(m_Param.nImgFlipX == 1)
|
driver_status |= McSetParamInt(m_hGrabChannel, MC_ImageFlipX, MC_ImageFlipX_ON);
|
|
driver_status |= McRegisterCallback(m_hGrabChannel, ProcessCallbackFunc, this);
|
|
g_pLog->DisplayMessage(_T("InitMulticam MCSTATUS : %#x"), driver_status);
|
if(driver_status != 0)
|
{
|
g_pLog->DisplayMessage(_T("Create driver Fail!:Id[%d],Frame[%d,%d]"),m_nBoardID,image_size_x_value,image_size_y_value);
|
return FALSE;
|
}
|
|
g_pLog->DisplayMessage(_T("Create driver Success!:Id[%d],Frame[%d,%d]"),m_nBoardID,image_size_x_value,image_size_y_value);
|
#endif
|
return TRUE;
|
}
|
|
BOOL CGrabberMulticam::CreateGrabBuffer(int nScanCount,int nBufSize, int nBufSizeX, int nBufSizeY)
|
{
|
SIZE_T tempBufferSize= nBufSize;
|
SIZE_T tempFrmCX = nBufSizeX;
|
SIZE_T tempFrmCY = nBufSizeY;
|
SIZE_T TotalBufferSize= tempBufferSize*tempFrmCX*tempFrmCY;
|
m_nAllocatedGrabBufSize = nBufSize;
|
|
if(m_pFrameBuffer != NULL)
|
delete m_pFrameBuffer;
|
m_pFrameBuffer = NULL;
|
|
m_pFrameBuffer = new CFrameBufferController;
|
|
if(TRUE == m_pFrameBuffer->CreateBuffer(m_nBoardID,nBufSizeX ,nBufSizeY,nBufSize, nScanCount))
|
{
|
g_pLog->DisplayMessage(_T("Create Buffer success!:Id[%d],Frame[%d,%d],Cnt[%d]"),m_nBoardID,nBufSizeX,nBufSizeY,nBufSize);
|
}
|
else
|
{
|
g_pLog->DisplayMessage(_T("Create Buffer Fail!:Id[%d],Frame[%d,%d],Cnt[%d]"),m_nBoardID,nBufSizeX,nBufSizeY,nBufSize);
|
return FALSE;
|
}
|
|
return TRUE;
|
}
|
|
void CGrabberMulticam::ClearBuffer()
|
{
|
if(m_pFrameBuffer != NULL)
|
m_pFrameBuffer->ClearBuffer();
|
}
|
|
void CGrabberMulticam::ClearGrabIdx()
|
{
|
CSingleLock MyLock(&m_csIdxLock);
|
MyLock.Lock();
|
m_dqCallbackFrame.clear();
|
MyLock.Unlock();
|
}
|
|
BOOL CGrabberMulticam::SetInsertFrame(int iScan,int iFrame)
|
{
|
CSingleLock MyLock(&m_csIdxLock);
|
MyLock.Lock();
|
stFrameIndex stFrame(iScan,iFrame);
|
m_dqCallbackFrame.push_back(stFrame);
|
MyLock.Unlock();
|
|
return TRUE;
|
}
|
|
BOOL CGrabberMulticam::FindGrabIdx(int iScan,int iFrame)
|
{
|
CSingleLock MyLock(&m_csIdxLock);
|
MyLock.Lock();
|
|
BOOL bRet = FALSE;
|
stFrameIndex stFrame;
|
for(dqGrabIdxIt it=m_dqCallbackFrame.begin();it!=m_dqCallbackFrame.end();it++)
|
{
|
stFrame = *it;
|
|
if(stFrame.nScanIdx == iScan)
|
{
|
if(stFrame.nFrameIdx < iFrame)
|
bRet = TRUE;
|
}
|
}
|
MyLock.Unlock();
|
|
return bRet;
|
}
|
|
int CGrabberMulticam::GetGrabFrameCount()
|
{
|
return (int)m_dqCallbackFrame.size();
|
}
|
|
stFrameIndex CGrabberMulticam::GetGrabFrameNoRemove()
|
{
|
stFrameIndex stPop(-1, -1);
|
|
CSingleLock MyLock(&m_csIdxLock);
|
MyLock.Lock();
|
if(IsHasGrabFrame() == FALSE)
|
{
|
MyLock.Unlock();
|
return stPop;
|
}
|
|
stPop = m_dqCallbackFrame.front();
|
|
TRACE("Pop Frame Lock[%d]\r\n", stPop.nFrameIdx);
|
MyLock.Unlock();
|
return stPop;
|
}
|
|
stFrameIndex CGrabberMulticam::GetGrabFrame()
|
{
|
stFrameIndex stPop(-1, -1);
|
|
CSingleLock MyLock(&m_csIdxLock);
|
MyLock.Lock();
|
if(IsHasGrabFrame() == FALSE)
|
{
|
MyLock.Unlock();
|
return stPop;
|
}
|
|
stPop = m_dqCallbackFrame.front();
|
m_dqCallbackFrame.pop_front();
|
|
TRACE("Pop Frame Lock[%d]\r\n", stPop.nFrameIdx);
|
MyLock.Unlock();
|
return stPop;
|
}
|
|
BOOL CGrabberMulticam::IsHasGrabFrame()
|
{
|
return !m_dqCallbackFrame.empty();
|
}
|