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

X11MultiCaptureTest.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 <X11MultiCaptureTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 
00018 /* ------------------------------------------------------------------------ */
00019 int usage ()
00020 {
00021     printf("\n\nUsage:\n");
00022     printf("\t--help            Display usage\n");
00023     printf("\t--nodisplay       Disable the allocation, opening or any use of a display.\n");
00024     printf("\t--test <value>    Sleep 'value' seconds and then close test\n");
00025     printf("\n\n");
00026     exit(1);
00027 }
00028         
00029 /* ------------------------------------------------------------------------ */
00030 int main(int argc, char *argv[] )
00031 {
00032     phFUNCTION("main")
00033 
00034     uint32_t        i           = 0;
00035 
00036     uint32_t            width       = 320;
00037     uint32_t            height      = 240;
00038     uint32_t            nDisplays   = 4;
00039     int                 displaysOpen= 1;
00040     char                title[255];
00041     phDisplayInterface  **display   = NULL;
00042     
00043     uint32_t        nCaptures   = 4;
00044     char            device[255];
00045 #ifdef WIN32
00046     VFWSource       *capture[nCaptures]; 
00047 #else
00048     V4LCapture      *capture[nCaptures];
00049 #endif
00050     
00051     /* Utility class to ease the starting and stopping of displays, captures and
00052      * pipelines */
00053     phSystem        system;
00054    
00055     /* Remove the code below when using this code as an example.
00056      * 
00057      * This just checks whether "--test" has been specified with
00058      * a time value argument. It's for testing all the examples
00059      * without the need for human intervention. */
00060     int             test = 0;
00061 
00062     phArgTable      *arg_parser = new phArgTable();
00063 
00064     rc = arg_parser->add("--test",&test,phARG_INT);
00065     phCHECK_RC(rc,NULL,"arg_parser->add");
00066     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00067     phCHECK_RC(rc,NULL,"arg_parser->add");
00068     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00069     phCHECK_RC(rc,NULL,"arg_parser->add");
00070     
00071     rc = arg_parser->parse(argc,argv);
00072     phCHECK_RC(rc,NULL,"arg_parser->parse");
00073     
00074     if (glbl_disable_displays) nDisplays = 0;
00075 
00076     for (i = 0; i < nCaptures; i++ )
00077     {   
00078 #ifdef WIN32
00079         sprintf(device,"%d",i);
00080         capture[i] = new VFWSource();
00081 #else
00082         sprintf(device,"/dev/video%d",i);
00083         capture[i] = new V4LCapture();
00084 #endif
00085         capture[i]->set(width,height,device);
00086         capture[i]->setChannel(0);
00087         capture[i]->setBrightness(20000);
00088 
00089         rc = system.addCapture(capture[i]);
00090         phPRINT_RC(rc,NULL,"system.addCapture(capture[%u])",i);
00091     }
00092 
00093     display = new phDisplayInterface *[nDisplays];
00094     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00095 
00096     for (i = 0; i < nDisplays; i++)
00097     {
00098         sprintf(title,"X11MultiCaptureTest[%u]",i);
00099 
00100         display[i] = new X11Display(width,height,title);
00101 
00102         if (i < nCaptures)
00103             display[i]->setLiveSourceInput(capture[i]->getLiveSourceOutput());
00104         
00105         rc = system.addDisplay(display[i]);
00106         phPRINT_RC(rc,NULL,"system.addDisplay(display[i:%d])",i);
00107     }
00108     
00109     
00110     /* startup */
00111     rc = system.startup();
00112     phPRINT_RC(rc,NULL,"system.startup()");
00113    
00114     displaysOpen = 1;
00115     while (displaysOpen)
00116     {
00117         /* Sleep a while, don't loop tightly */
00118 
00119         phMSleep(100);
00120         
00121         /* Yielding is optional. This gives up the thread's timeslice
00122          * to prevent slow response in other threads. It consumes more
00123          * CPU cycles than sleeping. Use it instead of sleeping if
00124          * this loop is processing anything */
00125         
00126         /* phYield(); */
00127         
00128         if (nDisplays > 0)
00129         {       
00130             displaysOpen = 0;
00131             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00132             {
00133                 if (display[i]->isOpen() == 1)
00134                 {
00135                     displaysOpen = 1;
00136                 }
00137             }
00138         }
00139         
00140         /* Remove this if block when using this code as an example */
00141         /* Set the loop control value to end the loop when testing */
00142         if (test > 0)
00143         { 
00144             displaysOpen = 0;
00145             phSleep(test); /* test's value should be a time (in secs) value > 0*/
00146         }
00147     }
00148     
00149     rc = system.shutdown();
00150     phPRINT_RC(rc,NULL,"system.shutdown()");
00151 
00152 
00153 error:
00154     for (i = 0; i < nCaptures; i++)
00155     {
00156         phDelete(capture[i]);
00157     }
00158 
00159     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00160     {
00161         phDelete(display[i]);
00162     }
00163  
00164     phDeleteArray(display);
00165 
00166     phDelete(arg_parser);
00167 
00168     return phSUCCESS;
00169 }




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:08 2007 for phission by  doxygen 1.4.4