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

NetProcessorTest.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 /* Phission must be first for some reason */
00013 #include <NetProcessorTest.h>
00014 #include <phission.h>
00015 #include <signal.h>
00016 
00017 /* ------------------------------------------------------------------------ */
00018 int glbl_signal_caught = 0;
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--test <value>\tsleep 'value' seconds and then close test\n");
00026     printf("\t\t\t--host|-h <host>\tthe host of the NetDisplay server\n");
00027     printf("\t\t\t--nports|-np <value>\t the number of source/dest ports\n");
00028     printf("\t\t\t--srcport|-sp <port>\tthe base port to connect on the host\n");
00029     printf("\t\t\t--dstport|-dp <port>\tthe base port to set the output server to\n");
00030                 
00031     printf("\n\n");
00032     exit(1);
00033 }
00034 
00035 /* ----------------------------------------------------------------------- */
00036 void signal_cleanup(int signal )
00037 {
00038     phFUNCTION("signal_cleanup")
00039 
00040     glbl_signal_caught = 1;
00041 
00042     exit(1);
00043 }
00044 
00045 /* ------------------------------------------------------------------------ */
00046 /* ------------------------------------------------------------------------ */
00047 int main(int argc, char *argv[] )
00048 {
00049     phFUNCTION("main")
00050 
00051     unsigned int    i               = 0;
00052 
00053     int                 displaysOpen    = 1;
00054 
00055     
00056     /* Note: For the net repeater example, if you set this to something other
00057      * than the input format, it will convert it to the new format. Then,
00058      * the new format will be sent out onto the destination port */
00059 
00060     /* Zlib supports any format; the following is a sample */
00061     //uint32_t            outputFormat    = phImageYUV9 | phImageZlib;
00062     //uint32_t            outputFormat    = phImageGREY8 | phImageZlib;
00063     //uint32_t            outputFormat    = phImageRGB24 | phImageZlib;
00064 
00065     /* Valid JPEG supported format combinations: */
00066     //uint32_t            outputFormat    = phImageRGB24;
00067     //uint32_t            outputFormat    = phImageRGB24 | phImageJPEG;
00068     //uint32_t            outputFormat    = phImageGREY8 | phImageJPEG;
00069     //uint32_t            outputFormat    = phImageRGB24 | phImageJPEG | phImageZlib;
00070     //uint32_t            outputFormat    = phImageGREY8 | phImageJPEG | phImageZlib;
00071     
00072     /* Invalid format; Contains phImageRGBA32 which isn't supported by the     
00073      * JPEG code. */
00074     //uint32_t            outputFormat    = phImageRGBA32 | phImageJPEG;
00075 
00076     
00077     uint32_t            width           = 320;
00078     uint32_t            height          = 240;
00079     phDisplayInterface  **display       = NULL;
00080 
00081     phNetSource    **capture = NULL;
00082     uint32_t        nport = 1;
00083     uint32_t        srcport = 22345;
00084     uint32_t        dstport = 22350;
00085     char           *host = NULL;
00086     char           *path = NULL;
00087 
00088     phPipeline **pipeline   = NULL;
00089     phFilter   **filter     = NULL;
00090     
00091     /* Utility class to ease the starting and stopping of displays, captures and
00092      * pipelines */
00093     phSystem        net_system;
00094 
00095     /* Remove the code below when using this code as an example.
00096      * 
00097      * This just checks whether "--test" has been specified with
00098      * a time value argument. It's for testing all the examples
00099      * without the need for human intervention. */
00100     int             test = 0;
00101 
00102     phArgTable      *arg_parser = new phArgTable();
00103 
00104     /* Setup and parse all the arguments */
00105     rc = arg_parser->add("--test", &test, phARG_INT);
00106     phCHECK_RC(rc,NULL,"arg_parser->add");
00107     rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC);
00108     phCHECK_RC(rc,NULL,"arg_parser->add");
00109    
00110     /* Get the host and port from the command line */
00111     rc = arg_parser->add("--host", &host, phARG_CHAR);
00112     phCHECK_RC(rc, NULL, "arg_parser->add");
00113     rc = arg_parser->add("-h", &host, phARG_CHAR);
00114     phCHECK_RC(rc, NULL, "arg_parser->add");
00115 
00116     rc = arg_parser->add("--srcport", &srcport, phARG_UINT32);
00117     phCHECK_RC(rc, NULL, "arg_parser->add");
00118     rc = arg_parser->add("-sp", &srcport, phARG_UINT32);
00119     phCHECK_RC(rc, NULL, "arg_parser->add");
00120     
00121     rc = arg_parser->add("--dstport", &dstport, phARG_UINT32);
00122     phCHECK_RC(rc, NULL, "arg_parser->add");
00123     rc = arg_parser->add("-dp", &dstport, phARG_UINT32);
00124     phCHECK_RC(rc, NULL, "arg_parser->add");
00125 
00126     rc = arg_parser->parse(argc,argv);
00127     phCHECK_RC(rc,NULL,"arg_parser->parse");
00128 
00129     /* Set up a signal handler to shut the net_system down properly */
00130     for (i = 0; i < 17; i++ )
00131     {
00132         signal(i,signal_cleanup);
00133     }
00134 //    signal(SIGINT,signal_cleanup);
00135    
00136     /* Set up the capture stuff */
00137     capture = new phNetSource *[nport];
00138     phCHECK_NULLPTR(capture,"new","new phNetSource *[nport:%d];",nport);
00139  
00140     /* Set up the pipeline stuff */
00141     pipeline = new phPipeline *[nport];
00142     phCHECK_NULLPTR(pipeline,"new","new phPipeline *[nport:%d];",nport);
00143     
00144     filter = new phFilter *[nport];
00145     phCHECK_NULLPTR(filter,"new","new phFilter *[nport:%d];",nport);
00146     
00147     /* Set up the display stuff */
00148     display = new phDisplayInterface *[nport];
00149     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nport:%d];",nport);
00150     
00151     for (i = 0; i < nport; i++)
00152     {
00153         /* CAPTURE/SOURCE */
00154         capture[i] = new phNetSource();
00155 
00156         rc = phNetSource::makePath(host,srcport+i,phNetTypeTCP,&path);
00157         phCHECK_RC(rc,NULL,"phNetSource::makePath");
00158     
00159         rc = capture[i]->setPath(path);
00160         phCHECK_RC(rc,NULL,"capture[i:%d]->setPath(%s)",i,path);
00161 
00162         rc = net_system.addCapture(capture[i]);
00163         phPRINT_RC(rc,NULL,"net_system.addCapture(capture[i:%d])",i);
00164 
00165         /* PIPELINE STUFF */
00166         pipeline[i] = new phPipeline();
00167         //filter[i]   = ((phFilter *)new inverse_Filter());
00168         filter[i]   = ((phFilter *)new canny_Filter());
00169         
00170         rc = pipeline[i]->setLiveSourceInput(capture[i]->getLiveSourceOutput());
00171         phCHECK_RC(rc,NULL,"pipeline[i]->setLiveSourceInput()");
00172         
00173         rc = net_system.addPipeline(pipeline[i]);
00174         phPRINT_RC(rc,NULL,"system.addPipeline(pipeline[i:%d])",i);
00175         
00176         rc = pipeline[i]->add(filter[i]);
00177         phCHECK_RC(rc,NULL,"pipeline[i:%d]->add(%s[i:%d])",
00178                    i,filter[i]->getName(),i);
00179 
00180         /* DISPLAY */
00181         NetDisplay *n = new NetDisplay(width,height);
00182     
00183         display[i] = (phDisplayInterface *)n;
00184         //display[i]->setLiveSourceInput(capture[i]->getLiveSourceOutput());
00185         display[i]->setLiveSourceInput(pipeline[i]->getLiveSourceOutput());
00186         
00187         phPROGRESS("Setting display[%d] to listen on port %d\n",
00188                  i, dstport + i);
00189         n->setPort(dstport + i);
00190         //n->setFormat(outputFormat);
00191 
00192         rc = net_system.addDisplay(display[i]);
00193         phPRINT_RC(rc,NULL,"net_system.addDisplay(display[i:%u])",i);
00194     }
00195 
00196     /* startup the net_system */
00197     rc = net_system.startup();
00198     phPRINT_RC(rc,NULL,"net_system.startup()");
00199    
00200     displaysOpen = 1;
00201     while ((displaysOpen) && (glbl_signal_caught == 0))
00202     {
00203         /* Sleep a while, don't loop tightly */
00204 
00205         phMSleep(100);
00206         
00207         /* Yielding is optional. This gives up the thread's timeslice
00208          * to prevent slow response in other threads. It consumes more
00209          * CPU cycles than sleeping. Use it instead of sleeping if
00210          * this loop is processing anything */
00211         
00212         /* phYield(); */
00213 
00214         if (nport > 0)
00215         {
00216             displaysOpen = 0;
00217             for (i = 0; (i < nport) && (displaysOpen == 0); i++)
00218             {
00219                 if (display[i]->isOpen() == 1)
00220                 {
00221                     displaysOpen = 1;
00222                 }
00223             }
00224         }
00225         
00226         /* Remove this if block when using this code as an example */
00227         /* Set the loop control value to end the loop when testing */
00228         if (test > 0)
00229         { 
00230             displaysOpen = 0;
00231             phSleep(test); /* test's value should be a time (in secs) value > 0*/
00232         }
00233     }
00234 
00235     glbl_signal_caught = 0;
00236     
00237     rc = net_system.shutdown();
00238     phPRINT_RC(rc,NULL,"net_system.shutdown()");
00239 
00240 error:
00241     /* Delete individual captures */
00242     for (i = 0; (i < nport) && (capture != NULL); i++)
00243     {
00244         phDelete(capture[i]);
00245     }
00246  
00247     /* Delete the allocated array */
00248     phDeleteArray(capture);
00249 
00250     /* Delete individual pipelines */
00251     for (i = 0; (i < nport) && (pipeline != NULL); i++)
00252     {
00253         phDelete(pipeline[i]);
00254     }
00255  
00256     /* Delete the allocated array */
00257     phDeleteArray(pipeline);
00258 
00259     /* Delete individual filters */
00260     for (i = 0; (i < nport) && (filter != NULL); i++)
00261     {
00262         phDelete(filter[i]);
00263     }
00264  
00265     /* Delete the allocated array */
00266     phDeleteArray(filter);
00267 
00268     /* Delete individual displays */
00269     for (i = 0; (i < nport) && (display != NULL); i++)
00270     {
00271         phDelete(display[i]);
00272     }
00273  
00274     /* Delete the allocated array */
00275     phDeleteArray(display);
00276 
00277     phDelete(arg_parser);
00278 
00279     return phSUCCESS;
00280 }




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