00001 #ifndef FCAM_F2_DAEMON_H
00002 #define FCAM_F2_DAEMON_H
00003
00004 #include <queue>
00005 #include <pthread.h>
00006 #include <semaphore.h>
00007
00008 #include "FCam/F2/Sensor.h"
00009 #include "FCam/F2/Frame.h"
00010 #include "FCam/TSQueue.h"
00011
00012 #include "V4L2Sensor.h"
00013
00014
00015 namespace FCam { namespace F2 {
00016
00017
00018
00019 class Daemon {
00020 public:
00021
00022 class Action {
00023 public:
00024
00025
00026
00027 Time time;
00028 FCam::Action *action;
00029
00030 bool operator<(const Action &other) const {
00031
00032 return time > other.time;
00033 }
00034
00035 bool operator>(const Action &other) const {
00036
00037 return time < other.time;
00038 }
00039 };
00040
00041 Daemon(Sensor *sensor);
00042 ~Daemon();
00043
00044
00045 void setDropPolicy(FCam::Sensor::DropPolicy p, int f);
00046
00047
00048
00049 TSQueue<_Frame *> requestQueue;
00050
00051
00052
00053 TSQueue<_Frame *> frameQueue;
00054
00055 void launchThreads();
00056
00057 void debugTiming(bool);
00058
00059 private:
00060
00061
00062 V4L2Sensor *v4l2Sensor;
00063
00064
00065 Sensor *sensor;
00066
00067
00068 int rowSkipDriver(RowSkip::e v) { return static_cast<int>(v)-1; }
00069 int colSkipDriver(ColSkip::e v) { return static_cast<int>(v)-1; }
00070 int rowBinDriver(RowBin::e v) {return static_cast<int>(v)-1; }
00071 int colBinDriver(ColBin::e v) {return static_cast<int>(v)-1; }
00072
00073 RowSkip::e rowSkipFCam(int v) { return static_cast<RowSkip::e>(v+1); }
00074 ColSkip::e colSkipFCam(int v) { return static_cast<ColSkip::e>(v+1); }
00075 RowBin::e rowBinFCam(int v) {return static_cast<RowBin::e>(v+1); }
00076 ColBin::e colBinFCam(int v) {return static_cast<ColBin::e>(v+1); }
00077
00078 bool stop;
00079
00080 void setReadoutParams(_Frame *req, bool modeSwitch = false);
00081 void setExposureParams(_Frame *req, bool modeSwitch = false);
00082
00083 void setTimes(_Frame *req, const Time &, bool modeSwitch = false);
00084
00085
00086 size_t frameLimit;
00087
00088 FCam::Sensor::DropPolicy dropPolicy;
00089 void enforceDropPolicy();
00090
00091
00092
00093 TSQueue<_Frame *> inFlightQueue;
00094
00095
00096
00097
00098 pthread_mutex_t cameraMutex;
00099
00100
00101 bool pipelineFlush;
00102
00103
00104
00105 std::priority_queue<Action> actionQueue;
00106 pthread_mutex_t actionQueueMutex;
00107 sem_t actionQueueSemaphore;
00108
00109
00110
00111 void runSetter();
00112 pthread_t setterThread;
00113
00114 void tickSetter(Time hs_vs);
00115 bool setterRunning;
00116
00117
00118 _Frame current;
00119
00120
00121 Shot prevShot;
00122
00123
00124 void runHandler();
00125 pthread_t handlerThread;
00126 bool handlerRunning;
00127
00128
00129 void runAction();
00130 pthread_t actionThread;
00131 bool actionRunning;
00132
00133 bool waitingForFirstRequest;
00134
00135 bool debugMode;
00136
00137 friend void *daemon_setter_thread_(void *arg);
00138 friend void *daemon_handler_thread_(void *arg);
00139 friend void *daemon_action_thread_(void *arg);
00140 };
00141
00142 }}
00143
00144 #endif