00001 #include "Sensor.h"
00002 #include "../Action.h"
00003 #include <pthread.h>
00004
00005 #include "linux/mt9p031.h"
00006
00007 namespace FCam { namespace F2 {
00008
00009
00010 Sensor::Sensor() : FCam::Sensor(), shotsPending_(0) {
00011 pthread_mutex_init(&requestMutex, NULL);
00012 }
00013
00014 Sensor::~Sensor() {
00015 pthread_mutex_lock(&requestMutex);
00016 daemon.setRequestGenerator(NULL);
00017 pthread_mutex_unlock(&requestMutex);
00018 pthread_mutex_destroy(&requestMutex);
00019 }
00020
00021 void Sensor::capture(const FCam::Shot &s) {
00022 Shot F2s(s);
00023 F2s.id = s.id;
00024 capture(F2s);
00025 }
00026
00027 void Sensor::capture(const Shot &shot) {
00028 Frame *f = new Frame;
00029
00030
00031 f->f2Request = new Shot(shot);
00032
00033
00034 f->request = static_cast<FCam::Shot *>(f->f2Request);
00035
00036
00037 f->f2Request->id = shot.id;
00038
00039
00040 pthread_mutex_lock(&requestMutex);
00041 shotsPending_++;
00042 daemon.requestFrame(f);
00043 pthread_mutex_unlock(&requestMutex);
00044 }
00045
00046 void Sensor::capture(const std::vector<FCam::Shot> &burst) {
00047 std::vector<Shot> F2Burst;
00048 F2Burst.reserve(burst.size());
00049 for (unsigned int i=0; i < burst.size(); i++ ) {
00050 F2Burst.push_back(Shot(burst[i]));
00051 F2Burst[i].id = burst[i].id;
00052 }
00053 capture(F2Burst);
00054 }
00055
00056 void Sensor::capture(const std::vector<Shot> &burst) {
00057 std::vector<Frame *> frames;
00058
00059 for (size_t i = 0; i < burst.size(); i++) {
00060 Frame *f = new Frame;
00061 f->f2Request = new Shot(burst[i]);
00062 f->request = static_cast<FCam::Shot *>(f->f2Request);
00063
00064
00065 f->f2Request->id = burst[i].id;
00066
00067 frames.push_back(f);
00068 }
00069
00070 pthread_mutex_lock(&requestMutex);
00071 for (size_t i = 0; i < frames.size(); i++) {
00072 shotsPending_++;
00073 daemon.requestFrame(frames[i]);
00074 }
00075 pthread_mutex_unlock(&requestMutex);
00076 }
00077
00078 void Sensor::stream(const FCam::Shot &s) {
00079 Shot F2s(s);
00080 F2s.id = s.id;
00081 stream(F2s);
00082 }
00083
00084 void Sensor::stream(const Shot &shot) {
00085 pthread_mutex_lock(&requestMutex);
00086 streamingShot.clear();
00087
00088 streamingShot.push_back(shot);
00089 streamingShot[0].id = shot.id;
00090 pthread_mutex_unlock(&requestMutex);
00091 daemon.setRequestGenerator(this);
00092 }
00093
00094 void Sensor::stream(const std::vector<FCam::Shot> &burst) {
00095 std::vector<Shot> F2Burst;
00096 F2Burst.reserve(burst.size());
00097 for (unsigned int i=0; i < burst.size(); i++ ) {
00098 F2Burst.push_back(Shot(burst[i]));
00099 F2Burst[i].id = burst[i].id;
00100 }
00101 stream(F2Burst);
00102 }
00103
00104 void Sensor::stream(const std::vector<Shot> &burst) {
00105 pthread_mutex_lock(&requestMutex);
00106
00107
00108 streamingShot.clear();
00109 streamingShot.reserve(burst.size());
00110
00111 for (unsigned int i=0; i<burst.size(); i++) {
00112 streamingShot.push_back(burst[i]);
00113 streamingShot[i].id = burst[i].id;
00114 }
00115 pthread_mutex_unlock(&requestMutex);
00116 daemon.setRequestGenerator(this);
00117 }
00118
00119 bool Sensor::streaming() {
00120 return streamingShot.size() > 0;
00121 }
00122
00123 void Sensor::stopStreaming() {
00124 pthread_mutex_lock(&requestMutex);
00125 streamingShot.clear();
00126 pthread_mutex_unlock(&requestMutex);
00127 }
00128
00129 FCam::Frame::Ptr Sensor::getFrame() {
00130 FCam::Frame *f = static_cast<FCam::Frame *>(daemon.getNextFrame());
00131 for (size_t i=0; i< devices.size(); i++) {
00132 devices[i]->tagFrame(f);
00133 }
00134 f->sensor = this;
00135 FCam::Frame::Ptr fp(f);
00136 shotsPending_--;
00137 return fp;
00138 }
00139
00140 Frame::Ptr Sensor::getF2Frame() {
00141 Frame *f = daemon.getNextFrame();
00142 for (size_t i=0; i< devices.size(); i++) {
00143 devices[i]->tagFrame(f);
00144 }
00145 f->sensor = this;
00146 Frame::Ptr fp(f);
00147 return fp;
00148 }
00149
00150 Size Sensor::minImageSize() const {
00151 return Size(640, 480);
00152 }
00153 Size Sensor::maxImageSize() const {
00154 return Size(MT9P031_ACTIVE_WIDTH, MT9P031_ACTIVE_HEIGHT);
00155 }
00156 Size Sensor::pixelArraySize() {
00157 return Size(MT9P031_ARRAY_WIDTH, MT9P031_ARRAY_HEIGHT);
00158 }
00159
00160 Rect Sensor::activeArrayRect() {
00161 return Rect(0,0,
00162 MT9P031_ACTIVE_WIDTH, MT9P031_ACTIVE_HEIGHT);
00163 }
00164 Rect Sensor::pixelArrayRect() {
00165 return Rect(MT9P031_MIN_COL,
00166 MT9P031_MIN_ROW,
00167 MT9P031_ARRAY_WIDTH,
00168 MT9P031_ARRAY_HEIGHT);
00169 }
00170
00171 int Sensor::getRollingShutterTime(const Shot &s) const {
00172
00173 if (s.image.size.height > 960) return 77000;
00174 else return 33000;
00175 }
00176
00177 int Sensor::getRollingShutterTime(const FCam::Shot &s) const {
00178
00179 if (s.image.size.height > 960) return 77000;
00180 else return 33000;
00181 }
00182
00183
00184 void Sensor::generateRequest() {
00185 if (streamingShot.size()) {
00186 capture(streamingShot);
00187 }
00188 }
00189
00190 void Sensor::enforceDropPolicy() {
00191 daemon.setDropPolicy(dropPolicy, frameLimit);
00192 }
00193
00194 int Sensor::framesPending() const {
00195 return daemon.framesPending();
00196 }
00197
00198 int Sensor::shotsPending() const {
00199 return shotsPending_;
00200 }
00201
00202 void Sensor::debugTiming(bool enable) {
00203 daemon.debugTiming(enable);
00204 }
00205
00206
00207 float Sensor::XYZToRawColorMatrixTungsten[] = {
00208 3.8135, -2.1259, -0.6033,
00209 0.5792, 0.6603, -0.2288,
00210 0.4120, 0.0049, 0.1688
00211 };
00212
00213
00214 float Sensor::XYZToRawColorMatrixDaylight[] = {
00215 0.9811, -0.0465, -0.2289,
00216 -1.2482, 1.9812, 0.1418,
00217 -0.7267, 0.8387, 0.6373
00218 };
00219
00220 std::string Sensor::manufacturer = "Stanford University";
00221 std::string Sensor::model = "Aptina MT9P031 - F2 Frankencamera";
00222
00223 }}