00001
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
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
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
00063 unsigned int frameNumber;
00064 std::vector<char> buffer;
00065 char * img;
00066 size_t imgSize;
00067
00068 private:
00069
00070 static const std::string autoRegisterImageStreamDriver;
00071 ImageStreamDriver(const ImageStreamDriver&);
00072 ImageStreamDriver operator=(const ImageStreamDriver&);
00073 };
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #endif