Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RawCam Class Reference

Forwards images from camera over wireless. More...

#include <RawCam.h>

Inheritance diagram for RawCam:

Detailed Description

Forwards images from camera over wireless.

The format used for serialization is basically defined by the subclass of FilterBankGenerator being used. I suggest looking at that classes's documentation to determine the format used. (Generally either RawCameraGenerator or JPEGGenerator)

However, RawCam will add a few fields at the beginning of each packet to assist in processing the image stream.

I emphasize: beginning of each Vision packet, before the FilterBankGenerator header.

  • <string:"TekkotsuImage">
  • <Config::vision_config::encoding_t: rawcam.encoding> (expect single or multiple channels, 0 means color (3 channels), 1 means intensity (1 channel))
  • <Config::vision_config::compression_t: rawcam.compression> (0==none, 1==jpeg, 2==rle)
  • <unsigned int: width> (this is the width of the largest channel - note different channels can be sent at different resolutions! Provides cheap "compression" of chromaticity channels)
  • <unsigned int: height> (similarly, height of largest channel)
  • <unsigned int: timestamp> (time image was taken, milliseconds since boot)
  • <unsigned int: framenumber> (incremented for each frame, so we can tell if/when we drop one)

Alternatively, RawCameraGenerator may send a "Close Connection" packet when the server is shutting down. This is to help UDP connections, which otherwise wouldn't realize that they need to start trying to reconnect.

  • <string:"CloseConnection">

This is exactly the same protocol that is followed by the SegCamBehavior as well - the same code can parse either stream.

This is a binary protocol -- the fields listed indicate binary values in the AIBO's byte order (little endian). Strings are encoded using the LoadSave::encode(char*,unsigned int, unsigned int) method.

Definition at line 41 of file RawCam.h.

List of all members.

Public Member Functions

 RawCam ()
 constructor
 ~RawCam ()
 destructor
virtual void doStart ()
 Delegate function for subclasses to be notified when the behavior starts up.
virtual void doStop ()
 Delegate function for subclasses to be notified when the behavior starts up.
virtual void doEvent ()
 Delegate function for event processing, the event itself is pointed to (only for the duration of the doEvent() call!) by event.
virtual std::string getDescription () const
 Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

Static Public Member Functions

static std::string getClassDescription ()
 Gives a short description of what this class of behaviors does... you should override this (but don't have to).
static unsigned int getSourceLayer (unsigned int chan, unsigned int numLayers)
 returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)
static unsigned int getSourceYLayer (unsigned int numLayers)
 returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)
static unsigned int getSourceULayer (unsigned int numLayers)
 returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)
static unsigned int getSourceVLayer (unsigned int numLayers)
 returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)

Static Public Attributes

static const unsigned int TCP_WIRELESS_BUFFER_SIZE = 901*1024
 900KB for max of full-color 640x480 + 1KB for header
static const unsigned int UDP_WIRELESS_BUFFER_SIZE = 64*1024
 64KB is the max udp packet size

Protected Member Functions

void closeServer ()
 tear down the server socket (visRaw)
void setupServer ()
 setup the server socket (visRaw)
void drawShapesIntoBuffer (const FilterBankEvent &fbke)
 draw contents of drawShapes vector into camera buffer
bool openPacket (FilterBankGenerator &fbkgen, unsigned int time, unsigned int layer)
 opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error)
bool writeColor (const FilterBankEvent &fbke)
 writes a color image
bool writeSingleChannel (const FilterBankEvent &fbke)
 writes a single channel
void closePacket ()
 closes and sends a packet, does nothing if no packet open
bool sendCloseConnectionPacket ()
 sends a packet signaling the server is closing the connection (good for UDP connections)

Static Protected Member Functions

static int networkCallback (char *buf, int bytes)
 function for network data to be sent to -- forwards to theOne's receiveData()

Protected Attributes

SocketvisRaw
 socket for sending the image stream
char * packet
 point to the current buffer being prepared to be sent
char * cur
 current location within that buffer
unsigned int avail
 the number of bytes remaining in the buffer
unsigned int max_buf
 the buffer size requested from Wireless when the socket was allocated
unsigned int lastProcessedTime
 the time that the last event was processed

Static Protected Attributes

static RawCamtheOne = NULL

Private Member Functions

 RawCam (const RawCam &)
 don't call
RawCamoperator= (const RawCam &)
 don't call

Constructor & Destructor Documentation

RawCam::RawCam (  ) 

constructor

Definition at line 31 of file RawCam.cc.

RawCam::~RawCam (  ) 

destructor

Definition at line 47 of file RawCam.h.

RawCam::RawCam ( const RawCam  )  [private]

don't call


Member Function Documentation

void RawCam::closePacket (  )  [protected]

closes and sends a packet, does nothing if no packet open

Definition at line 514 of file RawCam.cc.

Referenced by doEvent(), writeColor(), and writeSingleChannel().

void RawCam::closeServer (  )  [protected]

tear down the server socket (visRaw)

Definition at line 334 of file RawCam.cc.

Referenced by doEvent(), and doStop().

void RawCam::doEvent (  )  [virtual]

Delegate function for event processing, the event itself is pointed to (only for the duration of the doEvent() call!) by event.

Default implementation watches for 'private' text message events (those forwarded by a BehaviorSwitchControl from ControllerGUI input) and will publically rebroadcast them. The idea is that your own processEvent gets first dibs, but if the behavior doesn't handle the text message, it will be handed off for others.

Reimplemented from CameraStreamBehavior.

Definition at line 58 of file RawCam.cc.

void RawCam::doStart (  )  [virtual]

Delegate function for subclasses to be notified when the behavior starts up.

Should be overridden by subclasses to subscribe to events, install motion commands, etc.

doStart() is basically a hook to allow subclasses to jump in and do some customization of behavior parameters while the behavior is starting. If you are writing a behavior class and do not expect further derivation, just override doStart() yourself. However, if you do expect further derivation of your class, consider using preStart() or postStart() instead, and leave doStart() for the 'leaf' classes.

Reimplemented from BehaviorBase.

Definition at line 38 of file RawCam.cc.

void RawCam::doStop (  )  [virtual]

Delegate function for subclasses to be notified when the behavior starts up.

May be overridden to cleanup when the behavior is shutting down. However events will automatically be unsubscribed, and by using addMotion(), motions will automatically be removed by stop(), so you may not need any cleanup.

Reimplemented from BehaviorBase.

Definition at line 52 of file RawCam.cc.

void RawCam::drawShapesIntoBuffer ( const FilterBankEvent fbke  )  [protected]

draw contents of drawShapes vector into camera buffer

Definition at line 161 of file RawCam.cc.

Referenced by doEvent().

static std::string RawCam::getClassDescription (  )  [static]

Gives a short description of what this class of behaviors does... you should override this (but don't have to).

If you do override this, also consider overriding getDescription() to return it

Reimplemented from CameraStreamBehavior.

Definition at line 64 of file RawCam.h.

Referenced by getDescription().

virtual std::string RawCam::getDescription (  )  const [virtual]

Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

By default simply returns getName(), because any calls from a BehaviorBase function to getClassDescription() are going to call BehaviorBase::getClassDescription(), not ~YourSubClass~getClassDescription(), because static functions can't be virtual in C++ (doh!)

This means that getDescription called on a pointer to a BehaviorBase of unknown subtype would always return an empty string, which is pretty useless. So instead we return the name in this situation. If you want getDescription to return getClassDescription, you'll have to override it in your subclass to do so.

Reimplemented from CameraStreamBehavior.

Definition at line 69 of file RawCam.h.

unsigned int RawCam::getSourceLayer ( unsigned int  chan,
unsigned int  numLayers 
) [static]

returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)

Definition at line 123 of file RawCam.cc.

Referenced by getSourceULayer(), getSourceVLayer(), and getSourceYLayer().

unsigned int RawCam::getSourceULayer ( unsigned int  numLayers  )  [static]

returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)

Definition at line 153 of file RawCam.cc.

unsigned int RawCam::getSourceVLayer ( unsigned int  numLayers  )  [static]

returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)

Definition at line 157 of file RawCam.cc.

unsigned int RawCam::getSourceYLayer ( unsigned int  numLayers  )  [static]

returns the layer which will be used out of the source, based on current config settings (i.e. compression, skip, etc)

Definition at line 149 of file RawCam.cc.

static int RawCam::networkCallback ( char *  buf,
int  bytes 
) [static, protected]

function for network data to be sent to -- forwards to theOne's receiveData()

Definition at line 79 of file RawCam.h.

Referenced by setupServer().

bool RawCam::openPacket ( FilterBankGenerator fbkgen,
unsigned int  time,
unsigned int  layer 
) [protected]

opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error)

see the class documentation for RawCam for the protocol documentation

Definition at line 370 of file RawCam.cc.

Referenced by writeColor(), and writeSingleChannel().

RawCam& RawCam::operator= ( const RawCam  )  [private]

don't call

bool RawCam::sendCloseConnectionPacket (  )  [protected]

sends a packet signaling the server is closing the connection (good for UDP connections)

Definition at line 523 of file RawCam.cc.

Referenced by closeServer().

void RawCam::setupServer (  )  [protected]

setup the server socket (visRaw)

Definition at line 345 of file RawCam.cc.

Referenced by doEvent(), and doStart().

bool RawCam::writeColor ( const FilterBankEvent fbke  )  [protected]

writes a color image

Definition at line 394 of file RawCam.cc.

Referenced by doEvent().

bool RawCam::writeSingleChannel ( const FilterBankEvent fbke  )  [protected]

writes a single channel

Definition at line 492 of file RawCam.cc.

Referenced by doEvent().


Member Data Documentation

unsigned int RawCam::avail [protected]

the number of bytes remaining in the buffer

Definition at line 99 of file RawCam.h.

Referenced by closePacket(), openPacket(), writeColor(), and writeSingleChannel().

char* RawCam::cur [protected]

current location within that buffer

Definition at line 98 of file RawCam.h.

Referenced by closePacket(), doEvent(), openPacket(), writeColor(), and writeSingleChannel().

unsigned int RawCam::lastProcessedTime [protected]

the time that the last event was processed

Reimplemented from CameraStreamBehavior.

Definition at line 101 of file RawCam.h.

Referenced by closePacket(), and doEvent().

unsigned int RawCam::max_buf [protected]

the buffer size requested from Wireless when the socket was allocated

Definition at line 100 of file RawCam.h.

Referenced by openPacket(), and setupServer().

char* RawCam::packet [protected]

point to the current buffer being prepared to be sent

Definition at line 97 of file RawCam.h.

Referenced by closePacket(), doEvent(), and openPacket().

const unsigned int RawCam::TCP_WIRELESS_BUFFER_SIZE = 901*1024 [static]

900KB for max of full-color 640x480 + 1KB for header

Definition at line 54 of file RawCam.h.

Referenced by setupServer().

RawCam * RawCam::theOne = NULL [static, protected]

global instance of RawCam acting as server

Definition at line 77 of file RawCam.h.

Referenced by networkCallback(), RawCam(), and ~RawCam().

const unsigned int RawCam::UDP_WIRELESS_BUFFER_SIZE = 64*1024 [static]

64KB is the max udp packet size

Definition at line 56 of file RawCam.h.

Referenced by setupServer().

Socket* RawCam::visRaw [protected]

socket for sending the image stream

Definition at line 96 of file RawCam.h.

Referenced by closePacket(), closeServer(), doEvent(), openPacket(), sendCloseConnectionPacket(), and setupServer().


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:15 2016 by Doxygen 1.6.3