Fawkes API Fawkes Development Version
firevision::SharedMemoryCamera Class Reference

Shared memory camera. More...

#include <>>

Inheritance diagram for firevision::SharedMemoryCamera:

Public Member Functions

 SharedMemoryCamera (const char *image_id, bool deep_copy=false)
 Constructor. More...
 
 SharedMemoryCamera (const CameraArgumentParser *cap)
 Constructor. More...
 
 ~SharedMemoryCamera ()
 Destructor. More...
 
virtual void open ()
 Open the camera. More...
 
virtual void start ()
 Start image transfer from the camera. More...
 
virtual void stop ()
 Stop image transfer from the camera. More...
 
virtual void close ()
 Close camera. More...
 
virtual void flush ()
 Flush image queue. More...
 
virtual void capture ()
 Capture an image. More...
 
virtual void print_info ()
 Print out camera information. More...
 
virtual bool ready ()
 Camera is ready for taking pictures. More...
 
virtual unsigned char * buffer ()
 Get access to current image buffer. More...
 
virtual unsigned int buffer_size ()
 Size of buffer. More...
 
virtual void dispose_buffer ()
 Dispose current buffer. More...
 
virtual unsigned int pixel_width ()
 Width of image in pixels. More...
 
virtual unsigned int pixel_height ()
 Height of image in pixels. More...
 
virtual colorspace_t colorspace ()
 Colorspace of returned image. More...
 
virtual fawkes::Timecapture_time ()
 Get the Time of the last successfully captured image. More...
 
virtual void set_image_number (unsigned int n)
 Set image number to retrieve. More...
 
SharedMemoryImageBuffershared_memory_image_buffer ()
 Get the shared memory image buffer. More...
 
virtual void lock_for_read ()
 Lock image for reading. More...
 
virtual bool try_lock_for_read ()
 Try to lock for reading. More...
 
virtual void lock_for_write ()
 Lock image for writing. More...
 
virtual bool try_lock_for_write ()
 Try to lock for reading. More...
 
virtual void unlock ()
 Unlock buffer. More...
 
- Public Member Functions inherited from firevision::Camera
virtual ~Camera ()
 Virtual empty destructor. More...
 
virtual void open ()=0
 Open the camera. More...
 
virtual void start ()=0
 Start image transfer from the camera. More...
 
virtual void stop ()=0
 Stop image transfer from the camera. More...
 
virtual void close ()=0
 Close camera. More...
 
virtual void capture ()=0
 Capture an image. More...
 
virtual void flush ()=0
 Flush image queue. More...
 
virtual bool ready ()=0
 Camera is ready for taking pictures. More...
 
virtual void print_info ()=0
 Print out camera information. More...
 
virtual unsigned char * buffer ()=0
 Get access to current image buffer. More...
 
virtual unsigned int buffer_size ()=0
 Size of buffer. More...
 
virtual void dispose_buffer ()=0
 Dispose current buffer. More...
 
virtual unsigned int pixel_width ()=0
 Width of image in pixels. More...
 
virtual unsigned int pixel_height ()=0
 Height of image in pixels. More...
 
virtual colorspace_t colorspace ()=0
 Colorspace of returned image. More...
 
virtual fawkes::Timecapture_time ()
 Get the Time of the last successfully captured image. More...
 
virtual void set_image_number (unsigned int n)=0
 Set image number to retrieve. More...
 

Detailed Description

Shared memory camera.

Camera to retrieve images from a shared memory segment.

The camera can operate in a so-called deep-copy mode. In this mode a local internal buffer is created of the size of the image. On capture() the image is copied from the shared memory buffer to the local buffer with the shared memory segment locked for reading. This can be used if the image writing and the image reading processess run asynchronously. While locking would suffice the copying will account for only short locking times so that the interference between the two processes is minimal.

Author
Tim Niemueller

Definition at line 35 of file shmem.h.

Constructor & Destructor Documentation

◆ SharedMemoryCamera() [1/2]

firevision::SharedMemoryCamera::SharedMemoryCamera ( const char *  image_id,
bool  deep_copy = false 
)

Constructor.

Parameters
image_idimage ID to open
deep_copytrue to operate in deep-copy mode, false otherwise

Definition at line 57 of file shmem.cpp.

◆ SharedMemoryCamera() [2/2]

firevision::SharedMemoryCamera::SharedMemoryCamera ( const CameraArgumentParser cap)

Constructor.

Take configuration data from camera argument parser. The following options are supported.

  • image_id=ID, where ID is the image ID
    Parameters
    capcamera argument parser

Definition at line 77 of file shmem.cpp.

References firevision::CameraArgumentParser::get(), and firevision::CameraArgumentParser::has().

◆ ~SharedMemoryCamera()

firevision::SharedMemoryCamera::~SharedMemoryCamera ( )

Destructor.

Definition at line 101 of file shmem.cpp.

Member Function Documentation

◆ buffer()

unsigned char * firevision::SharedMemoryCamera::buffer ( )
virtual

Get access to current image buffer.

This will return a pointer to the current buffer. The buffer contains an image of the given colorspace, width and height.

Returns
pointer to image buffer

Implements firevision::Camera.

Definition at line 165 of file shmem.cpp.

References firevision::SharedMemoryImageBuffer::buffer().

Referenced by fawkes::WebviewJpegStreamProducer::loop().

◆ buffer_size()

unsigned int firevision::SharedMemoryCamera::buffer_size ( )
virtual

Size of buffer.

Gets the size in bytes of the buffer returned by buffer().

Returns
size of buffer in bytes

Implements firevision::Camera.

Definition at line 175 of file shmem.cpp.

References firevision::SharedMemoryImageBuffer::colorspace(), firevision::SharedMemoryImageBuffer::height(), and firevision::SharedMemoryImageBuffer::width().

◆ capture()

void firevision::SharedMemoryCamera::capture ( )
virtual

Capture an image.

Although cameras shall operate with a continuous image flow where possible sometimes capturing an image means copying a buffer or advancing a buffer list pointer. This shall be done in this method. For a camera-using application it is mandatory to call capture() just before accessing the image buffer.

Implements firevision::Camera.

Definition at line 153 of file shmem.cpp.

References firevision::SharedMemoryImageBuffer::buffer(), firevision::SharedMemoryImageBuffer::capture_time(), fawkes::SharedMemory::data_size(), fawkes::SharedMemory::lock_for_read(), fawkes::Time::set_time(), and fawkes::SharedMemory::unlock().

Referenced by fawkes::WebviewJpegStreamProducer::loop().

◆ capture_time()

fawkes::Time * firevision::SharedMemoryCamera::capture_time ( )
virtual

Get the Time of the last successfully captured image.

Returns a Time representing the time when the last image was captured successfully. Note that calling this function is only valid after capture() and before dispose_buffer() has been called – it is only valid when an image is currently available.

Returns
Time of the currently processed image. The pointer shall be valid at least until the next call to dispose_buffer().
Exceptions
NotImplementedExceptionthrown if Camera does not support time stamping

Reimplemented from firevision::Camera.

Definition at line 211 of file shmem.cpp.

◆ close()

void firevision::SharedMemoryCamera::close ( )
virtual

Close camera.

This closes the camera device. The camera must have been stopped before calling close().

Implements firevision::Camera.

Definition at line 183 of file shmem.cpp.

◆ colorspace()

colorspace_t firevision::SharedMemoryCamera::colorspace ( )
virtual

Colorspace of returned image.

Returns
colorspace of image returned by buffer()

Implements firevision::Camera.

Definition at line 205 of file shmem.cpp.

References firevision::SharedMemoryImageBuffer::colorspace().

Referenced by fawkes::WebviewJpegStreamProducer::loop().

◆ dispose_buffer()

void firevision::SharedMemoryCamera::dispose_buffer ( )
virtual

Dispose current buffer.

Some cameras need disposal of the current buffer (for example to free space in a queue to retrieve the next image). This is done with this method. It has to be called after all work has been done on the image as desired. After dispose_buffer() has been called no further access may happen to the image buffer or undesired behavior may happen.

Implements firevision::Camera.

Definition at line 188 of file shmem.cpp.

Referenced by fawkes::WebviewJpegStreamProducer::loop().

◆ flush()

void firevision::SharedMemoryCamera::flush ( )
virtual

Flush image queue.

Some cameras may have an image buffer queue. With this it can happen that if the processing of an image took longer than desired it is needed to flush this buffer queue.

Implements firevision::Camera.

Definition at line 217 of file shmem.cpp.

◆ lock_for_read()

void firevision::SharedMemoryCamera::lock_for_read ( )
virtual

Lock image for reading.

Aquire the lock to read images.

Definition at line 246 of file shmem.cpp.

References fawkes::SharedMemory::lock_for_read().

Referenced by fawkes::WebviewJpegStreamProducer::loop().

◆ lock_for_write()

void firevision::SharedMemoryCamera::lock_for_write ( )
virtual

Lock image for writing.

Aquire the lock to write images.

Definition at line 264 of file shmem.cpp.

References fawkes::SharedMemory::lock_for_write().

◆ open()

void firevision::SharedMemoryCamera::open ( )
virtual

Open the camera.

The camera is opened, but image transfer not yet started. This can be used to detect general problems with the camera while delaying the real transfer startup until it is needed.

Implements firevision::Camera.

Definition at line 133 of file shmem.cpp.

◆ pixel_height()

unsigned int firevision::SharedMemoryCamera::pixel_height ( )
virtual

Height of image in pixels.

Returns
height of image in pixels

Implements firevision::Camera.

Definition at line 199 of file shmem.cpp.

References firevision::SharedMemoryImageBuffer::height().

Referenced by fawkes::WebviewJpegStreamProducer::init(), and fawkes::WebviewJpegStreamProducer::loop().

◆ pixel_width()

unsigned int firevision::SharedMemoryCamera::pixel_width ( )
virtual

Width of image in pixels.

Returns
width of image in pixels

Implements firevision::Camera.

Definition at line 193 of file shmem.cpp.

References firevision::SharedMemoryImageBuffer::width().

Referenced by fawkes::WebviewJpegStreamProducer::init(), and fawkes::WebviewJpegStreamProducer::loop().

◆ print_info()

void firevision::SharedMemoryCamera::print_info ( )
virtual

Print out camera information.

Shall print out camera information and current setup information on stdout.

Implements firevision::Camera.

Definition at line 148 of file shmem.cpp.

◆ ready()

bool firevision::SharedMemoryCamera::ready ( )
virtual

Camera is ready for taking pictures.

The camera has been opened and started correctly and may now provide images.

Returns
true, if the camera is ready, false otherwise

Implements firevision::Camera.

Definition at line 231 of file shmem.cpp.

◆ set_image_number()

void firevision::SharedMemoryCamera::set_image_number ( unsigned int  n)
virtual

Set image number to retrieve.

If a camera is able to retrieve several images this method can be used to select the image to be retrieved with the next call to capture().

Parameters
nimage number to set

Implements firevision::Camera.

Definition at line 237 of file shmem.cpp.

◆ shared_memory_image_buffer()

SharedMemoryImageBuffer * firevision::SharedMemoryCamera::shared_memory_image_buffer ( )

Get the shared memory image buffer.

Returns
shared memory image buffer used to access image

Definition at line 225 of file shmem.cpp.

◆ start()

void firevision::SharedMemoryCamera::start ( )
virtual

Start image transfer from the camera.

For many cameras opening the camera and starting transmission of images are two tasks. This method will simply initiate the transfer after the camera as been opened. And exception shall be thrown if the camera has not been opened.

Implements firevision::Camera.

Definition at line 138 of file shmem.cpp.

◆ stop()

void firevision::SharedMemoryCamera::stop ( )
virtual

Stop image transfer from the camera.

This will stop the image transfer initiated with start(). This can be used to start and stop the image transfer at will without opening and closing operations inbetween.

Implements firevision::Camera.

Definition at line 143 of file shmem.cpp.

◆ try_lock_for_read()

bool firevision::SharedMemoryCamera::try_lock_for_read ( )
virtual

Try to lock for reading.

Returns
true if the lock has been aquired, false otherwise

Definition at line 255 of file shmem.cpp.

References fawkes::SharedMemory::try_lock_for_read().

◆ try_lock_for_write()

bool firevision::SharedMemoryCamera::try_lock_for_write ( )
virtual

Try to lock for reading.

Returns
true if the lock has been aquired, false otherwise

Definition at line 273 of file shmem.cpp.

References fawkes::SharedMemory::try_lock_for_write().

◆ unlock()

void firevision::SharedMemoryCamera::unlock ( )
virtual

Unlock buffer.

Definition at line 280 of file shmem.cpp.

References fawkes::SharedMemory::unlock().

Referenced by fawkes::WebviewJpegStreamProducer::loop().


The documentation for this class was generated from the following files: