psycho-raw-movie.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Component/ModelManager.H"
00039 #include "Image/Image.H"
00040 #include "GUI/GUIOpts.H"
00041 #include "Media/MrawvInputStream.H"
00042 #include "Media/MediaOpts.H"
00043 #include "Psycho/PsychoDisplay.H"
00044 #include "Psycho/EyeTrackerConfigurator.H"
00045 #include "Psycho/EyeTracker.H"
00046 #include "Psycho/PsychoOpts.H"
00047 #include "Component/EventLog.H"
00048 #include "Component/ComponentOpts.H"
00049 #include "Util/MathFunctions.H"
00050 #include "Util/Types.H"
00051 #include "Video/VideoFrame.H"
00052 #include "rutz/time.h"
00053
00054 #include <deque>
00055
00056 #define CACHELEN 300
00057
00058
00059 static bool cacheFrame(nub::soft_ref<MrawvInputStream>& mp,
00060 std::deque<VideoFrame>& cache)
00061 {
00062 const VideoFrame frame = mp->readFrame().asVideo();
00063 if (!frame.initialized()) return false;
00064
00065 cache.push_front(frame);
00066 return true;
00067 }
00068
00069
00070 static int submain(const int argc, char** argv)
00071 {
00072 MYLOGVERB = LOG_INFO;
00073
00074
00075 ModelManager manager("Psycho Raw Movie");
00076
00077
00078 nub::soft_ref<MrawvInputStream> mp
00079 (new MrawvInputStream(manager, "Input Raw Video Stream", "MrawvInputStream"));
00080 manager.addSubComponent(mp);
00081
00082 nub::soft_ref<EventLog> el(new EventLog(manager));
00083 manager.addSubComponent(el);
00084
00085 nub::soft_ref<EyeTrackerConfigurator>
00086 etc(new EyeTrackerConfigurator(manager));
00087 manager.addSubComponent(etc);
00088
00089 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00090 manager.addSubComponent(d);
00091
00092
00093 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00094 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00095 manager.setOptionValString(&OPT_SDLdisplayDims, "1920x1080");
00096
00097
00098 if (manager.parseCommandLine(argc, argv,
00099 "<movie1.mraw> ... <movieN.mraw>", 1, -1)==false)
00100 return(1);
00101
00102
00103 nub::soft_ref<EyeTracker> et = etc->getET();
00104 d->setEyeTracker(et);
00105 d->setEventLog(el);
00106 et->setEventLog(el);
00107
00108
00109 if (etc->getModelParamString("EyeTrackerType").compare("EL") == 0)
00110 d->setModelParamVal("SDLslaveMode", true);
00111
00112
00113 manager.start();
00114
00115
00116 et->calibrate(d);
00117 d->clearScreen();
00118 d->displayText("<SPACE> for random play; other key for ordered");
00119 int c = d->waitForKey(true);
00120
00121
00122 uint nbmovies = manager.numExtraArgs(); int index[nbmovies];
00123 for (uint i = 0; i < nbmovies; i ++) index[i] = i;
00124 if (c == ' ') { LINFO("Randomizing movies..."); randShuffle(index,nbmovies);}
00125
00126
00127 for (uint i = 0; i < nbmovies; i ++)
00128 {
00129
00130 d->clearScreen();
00131 bool streaming = true;
00132 LINFO("Buffering '%s'...", manager.getExtraArg(index[i]).c_str());
00133 mp->setFileName(manager.getExtraArg(index[i]));
00134
00135 std::deque<VideoFrame> cache;
00136 for (uint j = 0; j < CACHELEN; j ++)
00137 {
00138 streaming = cacheFrame(mp, cache);
00139 if (streaming == false) break;
00140 }
00141 LINFO("'%s' ready.", manager.getExtraArg(index[i]).c_str());
00142
00143
00144 sleep(1); if (system("/bin/sync")) LERROR("error in sync()");
00145
00146
00147 d->displayFixation();
00148
00149
00150 d->waitForKey(true); int frame = 0;
00151 d->waitNextRequestedVsync(false, true);
00152 d->pushEvent(std::string("===== Playing movie: ") +
00153 manager.getExtraArg(index[i]) + " =====");
00154
00155
00156 et->track(true);
00157
00158
00159 d->displayFixationBlink();
00160
00161 LINFO("video dims: %d x %d ", mp->getWidth(), mp->getHeight());
00162
00163 if (cache.size() == 0) LFATAL("Zero-frame movie?");
00164 const int ovw = cache[0].getDims().w();
00165 const int ovh = cache[0].getDims().h();
00166 d->createVideoOverlay(VIDFMT_YUV420P,ovw, ovh);
00167
00168
00169 rutz::time start = rutz::time::wall_clock_now();
00170 while(cache.size())
00171 {
00172
00173 if (streaming) streaming = cacheFrame(mp, cache);
00174
00175
00176 VideoFrame vidframe = cache.back();
00177 d->displayVideoOverlay(vidframe, frame,
00178 SDLdisplay::NEXT_VSYNC);
00179 cache.pop_back();
00180
00181 ++frame;
00182 }
00183 rutz::time stop = rutz::time::wall_clock_now();
00184 const double secs = (stop-start).sec();
00185 LINFO("%d frames in %.02f sec (~%.02f fps)", frame, secs, frame/secs);
00186
00187
00188
00189
00190
00191 d->destroyYUVoverlay();
00192 d->clearScreen();
00193
00194
00195 usleep(50000);
00196 et->track(false);
00197
00198
00199 et->recalibrate(d,13);
00200 }
00201
00202 d->clearScreen();
00203 d->displayText("Experiment complete. Thank you!");
00204 d->waitForKey(true);
00205
00206
00207 manager.stop();
00208
00209
00210 return 0;
00211 }
00212
00213
00214 extern "C" int main(const int argc, char** argv)
00215 {
00216
00217
00218
00219
00220 try
00221 {
00222 return submain(argc, argv);
00223 }
00224 catch (...)
00225 {
00226 REPORT_CURRENT_EXCEPTION;
00227 }
00228
00229 return 1;
00230 }
00231
00232
00233
00234
00235
00236