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

phNetSourceTest.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 <phNetSourceTest.h>
00013 #include <stdio.h>
00014 #include <phission.h>
00015 
00016 /* ------------------------------------------------------------------------ */
00017 int glbl_disable_displays = 0;
00018 int glbl_preload_images = 1;
00019 
00020 /* ------------------------------------------------------------------------ */
00021 int usage()
00022 {
00023     printf("\n\n\tUsage:\n");
00024     printf("\t\t\t--help\t\t\tdisplay usage\n");
00025     printf("\t\t\t--nodisplay\tdisable the allocation, opening or any use of a display.\n");
00026     printf("\t\t\t--test <value>\tload 'value' number of frames/files/images\n");
00027     printf("\t\t\t--host|-h <host>\tthe host of the NetDisplay server\n");
00028     printf("\t\t\t--port|-p <port>\tthe port to connect on the host\n");
00029     printf("\n\n");
00030     exit(1);
00031 }
00032 
00033 
00034 /* ------------------------------------------------------------------------ */
00035 int main(int argc, char *argv[] )
00036 {
00037     phFUNCTION("main")
00038 
00039     int             displaysOpen= 1;
00040 
00041     uintmax_t       count       = 0;
00042     unsigned int    i           = 0;
00043 
00044     uint32_t        port = 0;
00045     char            *host = NULL;
00046     char            *path = NULL;
00047 
00048     phDisplayInterface *display = NULL;
00049 
00050     phImage temp;
00051     char    temp_filename[245];
00052     
00053     /* Utility class to ease the starting and stopping of displays, captures and
00054      * pipelines */
00055     phSystem        system;
00056     phNetSource     *capture = new phNetSource();
00057    
00058     /* Remove the code below when using this code as an example.
00059      * 
00060      * This just checks whether "--test" has been specified with
00061      * a time value argument. It's for testing all the examples
00062      * without the need for human intervention. */
00063     int             test = 0;
00064 
00065     phArgTable      *arg_parser = new phArgTable();
00066 
00067     /* Setup and parse all the arguments */
00068     rc = arg_parser->add("--test", &test, phARG_INT);
00069     phCHECK_RC(rc,NULL,"arg_parser->add");
00070     rc = arg_parser->add("--nodisplay", (void *)&glbl_disable_displays, phARG_BOOL);
00071     phCHECK_RC(rc,NULL,"arg_parser->add");
00072     rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC);
00073     phCHECK_RC(rc,NULL,"arg_parser->add");
00074    
00075     /* Get the host and port from the command line */
00076     rc = arg_parser->add("--host", &host, phARG_CHAR);
00077     phCHECK_RC(rc, NULL, "arg_parser->add");
00078     rc = arg_parser->add("-h", &host, phARG_CHAR);
00079     phCHECK_RC(rc, NULL, "arg_parser->add");
00080     rc = arg_parser->add("--port", &port, phARG_UINT32);
00081     phCHECK_RC(rc, NULL, "arg_parser->add");
00082     rc = arg_parser->add("-p", &port, phARG_UINT32);
00083     phCHECK_RC(rc, NULL, "arg_parser->add");
00084     
00085     rc = arg_parser->parse(argc,argv);
00086     phCHECK_RC(rc,NULL,"arg_parser->parse");
00087 
00088     capture->setSize(320,240);
00089 
00090     //capture->setFormat(phImageRGB24);
00091     
00092 #if 0
00093     #if 1
00094     rc = capture->setHost(host);
00095     phCHECK_RC(rc,NULL,"capture->setHost(host:%s);",host);
00096         
00097     rc = capture->setPort(port);
00098     phCHECK_RC(rc,NULL,"capture->setPort(port:%d);",port);
00099     #else
00100     rc = capture->set(host,port);
00101     phCHECK_RC(rc,NULL,"capture->set(host:%s,port:%d);",host,port);
00102     #endif
00103 #else
00104     rc = phNetSource::makePath(host,port,phNetTypeTCP,&path);
00105     phCHECK_RC(rc,NULL,"phNetSource::makePath");
00106     
00107     rc = capture->setPath(path);
00108     phCHECK_RC(rc,NULL,"capture->setPath(%s)",path);
00109 #endif
00110     
00111     rc = system.add(capture);
00112     phCHECK_RC(rc,NULL,"system.add(capture:%p)",capture);
00113     
00114     if (glbl_disable_displays == 0)
00115     {
00116         /* this will set up with some value, but not necessarily the correct
00117          * value for the image size. When the capture is activated, it will
00118          * output images of some size and the window will resize on it's own.
00119          * However, one can call setSize on the capture object before here
00120          * for a desired size, which will not change when the new image comes
00121          * across */
00122 #if defined(WIN32)
00123         display = new GDIDisplay(capture->getWidth(),
00124                                  capture->getHeight(),
00125                                  "phNetSourceTest");
00126 #else
00127         display = new X11Display(capture->getWidth(),
00128                                  capture->getHeight(),
00129                                  "phNetSourceTest");
00130 #endif
00131         phCHECK_PTR(display,"new","new X11Display failed.");
00132         
00133         display->setLiveSourceInput(capture->getLiveSourceOutput());
00134         
00135         rc = system.addDisplay(display);
00136     }
00137 
00138     temp.connect(capture->getLiveSourceOutput());
00139 
00140     phPROGRESS("%s:%d\n",capture->getHost(),capture->getPort());
00141 
00142     /* startup */
00143     rc = system.startup();
00144     phPRINT_RC(rc,NULL,"system.startup()");
00145     
00146     // now loop continuously for as long as we have a display open and a frame available from the avi file
00147     while ((displaysOpen) && (system.capturesActive()))
00148     {
00149         if (glbl_disable_displays == 0)
00150         {
00151             displaysOpen = 0;
00152             if (system.displaysOpen())
00153             {
00154                 displaysOpen = 1;
00155             }
00156         }
00157 
00158         temp.update();
00159         phPROGRESS("%u\n",count);
00160         count++;
00161 
00162         /* Remove this if block when using this code as an example */
00163         /* Set the loop control value to end the loop when testing */
00164         if (test > 0)
00165         { 
00166             test--;
00167             if (test == 0)
00168                 displaysOpen = 0;
00169         }
00170 
00171         phMSleep(100);
00172     }
00173     
00174 error:
00175     rc = system.shutdown();
00176     phPRINT_RC(rc,NULL,"system.shutdown()");
00177     
00178     phDelete(display);
00179 
00180     // free up the filename string allocation
00181     phFree(host);
00182     phFree(path);
00183 
00184     phDelete(arg_parser);
00185 
00186     return phSUCCESS;
00187 }




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