Public Member Functions | Static Protected Member Functions | Protected Attributes

JAUS::SharedImage Class Reference

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>

List of all members.

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.

Detailed Description

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.


Constructor & Destructor Documentation

SharedImage::SharedImage (  )

Constructor.

Definition at line 57 of file sharedimage.cpp.

SharedImage::~SharedImage (  )

Destructor.

Definition at line 71 of file sharedimage.cpp.


Member Function Documentation

int SharedImage::ClearCallback (  )

Clears the callback.

Returns:
OK if cleared, otherwise FAILURE.

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.

Parameters:
[in]srcSource ID of the provider of the data.
[in]cameraIDThe ID of the camera on the source.
[in]sizeHow many bytes needed to store image.
Returns:
OK if created, otherwise FAILURE.

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.

Parameters:
imgCurrent image data.
Returns:
OK if created, otherwise FAILURE.

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.

Parameters:
[out]imagePointer to array to copy data to. If pointer is NULL, or array is not large enough, it is automatically resized.
[out]sizeThe size of the array.
[out]widthImage width (pixels).
[out]heightImage height (pixels).
[out]channelsNumber of channels in the image.
[out]frameNumberImage frame number.
Returns:
OK if created, otherwise FAILURE.

Definition at line 352 of file sharedimage.cpp.

UInt SharedImage::GetFrameNumber (  ) const

Get the sequence number for the image.

Returns:
Image sequence number (0) if no image data.

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.

Returns:
True if active, otherwise false.

Definition at line 444 of file sharedimage.cpp.

bool SharedImage::IsOpen (  ) const
Returns:
True if shared image is open/active, otherwise false.

Definition at line 425 of file sharedimage.cpp.

int SharedImage::OpenSharedImage ( const Address src,
const Byte  cameraID 
)

Created a shared image memory space.

Parameters:
[in]srcSource ID of the provider of the data.
[in]cameraIDCamera ID on the sensor.
Returns:
OK if created, otherwise FAILURE.

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.

Parameters:
funcCallback function (arguments are source of image data and a raw image, plus additional arguments).
fargsArguments to function callback.
Returns:
OK if registered, otherwise FAILURE.

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.

Returns:
OK if created, otherwise FAILURE.

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.


Member Data Documentation

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.

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.

Callback arguments.

Definition at line 126 of file sharedimage.h.

Source ID of data.

Definition at line 114 of file sharedimage.h.

Temporary image for storing data.

Definition at line 117 of file sharedimage.h.

If true, writing to memory is allowed.

Definition at line 116 of file sharedimage.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines