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 <phAvcodecSourceTest.h> 00013 #include <stdio.h> 00014 #include <phission.h> 00015 00016 /* ------------------------------------------------------------------------ */ 00017 int glbl_disable_displays = 0; 00018 00019 /* ------------------------------------------------------------------------ */ 00020 int usage() 00021 { 00022 printf("\n\nUsage:\n"); 00023 printf("\t--delay <value:us> Delay between frame updates\n"); 00024 printf("\t--fps <fps> Frames per second speed for the displaying of the video.\n"); 00025 printf("\t--loop <value> Loop the video <value> times; -1 for infinity\n"); 00026 printf("\t--help Display usage\n"); 00027 printf("\t--nodisplay Disable the allocation, opening or any use of a display.\n"); 00028 printf("\t--test <value> Sleep <value> seconds before ending the test\n"); 00029 printf("\t--file <avi_data_file> avi source (required)\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 image_count = 50; 00043 char* filename = NULL; 00044 00045 phDisplayInterface *display = NULL; 00046 00047 int delay = 0; 00048 int fps = 0; 00049 int loop = 0; 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 phAvcodecSource *capture = new phAvcodecSource(); 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= new phArgTable(); 00067 00068 /* Setup and parse all the arguments */ 00069 rc = arg_parser->add("--delay", &delay, phARG_INT); 00070 phCHECK_RC(rc, NULL, "arg_parser->add"); 00071 rc = arg_parser->add("--fps", &fps, phARG_INT); 00072 phCHECK_RC(rc, NULL, "arg_parser->add"); 00073 rc = arg_parser->add("--file", &filename, phARG_CHAR); 00074 phCHECK_RC(rc, NULL, "arg_parser->add"); 00075 rc = arg_parser->add("--test", &test, phARG_INT); 00076 phCHECK_RC(rc,NULL,"arg_parser->add"); 00077 rc = arg_parser->add("--nodisplay", (void *)&glbl_disable_displays, phARG_BOOL); 00078 phCHECK_RC(rc,NULL,"arg_parser->add"); 00079 rc = arg_parser->add("--loop",&loop, phARG_INT); 00080 phCHECK_RC(rc,NULL,"arg_parser->add"); 00081 rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC); 00082 phCHECK_RC(rc,NULL,"arg_parser->add"); 00083 00084 rc = arg_parser->parse(argc,argv); 00085 phCHECK_RC(rc,NULL,"arg_parser->parse"); 00086 00087 if (filename == NULL) 00088 { 00089 phCHECK_PTR(filename,NULL,"filename not given"); 00090 } 00091 00092 capture->setDelay(delay); 00093 capture->setFps(fps); 00094 capture->setLoop(loop); 00095 capture->setFormat(phImageRGB24); 00096 00097 rc = capture->setPath(filename); 00098 phCHECK_RC(rc,NULL,"capture->setPath(%s)",filename); 00099 00100 rc = system.add(capture); 00101 phCHECK_RC(rc,NULL,"system.add(capture:%p)",capture); 00102 00103 /* TODO: init capture */ 00104 00105 if (glbl_disable_displays == 0) 00106 { 00107 display = new X11Display(capture->getWidth(), 00108 capture->getHeight(), 00109 "phAvcodecSourceTest"); 00110 phCHECK_PTR(display,"new","new X11Display failed."); 00111 00112 display->setLiveSourceInput(capture->getLiveSourceOutput()); 00113 00114 rc = system.addDisplay(display); 00115 } 00116 00117 temp.connect(capture->getLiveSourceOutput()); 00118 00119 /* startup */ 00120 rc = system.startup(); 00121 phPRINT_RC(rc,NULL,"system.startup()"); 00122 00123 // now loop continuously for as long as we have a display open and a frame available from the avi file 00124 while ((displaysOpen) && (system.capturesActive())) 00125 { 00126 if (glbl_disable_displays == 0) 00127 { 00128 displaysOpen = 0; 00129 if (system.displaysOpen()) 00130 { 00131 displaysOpen = 1; 00132 } 00133 } 00134 00135 /* Remove this if block when using this code as an example */ 00136 /* Set the loop control value to end the loop when testing */ 00137 if (test > 0) 00138 { 00139 /* loop once through for this test */ 00140 phSleep(test); 00141 displaysOpen = 0; 00142 } 00143 00144 phMSleep(100); 00145 } 00146 00147 error: 00148 rc = system.shutdown(); 00149 phPRINT_RC(rc,NULL,"system.shutdown()"); 00150 00151 phDelete(display); 00152 phDelete(arg_parser); 00153 00154 // free up the filename string allocation 00155 phFree(filename); 00156 00157 return phSUCCESS; 00158 }
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |