虚拟机调用摄像头设备一直 select timeout问题的解决

在VMware里面调用v4l2-ctl捕获图像,或者opencv的VideoCapture(0)捕获图像,或者直接调用v4l2的函数,在streamon后,调用select读取数据,均会一直提示select timeout的问题,大概率是由于USB版本的兼容性造成的,做如下设置基本能够解决。

另外,附上一个完整的例子:

/*
 *  V4L2 video capture example
 *
 *
 * This program is a plus version of program provided with the V4L2 API
 * 
 * dotphoenix@qq.com
 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <getopt.h>             /* getopt_long() */

#include <fcntl.h>              /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <unistd.h>
#include <time.h>
#include <linux/videodev2.h>

//gcc -g -Wall -o capture_v4l2 capture_v4l2.c

logger//Synsynchronization is not considered///

typedef struct {
        FILE * (*fopen)(char const * const filename, char const * const mode);
        int (*fprintf)(FILE *fp, char const * const fmt, ...);
        int (*vfprintf)(FILE *fp, char const * const fmt, va_list argp);
        int (*fclose)(FILE* fp);
} std_file_t;

void std_file_init(std_file_t * const std_file) {
        std_file->fopen = fopen;
        std_file->fprintf = fprintf;
        std_file->vfprintf = vfprintf;
        std_file->fclose = fclose;
}

typedef enum {
        OFF,
        DEBUG,
        INFO,
        WARNING,
        ERROR
} logger_level_t;

typedef struct {
        logger_level_t level;
        int write_to_file ;
        FILE *fp;
        std_file_t *std_file;
} logger_t;

    
static logger_t* logger;

static void logger_format_current_time(char* ts) {
        time_t rawtime;
        struct tm *info;
        time( &rawtime );
        info = localtime( &rawtime );
        strftime(ts, 80, "%Y-%m-%d %H:%M:%S", info);
}

static const char* logger_format_level(int level) {
        switch (level)
        {
        case DEBUG:
                return "[DEBUG]";
        case INFO:
                return "[INFO]";
        case WARNING:
                return "[WARNING]";
        case ERROR:
                return "[ERROR]";                                        
        default:
                return "[UNKNOWN]";
        }
}


void logger_log(logger_level_t const level, char const * const file, size_t const line, char const * const fmt, ...) {

        if (level < logger->level) {
                return;
        }

        char ts[64] = {0};
        logger_format_current_time(ts);
        logger->std_file->fprintf(logger->fp, "%s %s %s: %lu: ", logger_format_level(level), ts, file, line);
        va_list argp;
        va_start(argp, fmt);
        logger->std_file->vfprintf(logger->fp, fmt, argp);
        va_end(argp);    
        logger->std_file->fprintf(logger->fp, "\n");
}

#define log_debug(...) logger_log(DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define log_info(...)  logger_log(INFO, __FILE__, __LINE__, __VA_ARGS__)
#define log_warn(...)  logger_log(WARNING, __FILE__, __LINE__, __VA_ARGS__)
#define log_error(...) logger_log(ERROR, __FILE__, __LINE__, __VA_ARGS__)


static int logger_init(
    logger_level_t const level, 
    char const * const filename, 
    int const write_to_file
) {
        std_file_t* std_file = (std_file_t*)malloc(sizeof(std_file_t));
        logger = (logger_t*)malloc(sizeof(logger_t));
        std_file_init(std_file);
        logger->level = level;
        logger->write_to_file = write_to_file;
        logger->std_file = std_file;
        if (logger->write_to_file) {
                logger->fp = logger->std_file->fopen(filename, "a");
                if (logger->fp == NULL) {
                        fprintf(stderr, "append log file %s failed, error %d, %s\n", filename, errno, strerror(errno));
                        return -1;
                }
        } else {
                logger->fp = stderr;
        }
        char ts[128] = {0};
        logger_format_current_time(ts);
        strcat(ts, "   start new logger -------------------\n");
        log_warn(ts);
        return 0;
}

void logger_uninit() {
        if(logger == NULL) {
                return;
        }
        if(logger->write_to_file) {
                if(logger->fp != NULL) {
                        logger->std_file->fclose(logger->fp);
                        logger->fp = NULL;
                }
        }
        free(logger->std_file);
        free(logger);
}




//
#define CLEAR(x) memset(&(x), 0, sizeof(x))

enum io_method_t {
        IO_METHOD_READ,
        IO_METHOD_MMAP,
        IO_METHOD_USERPTR,
};

struct buffer_t {
        void   *start;
        size_t  length;
};

static char            *dev_name;
static enum io_method_t   io_method =  IO_METHOD_MMAP;
static int              fd = -1;
struct buffer_t          *buffers;
static unsigned int     n_buffers;
static int              save_to_file = 1; //save to file
static int              force_format_yuyv = 1; //force to use yuyv format
static int              force_format_mjpeg = 0;//force to use mjpeg 
static int              frame_count = 30 * 2; //total save frame count
static int req_width = 640;
static int req_height = 480;
static int req_rate_numerator   = 30;
static int req_rate_denominator = 1;


static int              frame_index = 0;



static void errno_exit(const char *s)
{
        fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno));
        log_error("%s error %d, %s\n", s, errno, strerror(errno));

        logger_uninit();
        exit(EXIT_FAILURE);
}

static void general_exit_v(char const * const fmt, ...)
{
        char msg[512] = {0};
        
        va_list argp;
        va_start(argp, fmt);
        vsprintf(msg, fmt, argp);
        va_end(argp); 

        strcat(msg, "\n");

        fprintf(stderr, "%s", msg);
        log_error(msg);

        logger_uninit();
        exit(EXIT_FAILURE);      
}

static int xioctl(int fh, int request, void *arg)
{
        int r;

        do {
                r = ioctl(fh, request, arg);
        } while (-1 == r && EINTR == errno);

        return r;
}


static void generate_save_to_fullpath(char* fullpath, const char*postfix, int file_index)
{
        char cwd[256] = {0};
        getcwd(cwd, 255);
        sprintf(fullpath, "%s/pictures/%06d.%s", cwd, file_index, postfix);
}

static void process_image(const void *p, int size)
{
        frame_index++;

        //mark one frame on the console
        fprintf(stderr, ".");
        fflush(stderr);

        if(save_to_file == 1) {
                char fullpath[128] = {0};
                if(force_format_mjpeg == 1) {
                        generate_save_to_fullpath(fullpath, "jpg", frame_index);
                }
                else {
                        generate_save_to_fullpath(fullpath, "yuyv", frame_index);
                }
                
                FILE *fp = fopen(fullpath, "wb");
                if(fp == NULL) {
                        fprintf(stderr, "create file failed, file %s, error %d, %s\n", fullpath, errno, strerror(errno));
                        log_error("create file failed, file %s, error %d, %s\n", fullpath, errno, strerror(errno));
                        return;   
                } else {
                        fwrite(p, size, 1, fp);
                        fflush(fp);
                        fclose(fp);
                        log_debug("one frame coming and save to file, size=%d, path=%s \n", size, fullpath);
                }
        }
        else {
                log_debug("one frame coming and not save to file, size=%d \n", size);
        }

}

static int read_frame(void)
{
        struct v4l2_buffer buf;
        unsigned int i;

        switch (io_method) {
        case IO_METHOD_READ:
                if (-1 == read(fd, buffers[0].start, buffers[0].length)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;

                        case EIO:
                                /* Could ignore EIO, see spec. */

                                /* fall through */

                        default:
                                errno_exit("read");
                        }
                }

                process_image(buffers[0].start, buffers[0].length);
                break;

        case IO_METHOD_MMAP:
                CLEAR(buf);

                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_MMAP;

                if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;

                        case EIO:
                                /* Could ignore EIO, see spec. */

                                /* fall through */

                        default:
                                errno_exit("VIDIOC_DQBUF");
                        }
                }

                assert(buf.index < n_buffers);

                process_image(buffers[buf.index].start, buf.bytesused);

                if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                        errno_exit("VIDIOC_QBUF");
                break;

        case IO_METHOD_USERPTR:
                CLEAR(buf);

                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_USERPTR;

                if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;

                        case EIO:
                                /* Could ignore EIO, see spec. */

                                /* fall through */

                        default:
                                errno_exit("VIDIOC_DQBUF");
                        }
                }

                for (i = 0; i < n_buffers; ++i)
                        if (buf.m.userptr == (unsigned long)buffers[i].start
                            && buf.length == buffers[i].length)
                                break;

                assert(i < n_buffers);

                process_image((void *)buf.m.userptr, buf.bytesused);

                if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                        errno_exit("VIDIOC_QBUF");
                break;
        }

        return 1;
}

static void mainloop(void)
{
        unsigned int count;

        count = frame_count;

        while (count-- > 0) {
                for (;;) {
                        fd_set fds;
                        struct timeval tv;
                        int r;

                        FD_ZERO(&fds);
                        FD_SET(fd, &fds);

                        /* Timeout. */
                        tv.tv_sec = 30;
                        tv.tv_usec = 0;

                        r = select(fd + 1, &fds, NULL, NULL, &tv);

                        if (-1 == r) {
                                if (EINTR == errno)
                                        continue;
                                errno_exit("select");
                        }

                        if (0 == r) {
                                general_exit_v("select timeout");
                        }

                        if (read_frame())
                                break;
                        /* EAGAIN - continue select loop. */
                }
        }
}

static void stop_capturing(void)
{
        enum v4l2_buf_type type;

        switch (io_method) {
        case IO_METHOD_READ:
                /* Nothing to do. */
                break;

        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &type))
                        errno_exit("VIDIOC_STREAMOFF");
                break;
        }
}

static void start_capturing(void)
{
        unsigned int i;
        enum v4l2_buf_type type;

        switch (io_method) {
        case IO_METHOD_READ:
                /* Nothing to do. */
                break;

        case IO_METHOD_MMAP:
                for (i = 0; i < n_buffers; ++i) {
                        struct v4l2_buffer buf;

                        CLEAR(buf);
                        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                        buf.memory = V4L2_MEMORY_MMAP;
                        buf.index = i;

                        if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                                errno_exit("VIDIOC_QBUF");
                }
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
                        errno_exit("VIDIOC_STREAMON");
                
                log_info("%s stream on", dev_name);

                break;

        case IO_METHOD_USERPTR:
                for (i = 0; i < n_buffers; ++i) {
                        struct v4l2_buffer buf;

                        CLEAR(buf);
                        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                        buf.memory = V4L2_MEMORY_USERPTR;
                        buf.index = i;
                        buf.m.userptr = (unsigned long)buffers[i].start;
                        buf.length = buffers[i].length;

                        if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                                errno_exit("VIDIOC_QBUF");
                }
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
                        errno_exit("VIDIOC_STREAMON");

                log_info("%s stream on", dev_name);
                break;
        }
}

static void uninit_device(void)
{
        unsigned int i;

        switch (io_method) {
        case IO_METHOD_READ:
                free(buffers[0].start);
                break;

        case IO_METHOD_MMAP:
                for (i = 0; i < n_buffers; ++i)
                        if (-1 == munmap(buffers[i].start, buffers[i].length))
                                errno_exit("munmap");
                break;

        case IO_METHOD_USERPTR:
                for (i = 0; i < n_buffers; ++i)
                        free(buffers[i].start);
                break;
        }

        free(buffers);
}

static void init_read(unsigned int buffer_size)
{
        buffers = calloc(1, sizeof(*buffers));

        if (!buffers) {
                general_exit_v("Out of memory");
        }

        buffers[0].length = buffer_size;
        buffers[0].start = malloc(buffer_size);

        if (!buffers[0].start) {
                general_exit_v("Out of memory");
        }

        log_info("initialize read&write method of %s successfully");
}

static void init_mmap(void)
{
        struct v4l2_requestbuffers req;

        CLEAR(req);

        req.count = 8;
        req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        req.memory = V4L2_MEMORY_MMAP;

        if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
                if (EINVAL == errno) {
                        general_exit_v("%s does not support "
                                 "memory mappingn", dev_name);
                } else {
                        errno_exit("VIDIOC_REQBUFS");
                }
        }

        if (req.count < 2) {
                general_exit_v("Insufficient buffer_t memory on %s", dev_name);
        }

        buffers = calloc(req.count, sizeof(*buffers));

        if (!buffers) {
                general_exit_v("Out of memory");
        }

        for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
                struct v4l2_buffer buf;

                CLEAR(buf);

                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory      = V4L2_MEMORY_MMAP;
                buf.index       = n_buffers;

                if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf))
                        errno_exit("VIDIOC_QUERYBUF");

                buffers[n_buffers].length = buf.length;
                buffers[n_buffers].start =
                        mmap(NULL /* start anywhere */,
                              buf.length,
                              PROT_READ | PROT_WRITE /* required */,
                              MAP_SHARED /* recommended */,
                              fd, buf.m.offset);

                if (MAP_FAILED == buffers[n_buffers].start)
                        errno_exit("mmap");
        }

        log_info("initialize mmap method of %s successfully", dev_name);

}

static void init_userp(unsigned int buffer_size)
{
        struct v4l2_requestbuffers req;

        CLEAR(req);

        req.count  = 4;
        req.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        req.memory = V4L2_MEMORY_USERPTR;

        if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
                if (EINVAL == errno) {
                        general_exit_v("%s does not support user pointer i/o", dev_name);
                } else {
                        errno_exit("VIDIOC_REQBUFS");
                }
        }

        buffers = calloc(4, sizeof(*buffers));

        if (!buffers) {
                general_exit_v("Out of memory");
        }

        for (n_buffers = 0; n_buffers < 4; ++n_buffers) {
                buffers[n_buffers].length = buffer_size;
                buffers[n_buffers].start = malloc(buffer_size);

                if (!buffers[n_buffers].start) {
                         general_exit_v("Out of memory");
                }
        }

        log_info("initialize userp method of %s successfully", dev_name);

}

static int check_fmt(int fd, __u32 fmt) 
{
        struct v4l2_format v4l2_fmt;
        CLEAR(v4l2_fmt);
        v4l2_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (ioctl (fd, VIDIOC_G_FMT, &v4l2_fmt) == -1) {
                log_error("ERROR camera VIDIOC_G_FMT Failed.");
                return -1;
        }
        if (v4l2_fmt.fmt.pix.pixelformat == fmt) {
                return 1;
        }
        else {
                log_error("ERROR camera VIDIOC_S_FMT Failed, %u vs %u.", v4l2_fmt.fmt.pix.pixelformat, fmt);
                return -1;
        }
}


static void init_device(void)
{
        struct v4l2_capability cap;
        struct v4l2_cropcap cropcap;
        struct v4l2_crop crop;
        struct v4l2_format fmt;
        struct v4l2_streamparm streamparm;

        unsigned int min;

        if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
                if (EINVAL == errno) {
                        general_exit_v("%s is no V4L2 device", dev_name);
                } else {
                        errno_exit("VIDIOC_QUERYCAP");
                }
        }

        if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
                general_exit_v("%s is no video capture device",
                         dev_name);
        }


        switch (io_method) {
        case IO_METHOD_READ:
                if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
                        general_exit_v("%s does not support read i/o",
                                 dev_name);
                }
                log_info("%s supports read and write", dev_name);
                break;

        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
                        general_exit_v("%s does not support streaming i/o",
                                 dev_name);
                }
                log_info("%s supports streaming", dev_name);
                break;
        }


        /* Select video input, video standard and tune here. */


        CLEAR(cropcap);

        cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

        if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {
                crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                crop.c = cropcap.defrect; /* reset to default */

                if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) {
                        switch (errno) {
                        case EINVAL:
                                /* Cropping not supported. */
                                break;
                        default:
                                /* Errors ignored. */
                                break;
                        }
                }
        } else {
                /* Errors ignored. */
        }


        CLEAR(streamparm);

        streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

        if (-1 == xioctl(fd, VIDIOC_G_PARM, &streamparm))
        errno_exit("VIDIOC_G_PARM");

        if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) {
                struct v4l2_fract *tpf = &(streamparm.parm.capture.timeperframe);

                // Swap numerator and denominator: rate is an inverted frame time :-)
                tpf->numerator = req_rate_denominator;
                tpf->denominator = req_rate_numerator;

                if (-1 == xioctl(fd, VIDIOC_S_PARM, &streamparm))
                        errno_exit("VIDIOC_S_PARM");

                if (tpf->numerator != req_rate_denominator ||
                        tpf->denominator != req_rate_numerator) {
                        log_error( "the driver changed the time per frame from "
                                "%d/%d to %d/%d failed",
                                req_rate_denominator, req_rate_numerator,
                                tpf->numerator, tpf->denominator);
                }
                else {
                        log_info( "the driver changed the time per frame from "
                                "%d/%d to %d/%d successfully",
                                req_rate_denominator, req_rate_numerator,
                                tpf->numerator, tpf->denominator);
                }
        } 
        else {
                log_error("the driver does not allow to change time per frame");
        }

        CLEAR(fmt);

        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (force_format_yuyv) {
                fmt.fmt.pix.width       = req_width;
                fmt.fmt.pix.height      = req_height;
                fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
                fmt.fmt.pix.field       = V4L2_FIELD_ANY;

                if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
                        errno_exit("VIDIOC_S_FMT");
                
                assert(check_fmt(fd, V4L2_PIX_FMT_YUYV) == 1);

                log_info("set format of %s to %u successfully", dev_name, fmt.fmt.pix.pixelformat);
                /* Note VIDIOC_S_FMT may change width and height. */
        } else if (force_format_mjpeg) {
                fmt.fmt.pix.width       = req_width;
                fmt.fmt.pix.height      = req_height;
                fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
                fmt.fmt.pix.field       = V4L2_FIELD_ANY;

                if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
                        errno_exit("VIDIOC_S_FMT");

                assert(check_fmt(fd, V4L2_PIX_FMT_MJPEG) == 1);

                log_info("set format of %s to %u successfully", dev_name, fmt.fmt.pix.pixelformat);
                /* Note VIDIOC_S_FMT may change width and height. */
        } else {
                /* Preserve original settings as set by v4l2-ctl for example */
                if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))
                        errno_exit("VIDIOC_G_FMT");
                
                log_info("format of %s is %u ", dev_name, fmt.fmt.pix.pixelformat);
        }

        /* Buggy driver paranoia. */
        min = fmt.fmt.pix.width * 2;
        if (fmt.fmt.pix.bytesperline < min)
                fmt.fmt.pix.bytesperline = min;
        min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
        if (fmt.fmt.pix.sizeimage < min)
                fmt.fmt.pix.sizeimage = min;

        switch (io_method) {
        case IO_METHOD_READ:
                init_read(fmt.fmt.pix.sizeimage);
                break;

        case IO_METHOD_MMAP:
                init_mmap();
                break;

        case IO_METHOD_USERPTR:
                init_userp(fmt.fmt.pix.sizeimage);
                break;
        }
}

static void close_device(void)
{
        if (-1 == close(fd))
                errno_exit("close");

        fd = -1;
}

static void open_device(void)
{
        struct stat st;

        if (-1 == stat(dev_name, &st)) {
                general_exit_v("Cannot identify device '%s': %d, %s",
                         dev_name, errno, strerror(errno));
        }

        if (!S_ISCHR(st.st_mode)) {
                general_exit_v("%s is no device", dev_name);
        }

        fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);

        if (-1 == fd) {
                general_exit_v("Cannot open '%s': %d, %s",
                         dev_name, errno, strerror(errno));
        }
        else {
                log_info("Open device %s successfully.", dev_name);
        }
}

static void usage(FILE *fp, int argc, char **argv)
{
        fprintf(fp,
                 "Usage: %s [options]\\n\\n"
                 "Version 1.3\\n"
                 "Options:\\n"
                 "-d | --device name   Video device name [%s]n"
                 "-h | --help          Print this messagen"
                 "-m | --mmap          Use memory mapped buffers [default]n"
                 "-r | --read          Use read() callsn"
                 "-u | --userp         Use application allocated buffersn"
                 "-s | --save          Save stream to file"
                 "-f | --format        Force format to 640x480 YUYVn"
                 "-c | --count         Number of frames to grab [%i]n"
                 "",
                 argv[0], dev_name, frame_count);
}

static const char short_options[] = "d:hmruofc:";

static const struct option
long_options[] = {
        { "device", required_argument, NULL, 'd' },
        { "help",   no_argument,       NULL, 'h' },
        { "mmap",   no_argument,       NULL, 'm' },
        { "read",   no_argument,       NULL, 'r' },
        { "userp",  no_argument,       NULL, 'u' },
        { "save", no_argument,         NULL, 's' },
        { "format", no_argument,       NULL, 'f' },
        { "count",  required_argument, NULL, 'c' },
        { 0, 0, 0, 0 }
};

int main(int argc, char **argv)
{
        dev_name = "/dev/video0";
        char log_filename[256] = {0};
        char cwd[256] = {0};
        getcwd(cwd, 255);
        sprintf(log_filename, "%s/v4l2_log.txt", cwd);
        logger_init(DEBUG, log_filename, 1);
        for (;;) {
                int idx;
                int c;

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

                if (-1 == c)
                        break;

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

                case 'd':
                        dev_name = optarg;
                        break;

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

                case 'm':
                        io_method = IO_METHOD_MMAP;
                        break;

                case 'r':
                        io_method = IO_METHOD_READ;
                        break;

                case 'u':
                        io_method = IO_METHOD_USERPTR;
                        break;

                case 's':
                        save_to_file = 1;
                        break;

                case 'j':
                        force_format_mjpeg = 1;
                        break;
                case 'n':
                        force_format_yuyv = 1;
                        break;
                case 'y':
                        errno = 0;
                        frame_count = strtol(optarg, NULL, 0);
                        if (errno)
                                errno_exit(optarg);
                        break;

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

        open_device();
        init_device();
        start_capturing();
        mainloop();
        stop_capturing();
        uninit_device();
        close_device();
        logger_uninit(&logger);
        return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/696653.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Oracle】Oracle导入导出dmp文件

文章目录 前言一、什么是dmp&#xff1f;二、imp/impdp、exp/expdp对比及示例1.区别2.imp/impdp对比及示例a. impb. impbp 3.exp/expdp对比及示例a. expb.expdp 3.其他事项 三、执行导入导出前置条件1.创建角色并授权2.创建目录映射 前言 在工作中&#xff0c;经常会遇到需要备…

【Linux】网络配置(静态/动态/手动/nmcli)

目录 一、手动修改网络配置文件&#xff1a;静态 二、手动修改网络配置文件&#xff1a;动态 三、nmcli工具命令修改网络配置文件&#xff1a;静态 四、nmcli工具命令修改网络配置文件&#xff1a;动态 错误排查分析&#xff1a;编辑虚拟网络编辑器不生效 1、排除VMware启…

Excel 将同一分类下的值依次填进分类格右边的格中

表格的第2列是分类&#xff0c;第3列是明细&#xff1a; ABC1S.noAccountProduct21AAAQatAAG32BAAQbIAAW43BAAQkJAAW54CAAQaAAP65DAAQaAAX76DAAQbAAX87DAAQcAAX 需要将同一分类下的值依次填入分类格右边的格中&#xff1a; ABCD1S.noAccountProduct21AAAQatAAG32BAAQbIAAWkJ…

[数据集][目标检测]厨房积水检测数据集VOC+YOLO格式88张2类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;88 标注数量(xml文件个数)&#xff1a;88 标注数量(txt文件个数)&#xff1a;88 标注类别数…

笔记-Python pip配置国内源

众所周知&#xff0c;Python使用pip方法安装第三方包时&#xff0c;需要从 https://pypi.org/ 资源库中下载&#xff0c;但是会面临下载速度慢&#xff0c;甚至无法下载的尴尬&#xff0c;这时&#xff0c;你就需要知道配置一个国内源有多么重要了&#xff0c;通过一番摸索和尝…

[office] 快速提取出Excel 2010单元格括号内的文字信息 #知识分享#经验分享

快速提取出Excel 2010单元格括号内的文字信息 实例演示 ①我们打开一份Excel电子表格&#xff0c;我们要将C列里面括号内的内容提取到D列里面&#xff0c;单击D2单元格&#xff0c;输入下面的函数公式&#xff1a; MID(C2,FIND("(",C2)1,LEN(C2)-FIND("("…

文案策划背后的秘密 | 职场高手养成记

要想在文案策划这个行当里混&#xff0c;首先得对自己的文字功底有足够的信心&#xff0c;那种“文章独步天下”的气势不可或缺。 要是没有这份自信&#xff0c;我建议你还是另寻他路。 要想跨入文案策划的大门&#xff0c;可以从以下几个方面入手&#xff1a; 1. 学习文案基…

4000亿薪酬被驳回!马斯克再次讨薪

特斯拉CEO埃隆马斯克的一笔巨额财产&#xff0c;将在数日后的特斯拉股东大会上&#xff0c;由股东投票决定何去何从。 事情是这样的。 3.5研究测试&#xff1a;hujiaoai.cn 4研究测试&#xff1a;askmanyai.cn Claude-3研究测试&#xff1a;hiclaude3.com 2018年&#xff0c;特…

QT 信号和槽 通过自定义信号和槽沟通 如何自定义槽和信号的业务,让它们自动关联 自定义信号功能

通过信号和槽机制通信&#xff0c;通信的源头和接收端之间是松耦合的&#xff1a; 源头只需要顾自己发信号就行&#xff0c;不用管谁会接收信号&#xff1b;接收端只需要关联自己感兴趣的信号&#xff0c;其他的信号都不管&#xff1b;只要源头发了信号&#xff0c;关联该信号…

常见机器学习的原理及优略势

有监督 一、线性回归&#xff08;Linear Regression) 1. 算法原理 线性回归&#xff08;Linear Regression&#xff09;是一种基本的回归算法&#xff0c;它通过拟合一个线性模型来预测连续型目标变量。线性回归模型的基本形式是&#xff1a;y w1 * x1 w2 * x2 … wn * …

操作系统真象还原:内存管理系统

第8章-内存管理系统 这是一个网站有所有小节的代码实现&#xff0c;同时也包含了Bochs等文件 8.1 Makefile简介 8.1.1 Makefile是什么 8.1.2 makefile基本语法 make 给咱们提供了方法&#xff0c;可以在命令之前加个字符’&#xff20;’&#xff0c;这样就不会输出命令本身…

作业07 递推算法2

作业&#xff1a; #include <iostream> using namespace std; int main(){int a[110][110]{0},b[110][110]{0},n;cin>>n;for(int i1;i<n;i){for(int j1;j<i;j){cin>>a[i][j];}}for(int in-1;i>1;i--){for(int j1;j<i;j){a[i][j]a[i][j]max(a[i1]…

【SQLAlChemy】Query函数可传入的参数有哪些?

Query 函数的使用 参数种类 一般可以传递的参数有如下三种&#xff1a; 模型名。指定查找这个模型的全部属性&#xff08;对应于数据库查询中的全表查询&#xff09;。模型中的属性。可以用来指定只查询某个模型的几个属性值。使用聚合函数。 func.count():统计行的数量。fu…

理财-商业保险

目录&#xff1a; 一、保险查询 1、金事通APP 2、商业保险APP 二、平安寿险 1、智能星 2、智富人生A 3、总结 三、保险中的掩藏项 一、保险查询 1、金事通APP 中国银行保险信息技术管理有限公司发挥金融基础设施作用&#xff0c;以“切实让数据多跑路、百姓少跑腿”为…

安装MySQL Sample Database

本文安装的示例数据库为官方的Employees Sample Database。 操作过程参考其安装部分。 在安装前&#xff0c;MySQL已安装完成&#xff0c;环境为Linux。 克隆github项目&#xff1a; $ git clone https://github.com/datacharmer/test_db.git Cloning into test_db... remo…

OpenAI与核聚变公司寻求合作,白宫拨款1.8亿美元用于核聚变商业化研究

在当下&#xff0c;由 AI 引发的新一轮能源危机已经不再是一个小概率的「黑天鹅」事件&#xff0c;而是一头正在向我们猛冲而来的「灰犀牛」。 Helion Energy&#xff0c;是一家总部位于美国华盛顿州埃弗雷特的能源创业公司。 3.5研究测试&#xff1a;hujiaoai.cn 4研究测试&am…

kaggle竞赛实战9——模型融合

有三种方法&#xff0c; 第一种&#xff1a;均值融合&#xff0c;代码如下 data pd.read_csv(\ result/submission_randomforest.csv\ ) data[randomforest] data[target].values temp pd.read_csv(\ result/submission_lightgbm.csv\ ) …

Elasticsearch index 设置 false,为什么还可以被检索到?

在 Elasticsearch 中&#xff0c;mapping 定义了索引中的字段类型及其处理方式。 近期有球友提问&#xff0c;为什么设置了 index: false 的字段仍能被检索。 本文将详细探讨这个问题&#xff0c;并引入列式存储的概念&#xff0c;帮助大家更好地理解 Elasticsearch 的存储和查…

Python 基础语法详解(三)

Python 基础语法详解&#xff08;三&#xff09; Python 运算符Python 算术运算符①理论讲解&#xff1a;②实操讲解&#xff1a; Python 比较运算符①理论讲解&#xff1a;②实操讲解&#xff1a; Python 赋值运算符Python 位运算符①理论讲解&#xff1a;②实操讲解&#xff…

Android——热点开关(优化中)

SoftAP打开与关闭 目录 1.三个名词的解释以及关系 Tethering——网络共享&#xff0c;WiFi热点、蓝牙、USB SoftAp——热点(无线接入点)&#xff0c;临时接入点 Hostapd——Hostapd是用于Linux系统的软件&#xff0c;&#xff0c;支持多种无线认证和加密协议&#xff0c;将任…