Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
RawCamBehavior.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_RawCamBehavior_h_ 00003 #define INCLUDED_RawCamBehavior_h_ 00004 00005 #include "Behaviors/BehaviorBase.h" 00006 #include "Shared/Config.h" 00007 00008 class Socket; 00009 class FilterBankGenerator; 00010 class FilterBankEvent; 00011 00012 //! Forwards images from camera over wireless 00013 /*! The format used for serialization is basically defined by the 00014 * subclass of FilterBankGenerator being used. I suggest looking at 00015 * that classes's documentation to determine the format used. (Generally 00016 * either RawCameraGenerator or JPEGGenerator) 00017 * 00018 * However, RawCamBehavior will add a few fields at the beginning of 00019 * each packet to assist in processing the image stream. 00020 * 00021 * I emphasize: <i>beginning</i> of each Vision packet, <i>before</i> the FilterBankGenerator header. 00022 * - <@c string:"TekkotsuImage"> 00023 * - <<tt>Config::vision_config::encoding_t</tt>: rawcam_encoding> <i>(expect single or multiple channels, 0 means color (3 channels), 1 means intensity (1 channel))</i> 00024 * - <<tt>Config::vision_config::compression_t</tt>: rawcam_compression> <i>(0==none, 1==jpeg, 2==rle)</i> 00025 * - <@c unsigned @c int: width> <i>(this is the width of the largest channel - note different channels can be sent at different resolutions! Provides cheap "compression" of chromaticity channels)</i> 00026 * - <@c unsigned @c int: height> <i>(similarly, height of largest channel)</i> 00027 * - <@c unsigned @c int: timestamp> <i>(time image was taken, milliseconds since boot)</i> 00028 * - <@c unsigned @c int: framenumber> <i>(incremented for each frame, so we can tell if/when we drop one)</i> 00029 * 00030 * Alternatively, RawCameraGenerator may send a "Close Connection" packet 00031 * when the server is shutting down. This is to help UDP connections, which 00032 * otherwise wouldn't realize that they need to start trying to reconnect. 00033 * - <@c string:"CloseConnection"> 00034 * 00035 * This is exactly the same protocol that is followed by the SegCamBehavior as well - the same code can parse either stream. 00036 * 00037 * This is a binary protocol -- the fields listed indicate binary values 00038 * in the AIBO's byte order (little endian). Strings are encoded using 00039 * the LoadSave::encode(char*,unsigned int, unsigned int) method. 00040 */ 00041 class RawCamBehavior : public BehaviorBase { 00042 public: 00043 //! constructor 00044 RawCamBehavior(); 00045 00046 static const unsigned int TCP_WIRELESS_BUFFER_SIZE=200000; //!< 200000 bytes for use up to 416x320 + 2*208x160 (double res Y, full res UV on ERS-7) 00047 static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size 00048 00049 virtual void DoStart(); 00050 00051 virtual void DoStop(); 00052 00053 virtual void processEvent(const EventBase& e); 00054 00055 static std::string getClassDescription() { 00056 char tmp[20]; 00057 snprintf(tmp,20,"%d",config->vision.rawcam_port); tmp[19]='\0'; 00058 return std::string("Forwards images from camera over port ")+tmp; 00059 } 00060 virtual std::string getDescription() const { return getClassDescription(); } 00061 00062 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) 00063 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) 00064 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) 00065 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) 00066 00067 protected: 00068 //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error) 00069 /*! see the class documentation for RawCamBehavior for the protocol documentation */ 00070 bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer); 00071 bool writeColor(const FilterBankEvent& fbke); //!< writes a color image 00072 bool writeSingleChannel(const FilterBankEvent& fbke); //!< writes a single channel 00073 void closePacket(); //!< closes and sends a packet, does nothing if no packet open 00074 00075 //! sends a packet signaling the server is closing the connection (good for UDP connections) 00076 bool sendCloseConnectionPacket(); 00077 00078 Socket * visRaw; //!< socket for sending the image stream 00079 char * packet; //!< point to the current buffer being prepared to be sent 00080 char * cur; //!< current location within that buffer 00081 unsigned int avail; //!< the number of bytes remaining in the buffer 00082 unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated 00083 unsigned int lastProcessedTime; //!< the time that the last event was processed 00084 private: 00085 RawCamBehavior(const RawCamBehavior&); //!< don't call 00086 RawCamBehavior& operator=(const RawCamBehavior&); //!< don't call 00087 }; 00088 00089 /*! @file 00090 * @brief Describes RawCamBehavior, which forwards images from camera over wireless 00091 * @author ejt (Creator) 00092 * 00093 * $Author: ejt $ 00094 * $Name: tekkotsu-2_4_1 $ 00095 * $Revision: 1.15 $ 00096 * $State: Exp $ 00097 * $Date: 2005/08/07 04:11:03 $ 00098 */ 00099 00100 #endif |
Tekkotsu v2.4.1 |
Generated Tue Aug 16 16:32:48 2005 by Doxygen 1.4.4 |