Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

StartupShutdownTest.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011  ---------------------------------------------------------------------------*/
00012 #include <StartupShutdownTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 int glbl_add_capture = 1;
00018 int glbl_add_display = 1;
00019 int glbl_add_pipeline = 1;
00020 
00021 /* ------------------------------------------------------------------------ */
00022 int usage ()
00023 {
00024     printf("\n\nUsage:\n");
00025     printf("\t--help                Display usage\n");
00026     printf("\t--nodisplay           Disable the allocation, opening or any use of a display.\n");
00027     printf("\t--ndisplays <value>   Open <value> displays\n");
00028     printf("\t--test <value>        Startup and Shutdown <value> times\n");
00029     printf("\t--sleep <value>       Pause <value> seconds between each iteration\n");
00030     printf("\n\n");
00031     exit(1);
00032 }
00033         
00034 /* ------------------------------------------------------------------------ */
00035 int main(int argc, char *argv[] )
00036 {
00037     phFUNCTION("main")
00038 
00039     uint32_t                i           = 0;
00040     uint32_t                j           = 0;
00041 
00042     /* --------------------------------------------------------------------- */
00043     empty_Filter            *empty      = new empty_Filter();
00044     /* HISTOGRAM Variables ------------------------------------------------- */
00045     /* Filters to run in the pipeline */
00046     unsigned int            nDisplays   = 4;
00047     char                    title[255];
00048     phDisplayInterface      **display   = NULL;
00049     phPipeline              *pipeline   = new phPipeline();
00050 
00051     unsigned int            cycle_count = 10;
00052     
00053     char        *capture_path   = NULL;
00054     int         channel         = 0;
00055         
00056     /* --------------------------------------------------------------------- */
00057 #ifdef WIN32
00058     VFWSource   *capture = new VFWSource();
00059 #else
00060     V4LCapture  *capture = new V4LCapture();
00061 #endif
00062 
00063     /* Utility class to ease the starting and stopping of displays, captures and
00064      * pipelines */
00065     phSystem    system;
00066    
00067     /* SDLDisplay, X11Display, FLDisplay, NetDisplay */
00068 #define nDISPLAY_TYPES 4
00069     uint32_t port = 22341;
00070     
00071     /* Remove the code below when using this code as an example.
00072      * 
00073      * This just checks whether "--test" has been specified with
00074      * a time value argument. It's for testing all the examples
00075      * without the need for human intervention. */
00076     int             test = 0;
00077     int             pause_val = 0;
00078 
00079     phArgTable      *arg_parser = new phArgTable();
00080 
00081     rc = arg_parser->add("--test",&test,phARG_INT);
00082     phCHECK_RC(rc,NULL,"arg_parser->add");
00083     rc = arg_parser->add("--ndisplays",&nDisplays,phARG_INT);
00084     phCHECK_RC(rc,NULL,"arg_parser->add");
00085     rc = arg_parser->add("--sleep",&pause_val,phARG_INT);
00086     phCHECK_RC(rc,NULL,"arg_parser->add");
00087     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00088     phCHECK_RC(rc,NULL,"arg_parser->add");
00089     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00090     phCHECK_RC(rc,NULL,"arg_parser->add");
00091     
00092     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00093     phCHECK_RC(rc,NULL,"arg_parser->add");
00094 
00095     rc = arg_parser->add("--channel",&channel,phARG_INT);
00096     phCHECK_RC(rc,NULL,"arg_parser->add");
00097     
00098     rc = arg_parser->parse(argc,argv);
00099     phCHECK_RC(rc,NULL,"arg_parser->parse");
00100     
00101     if (test) cycle_count = test;
00102     
00103     if (glbl_disable_displays) nDisplays = 0;
00104 
00105 
00106     /* Set up the capture device parameters */
00107     capture->set(320,240,capture_path);
00108     capture->setChannel(channel);
00109     capture->setColour(35000);
00110     capture->setHue(22700);
00111     capture->setContrast(27000);
00112     capture->setBrightness(22000);
00113 
00114     if (glbl_add_capture)
00115     {
00116         rc = system.addCapture(capture);
00117         phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00118     }
00119     
00120     display = new phDisplayInterface *[nDisplays];
00121     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00122     
00123     for (i = 0; i < nDisplays; i++ )
00124     {
00125         uint32_t n = 0;
00126 
00127 #if PH_HAVE_FLTK
00128         if (((i % nDISPLAY_TYPES) == n++) &&
00129             /* Can only have 1 FLDisplay open */
00130             ( i < nDISPLAY_TYPES))                
00131         {
00132             display[i] = new FLDisplay(320,240);
00133         }
00134 #if PH_HAVE_SDL
00135         else
00136 #endif
00137 #endif
00138 #if PH_HAVE_SDL
00139         if (((i % nDISPLAY_TYPES) == n++) &&
00140                   /* Can only have 1 SDLDisplay open */
00141                   ( i < nDISPLAY_TYPES)) 
00142         {
00143             display[i] = new SDLDisplay(320,240);
00144         }
00145 #if PH_HAVE_NET
00146         else 
00147 #endif
00148 #endif
00149 #if PH_HAVE_NET
00150         if ((i % nDISPLAY_TYPES) == n++)
00151         {
00152             NetDisplay *disp = new NetDisplay(320,240);
00153             display[i] = (phDisplayInterface *)disp;
00154             disp->setPort(port++);
00155         }
00156 #if PH_HAVE_X11
00157         else
00158 #endif
00159 #endif
00160 #if PH_HAVE_X11
00161         /* Can have any number of X11Displays */
00162         {
00163             display[i] = new X11Display(320,240);
00164         }
00165 #endif
00166         if (glbl_add_display)
00167         {
00168             rc = system.addDisplay(display[i]);
00169             phPRINT_RC(rc,NULL,"system.addDisplay(display[i:%d])",i);
00170         }
00171     }
00172 
00173     if (glbl_add_pipeline)
00174     {
00175         rc = system.addPipeline(pipeline);
00176         phPRINT_RC(rc,NULL,"system.addPipeline(pipeline)");
00177     }
00178     
00179     
00180     for (i = 0; i < nDisplays; i++ )
00181     {
00182         if ((i % 2) == 0)
00183             display[i]->setLiveSourceInput(pipeline->getLiveSourceOutput());
00184         else
00185             display[i]->setLiveSourceInput(capture->getLiveSourceOutput());
00186     }
00187 
00188     pipeline->setLiveSourceInput(capture->getLiveSourceOutput());
00189     
00190     pipeline->add(empty);
00191 
00192     for (i = 0; i < cycle_count; i++)
00193     {
00194         phPROGRESS("Cycle:%u\n",i);
00195         for (j = 0; j < nDisplays; j++ )
00196         {
00197             sprintf(title,"StartupShutdownTest[%u:%u:%s]",i,j,display[j]->getName());
00198 
00199             display[j]->setTitle(title);
00200         }
00201 
00202         phPROGRESS("\tsystem.startup()\n");
00203         rc = system.startup();
00204         phPRINT_RC(rc,NULL,"system.startup():%u",i);
00205 
00206         phSleep(pause_val);
00207         
00208         phPROGRESS("\tsystem.shutdown()\n");
00209         rc = system.shutdown();
00210         phPRINT_RC(rc,NULL,"system.shutdown():%u",i);
00211     }
00212     
00213     phPROGRESS("Test done. Cleaning up.\n\n");
00214 
00215 
00216 error:
00217     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00218     {
00219         phDelete(display[i]);
00220     }
00221     
00222     phDeleteArray(display);
00223 
00224     phDelete(empty);
00225     
00226     phDelete(pipeline);
00227     
00228     phDelete(capture);
00229 
00230     phFree(capture_path);
00231     phDelete(arg_parser);
00232 
00233     return phSUCCESS;
00234 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:07 2007 for phission by  doxygen 1.4.4