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