Fawkes API Fawkes Development Version
shm_image.h
1
2/***************************************************************************
3 * shm_image.h - shared memory image buffer
4 *
5 * Created: Thu Jan 12 13:12:24 2006
6 * Copyright 2005-2009 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
25#define _FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
26
27#include <fvutils/color/colorspaces.h>
28#include <fvutils/ipc/defs.h>
29#include <utils/ipc/shm.h>
30#include <utils/ipc/shm_lister.h>
31#include <utils/time/time.h>
32
33#include <string>
34
35// Magic token to identify FireVision shared memory images
36#define FIREVISION_SHM_IMAGE_MAGIC_TOKEN "FireVision Image"
37
38namespace firevision {
39
40// Not that there is a relation to ITPimage_packet_header_t
41/** Shared memory header struct for FireVision images. */
42typedef struct
43{
44 char image_id[IMAGE_ID_MAX_LENGTH]; /**< image ID */
45 char frame_id[FRAME_ID_MAX_LENGTH]; /**< coordinate frame ID */
46 unsigned int colorspace; /**< color space */
47 unsigned int width; /**< width */
48 unsigned int height; /**< height */
49 unsigned int roi_x; /**< ROI start x */
50 unsigned int roi_y; /**< ROI start y */
51 unsigned int roi_width; /**< ROI width */
52 unsigned int roi_height; /**< ROI height */
53 // Circle relative to ROI
54 int circle_x; /**< ROI circle center x */
55 int circle_y; /**< ROI circle center y */
56 unsigned int circle_radius; /**< ROI circle radius */
57 long int capture_time_sec; /**< Time in seconds since the epoch when
58 * the image was captured. */
59 long int capture_time_usec; /**< Addendum to capture_time_sec in
60 * micro seconds. */
61 unsigned int flag_circle_found : 1; /**< 1 if circle found */
62 unsigned int flag_image_ready : 1; /**< 1 if image ready */
63 unsigned int flag_reserved : 30; /**< reserved for future use */
65
67{
68public:
71 colorspace_t colorspace,
72 unsigned int width,
73 unsigned int height);
76
77 virtual fawkes::SharedMemoryHeader *clone() const;
78 virtual bool matches(void *memptr);
79 virtual size_t size();
80 virtual void print_info();
81 virtual bool create();
82 virtual void initialize(void *memptr);
83 virtual void set(void *memptr);
84 virtual void reset();
85 virtual size_t data_size();
86 virtual bool operator==(const fawkes::SharedMemoryHeader &s) const;
87
88 void set_image_id(const char *image_id);
89 void set_frame_id(const char *frame_id);
90 colorspace_t colorspace() const;
91 unsigned int width() const;
92 unsigned int height() const;
93 const char * image_id() const;
94 const char * frame_id() const;
95
97
98private:
99 char * _image_id;
100 char * _frame_id;
101 colorspace_t _colorspace;
102 unsigned int _width;
103 unsigned int _height;
104
105 char * _orig_image_id;
106 char * _orig_frame_id;
107 colorspace_t _orig_colorspace;
108 unsigned int _orig_width;
109 unsigned int _orig_height;
110
112};
113
115{
116public:
119
120 virtual void print_header();
121 virtual void print_footer();
122 virtual void print_no_segments();
123 virtual void print_no_orphaned_segments();
124 virtual void print_info(const fawkes::SharedMemoryHeader *header,
125 int shm_id,
126 int semaphore,
127 unsigned int mem_size,
128 const void * memptr);
129};
130
132{
133public:
134 std::string image_id; ///< Image buffer ID
135 std::string frame_id; ///< Coordinate frame ID
136 colorspace_t colorspace; ///< Colorspace
137 unsigned int width; ///< Image width
138 unsigned int height; ///< Image height
139
140 size_t mem_size; ///< Shared memory buffer size
141 bool mem_swapable; ///< True if memory might be moved to swap space
142 bool mem_destroyed; ///< True if memory has already been marked destroyed
143
146 const char * frame_id,
147 colorspace_t colorspace,
148 unsigned int width,
149 unsigned int height,
150 size_t mem_size,
151 bool mem_swapable,
152 bool mem_destroyed);
153};
154
156{
157public:
160
161 virtual void print_header();
162 virtual void print_footer();
163 virtual void print_no_segments();
164 virtual void print_no_orphaned_segments();
165 virtual void print_info(const fawkes::SharedMemoryHeader *header,
166 int shm_id,
167 int semaphore,
168 unsigned int mem_size,
169 const void * memptr);
170
171 /** Get meta data.
172 * @return image buffer meta data */
173 std::list<SharedMemoryImageBufferMetaData> &
175 {
176 return meta_data_;
177 }
178
179private:
180 std::list<SharedMemoryImageBufferMetaData> meta_data_;
181};
182
184{
185public:
187 colorspace_t cspace,
188 unsigned int width,
189 unsigned int height);
190 SharedMemoryImageBuffer(const char *image_id, bool is_read_only = true);
192
193 const char * image_id() const;
194 const char * frame_id() const;
195 unsigned char *buffer() const;
196 colorspace_t colorspace() const;
197 unsigned int width() const;
198 unsigned int height() const;
199 unsigned int roi_x() const;
200 unsigned int roi_y() const;
201 unsigned int roi_width() const;
202 unsigned int roi_height() const;
203 int circle_x() const;
204 int circle_y() const;
205 unsigned int circle_radius() const;
206 bool circle_found() const;
207 void set_roi_x(unsigned int roi_x);
208 void set_roi_y(unsigned int roi_y);
209 void set_roi_width(unsigned int roi_w);
210 void set_roi_height(unsigned int roi_h);
211 void set_roi(unsigned int roi_x, unsigned int roi_y, unsigned int roi_w, unsigned int roi_h);
212 void set_circle_x(int circle_x);
213 void set_circle_y(int circle_y);
214 void set_circle_radius(unsigned int circle_radius);
215 void set_circle(int x, int y, unsigned int r);
216 void set_circle_found(bool found);
217 bool set_image_id(const char *image_id);
218 void set_frame_id(const char *frame_id);
219
221 void capture_time(long int *sec, long int *usec) const;
222 void set_capture_time(fawkes::Time *time);
223 void set_capture_time(long int sec, long int usec);
224
225 static void list();
226 static void cleanup(bool use_lister = true);
227 static bool exists(const char *image_id);
228 static void wipe(const char *image_id);
229
230 static std::list<SharedMemoryImageBufferMetaData> list_meta_data();
231
232private:
233 void constructor(const char * image_id,
234 colorspace_t cspace,
235 unsigned int width,
236 unsigned int height,
237 bool is_read_only);
238
239 SharedMemoryImageBufferHeader * priv_header;
241
242 char * _image_id;
243 colorspace_t _colorspace;
244 unsigned int _width;
245 unsigned int _height;
246};
247
248} // end namespace firevision
249
250#endif
Interface for shared memory header.
Definition: shm.h:34
Format list output for shared memory segments.
Definition: shm_lister.h:38
Shared memory segment.
Definition: shm.h:53
bool is_read_only() const
Check for read-only mode.
Definition: shm.cpp:706
A class for handling time.
Definition: time.h:93
Shared memory image buffer header.
Definition: shm_image.h:67
virtual bool create()
Create if colorspace, width and height have been supplied.
Definition: shm_image.cpp:721
const char * image_id() const
Get image number.
Definition: shm_image.cpp:838
const char * frame_id() const
Get frame ID.
Definition: shm_image.cpp:847
virtual void set(void *memptr)
Set information from memptr.
Definition: shm_image.cpp:744
virtual bool matches(void *memptr)
Method to check if the given memptr matches this header.
Definition: shm_image.cpp:650
virtual void reset()
Reset information previously set with set().
Definition: shm_image.cpp:776
virtual void print_info()
Print some info.
Definition: shm_image.cpp:695
virtual fawkes::SharedMemoryHeader * clone() const
Clone this shared memory header.
Definition: shm_image.cpp:632
unsigned int width() const
Get width.
Definition: shm_image.cpp:814
virtual bool operator==(const fawkes::SharedMemoryHeader &s) const
Check for equality of headers.
Definition: shm_image.cpp:681
unsigned int height() const
Get height.
Definition: shm_image.cpp:826
SharedMemoryImageBuffer_header_t * raw_header()
Get raw header.
Definition: shm_image.cpp:878
void set_image_id(const char *image_id)
Set image id.
Definition: shm_image.cpp:856
colorspace_t colorspace() const
Get colorspace.
Definition: shm_image.cpp:802
virtual void initialize(void *memptr)
Initialize the header.
Definition: shm_image.cpp:727
virtual size_t data_size()
Return the size of the data.
Definition: shm_image.cpp:638
virtual ~SharedMemoryImageBufferHeader()
Destructor.
Definition: shm_image.cpp:613
virtual size_t size()
Size of the header.
Definition: shm_image.cpp:626
void set_frame_id(const char *frame_id)
Set frame ID.
Definition: shm_image.cpp:867
Shared memory image buffer lister.
Definition: shm_image.h:115
virtual void print_info(const fawkes::SharedMemoryHeader *header, int shm_id, int semaphore, unsigned int mem_size, const void *memptr)
Print info about segment.
Definition: shm_image.cpp:938
virtual void print_no_orphaned_segments()
Print this if no matching orphaned segment was found.
Definition: shm_image.cpp:932
virtual ~SharedMemoryImageBufferLister()
Destructor.
Definition: shm_image.cpp:893
virtual void print_no_segments()
Print this if no matching segment was found.
Definition: shm_image.cpp:926
virtual void print_footer()
Print footer of the table.
Definition: shm_image.cpp:921
virtual void print_header()
Print header of the table.
Definition: shm_image.cpp:898
Collect meta data about shared memory segments.
Definition: shm_image.h:156
virtual void print_no_orphaned_segments()
Print this if no matching orphaned segment was found.
Definition: shm_image.cpp:1035
virtual void print_info(const fawkes::SharedMemoryHeader *header, int shm_id, int semaphore, unsigned int mem_size, const void *memptr)
Print info about segment.
Definition: shm_image.cpp:1040
std::list< SharedMemoryImageBufferMetaData > & meta_data()
Get meta data.
Definition: shm_image.h:174
virtual void print_no_segments()
Print this if no matching segment was found.
Definition: shm_image.cpp:1030
virtual void print_header()
Print header of the table.
Definition: shm_image.cpp:1020
virtual void print_footer()
Print footer of the table.
Definition: shm_image.cpp:1025
Shared memory image buffer meta data container.
Definition: shm_image.h:132
bool mem_swapable
True if memory might be moved to swap space.
Definition: shm_image.h:141
bool mem_destroyed
True if memory has already been marked destroyed.
Definition: shm_image.h:142
unsigned int height
Image height.
Definition: shm_image.h:138
std::string image_id
Image buffer ID.
Definition: shm_image.h:134
size_t mem_size
Shared memory buffer size.
Definition: shm_image.h:140
std::string frame_id
Coordinate frame ID.
Definition: shm_image.h:135
Shared memory image buffer.
Definition: shm_image.h:184
void set_circle_radius(unsigned int circle_radius)
Set circle radius.
Definition: shm_image.cpp:420
void set_roi(unsigned int roi_x, unsigned int roi_y, unsigned int roi_w, unsigned int roi_h)
Set ROI data.
Definition: shm_image.cpp:378
static std::list< SharedMemoryImageBufferMetaData > list_meta_data()
Get meta data about image buffers.
Definition: shm_image.cpp:479
static void wipe(const char *image_id)
Erase a specific shared memory segment that contains an image.
Definition: shm_image.cpp:534
int circle_x() const
Get circle X.
Definition: shm_image.cpp:300
bool set_image_id(const char *image_id)
Set image number.
Definition: shm_image.cpp:135
unsigned int circle_radius() const
Get circle radius.
Definition: shm_image.cpp:318
unsigned int roi_x() const
Get ROI X.
Definition: shm_image.cpp:264
int circle_y() const
Get circle Y.
Definition: shm_image.cpp:309
static bool exists(const char *image_id)
Check image availability.
Definition: shm_image.cpp:520
unsigned int height() const
Get image height.
Definition: shm_image.cpp:255
fawkes::Time capture_time() const
Get the time when the image was captured.
Definition: shm_image.cpp:189
void set_circle(int x, int y, unsigned int r)
Set circle data.
Definition: shm_image.cpp:434
colorspace_t colorspace() const
Get color space.
Definition: shm_image.cpp:237
unsigned int roi_width() const
Get ROI width.
Definition: shm_image.cpp:282
void set_circle_y(int circle_y)
Set circle Y.
Definition: shm_image.cpp:408
void set_capture_time(fawkes::Time *time)
Set the capture time.
Definition: shm_image.cpp:198
static void list()
List all shared memory segments that contain a FireVision image.
Definition: shm_image.cpp:464
static void cleanup(bool use_lister=true)
Erase all shared memory segments that contain FireVision images.
Definition: shm_image.cpp:500
void set_roi_width(unsigned int roi_w)
Set ROI width.
Definition: shm_image.cpp:351
void set_circle_x(int circle_x)
Set circle X.
Definition: shm_image.cpp:396
void set_roi_height(unsigned int roi_h)
Set ROI height.
Definition: shm_image.cpp:363
const char * image_id() const
Get Image ID.
Definition: shm_image.cpp:160
unsigned int width() const
Get image width.
Definition: shm_image.cpp:246
unsigned int roi_height() const
Get ROI height.
Definition: shm_image.cpp:291
void set_roi_x(unsigned int roi_x)
Set ROI X.
Definition: shm_image.cpp:327
void set_circle_found(bool found)
Set circle found.
Definition: shm_image.cpp:448
void set_roi_y(unsigned int roi_y)
Set ROI Y.
Definition: shm_image.cpp:339
unsigned int roi_y() const
Get ROI Y.
Definition: shm_image.cpp:273
unsigned char * buffer() const
Get image buffer.
Definition: shm_image.cpp:228
void set_frame_id(const char *frame_id)
Set frame ID.
Definition: shm_image.cpp:150
bool circle_found() const
Check if circle was found .
Definition: shm_image.cpp:457
const char * frame_id() const
Get frame ID.
Definition: shm_image.cpp:169
SharedMemoryImageBuffer(const char *image_id, colorspace_t cspace, unsigned int width, unsigned int height)
Write Constructor.
Definition: shm_image.cpp:61
Shared memory header struct for FireVision images.
Definition: shm_image.h:43
unsigned int circle_radius
ROI circle radius.
Definition: shm_image.h:56
long int capture_time_usec
Addendum to capture_time_sec in micro seconds.
Definition: shm_image.h:59
unsigned int flag_image_ready
1 if image ready
Definition: shm_image.h:62
unsigned int flag_circle_found
1 if circle found
Definition: shm_image.h:61
long int capture_time_sec
Time in seconds since the epoch when the image was captured.
Definition: shm_image.h:57
unsigned int flag_reserved
reserved for future use
Definition: shm_image.h:63