| Tekkotsu 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 "CameraStreamBehavior.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 CameraStreamBehavior { 00042 public: 00043 //! constructor 00044 RawCamBehavior(); 00045 00046 //! destructor 00047 ~RawCamBehavior() { theOne=NULL; } 00048 00049 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) 00050 static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size 00051 00052 virtual void DoStart(); 00053 00054 virtual void DoStop(); 00055 00056 virtual void processEvent(const EventBase& e); 00057 00058 static std::string getClassDescription() { 00059 char tmp[20]; 00060 snprintf(tmp,20,"%d",config->vision.rawcam_port); tmp[19]='\0'; 00061 return std::string("Forwards images from camera over port ")+tmp; 00062 } 00063 virtual std::string getDescription() const { return getClassDescription(); } 00064 00065 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) 00066 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) 00067 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) 00068 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) 00069 00070 protected: 00071 static RawCamBehavior* theOne; //!< global instance of RawCamBehavior acting as server 00072 //! function for network data to be sent to -- forwards to #theOne's receiveData() 00073 static int networkCallback(char* buf, int bytes) { return theOne->receiveData(buf,bytes); } 00074 00075 void closeServer(); //!<tear down the server socket (#visRaw) 00076 void setupServer(); //!<setup the server socket (#visRaw) 00077 00078 //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error) 00079 /*! see the class documentation for RawCamBehavior for the protocol documentation */ 00080 bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer); 00081 bool writeColor(const FilterBankEvent& fbke); //!< writes a color image 00082 bool writeSingleChannel(const FilterBankEvent& fbke); //!< writes a single channel 00083 void closePacket(); //!< closes and sends a packet, does nothing if no packet open 00084 00085 //! sends a packet signaling the server is closing the connection (good for UDP connections) 00086 bool sendCloseConnectionPacket(); 00087 00088 Socket * visRaw; //!< socket for sending the image stream 00089 char * packet; //!< point to the current buffer being prepared to be sent 00090 char * cur; //!< current location within that buffer 00091 unsigned int avail; //!< the number of bytes remaining in the buffer 00092 unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated 00093 unsigned int lastProcessedTime; //!< the time that the last event was processed 00094 private: 00095 RawCamBehavior(const RawCamBehavior&); //!< don't call 00096 RawCamBehavior& operator=(const RawCamBehavior&); //!< don't call 00097 }; 00098 00099 /*! @file 00100 * @brief Describes RawCamBehavior, which forwards images from camera over wireless 00101 * @author ejt (Creator) 00102 * 00103 * $Author: ejt $ 00104 * $Name: tekkotsu-3_0 $ 00105 * $Revision: 1.18 $ 00106 * $State: Exp $ 00107 * $Date: 2006/09/16 17:32:38 $ 00108 */ 00109 00110 #endif |
|
Tekkotsu v3.0 |
Generated Wed Oct 4 00:03:45 2006 by Doxygen 1.4.7 |