AR2VideoParamWinDSVLT *ar2VideoOpenWinDSVL(const char *config) { AR2VideoParamWinDSVLT *vid = NULL; const 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>"; char *config0; // Allocate the parameters structure and fill it in. arMallocClear(vid, AR2VideoParamWinDSVLT, 1); if (!config || !config[0]) { config0 = _strdup(config_default); } else { config0 = _strdup(config); } CoInitialize(NULL); vid->graphManager = new DSVL_VideoSource(); if (strncmp(config0, "<?xml", 5) == 0) { if (FAILED(vid->graphManager->BuildGraphFromXMLString(config0))) goto bail; } else { if (FAILED(vid->graphManager->BuildGraphFromXMLFile(config0))) goto bail; } if (FAILED(vid->graphManager->EnableMemoryBuffer())) goto bail; free(config0); return (vid); bail: delete vid->graphManager; free(config0); free(vid); return (NULL); }
AR2VideoParamWinMCT *ar2VideoOpenWinMC(const char *config) { AR2VideoParamWinMCT *vid; int width = 320; int height = 240; int flipH = 0, flipV = 0; int devNum = 0; int showDialog = -1; const char *a; char b[256]; const char config_default[] = ""; int err_i = 0; //ARLOG("Entering ar2VideoOpenWinMC\n"); if (ar2VideoWinMCRefCount == 0) { if (!ar2VideoWinMCInit2()) return NULL; } ar2VideoWinMCRefCount++; arMallocClear(vid, AR2VideoParamWinMCT, 1); vid->format = AR_PIXEL_FORMAT_INVALID; vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Unknown; // Ensure the provided config is valid, otherwise use default config. if (!config) a = config_default; else if (!config[0]) a = config_default; else a = config; if (a != NULL) { for (;;) { while(*a == ' ' || *a == '\t') a++; if (*a == '\0') break; if (sscanf(a, "%s", b) == 0) break; if (strncmp(b, "-devNum=", 8) == 0) { if (sscanf(&b[8], "%d", &devNum) != 1) err_i = 1; else if (devNum < 0) { ARLOGe("Error: device number must be integer beginning with 1, or 0 to use default device.\n"); err_i = 1; } } else if( strncmp( b, "-format=", 8 ) == 0 ) { if (strcmp(b+8, "0") == 0) { vid->format = AR_PIXEL_FORMAT_INVALID; ARLOGi("Requesting images in system default format.\n"); } else if (strcmp(b+8, "BGRA") == 0) { vid->format = AR_PIXEL_FORMAT_BGRA; ARLOGi("Requesting images in BGRA format.\n"); } else if (strcmp(b+8, "BGR") == 0) { vid->format = AR_PIXEL_FORMAT_BGR; ARLOGi("Requesting images in BGR format.\n"); } else if (strcmp(b+8, "RGB_565") == 0) { vid->format = AR_PIXEL_FORMAT_RGB_565; ARLOGi("Requesting images in RGB_565 format.\n"); } else if (strcmp(b+8, "RGBA_5551") == 0) { vid->format = AR_PIXEL_FORMAT_RGBA_5551; ARLOGi("Requesting images in RGB_5551 format.\n"); } else if (strcmp(b+8, "2vuy") == 0 || strcmp(b+8, "UYVY") == 0) { vid->format = AR_PIXEL_FORMAT_2vuy; ARLOGi("Requesting images in 2vuy/UYVY format.\n"); } else if (strcmp(b+8, "yuvs") == 0 || strcmp(b+8, "YUY2") == 0) { vid->format = AR_PIXEL_FORMAT_yuvs; ARLOGi("Requesting images in yuvs/YUY2 format.\n"); } else if (strcmp(b+8, "NV21") == 0) { vid->format = AR_PIXEL_FORMAT_NV21; ARLOGi("Requesting images in NV21 format.\n"); } else if (strcmp(b+8, "420f") == 0 || strcmp(b+8, "NV12") == 0) { vid->format = AR_PIXEL_FORMAT_420f; ARLOGi("Requesting images in 420f/NV12 format.\n"); } else { ARLOGe("Ignoring request for unsupported video format '%s'.\n", b+8); } } else if( strncmp( b, "-position=", 10 ) == 0 ) { if (strcmp(b+10, "rear") == 0 || strcmp(b+10, "back") == 0) { vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Back; } else if (strcmp(b+10, "front") == 0) { vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Front; } else if (strcmp(b+10, "left") == 0) { vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Left; } else if (strcmp(b+10, "right") == 0) { vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Right; } else if (strcmp(b+10, "top") == 0) { vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Top; } else if (strcmp(b+10, "bottom") == 0) { vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Bottom; } else if (strcmp(b+10, "default") == 0) { vid->preferredDeviceLocation = Windows::Devices::Enumeration::Panel::Unknown; } else { ARLOGe("Error: unsupported video device position requested. Using default.\n"); } } else if( strncmp( b, "-width=", 7 ) == 0 ) { if( sscanf( &b[7], "%d", &width ) == 0 ) err_i = 1; } else if( strncmp( b, "-height=", 8 ) == 0 ) { if( sscanf( &b[8], "%d", &height ) == 0 ) err_i = 1; } else if (strcmp(b, "-showDialog") == 0) { showDialog = 1; } else if (strcmp(b, "-noShowDialog") == 0) { showDialog = 0; } else if (strcmp(b, "-flipH") == 0) { flipH = 1; } else if (strcmp(b, "-noFlipH") == 0) { flipH = 0; } else if (strcmp(b, "-flipV") == 0) { flipV = 1; } else if (strcmp(b, "-noFlipV") == 0) { flipV = 0; } else if (strcmp(b, "-device=WinMC") == 0) { //ARLOG("Device set to WinMC\n"); } else { ARLOGe("Unrecognized config token: '%s'\n", b); ar2VideoDispOptionWinMC(); return 0; } if (err_i) goto bail; while(*a != ' ' && *a != '\t' && *a != '\0') a++; } } // Defaults. if (vid->format == AR_PIXEL_FORMAT_INVALID) vid->format = AR_PIXEL_FORMAT_BGR; // Alloc and init WindowsMediaCapture. vid->wmc = new WindowsMediaCapture; if (!vid->wmc) { ARLOGe("Error creating instance of Windows.Media.Capture.\n"); goto bail; } if (flipV) vid->wmc->setFlipV(true); if (!startWMC(vid, width, height)) goto bail1; return vid; bail1: delete vid->wmc; vid->wmc = NULL; bail: free(vid); ar2VideoWinMCRefCount--; if (ar2VideoWinMCRefCount == 0) ar2VideoWinMCFinal2(); return NULL; }
AR2VideoParamAndroidT *ar2VideoOpenAndroid( const char *config ) { char *cacheDir = NULL; AR2VideoParamAndroidT *vid; const char *a; char line[1024]; int err_i = 0; int i; int width = 0, height = 0; arMallocClear( vid, AR2VideoParamAndroidT, 1 ); a = config; if( a != NULL) { for(;;) { while( *a == ' ' || *a == '\t' ) a++; if( *a == '\0' ) break; if (sscanf(a, "%s", line) == 0) break; if( strcmp( line, "-device=Android" ) == 0 ) { } else if( strncmp( line, "-width=", 7 ) == 0 ) { if( sscanf( &line[7], "%d", &width ) == 0 ) { ARLOGe("Error: Configuration option '-width=' must be followed by width in integer pixels.\n"); err_i = 1; } } else if( strncmp( line, "-height=", 8 ) == 0 ) { if( sscanf( &line[8], "%d", &height ) == 0 ) { ARLOGe("Error: Configuration option '-height=' must be followed by height in integer pixels.\n"); err_i = 1; } } else if( strncmp( line, "-format=", 8 ) == 0 ) { if (strcmp(line+8, "0") == 0) { vid->format = 0; ARLOGi("Requesting images in system default format.\n"); } else if (strcmp(line+8, "RGBA") == 0) { vid->format = AR_PIXEL_FORMAT_RGBA; ARLOGi("Requesting images in RGBA format.\n"); } else if (strcmp(line+8, "NV21") == 0) { vid->format = AR_PIXEL_FORMAT_NV21; ARLOGi("Requesting images in NV21 format.\n"); } else if (strcmp(line+8, "420f") == 0 || strcmp(line+8, "NV12") == 0) { vid->format = AR_PIXEL_FORMAT_420f; ARLOGi("Requesting images in 420f/NV12 format.\n"); } else { ARLOGe("Ignoring request for unsupported video format '%s'.\n", line+8); } } else if (strncmp(a, "-cachedir=", 10) == 0) { // Attempt to read in pathname, allowing for quoting of whitespace. a += 10; // Skip "-cachedir=" characters. if (*a == '"') { a++; // Read all characters up to next '"'. i = 0; while (i < (sizeof(line) - 1) && *a != '\0') { line[i] = *a; a++; if (line[i] == '"') break; i++; } line[i] = '\0'; } else { sscanf(a, "%s", line); } if (!strlen(line)) { ARLOGe("Error: Configuration option '-cachedir=' must be followed by path (optionally in double quotes).\n"); err_i = 1; } else { free(cacheDir); cacheDir = strdup(line); } } else { err_i = 1; } if (err_i) { ARLOGe("Error: Unrecognised configuration option '%s'.\n", a); ar2VideoDispOptionAndroid(); goto bail; } while( *a != ' ' && *a != '\t' && *a != '\0') a++; } } // Initial state. if (!vid->format) vid->format = AR_INPUT_ANDROID_PIXEL_FORMAT; if (!vid->focal_length) vid->focal_length = AR_VIDEO_ANDROID_FOCAL_LENGTH_DEFAULT; // In lieu of identifying the actual camera, we use manufacturer/model/board to identify a device, // and assume that identical devices have identical cameras. // Handset ID, via <sys/system_properties.h>. int len; len = __system_property_get(ANDROID_OS_BUILD_MANUFACTURER, vid->device_id); // len = (int)strlen(device_id). vid->device_id[len] = '/'; len++; len += __system_property_get(ANDROID_OS_BUILD_MODEL, vid->device_id + len); vid->device_id[len] = '/'; len++; len += __system_property_get(ANDROID_OS_BUILD_BOARD, vid->device_id + len); // Set width and height if specified. if (width && height) { vid->width = width; vid->height = height; } if (cparamSearchInit(cacheDir, false) < 0) { ARLOGe("Unable to initialise cparamSearch.\n"); goto bail; }; goto done; bail: free(vid); vid = NULL; done: free(cacheDir); return (vid); }