00001 #ifndef FCAM_V4L2_SENSOR_H
00002 #define FCAM_V4L2_SENSOR_H
00003
00004 #include <vector>
00005 #include <string>
00006 #include <map>
00007
00008 #include "FCam/Base.h"
00009 #include "FCam/Time.h"
00010 #include <FCam/Histogram.h>
00011 #include <FCam/SharpnessMap.h>
00012
00013 namespace FCam {
00014 namespace F2 {
00015
00016
00017
00018
00019
00020 class V4L2Sensor {
00021 public:
00022
00023 struct V4L2Frame {
00024 Time processingDoneTime;
00025 unsigned char *data;
00026 size_t length;
00027 int index;
00028 };
00029
00030 struct Mode {
00031 int width, height;
00032 ImageFormat type;
00033 };
00034
00035 static V4L2Sensor *instance(std::string);
00036
00037
00038 void open();
00039 void close();
00040
00041
00042 void startStreaming(Mode,
00043 const HistogramConfig &,
00044 const SharpnessMapConfig &);
00045 void stopStreaming();
00046
00047 V4L2Frame *acquireFrame(bool blocking);
00048 void releaseFrame(V4L2Frame *frame);
00049
00050 Mode getMode() {return currentMode;}
00051
00052 enum Errors {
00053 InvalidId,
00054 OutOfRangeValue,
00055 ControlBusy
00056 };
00057
00058 void setControl(unsigned int id, int value);
00059 int getControl(unsigned int id);
00060
00061 void setExposure(int);
00062 int getExposure();
00063
00064 void setFrameTime(int);
00065 int getFrameTime();
00066
00067 void setGain(float);
00068 float getGain();
00069
00070 Histogram getHistogram(Time t, const HistogramConfig &conf);
00071 void setHistogramConfig(const HistogramConfig &);
00072
00073 SharpnessMap getSharpnessMap(Time t, const SharpnessMapConfig &conf);
00074 void setSharpnessMapConfig(const SharpnessMapConfig &);
00075
00076 int getFD();
00077
00078 private:
00079 V4L2Sensor(std::string);
00080
00081 Mode currentMode;
00082 SharpnessMapConfig currentSharpness;
00083 HistogramConfig currentHistogram;
00084
00085 std::vector<V4L2Frame> buffers;
00086
00087 enum {CLOSED=0, IDLE, STREAMING} state;
00088 int fd;
00089
00090 std::string filename;
00091
00092
00093 static std::map<std::string, V4L2Sensor *> instances_;
00094 };
00095
00096 }
00097 }
00098
00099 #endif
00100