FACT++  1.0
Int_t Camera::Thread ( )
privatevirtual

Implements MThread.

Definition at line 72 of file Camera.cc.

References MVideo::CaptureStart(), MVideo::CaptureWait(), fNumFrame, fNumSkipped, fVideo, MVideo::GetNumBuffers(), MVideo::IsOpen(), ProcessFrame(), and MVideo::Start().

73 {
74  fNumSkipped = 0;
75  fNumFrame = 0;
76 
77  if (!fVideo->IsOpen())
78  {
79  cout << "Camera::Thread: ERROR - Device not open." << endl;
80  return kFALSE;
81  }
82 
83  cout << "Start Camera::Thread at frame " << fNumFrame%fVideo->GetNumBuffers() << endl;
84 
85  for (int f=0; f<fVideo->GetNumBuffers(); f++)
86  {
87  if (!fVideo->CaptureStart(f))
88  return kFALSE;
89  }
90 
91  if (!fVideo->Start())
92  return kFALSE;
93 
94  Int_t timeouts = 0;
95  while (1)
96  {
97 
98  /*
99  // Switch channel if necessary
100  switch (fVideo->SetChannel(fChannel))
101  {
102  case kFALSE: // Error swucthing channel
103  return kFALSE;
104  case kSKIP: // No channel switching necessary
105  break;
106  case kTRUE: // Channel switched (skip filled buffers)
107  for (int f=0; f<fVideo->GetNumBuffers(); f++)
108  if (!fVideo->CaptureWait(fNumFrame+f))
109  return kFALSE;
110  fNumFrame=0;
111  for (int f=0; f<fVideo->GetNumBuffers(); f++)
112  if (!fVideo->CaptureStart(f))
113  return kFALSE;
114  break;
115  }*/
116 
117  //cout << "*** Wait " << fNumFrame << endl;
118 
119  // Check and wait until capture into the next buffer is finshed
120  unsigned char *img = 0;
121  switch (fVideo->CaptureWait(fNumFrame, &img))
122  {
123  case kTRUE: // Process frame
124  // If cacellation is requested cancel here
125  TThread::CancelPoint();
126 
127  ProcessFrame(img);
128 
129  // If cacellation is requested cancel here
130  TThread::CancelPoint();
131 
132  // Start to capture into the buffer which has just been processed
133  if (!fVideo->CaptureStart(fNumFrame-1))
134  break;
135 
136  fNumFrame++;
137  timeouts = 0;
138  continue;
139 
140  case kFALSE: // Waiting failed
141  break;
142 
143  case -1: // Skip frame
144  usleep(10000); // Wait half a frame
145  continue;
146 
147  fNumFrame--;
148  fNumSkipped++;
149  if (timeouts++<5)
150  continue;
151 
152  cout << "ERROR - At least five captured images timed out." << endl;
153  break;
154  }
155 
156  break;
157  }
158 
159  // Is this necessary?!?
160  //for (int i=0; i<frames-1; i++)
161  // video.CaptureWait((f+i+1)%frames);
162 
163  cout << fNumFrame-1 << " frames processed." << endl;
164  cout << fNumSkipped << " frames skipped." << endl;
165 
166  return kTRUE;
167 }
UInt_t fNumSkipped
Definition: Camera.h:33
Bool_t IsOpen() const
Definition: MVideo.h:105
UInt_t fNumFrame
Definition: Camera.h:32
Int_t CaptureWait(unsigned int frame, unsigned char **ptr=0) const
Definition: MVideo.cc:782
void ProcessFrame(unsigned char *img)
Definition: Camera.cc:50
Int_t GetNumBuffers() const
Definition: MVideo.cc:878
MVideo * fVideo
Definition: Camera.h:30
Bool_t CaptureStart(unsigned int frame) const
Definition: MVideo.cc:736
Bool_t Start()
Definition: MVideo.cc:677

+ Here is the call graph for this function: