23 #include "acquisition_thread.h"
24 #include "aqt_vision_threads.h"
26 #include <core/exceptions/system.h>
27 #include <core/exceptions/software.h>
28 #ifdef FVBASE_TIMETRACKER
29 #include <utils/time/clock.h>
30 #include <utils/time/tracker.h>
32 #include <logging/logger.h>
34 #include <fvcams/shmem.h>
35 #include <fvutils/color/conversions.h>
64 :
Thread((
std::string(
"FvAcquisitionThread::") + id).c_str())
67 __image_id = strdup(
id);
76 logger->
log_debug(
name(),
"Camera opened, w=%u h=%u c=%s", __width, __height,
77 colorspace_to_string(__colorspace));
82 #ifdef FVBASE_TIMETRACKER
85 __ttc_capture = __tt->add_class(
"Capture");
86 __ttc_lock = __tt->add_class(
"Lock");
87 __ttc_convert = __tt->add_class(
"Convert");
88 __ttc_unlock = __tt->add_class(
"Unlock");
89 __ttc_dispose = __tt->add_class(
"Dispose");
99 for (__shmit = __shm.begin(); __shmit != __shm.end(); ++__shmit) {
100 delete __shmit->second;
146 const char *img_id = NULL;
148 if (cspace == CS_UNKNOWN) {
151 throw Exception(
"Only one vision thread may access the raw camera.");
157 if (__shm.find(cspace) == __shm.end()) {
158 if ( asprintf(&tmp,
"%s.%zu", __image_id, __shm.size()) == -1) {
164 img_id = __shm[cspace]->image_id();
239 __logger->
log_warn(
name(),
"At least one thread was being finalized while prepfin hold "
240 "was about to be acquired");
253 #ifdef FVBASE_TIMETRACKER
255 __tt->ping_start(__ttc_capture);
257 __tt->ping_end(__ttc_capture);
260 for (__shmit = __shm.begin(); __shmit != __shm.end(); ++__shmit) {
261 if (__shmit->first == CS_UNKNOWN)
continue;
262 __tt->ping_start(__ttc_lock);
263 __shmit->second->lock_for_write();
264 __tt->ping_end(__ttc_lock);
265 __tt->ping_start(__ttc_convert);
266 convert(__colorspace, __shmit->first,
267 __camera->
buffer(), __shmit->second->buffer(),
270 __shmit->second->set_capture_time(__camera->
capture_time());
274 __tt->ping_end(__ttc_convert);
275 __tt->ping_start(__ttc_unlock);
276 __shmit->second->unlock();
277 __tt->ping_end(__ttc_unlock);
284 __tt->ping_start(__ttc_dispose);
286 __tt->ping_end(__ttc_dispose);
288 if ( (++__loop_count % FVBASE_TT_PRINT_INT) == 0 ) {
289 __tt->print_to_stdout();
292 #else // no time tracking
296 for (__shmit = __shm.begin(); __shmit != __shm.end(); ++__shmit) {
297 if (__shmit->first == CS_UNKNOWN)
continue;
298 __shmit->second->lock_for_write();
299 convert(__colorspace, __shmit->first,
300 __camera->
buffer(), __shmit->second->buffer(),
303 __shmit->second->set_capture_time(__camera->
capture_time());
307 __shmit->second->unlock();
void set_aqtmode(AqtMode mode)
Set acquisition thread mode.
void wakeup_and_wait_cyclic_threads()
Wakeup and wait for all cyclic threads.
AqtMode
Acquisition thread mode.
Camera interface for image aquiring devices in FireVision.
Fawkes library namespace.
fawkes::Thread * raw_subscriber_thread
Vision thread registered for raw camera access on this camera.
Called method has not been implemented.
This is supposed to be the central clock in Fawkes.
virtual unsigned int pixel_width()=0
Width of image in pixels.
FvAqtVisionThreads * vision_threads
Vision threads assigned to this acquisition thread.
Aquisition-dependant threads.
Thread class encapsulation of pthreads.
void set_prepfin_hold(bool hold)
Set prepfin hold fo cyclic threads.
virtual colorspace_t colorspace()=0
Colorspace of returned image.
static void set_cancel_state(CancelState new_state, CancelState *old_state=0)
Set the cancel state of the current thread.
virtual ~FvAcquisitionThread()
Destructor.
Base class for exceptions in Fawkes.
virtual void capture()=0
Capture an image.
virtual fawkes::Time * capture_time()
Get the Time of the last successfully captured image.
void set_opmode(OpMode op_mode)
Set operation mode.
Shared memory image buffer.
firevision::Camera * get_camera()
Get the Camera of this acquisition thread.
void set_vt_prepfin_hold(bool hold)
Set prepfin hold status for vision threads.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
firevision::Camera * camera_instance(firevision::colorspace_t cspace, bool deep_copy)
Get a camera instance.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
virtual void loop()
Code to execute in the thread.
const char * name() const
Get name of thread.
cyclic mode, use if there is at least one cyclic thread for this acquisition thread.
void set_enabled(bool enabled)
Enable or disable image retrieval.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual void close()=0
Close camera.
virtual unsigned char * buffer()=0
Get access to current image buffer.
FvAcquisitionThread(const char *id, firevision::Camera *camera, fawkes::Logger *logger, fawkes::Clock *clock)
Constructor.
virtual unsigned int pixel_height()=0
Height of image in pixels.
continuous mode, use if there are only continuous threads for this acquisition thread.
System ran out of memory and desired operation could not be fulfilled.
AqtMode aqtmode()
Get acquisition thread mode.
virtual void dispose_buffer()=0
Dispose current buffer.