Shared memory buffer for storing image data for other JAUS components on local host to bypass serializing image data for transfer. More...
#include <sharedimage.h>
Public Member Functions | |
SharedImage () | |
Constructor. | |
~SharedImage () | |
Destructor. | |
int | CreateSharedImage (const Address &src, const Byte cameraID, const unsigned int size=2097152) |
Created a shared image memory space. | |
int | OpenSharedImage (const Address &src, const Byte cameraID) |
Created a shared image memory space. | |
int | CloseSharedImage () |
Closes shared image. | |
int | RegisterCallback (void(*func)(const Address &src, const Byte cameraID, const Image &img, const unsigned int frameNumber, void *args), void *fargs) |
Registers a callback to be done every time the shared image updates. | |
int | ClearCallback () |
Clears the callback. | |
int | GetFrame (Image &img) const |
Gets the image from shared memory. | |
int | GetFrame (unsigned char *&image, unsigned int &size, unsigned int &width, unsigned int &height, unsigned char &channels, unsigned int &frameNumber) const |
Gets the image from shared memory, reading directly into an existing buffer. | |
int | SetFrame (const unsigned char *rawImage, const unsigned int width, const unsigned int height, const unsigned char channels, const unsigned int frameNumber) |
Sets the value of the image data. | |
UInt | GetFrameNumber () const |
Get the sequence number for the image. | |
unsigned int | GetBufferSize () const |
bool | IsOpen () const |
bool | IsActive (const unsigned int timeout=1000) const |
Method checks to see if the shared image buffer is being updated or not. | |
Address | GetSourceID () const |
Byte | GetCameraID () const |
Static Protected Member Functions | |
static void | SharedImageUpdate (void *args) |
Function called by thread which keeps trying to get the latest data from shared memory image. | |
Protected Attributes | |
Address | mSourceID |
Source ID of data. | |
Byte | mCameraID |
Camera ID. | |
bool | mWriteFlag |
If true, writing to memory is allowed. | |
Image | mTempImage |
Temporary image for storing data. | |
CxUtils::MappedMemory | mImageBuffer |
Shared memory image buffer. | |
CxUtils::Thread | mCallbackThread |
Thread to poll for image data. | |
CxUtils::Mutex | mCallbackMutex |
Mutex for image callbacks. | |
void(* | mpCallback )(const Address &src, const Byte cameraID, const CxUtils::Image &img, const unsigned int frameNumber, void *args) |
Callback to perform when image updates. | |
void * | mpCallbackArgs |
Callback arguments. | |
bool | mExitFlag |
Indicates program is exiting. |
Shared memory buffer for storing image data for other JAUS components on local host to bypass serializing image data for transfer.
Using the standard approach, a component wanting to access video data from a JAUS Visual Sensor would need to send a query or create an Event or Service Connection to get video data. This results in image data being serialized into multiple JAUS packets or being compressed using some type of compression method. Although this approach is fine (and necessary for communication with other computers), it is faster to just access the data directly when the sensor is on the same node as the requesting component.
This class is used by the VisualSensor component class to provide an alternative method for accessing video data on the same computer. The VisualSensorController component uses this video to just directly get data from the Visual Sensor component without having to get a bunch of JAUS packets or decompress image data.
Definition at line 77 of file sharedimage.h.
SharedImage::SharedImage | ( | ) |
Constructor.
Definition at line 57 of file sharedimage.cpp.
SharedImage::~SharedImage | ( | ) |
Destructor.
Definition at line 71 of file sharedimage.cpp.
int SharedImage::ClearCallback | ( | ) |
Clears the callback.
Definition at line 244 of file sharedimage.cpp.
int SharedImage::CloseSharedImage | ( | ) |
Closes shared image.
Definition at line 168 of file sharedimage.cpp.
int SharedImage::CreateSharedImage | ( | const Address & | src, |
const Byte | cameraID, | ||
const unsigned int | size = 2097152 |
||
) |
Created a shared image memory space.
[in] | src | Source ID of the provider of the data. |
[in] | cameraID | The ID of the camera on the source. |
[in] | size | How many bytes needed to store image. |
Definition at line 88 of file sharedimage.cpp.
unsigned int JAUS::SharedImage::GetBufferSize | ( | ) | const [inline] |
Definition at line 107 of file sharedimage.h.
Byte JAUS::SharedImage::GetCameraID | ( | ) | const [inline] |
Definition at line 111 of file sharedimage.h.
int SharedImage::GetFrame | ( | Image & | img ) | const |
Gets the image from shared memory.
img | Current image data. |
Definition at line 305 of file sharedimage.cpp.
int SharedImage::GetFrame | ( | unsigned char *& | image, |
unsigned int & | size, | ||
unsigned int & | width, | ||
unsigned int & | height, | ||
unsigned char & | channels, | ||
unsigned int & | frameNumber | ||
) | const |
Gets the image from shared memory, reading directly into an existing buffer.
[out] | image | Pointer to array to copy data to. If pointer is NULL, or array is not large enough, it is automatically resized. |
[out] | size | The size of the array. |
[out] | width | Image width (pixels). |
[out] | height | Image height (pixels). |
[out] | channels | Number of channels in the image. |
[out] | frameNumber | Image frame number. |
Definition at line 352 of file sharedimage.cpp.
UInt SharedImage::GetFrameNumber | ( | ) | const |
Get the sequence number for the image.
Definition at line 401 of file sharedimage.cpp.
Address JAUS::SharedImage::GetSourceID | ( | ) | const [inline] |
Definition at line 110 of file sharedimage.h.
bool SharedImage::IsActive | ( | const unsigned int | timeout = 1000 ) |
const |
Method checks to see if the shared image buffer is being updated or not.
Definition at line 444 of file sharedimage.cpp.
bool SharedImage::IsOpen | ( | ) | const |
Definition at line 425 of file sharedimage.cpp.
Created a shared image memory space.
[in] | src | Source ID of the provider of the data. |
[in] | cameraID | Camera ID on the sensor. |
Definition at line 141 of file sharedimage.cpp.
int SharedImage::RegisterCallback | ( | void(*)(const Address &src, const Byte cameraID, const Image &img, const unsigned int frameNumber, void *args) | func, |
void * | fargs | ||
) |
Registers a callback to be done every time the shared image updates.
func | Callback function (arguments are source of image data and a raw image, plus additional arguments). |
fargs | Arguments to function callback. |
Definition at line 214 of file sharedimage.cpp.
int SharedImage::SetFrame | ( | const unsigned char * | rawImage, |
const unsigned int | width, | ||
const unsigned int | height, | ||
const unsigned char | channels, | ||
const unsigned int | frameNumber | ||
) |
Sets the value of the image data.
Image data can only be set if you create the shared image using the CreateSharedImage method.
Definition at line 265 of file sharedimage.cpp.
void SharedImage::SharedImageUpdate | ( | void * | args ) | [static, protected] |
Function called by thread which keeps trying to get the latest data from shared memory image.
Definition at line 469 of file sharedimage.cpp.
CxUtils::Mutex JAUS::SharedImage::mCallbackMutex [protected] |
Mutex for image callbacks.
Definition at line 120 of file sharedimage.h.
CxUtils::Thread JAUS::SharedImage::mCallbackThread [protected] |
Thread to poll for image data.
Definition at line 119 of file sharedimage.h.
Byte JAUS::SharedImage::mCameraID [protected] |
Camera ID.
Definition at line 115 of file sharedimage.h.
bool JAUS::SharedImage::mExitFlag [protected] |
Indicates program is exiting.
Definition at line 127 of file sharedimage.h.
CxUtils::MappedMemory JAUS::SharedImage::mImageBuffer [protected] |
Shared memory image buffer.
Definition at line 118 of file sharedimage.h.
void(* JAUS::SharedImage::mpCallback)(const Address &src, const Byte cameraID, const CxUtils::Image &img, const unsigned int frameNumber, void *args) [protected] |
Callback to perform when image updates.
Definition at line 121 of file sharedimage.h.
void* JAUS::SharedImage::mpCallbackArgs [protected] |
Callback arguments.
Definition at line 126 of file sharedimage.h.
Address JAUS::SharedImage::mSourceID [protected] |
Source ID of data.
Definition at line 114 of file sharedimage.h.
Image JAUS::SharedImage::mTempImage [protected] |
Temporary image for storing data.
Definition at line 117 of file sharedimage.h.
bool JAUS::SharedImage::mWriteFlag [protected] |
If true, writing to memory is allowed.
Definition at line 116 of file sharedimage.h.