Exemplo n.º 1
0
int main(int argc, char **argv)
{

    for (;;) {
        int index, c = 0;

        c = getopt_long(argc, argv, short_options, long_options, &index);

        if (-1 == c)
            break;

        switch (c) {
        case 0: /* getopt_long() flag */
            break;

        case 'd':
            deviceName = optarg;
            break;

        case 'h':
            // print help
            usage(stdout, argc, argv);
            exit(EXIT_SUCCESS);

        case 'o':
            // set jpeg filename
            jpegFilename = optarg;
            break;

        case 'q':
            // set jpeg quality
            jpegQuality = atoi(optarg);
            break;

        case 'm':
#ifdef IO_MMAP
            io = IO_METHOD_MMAP;
#else
            fprintf(stderr, "You didn't compile for mmap support.\n");
            exit(EXIT_FAILURE);
#endif
            break;

        case 'r':
#ifdef IO_READ
            io = IO_METHOD_READ;
#else
            fprintf(stderr, "You didn't compile for read support.\n");
            exit(EXIT_FAILURE);
#endif
            break;

        case 'u':
#ifdef IO_USERPTR
            io = IO_METHOD_USERPTR;
#else
            fprintf(stderr, "You didn't compile for userptr support.\n");
            exit(EXIT_FAILURE);
#endif
            break;

        case 'W':
            // set width
            width = atoi(optarg);
            break;

        case 'H':
            // set height
            height = atoi(optarg);
            break;

        case 'I':
            // set fps
            fps = atoi(optarg);
            break;

        case 'c':
            // set flag for continuous capture, interuptible by sigint
            continuous = 1;
            InstallSIGINTHandler();
            break;


        case 'v':
            printf("Version: %s\n", VERSION);
            exit(EXIT_SUCCESS);
            break;

        default:
            usage(stderr, argc, argv);
            exit(EXIT_FAILURE);
        }
    }

    // check for need parameters
    if (!jpegFilename) {
        fprintf(stderr, "You have to specify JPEG output filename!\n\n");
        usage(stdout, argc, argv);
        exit(EXIT_FAILURE);
    }

    if(continuous == 1) {
        int max_name_len = snprintf(NULL,0,continuousFilenameFmt,jpegFilename,UINT32_MAX,INT64_MAX);
        jpegFilenamePart = jpegFilename;
        jpegFilename = calloc(max_name_len+1,sizeof(char));
        strcpy(jpegFilename,jpegFilenamePart);
    }


    // open and initialize device
    deviceOpen();
    deviceInit();

    // start capturing
    captureStart();

    // process frames
    mainLoop();

    // stop capturing
    captureStop();

    // close device
    deviceUninit();
    deviceClose();

    if(jpegFilenamePart != 0) {
        free(jpegFilename);
    }

    exit(EXIT_SUCCESS);

    return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{

	for (;;) {
		int index, c = 0;

		c = getopt_long(argc, argv, short_options, long_options, &index);

		if (-1 == c)
			break;

		switch (c) {
			case 0: /* getopt_long() flag */
				break;

			case 'd':
				deviceName = optarg;
				break;

			case 'h':
				// print help
				usage(stdout, argc, argv);
				exit(EXIT_SUCCESS);

			case 'o':
				// set jpeg filename
				jpegFilename = optarg;
				break;

			case 'q':
				// set jpeg quality
				jpegQuality = atoi(optarg);
				break;

			case 'm':
#ifdef IO_MMAP
				io = IO_METHOD_MMAP;
#else
				fprintf(stderr, "You didn't compile for mmap support.\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case 'r':
#ifdef IO_READ
				io = IO_METHOD_READ;
#else
				fprintf(stderr, "You didn't compile for read support.\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case 'u':
#ifdef IO_USERPTR
				io = IO_METHOD_USERPTR;
#else
				fprintf(stderr, "You didn't compile for userptr support.\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case 'W':
				// set width
				width = atoi(optarg);
				break;

			case 'H':
				// set height
				height = atoi(optarg);
				break;
				
			case 'I':
				// set fps
				fps = atoi(optarg);
				break;

			case 'v':
				printf("Version: %s\n", VERSION);
				exit(EXIT_SUCCESS);
				break;

			default:
				usage(stderr, argc, argv);
				exit(EXIT_FAILURE);
		}
	}

	// check for need parameters
	if (!jpegFilename) {
		fprintf(stderr, "You have to specify JPEG output filename!\n\n");
		usage(stdout, argc, argv);
		exit(EXIT_FAILURE);
	}

	// open and initialize device
	deviceOpen();
	deviceInit();

	// start capturing
	captureStart();

	// process frames
	mainLoop();

	// stop capturing
	captureStop();

	// close device
	deviceUninit();
	deviceClose();

	exit(EXIT_SUCCESS);

	return 0;
}