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




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