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