psycho-mplayer.C

Go to the documentation of this file.
00001 /*!@file AppPsycho/psycho-mplayer.C simple program to run SDL and MPlayer */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: John Shen <shenjohn at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppPsycho/psycho-mplayer.C $
00035 // $Id: psycho-mplayer.C 13712 2010-07-28 21:00:40Z itti $
00036 //
00037 
00038 #ifndef APPPSYCHO_PSYCHO_MPLAYER_C_DEFINED
00039 #define APPPSYCHO_PSYCHO_MPLAYER_C_DEFINED
00040 
00041 #include "Component/ModelManager.H"
00042 #include "Psycho/MPlayerWrapper.H"
00043 #include "Component/ComponentOpts.H"
00044 #include "Media/MediaOpts.H"
00045 #include <stdio.h>
00046 #include "Media/MPEGStream.H"
00047 #include "Psycho/EyeTrackerConfigurator.H"
00048 #include "Psycho/EyeTracker.H"
00049 #include "Psycho/PsychoOpts.H"
00050 #include <unistd.h>
00051 
00052 int submain(const int argc, char ** argv)
00053 {
00054   ModelManager manager("Psycho-mplayer");
00055   // Instantiate our various ModelComponents:
00056   nub::soft_ref<EventLog> log(new EventLog(manager));
00057   nub::soft_ref<MPlayerWrapper> player(new MPlayerWrapper(manager));
00058   nub::soft_ref<PsychoDisplay> display(new PsychoDisplay(manager));
00059   nub::soft_ref<EyeTrackerConfigurator>
00060     configurator(new EyeTrackerConfigurator(manager));
00061 
00062   //redundant
00063 
00064   manager.addSubComponent(configurator);
00065   manager.addSubComponent(player);
00066   manager.addSubComponent(log);
00067   manager.addSubComponent(display);
00068 
00069   // Parse command-line:
00070   if (manager.parseCommandLine(argc, argv,
00071                                "<movie1.mpg> ... <movieN.mpg>", 1, -1)==false)
00072     return(1);
00073 
00074   //Set input video stream/output file
00075   //manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00076   manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00077 
00078   // hook our various babies up and do post-command-line configs:
00079   nub::soft_ref<EyeTracker> tracker = configurator->getET();
00080   display->setEyeTracker(tracker);
00081   display->setEventLog(log);
00082   tracker->setEventLog(log);
00083   player->setEventLog(log);
00084 
00085   // EyeLink opens the screen for us, so make sure SDLdisplay is slave:
00086   if (configurator->getModelParamString("EyeTrackerType").compare("EL") == 0)
00087     display->setModelParamVal("SDLslaveMode", true);
00088 
00089 
00090   manager.start();
00091 
00092   //let's do an eye tracker calibration
00093   tracker->calibrate(display);
00094   display->clearScreen();
00095   display->displayText("<SPACE> for random play; other key for ordered");
00096 
00097   int c;
00098   c = display->waitForKey(true);
00099 
00100   //setup array of movie indices
00101   uint nbmovies = manager.numExtraArgs(); int index[nbmovies];
00102   for (uint i = 0; i < nbmovies; i++) index[i]=i;
00103   if(c == ' ')
00104     {
00105       LINFO("Randomizing movies...");
00106       randShuffle(index, nbmovies);
00107     }
00108 
00109   for(uint i = 0; i < nbmovies; i++)
00110     {
00111       display->clearScreen();
00112 
00113       LDEBUG("Playing '%s'...",manager.getExtraArg(index[i]).c_str());
00114       player->setSourceVideo(manager.getExtraArg(index[i]));
00115 
00116       //give a chance to other processes (useful on single-CPUT machines):
00117       sleep(1); if (system("/bin/sync")) LERROR("error in sync");
00118 
00119       // display fixation to indicate that we are ready:
00120       display->displayFixation();
00121 
00122       // ready to go whenever the user is ready:
00123       display->waitForKey(true);
00124       display->waitNextRequestedVsync(false, true);
00125       display->displayFixationBlink();
00126 
00127       tracker->track(true);
00128       player->runfromSDL(display);
00129 
00130       usleep(50000);
00131       tracker->track(false);
00132 
00133       display->clearScreen();
00134       //every other trial, let's do a quick eye tracker recalibration
00135       if(i%2==1 && i != nbmovies-1) tracker->recalibrate(display,13);
00136     }
00137 
00138 
00139   display->clearScreen();
00140   display->displayText("Experiment complete.  Thank you for participating!");
00141   display->waitForKey(true);
00142 
00143 
00144   // stop all our ModelComponents
00145   manager.stop();
00146   return 0;
00147 }
00148 
00149 // ######################################################################
00150 /* So things look consistent in everyone's emacs... */
00151 /* Local Variables: */
00152 /* indent-tabs-mode: nil */
00153 /* End: */
00154 
00155 int main(const int argc, char **argv)
00156 {
00157   try
00158     {
00159       return submain(argc, argv);
00160     }
00161   catch (...)
00162     {
00163       REPORT_CURRENT_EXCEPTION;
00164     }
00165 
00166   return 1;
00167 }
00168 #endif // APPPSYCHO_PSYCHO_MPLAYER_C_DEFINED
Generated on Sun May 8 08:40:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3