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