00001 #ifndef FCAM_N900_DAEMON_H
00002 #define FCAM_N900_DAEMON_H
00003
00004 #include <queue>
00005 #include <pthread.h>
00006 #include <semaphore.h>
00007
00008 #include "FCam/Frame.h"
00009 #include "FCam/N900/Sensor.h"
00010 #include "FCam/TSQueue.h"
00011 #include "FCam/N900/Frame.h"
00012
00013 #include "V4L2Sensor.h"
00014
00015
00016
00017 namespace FCam { namespace N900 {
00018
00019
00020
00021 class Daemon {
00022 public:
00023
00024 class Action {
00025 public:
00026
00027
00028
00029 Time time;
00030 FCam::Action *action;
00031
00032 bool operator<(const Action &other) const {
00033
00034 return time > other.time;
00035 }
00036
00037 bool operator>(const Action &other) const {
00038
00039 return time < other.time;
00040 }
00041 };
00042
00043
00044 Daemon(Sensor *sensor);
00045 ~Daemon();
00046
00047
00048 void setDropPolicy(Sensor::DropPolicy p, int f);
00049
00050
00051
00052 TSQueue<_Frame *> requestQueue;
00053
00054
00055
00056 TSQueue<_Frame *> frameQueue;
00057
00058 void launchThreads();
00059
00060 private:
00061
00062
00063 V4L2Sensor *v4l2Sensor;
00064
00065
00066 Sensor *sensor;
00067
00068 bool stop;
00069
00070
00071 size_t frameLimit;
00072
00073 Sensor::DropPolicy dropPolicy;
00074 void enforceDropPolicy();
00075
00076
00077
00078 TSQueue<_Frame *> inFlightQueue;
00079
00080
00081
00082
00083 pthread_mutex_t cameraMutex;
00084
00085
00086 bool pipelineFlush;
00087
00088
00089
00090 std::priority_queue<Action> actionQueue;
00091 pthread_mutex_t actionQueueMutex;
00092 sem_t actionQueueSemaphore;
00093
00094
00095 void runSetter();
00096 pthread_t setterThread;
00097 void tickSetter(Time hs_vs);
00098 bool setterRunning;
00099
00100 _Frame current;
00101 Shot lastGoodShot;
00102
00103
00104 void runHandler();
00105 pthread_t handlerThread;
00106 bool handlerRunning;
00107
00108
00109 void runAction();
00110 pthread_t actionThread;
00111 bool actionRunning;
00112
00113 int daemon_fd;
00114
00115
00116 bool threadsLaunched;
00117
00118 friend void *daemon_setter_thread_(void *arg);
00119 friend void *daemon_handler_thread_(void *arg);
00120 friend void *daemon_action_thread_(void *arg);
00121 };
00122
00123 }
00124 }
00125
00126 #endif