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

phAvcodecSourceTest.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 <phAvcodecSourceTest.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\nUsage:\n");
00024     printf("\t--delay <value:us>        Delay between frame updates\n");
00025     printf("\t--fps <fps>               Frames per second speed for the displaying of the video.\n");
00026     printf("\t--loop <value>            Loop the video <value> times; -1 for infinity\n");
00027     printf("\t--help                    Display usage\n");
00028     printf("\t--nodisplay               Disable the allocation, opening or any use of a display.\n");
00029     printf("\t--test <value>            Load <value> number of frames/files/images\n");
00030     printf("\t--file <avi_data_file>    avi source (required)\n");
00031     printf("\n\n");
00032     exit(1);
00033 }
00034 
00035 
00036 /* ------------------------------------------------------------------------ */
00037 int main(int argc, char *argv[] )
00038 {
00039     phFUNCTION("main")
00040 
00041     int             displaysOpen= 1;
00042     
00043     unsigned int    i           = 0;
00044     unsigned int    image_count = 50;
00045     char*           filename    = NULL;
00046 
00047     phDisplayInterface *display = NULL;
00048 
00049     int             delay           = 0;
00050     int             fps             = 0;
00051     int             loop            = 0;
00052 
00053     phImage temp;
00054     char    temp_filename[245];
00055     
00056     /* Utility class to ease the starting and stopping of displays, captures and
00057      * pipelines */
00058     phSystem        system;
00059     phAvcodecSource  *capture = new phAvcodecSource();
00060    
00061     /* Remove the code below when using this code as an example.
00062      * 
00063      * This just checks whether "--test" has been specified with
00064      * a time value argument. It's for testing all the examples
00065      * without the need for human intervention. */
00066     int             test = 0;
00067 
00068     phArgTable      *arg_parser= new phArgTable();
00069 
00070     /* Setup and parse all the arguments */
00071     rc = arg_parser->add("--delay", &delay, phARG_INT);
00072     phCHECK_RC(rc, NULL, "arg_parser->add");
00073     rc = arg_parser->add("--fps", &fps, phARG_INT);
00074     phCHECK_RC(rc, NULL, "arg_parser->add");
00075     rc = arg_parser->add("--file", &filename, phARG_CHAR);
00076     phCHECK_RC(rc, NULL, "arg_parser->add");
00077     rc = arg_parser->add("--test", &test, phARG_INT);
00078     phCHECK_RC(rc,NULL,"arg_parser->add");
00079     rc = arg_parser->add("--nodisplay", (void *)&glbl_disable_displays, phARG_BOOL);
00080     phCHECK_RC(rc,NULL,"arg_parser->add");
00081     rc = arg_parser->add("--loop",&loop, phARG_INT);
00082     phCHECK_RC(rc,NULL,"arg_parser->add");
00083     rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC);
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     if (filename == NULL)
00090     {
00091         phCHECK_PTR(filename,NULL,"filename not given");
00092     }
00093 
00094     capture->setDelay(delay);
00095     capture->setFps(fps);
00096     capture->setLoop(loop);
00097     capture->setFormat(phImageRGB24);
00098     
00099     rc = capture->setPath(filename);
00100     phCHECK_RC(rc,NULL,"capture->setPath(%s)",filename);
00101   
00102     rc = system.add(capture);
00103     phCHECK_RC(rc,NULL,"system.add(capture:%p)",capture);
00104     
00105     /* TODO: init capture */
00106 
00107     if (glbl_disable_displays == 0)
00108     {
00109         display = new X11Display(capture->getWidth(),
00110                                  capture->getHeight(),
00111                                  "phAvcodecSourceTest");
00112         phCHECK_PTR(display,"new","new X11Display failed.");
00113         
00114         display->setLiveSourceInput(capture->getLiveSourceOutput());
00115         
00116         rc = system.addDisplay(display);
00117     }
00118 
00119     temp.connect(capture->getLiveSourceOutput());
00120 
00121     /* startup */
00122     rc = system.startup();
00123     phPRINT_RC(rc,NULL,"system.startup()");
00124     
00125     // now loop continuously for as long as we have a display open and a frame available from the avi file
00126     while ((displaysOpen) && (system.capturesActive()))
00127     {
00128         if (glbl_disable_displays == 0)
00129         {
00130             displaysOpen = 0;
00131             if (system.displaysOpen())
00132             {
00133                 displaysOpen = 1;
00134             }
00135         }
00136 
00137         /* Remove this if block when using this code as an example */
00138         /* Set the loop control value to end the loop when testing */
00139         if (test > 0)
00140         { 
00141             /* loop once through for this test */
00142             if (i == test)
00143             {
00144                 phMSleep(1000);
00145                 displaysOpen = 0;
00146             }
00147         }
00148 
00149         phMSleep(100);
00150     }
00151     
00152  error:
00153     rc = system.shutdown();
00154     phPRINT_RC(rc,NULL,"system.shutdown()");
00155     
00156     phDelete(display);
00157     phDelete(arg_parser);
00158 
00159     // free up the filename string allocation
00160     phFree(filename);
00161 
00162     return phSUCCESS;
00163 }




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