Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SegCamBehavior Class Reference

#include <SegCamBehavior.h>

Inheritance diagram for SegCamBehavior:

List of all members.


Detailed Description

Forwards segmented 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 SegmentedColorGenerator or RLEGenerator)

However, SegCamBehavior 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: Config::vision_config::ENCODE_SINGLE_CHANNEL> (always just sends a single channel)
  • <Config::vision_config::compression_t: Config::vision_config::COMPRESS_RLE> (This is misleading - may actually be uncompressed, but this signals it's a segmented color image)
  • <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, SegCamBehavior 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 RawCamBehavior as well - the same code can parse either stream.

However, one odd bit - since the RLEGenerator doesn't save the color information itself, SegCamBehavior will do it instead. So, if SegCamBehavior is using RLE compression, it will tack a footer at the end of the packet: (from SegmentedColorGenerator::encodeColors())

  • <unsigned int: num_cols> (number of different colors available)
  • for each of num_col:
    • <char: red> red color to use for display of this index
    • <char: green> green color to use for display of this index
    • <char: blue> blue color to use for display of this index

You can tell whether to expect the color footer by the creator string that follows the SegCamBehavior header. (The compression field listed is considering segmented color itself a type of compression, whether or not it's RLE encoded, so you can't use that to tell whether the data is RLE encoded until you get to the data section.)

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 58 of file SegCamBehavior.h.


Public Member Functions

 SegCamBehavior ()
 constructor
 ~SegCamBehavior ()
 destructor
virtual void DoStart ()
 By default, merely adds to the reference counter (through AddReference()); Note you should still call this from your overriding methods.
virtual void DoStop ()
 By default, subtracts from the reference counter (RemoveReference()), and thus may deletex if zero; Don't forget to still call this when you override this; Warning: call this at the end of your DoStop(), not beginning (it might delete this ).
virtual void processEvent (const EventBase &e)
 By defining here, allows you to get away with not supplying a processEvent() function for the EventListener interface. By default, does nothing.
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 Public Attributes

static const unsigned int TCP_WIRELESS_BUFFER_SIZE = 85000
 85000 bytes for use up to 416x320 pixels / 8 min expected runs * 5 bytes per run + some padding
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 (visRLE)
void setupServer ()
 setup the server socket (visRLE )
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 writeRLE (const FilterBankEvent &fbke)
 writes a color image
bool writeSeg (const FilterBankEvent &fbke)
 writes a color image
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

SocketvisRLE
 socket to send image stream over
char * packet
 buffer being filled out to be sent
char * cur
 current location in packet
unsigned int avail
 number of bytes remaining in packet
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 SegCamBehaviortheOne = NULL

Private Member Functions

 SegCamBehavior (const SegCamBehavior &)
 don't call
SegCamBehavioroperator= (const SegCamBehavior &)
 don't call

Constructor & Destructor Documentation

SegCamBehavior::SegCamBehavior (  ) 

constructor

Definition at line 12 of file SegCamBehavior.cc.

SegCamBehavior::~SegCamBehavior (  )  [inline]

destructor

Definition at line 64 of file SegCamBehavior.h.

SegCamBehavior::SegCamBehavior ( const SegCamBehavior  )  [private]

don't call


Member Function Documentation

void SegCamBehavior::DoStart (  )  [virtual]

By default, merely adds to the reference counter (through AddReference()); Note you should still call this from your overriding methods.

Reimplemented from BehaviorBase.

Definition at line 20 of file SegCamBehavior.cc.

void SegCamBehavior::DoStop (  )  [virtual]

By default, subtracts from the reference counter (RemoveReference()), and thus may deletex if zero; Don't forget to still call this when you override this; Warning: call this at the end of your DoStop(), not beginning (it might delete this ).

Reimplemented from BehaviorBase.

Definition at line 28 of file SegCamBehavior.cc.

Referenced by processEvent().

void SegCamBehavior::processEvent ( const EventBase  )  [virtual]

By defining here, allows you to get away with not supplying a processEvent() function for the EventListener interface. By default, does nothing.

Reimplemented from CameraStreamBehavior.

Definition at line 35 of file SegCamBehavior.cc.

static std::string SegCamBehavior::getClassDescription (  )  [inline, 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 78 of file SegCamBehavior.h.

virtual std::string SegCamBehavior::getDescription (  )  const [inline, 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 83 of file SegCamBehavior.h.

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

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

Definition at line 88 of file SegCamBehavior.h.

Referenced by setupServer().

void SegCamBehavior::closeServer (  )  [protected]

tear down the server socket (visRLE)

Definition at line 85 of file SegCamBehavior.cc.

Referenced by DoStop(), and processEvent().

void SegCamBehavior::setupServer (  )  [protected]

setup the server socket (visRLE )

Definition at line 97 of file SegCamBehavior.cc.

Referenced by DoStart(), and processEvent().

bool SegCamBehavior::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 SegCamBehavior for the protocol documentation

Definition at line 123 of file SegCamBehavior.cc.

Referenced by writeRLE(), and writeSeg().

bool SegCamBehavior::writeRLE ( const FilterBankEvent fbke  )  [protected]

writes a color image

Definition at line 149 of file SegCamBehavior.cc.

Referenced by processEvent().

bool SegCamBehavior::writeSeg ( const FilterBankEvent fbke  )  [protected]

writes a color image

Definition at line 174 of file SegCamBehavior.cc.

Referenced by processEvent().

void SegCamBehavior::closePacket (  )  [protected]

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

Definition at line 191 of file SegCamBehavior.cc.

Referenced by processEvent(), writeRLE(), and writeSeg().

bool SegCamBehavior::sendCloseConnectionPacket (  )  [protected]

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

Definition at line 201 of file SegCamBehavior.cc.

Referenced by closeServer().

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

don't call


Member Data Documentation

const unsigned int SegCamBehavior::TCP_WIRELESS_BUFFER_SIZE = 85000 [static]

85000 bytes for use up to 416x320 pixels / 8 min expected runs * 5 bytes per run + some padding

Definition at line 67 of file SegCamBehavior.h.

Referenced by setupServer().

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

64KB is the max udp packet size

Definition at line 70 of file SegCamBehavior.h.

Referenced by setupServer().

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

global instance of SegCamBehavior acting as server

Definition at line 86 of file SegCamBehavior.h.

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

socket to send image stream over

Definition at line 103 of file SegCamBehavior.h.

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

char* SegCamBehavior::packet [protected]

buffer being filled out to be sent

Definition at line 104 of file SegCamBehavior.h.

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

char* SegCamBehavior::cur [protected]

current location in packet

Definition at line 105 of file SegCamBehavior.h.

Referenced by closePacket(), openPacket(), processEvent(), writeRLE(), and writeSeg().

unsigned int SegCamBehavior::avail [protected]

number of bytes remaining in packet

Definition at line 106 of file SegCamBehavior.h.

Referenced by closePacket(), openPacket(), writeRLE(), and writeSeg().

unsigned int SegCamBehavior::max_buf [protected]

the buffer size requested from Wireless when the socket was allocated

Definition at line 107 of file SegCamBehavior.h.

Referenced by openPacket(), and setupServer().

unsigned int SegCamBehavior::lastProcessedTime [protected]

the time that the last event was processed

Reimplemented from CameraStreamBehavior.

Definition at line 108 of file SegCamBehavior.h.

Referenced by closePacket(), and processEvent().


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

Tekkotsu v4.0
Generated Thu Nov 22 00:58:40 2007 by Doxygen 1.5.4