Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "DSVL.h"
00043
00044 #include <AR/video.h>
00045 #include <stdlib.h>
00046 #include "comutil.h"
00047
00048
00049
00050 struct _AR2VideoParamT {
00051 DSVL_VideoSource *graphManager;
00052 MemoryBufferHandle g_Handle;
00053 bool bufferCheckedOut;
00054 __int64 g_Timestamp;
00055
00056
00057 };
00058
00059
00060
00061 static AR2VideoParamT *gVid = NULL;
00062
00063 #ifdef FLIPPED // compatibility with videoLinux*
00064 static const bool FLIPPED_defined = true;
00065 #else
00066 static const bool FLIPPED_defined = false;
00067 #endif
00068 const long frame_timeout_ms = 0L;
00069
00070
00071
00072
00073 int arVideoDispOption(void)
00074 {
00075 return (ar2VideoDispOption());
00076 }
00077
00078 int arVideoOpen(char *config)
00079 {
00080 if (gVid != NULL) {
00081 fprintf(stderr, "arVideoOpen(): Error, device is already open.\n");
00082 return (-1);
00083 }
00084 gVid = ar2VideoOpen(config);
00085 if (gVid == NULL) return (-1);
00086
00087 return (0);
00088 }
00089
00090 int arVideoClose(void)
00091 {
00092 int result;
00093
00094 if (gVid == NULL) return (-1);
00095
00096 result = ar2VideoClose(gVid);
00097 gVid = NULL;
00098 return (result);
00099 }
00100
00101 int arVideoInqSize(int *x, int *y)
00102 {
00103 if (gVid == NULL) return (-1);
00104
00105 return (ar2VideoInqSize(gVid, x, y));
00106 }
00107
00108 ARUint8 *arVideoGetImage(void)
00109 {
00110 if (gVid == NULL) return (NULL);
00111
00112 return (ar2VideoGetImage(gVid));
00113 }
00114
00115 int arVideoCapStart(void)
00116 {
00117 if (gVid == NULL) return (-1);
00118
00119 return (ar2VideoCapStart(gVid));
00120 }
00121
00122 int arVideoCapStop(void)
00123 {
00124 if (gVid == NULL) return (-1);
00125
00126 return (ar2VideoCapStop(gVid));
00127 }
00128
00129 int arVideoCapNext(void)
00130 {
00131 if (gVid == NULL) return (-1);
00132
00133 return (ar2VideoCapNext(gVid));
00134 }
00135
00136
00137
00138 int ar2VideoDispOption(void)
00139 {
00140 printf("parameter is a file name (e.g. 'config.XML') conforming to the DSVideoLib XML Schema (DsVideoLib.xsd).\n");
00141 return (0);
00142 }
00143
00144 AR2VideoParamT *ar2VideoOpen(char *config)
00145 {
00146 AR2VideoParamT *vid = NULL;
00147 char config_default[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dsvl_input><camera show_format_dialog=\"true\" friendly_name=\"\"><pixel_format><RGB32 flip_h=\"false\" flip_v=\"true\"/></pixel_format></camera></dsvl_input>";
00148
00149
00150
00151 arMalloc(vid, AR2VideoParamT, 1);
00152 memset(vid, 0, sizeof(AR2VideoParamT));
00153
00154 CoInitialize(NULL);
00155
00156 vid->graphManager = new DSVL_VideoSource();
00157 if (!config) {
00158
00159 config = getenv("ARTOOLKIT_CONFIG");
00160
00161 if (config == NULL) {
00162 config = &config_default[0];
00163 }
00164 if (FAILED(vid->graphManager->BuildGraphFromXMLString(config))) return(NULL);
00165
00166 } else {
00167 if (strncmp(config, "<?xml", 5) == 0) {
00168 if (FAILED(vid->graphManager->BuildGraphFromXMLString(config))) return(NULL);
00169 } else {
00170 if (FAILED(vid->graphManager->BuildGraphFromXMLFile(config))) return(NULL);
00171 }
00172 }
00173 if (FAILED(vid->graphManager->EnableMemoryBuffer())) return(NULL);
00174
00175 return (vid);
00176 }
00177
00178
00179 int ar2VideoClose(AR2VideoParamT *vid)
00180 {
00181 int _ret = -1;
00182
00183 if (vid == NULL) return (_ret);
00184
00185 if (vid->graphManager != NULL) {
00186
00187 if (vid->bufferCheckedOut)
00188 vid->graphManager->CheckinMemoryBuffer(vid->g_Handle, true);
00189
00190 vid->graphManager->Stop();
00191 delete vid->graphManager;
00192 vid->graphManager = NULL;
00193
00194 _ret = 0;
00195 }
00196
00197 free(vid);
00198
00199
00200 vid = NULL;
00201
00202
00203 CoUninitialize();
00204
00205 return(_ret);
00206 }
00207
00208 unsigned char *ar2VideoGetImage(AR2VideoParamT *vid)
00209 {
00210 DWORD wait_result;
00211 unsigned char* pixelBuffer;
00212
00213 if (vid == NULL) return (NULL);
00214 if (vid->graphManager == NULL) return (NULL);
00215
00216 if (vid->bufferCheckedOut) {
00217 if (FAILED(vid->graphManager->CheckinMemoryBuffer(vid->g_Handle))) return (NULL);
00218 vid->bufferCheckedOut = false;
00219 }
00220 wait_result = vid->graphManager->WaitForNextSample(frame_timeout_ms);
00221 if (wait_result == WAIT_OBJECT_0) {
00222 if (FAILED(vid->graphManager->CheckoutMemoryBuffer(&(vid->g_Handle), &pixelBuffer, NULL, NULL, NULL, &(vid->g_Timestamp)))) return(NULL);
00223 vid->bufferCheckedOut = true;
00224 return (pixelBuffer);
00225 }
00226
00227 return(NULL);
00228 }
00229
00230 int ar2VideoCapStart(AR2VideoParamT *vid)
00231 {
00232 if (vid == NULL) return (-1);
00233 if (vid->graphManager == NULL) return (-1);
00234
00235 if (FAILED(vid->graphManager->Run())) return (-1);
00236 return (0);
00237 }
00238
00239 int ar2VideoCapStop(AR2VideoParamT *vid)
00240 {
00241 if (vid == NULL) return (-1);
00242 if (vid->graphManager == NULL) return (-1);
00243
00244 if (vid->bufferCheckedOut) {
00245 if (FAILED(vid->graphManager->CheckinMemoryBuffer(vid->g_Handle, true))) return (-1);
00246 vid->bufferCheckedOut = false;
00247 }
00248
00249
00250
00251
00252
00253
00254 return (0);
00255 }
00256
00257 int ar2VideoCapNext(AR2VideoParamT *vid)
00258 {
00259 if (vid == NULL) return (-1);
00260 if (vid->graphManager == NULL) return (-1);
00261
00262 if (vid->bufferCheckedOut) {
00263 if (FAILED(vid->graphManager->CheckinMemoryBuffer(vid->g_Handle, true))) return (-1);
00264 vid->bufferCheckedOut = false;
00265 }
00266 return (0);
00267 }
00268
00269 int ar2VideoInqSize(AR2VideoParamT *vid, int *x, int *y)
00270 {
00271 if (vid == NULL) return (-1);
00272 if (vid->graphManager == NULL) return(-1);
00273
00274 long frame_width;
00275
00276 long frame_height;
00277
00278 vid->graphManager->GetCurrentMediaFormat(&frame_width, &frame_height,NULL,NULL);
00279
00280 *x = (int) frame_width;
00281
00282 *y = (int) frame_height;
00283
00284
00285 return (0);
00286 }
00287
00288
00289
00290 int ar2VideoInqFlipping(AR2VideoParamT *vid, int *flipH, int *flipV)
00291 {
00292
00293
00294
00295
00296
00297 return (-1);
00298 }
00299
00300 int ar2VideoInqFreq(AR2VideoParamT *vid, float *fps)
00301 {
00302 if (vid == NULL) return (-1);
00303 if (vid->graphManager == NULL) return(-1);
00304
00305 double frames_per_second;
00306
00307 vid->graphManager->GetCurrentMediaFormat(NULL,NULL,&frames_per_second,NULL);
00308
00309 *fps = (float) frames_per_second;
00310
00311
00312 return (0);
00313 }
00314
00315 unsigned char *ar2VideoLockBuffer(AR2VideoParamT *vid, MemoryBufferHandle* pHandle)
00316 {
00317 unsigned char *pixelBuffer;
00318
00319 if (vid == NULL) return (NULL);
00320 if (vid->graphManager == NULL) return (NULL);
00321
00322 if (FAILED(vid->graphManager->CheckoutMemoryBuffer(pHandle, &pixelBuffer))) return (NULL);
00323 vid->bufferCheckedOut = true;
00324
00325 return (pixelBuffer);
00326 }
00327
00328 int ar2VideoUnlockBuffer(AR2VideoParamT *vid, MemoryBufferHandle Handle)
00329 {
00330 if (vid == NULL) return (-1);
00331 if (vid->graphManager == NULL) return(-1);
00332
00333 if (FAILED(vid->graphManager->CheckinMemoryBuffer(Handle))) return(-1);
00334 vid->bufferCheckedOut = false;
00335
00336 return (0);
00337 }
00338
00339
00340