video.c
Go to the documentation of this file.
00001 /*******************************************************
00002  *
00003  * Author: Hirokazu Kato, Atsishi Nakazawa
00004  *
00005  *         kato@sys.im.hiroshima-cu.ac.jp
00006  *         nakazawa@inolab.sys.es.osaka-u.ac.jp
00007  *
00008  * Revision: 5.1
00009  * Date: 00/05/06
00010  *
00011 *******************************************************/
00012 
00013 #include <string.h>
00014 #include <AR/config.h>
00015 #include <AR/video.h>
00016 
00017 
00018 static int             init      = 0;             /* initialize flag */
00019 static AR2VideoParamT  *gVid = NULL;
00020 
00021 
00022 int arVideoDispOption( void )
00023 {
00024     return  ar2VideoDispOption();
00025 }
00026 
00027 int arVideoOpen( char *config )
00028 {
00029     if( gVid != NULL ) {
00030         printf("Device has been opened!!\n");
00031         return -1;
00032     }
00033     gVid = ar2VideoOpen( config );
00034     if( gVid == NULL ) return -1;
00035 
00036     return 0;
00037 }
00038 
00039 int arVideoClose( void )
00040 {
00041         int result;
00042         
00043     if( gVid == NULL ) return -1;
00044 
00045         result = ar2VideoClose(gVid);
00046         gVid = NULL;
00047     return (result);
00048 }
00049 
00050 int arVideoInqSize( int *x, int *y )
00051 {
00052     if( gVid == NULL ) return -1;
00053 
00054     return ar2VideoInqSize( gVid, x, y );
00055 }
00056 
00057 ARUint8 *arVideoGetImage( void )
00058 {
00059     if( gVid == NULL ) return NULL;
00060 
00061     return ar2VideoGetImage( gVid );
00062 }
00063 
00064 int arVideoCapStart( void )
00065 {
00066     if( gVid == NULL ) return -1;
00067 
00068     return ar2VideoCapStart( gVid );
00069 }
00070 
00071 int arVideoCapStop( void )
00072 {
00073     if( gVid == NULL ) return -1;
00074 
00075     return ar2VideoCapStop( gVid );
00076 }
00077 
00078 int arVideoCapNext( void )
00079 {
00080     if( gVid == NULL ) return -1;
00081 
00082     return ar2VideoCapNext( gVid );
00083 }
00084 
00085 /*-------------------------------------------*/
00086 
00087 
00088 int ar2VideoDispOption( void )
00089 {
00090     printf("ARVideo may be configured using one or more of the following options,\n");
00091     printf("separated by a space:\n\n");
00092     printf(" -size=[FULL/HALF]\n");
00093     printf("    specifies size of image.\n");
00094     printf(" -device=N\n");
00095     printf("    specifies device number.\n");
00096     printf(" -bufsize=N\n");
00097     printf("    specifies video buffer size.\n");
00098     printf("\n");
00099 
00100     return 0;
00101 }
00102 
00103 AR2VideoParamT *ar2VideoOpen( char *config )
00104 {
00105     AR2VideoParamT    *vid;
00106     char              *a, line[256];
00107     int               i;
00108 
00109     arMalloc( vid, AR2VideoParamT, 1 );
00110     vid->did       = 0;
00111     vid->format    = AR_VIDEO_INTERLEAVED;
00112     vid->packing   = AR_VIDEO_RGB_8;
00113     if( DEFAULT_VIDEO_SIZE == VIDEO_FULL ) {
00114         vid->zoom      = AR_VIDEO_1_P_1;
00115     }
00116     else {
00117         vid->zoom      = AR_VIDEO_1_P_2;
00118     }
00119     vid->buf_size  = -1;
00120     
00121     a = config;
00122     if( a != NULL) {
00123         for(;;) {
00124             while( *a == ' ' || *a == '\t' ) a++;
00125             if( *a == '\0' ) break;
00126 
00127             if( strncmp( a, "-size=", 6 ) == 0 ) {
00128                 if( strncmp( &a[6], "FULL", 4 ) == 0 )       vid->zoom = AR_VIDEO_1_P_1;
00129                 else if( strncmp( &a[6], "HALF", 4 ) == 0 )  vid->zoom = AR_VIDEO_1_P_2;
00130                 else {
00131                     arVideoDispOption();
00132                     free( vid );
00133                     return 0;
00134                 }
00135             }
00136             else if( strncmp( a, "-device=", 8 ) == 0 ) {
00137                 sscanf( a, "%s", line );
00138                 if( sscanf( &line[8], "%d", &vid->did ) == 0 ) {
00139                     arVideoDispOption();
00140                     free( vid );
00141                     return 0;
00142                 }
00143             }
00144             else if( strncmp( a, "-bufsize=", 9 ) == 0 ) {
00145                 sscanf( a, "%s", line );
00146                 if( sscanf( &line[9], "%d", &vid->buf_size ) == 0 ) {
00147                     arVideoDispOption();
00148                     free( vid );
00149                     return 0;
00150                 }
00151             }
00152             else {
00153                 arVideoDispOption();
00154                 free( vid );
00155                 return 0;
00156             }
00157 
00158             while( *a != ' ' && *a != '\t' && *a != '\0') a++;
00159         }
00160     }
00161 
00162     if( init  == 0 ) {
00163         if( arVideoOpen2() < 0 ) {
00164             free( vid );
00165             return 0;
00166         }
00167         init = 1;
00168     }
00169 
00170     if( arVideoSetupDevice2(vid->did, vid->format, vid->packing, vid->zoom) < 0 ) {
00171         free( vid );
00172         return 0;
00173     }
00174     if( vid->buf_size > 0 ) {
00175         arVideoSetBufferSize2( vid->did, vid->buf_size );
00176     }
00177 
00178     return vid;
00179 }
00180 
00181 int ar2VideoClose( AR2VideoParamT *vid )
00182 {
00183     if(arVideoCleanupDevice2(vid->did) < 0) return -1;
00184     free( vid );
00185 
00186     return 0;
00187 }
00188 
00189 int ar2VideoInqSize(AR2VideoParamT *vid, int *x,int *y)
00190 {
00191     return arVideoInqSize2( vid->did, x, y );
00192 }
00193 
00194 int ar2VideoCapStart( AR2VideoParamT *vid )
00195 {
00196     return arVideoStart2( vid->did );
00197 }
00198 
00199 int ar2VideoCapStop( AR2VideoParamT *vid )
00200 {
00201     return arVideoStop2( vid->did );
00202 }
00203 
00204 int ar2VideoCapNext( AR2VideoParamT *vid )
00205 {
00206     return 0;
00207 }
00208 
00209 ARUint8 *ar2VideoGetImage( AR2VideoParamT *vid )
00210 {
00211     return arVideoGetImage2( vid->did );
00212 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:15:00