Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
RawCam.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_RawCam_h_ 00003 #define INCLUDED_RawCam_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, RawCam 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 RawCam : public CameraStreamBehavior { 00042 public: 00043 //! constructor 00044 RawCam(); 00045 00046 //! destructor 00047 ~RawCam() { theOne=NULL; } 00048 00049 #ifdef PLATFORM_APERIOS 00050 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) 00051 #elif defined(TGT_IS_CALLIOPE3) 00052 static const unsigned int TCP_WIRELESS_BUFFER_SIZE=1280 * 720 * 3 + 1024; 00053 #else 00054 static const unsigned int TCP_WIRELESS_BUFFER_SIZE=901*1024; //!< 900KB for max of full-color 640x480 + 1KB for header 00055 #endif 00056 static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size 00057 00058 virtual void doStart(); 00059 00060 virtual void doStop(); 00061 00062 virtual void doEvent(); 00063 00064 static std::string getClassDescription() { 00065 char tmp[20]; 00066 snprintf(tmp,20,"%d",*config->vision.rawcam.port); tmp[19]='\0'; 00067 return std::string("Forwards images from camera over port ")+tmp; 00068 } 00069 virtual std::string getDescription() const { return getClassDescription(); } 00070 00071 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) 00072 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) 00073 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) 00074 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) 00075 00076 protected: 00077 static RawCam* theOne; //!< global instance of RawCam acting as server 00078 //! function for network data to be sent to -- forwards to #theOne's receiveData() 00079 static int networkCallback(char* buf, int bytes) { return theOne->receiveData(buf,bytes); } 00080 00081 void closeServer(); //!<tear down the server socket (#visRaw) 00082 void setupServer(); //!<setup the server socket (#visRaw) 00083 00084 void drawShapesIntoBuffer(const FilterBankEvent &fbke); //!< draw contents of drawShapes vector into camera buffer 00085 00086 //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error) 00087 /*! see the class documentation for RawCam for the protocol documentation */ 00088 bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer); 00089 bool writeColor(const FilterBankEvent& fbke); //!< writes a color image 00090 bool writeSingleChannel(const FilterBankEvent& fbke); //!< writes a single channel 00091 void closePacket(); //!< closes and sends a packet, does nothing if no packet open 00092 00093 //! sends a packet signaling the server is closing the connection (good for UDP connections) 00094 bool sendCloseConnectionPacket(); 00095 00096 Socket * visRaw; //!< socket for sending the image stream 00097 char * packet; //!< point to the current buffer being prepared to be sent 00098 char * cur; //!< current location within that buffer 00099 unsigned int avail; //!< the number of bytes remaining in the buffer 00100 unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated 00101 unsigned int lastProcessedTime; //!< the time that the last event was processed 00102 private: 00103 RawCam(const RawCam&); //!< don't call 00104 RawCam& operator=(const RawCam&); //!< don't call 00105 }; 00106 00107 /*! @file 00108 * @brief Describes RawCam, which forwards images from camera over wireless 00109 * @author ejt (Creator) 00110 */ 00111 00112 #endif |
Tekkotsu v5.1CVS |
Generated Mon May 9 04:58:49 2016 by Doxygen 1.6.3 |