I have got a program which display image from usb webcam. I can display two webcam image without problem (using wxthread sending event to GUI). When I want to open 3 webcam GUI is blocked or very slow (with four webcam GUI is blocked) but program is still running using only 8% of cpu. I think something is wrong in my program.
In wxThread I use those lines to send event to GUI with a critical section :
Code: Select all
while(attendre && nbBoucle<100)
{
if (!parent)
break;
{
wxCriticalSectionLocker enter(((FenetrePrincipale*)parent)->travailCam);
if (((FenetrePrincipale*)parent)->IndEvtCam()==indEvt-1 || nbBoucle==99)
{
EvtPointSuivis *x = new EvtPointSuivis(VAL_EVT_PTS_SUIVIS);
x->ptId = repereIni;
x->ptApp = repere;
x->SetTimestamp(wxGetUTCTimeMillis().GetLo());
x->indEvt = indEvt;
indEvt++;
wxQueueEvent( ((FenetrePrincipale*)parent)->GetEventHandler(), x);
attendre=false;
}
}
nbBoucle++;
if (attendre)this->Sleep(1);
}
Code: Select all
void FenetrePrincipale::OnThreadUpdateQueue(EvtPointSuivis &w)
{
if (cam && (cam->IsRunning() || cam->IsPaused()))
{
long x=wxGetUTCTimeMillis().GetLo();
{
wxCriticalSectionLocker enter(travailCam);
delete feuille->BitmapAffichee();
feuille->BitmapAffichee(NULL);
DIB(imAcq);
feuille->Refresh(false);
}
indEvtCam=w.indEvt;
nbImageCam++;
if (nbImageCam==25)
{
cam->DefTpsInactif((x - tpsPreEvt) / 25);
nbImageCam=0;
tpsPreEvt=x;
osgApp->CtrlCamera()->DrawOngletStatus();
}
}
return;
}
Thanks in advance