00001 #include "Sensor.h"
00002 #include "ButtonListener.h"
00003 #include "../Action.h"
00004 #include <pthread.h>
00005
00006 namespace FCam { namespace N900 {
00007
00008 Sensor::Sensor() : FCam::Sensor(), shotsPending_(0) {
00009
00010
00011
00012 ButtonListener::instance();
00013
00014 pthread_mutex_init(&requestMutex, NULL);
00015
00016 }
00017
00018 Sensor::~Sensor() {
00019 pthread_mutex_lock(&requestMutex);
00020 daemon.setRequestGenerator(NULL);
00021 pthread_mutex_unlock(&requestMutex);
00022 pthread_mutex_destroy(&requestMutex);
00023 }
00024
00025 void Sensor::capture(const FCam::Shot &shot) {
00026 Frame *f = new Frame;
00027
00028
00029 f->request = new FCam::Shot(shot);
00030
00031
00032 f->request->id = shot.id;
00033
00034
00035 pthread_mutex_lock(&requestMutex);
00036 shotsPending_++;
00037 daemon.requestFrame(f);
00038 pthread_mutex_unlock(&requestMutex);
00039 }
00040
00041 void Sensor::capture(const std::vector<FCam::Shot> &burst) {
00042 std::vector<Frame *> frames;
00043
00044 for (size_t i = 0; i < burst.size(); i++) {
00045 Frame *f = new Frame;
00046 f->request = new FCam::Shot(burst[i]);
00047
00048
00049 f->request->id = burst[i].id;
00050
00051 frames.push_back(f);
00052 }
00053
00054 pthread_mutex_lock(&requestMutex);
00055 for (size_t i = 0; i < frames.size(); i++) {
00056 shotsPending_++;
00057 daemon.requestFrame(frames[i]);
00058 }
00059 pthread_mutex_unlock(&requestMutex);
00060 }
00061
00062 void Sensor::stream(const FCam::Shot &shot) {
00063 pthread_mutex_lock(&requestMutex);
00064 streamingShot.clear();
00065
00066 streamingShot.push_back(shot);
00067 streamingShot[0].id = shot.id;
00068 pthread_mutex_unlock(&requestMutex);
00069 daemon.setRequestGenerator(this);
00070 }
00071
00072 void Sensor::stream(const std::vector<FCam::Shot> &burst) {
00073 pthread_mutex_lock(&requestMutex);
00074
00075
00076 streamingShot = burst;
00077
00078
00079 for (size_t i = 0; i < burst.size(); i++) {
00080 streamingShot[i].id = burst[i].id;
00081 }
00082 pthread_mutex_unlock(&requestMutex);
00083 daemon.setRequestGenerator(this);
00084 }
00085
00086 bool Sensor::streaming() {
00087 return streamingShot.size() > 0;
00088 }
00089
00090 void Sensor::stopStreaming() {
00091 pthread_mutex_lock(&requestMutex);
00092 streamingShot.clear();
00093 pthread_mutex_unlock(&requestMutex);
00094 }
00095
00096 Frame::Ptr Sensor::getFrame() {
00097 Frame *f = daemon.getNextFrame();
00098 for (size_t i = 0; i < devices.size(); i++) {
00099 devices[i]->tagFrame(f);
00100 }
00101 f->sensor = this;
00102 Frame::Ptr fp(f);
00103 shotsPending_--;
00104 return fp;
00105 }
00106
00107 int Sensor::getRollingShutterTime(const Shot &s) const {
00108
00109 if (s.image.size.height > 960) return 77000;
00110 else return 33000;
00111 }
00112
00113
00114 void Sensor::generateRequest() {
00115 if (streamingShot.size()) {
00116 capture(streamingShot);
00117 }
00118 }
00119
00120 void Sensor::enforceDropPolicy() {
00121 daemon.setDropPolicy(dropPolicy, frameLimit);
00122 }
00123
00124 int Sensor::framesPending() const {
00125 return daemon.framesPending();
00126 }
00127
00128 int Sensor::shotsPending() const {
00129 return shotsPending_;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 float Sensor::XYZToRawColorMatrixTungsten[] = {
00142 3.8135, -2.1259, -0.6033,
00143 0.5792, 0.6603, -0.2288,
00144 0.4120, 0.0049, 0.1688
00145 };
00146
00147 float Sensor::XYZToRawColorMatrixDaylight[] = {
00148 1.3577, -0.5369, -0.2804,
00149 0.0001, 0.9539, -0.0027,
00150 0.4495, -0.0253, 0.7017
00151 };
00152
00153 std::string Sensor::manufacturer = "Nokia";
00154 std::string Sensor::model = "Nokia N900";
00155
00156
00157 }}