Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ImageStreamDriver.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_ImageStreamDriver_h_
00003 #define INCLUDED_ImageStreamDriver_h_
00004 
00005 #include "local/DeviceDriver.h"
00006 #include "local/DataSource.h"
00007 #include "local/CommPort.h"
00008 #include "Shared/plist.h"
00009 #include <iostream>
00010 
00011 //! description of ImageStreamDriver
00012 class ImageStreamDriver : public virtual DeviceDriver, public DataSource, public virtual plist::PrimitiveListener {
00013 public:
00014   explicit ImageStreamDriver(const std::string& name)
00015   : DeviceDriver(autoRegisterImageStreamDriver,name), DataSource(),
00016   commName(), format(FORMAT_JPEG,formatNames), frameNumber(0), buffer(), img(NULL), imgSize(0)
00017   {
00018     format.addNameForVal("jpg",FORMAT_JPEG);
00019     addEntry("CommPort",commName,"The name of the comm port from which data will be read.");
00020     addEntry("Format",format,"The type of format to expect from the comm port.\n"
00021          "'YUV' expects interleaved components 'CameraResolutionX' wide and 'CameraResolutionY' high\n"
00022          "(defined in target's RobotInfo namespace)");
00023     format.addPrimitiveListener(this);
00024   }
00025   virtual ~ImageStreamDriver() {
00026     format.removePrimitiveListener(this);
00027   }
00028 
00029   virtual std::string getClassName() const { return autoRegisterImageStreamDriver; }
00030 
00031   virtual void getSensorSources(std::map<std::string,DataSource*>& sources) {
00032     sources.clear();
00033     //sources["Sensors"]=sensors;
00034   }
00035   virtual void getImageSources(std::map<std::string,DataSource*>& sources) {
00036     sources.clear();
00037     sources["Camera"]=this;
00038   }
00039   
00040   virtual unsigned int nextTimestamp();
00041   virtual const std::string& nextName() { return instanceName; }
00042   virtual unsigned int getData(const char *& payload, unsigned int& payloadSize, unsigned int& timestamp, std::string& name);
00043   virtual void setDataSourceThread(LoadDataThread* th);
00044 
00045   virtual void plistValueChanged(const plist::PrimitiveBase& pl);
00046 
00047   plist::Primitive<std::string> commName;
00048   
00049   enum format_t {
00050     FORMAT_YUV=0,
00051     FORMAT_PNG,
00052     FORMAT_JPEG,
00053     FORMAT_TEKKOTSU
00054   };
00055   static const size_t NUM_FORMATS = 4;
00056   static const char * formatNames[NUM_FORMATS+1];
00057   plist::NamedEnumeration<format_t> format;
00058 
00059 protected:
00060   void copyImage(char * buf, unsigned int width, unsigned int height, unsigned int channels, const char * chan, unsigned int lwidth, unsigned int lheight, unsigned int chan);
00061   
00062   //BufferSource sensors; //!< separate DataSource for sensor frames, if embedded in image stream
00063   unsigned int frameNumber; //!< image frame number
00064   std::vector<char> buffer; //!< image buffer
00065   char * img; //!< temporary storage for jpeg/png decompression
00066   size_t imgSize; //!< size of allocation of #img
00067 
00068 private:
00069   //! holds the class name, set via registration with the DeviceDriver registry
00070   static const std::string autoRegisterImageStreamDriver;
00071   ImageStreamDriver(const ImageStreamDriver&); //!< no call
00072   ImageStreamDriver operator=(const ImageStreamDriver&); //!< no call
00073 };
00074 
00075 /*! @file
00076  * @brief 
00077  * @author Ethan Tira-Thompson (ejt) (Creator)
00078  *
00079  * $Author: ejt $
00080  * $Name: tekkotsu-4_0 $
00081  * $Revision: 1.5 $
00082  * $State: Exp $
00083  * $Date: 2007/07/19 23:14:50 $
00084  */
00085 
00086 #endif

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4