linux v4l2 api

抽空做了个集成v4l2api, 实力有限, 有粗糙的地方还望不吝赐教 ^_^

v4l2_lib.h

/* This driver provid v4l2 API
 *
 * (You can use this driver as abouve steps)
 *
 *
 *
 * STEP ONE: define value
 *
 *
 * step 1.1: define the pointer of your device's name
 *           demo : static char *my_device = "/dev/video4";
 *
 * step 1.2: define file descriptor of your device
 *           demo : static int my_file_descriptor = -1;
 *
 * step 1.3: define ther buffer pointer of your buffers
 *           demo : struct buffer *my_buffers;
 *
 *
 *
 * STEP TWO: call api function
 *
 * step 2.1: open the device by fun : open_device(my_device, &my_file_descriptor);
 *
 * step 2.2: init the device by fun : init_device(my_device, my_file_descriptor, my_buffers);
 *
 * step 2.3: start the device to capturing by fun : start_capturing(my_file_descriptor, my_buffers);
 *
 * step 2.4: call your process fun that hase be defined
 *           you can grab a frame in your fun by call the fun : read_frame(my_file_descriptor, my_buffers)
 *			 and rewrite the fun process_image() in driver.c to implement your attention
 *
 * step 2.5: stop the device's capture by fun : stop_capturing(my_file_descriptor);
 *
 * step 2.6: uninit the device by fun : uninit_device(my_buffers);
 *
 * step 2.7: close the device bu fun : close_device(my_file_descriptor);
 *
 *
 *
 * FOR MORE CONFIGURATION CAN BE CONFIG BY UPDATE THE BELOW DEFINES
 *
 * METALSEED_TAG whether print log
 *
 * FRAME_QUEUE_LENGTH (the value of frame queue's length)
 *
 * V4L2_IO_METHOD (frame date exchange method)
 *
 * V4L2_FORCE_FORMAT (about format set : as bellow parameter)
 *
 * V4L2_FORCE_FORMAT_WIDTH
 *
 * V4L2_FORCE_FORMAT_HIGHT
 *
 * V4L2_FORCE_FORMAT_PIXEL_FORMAT
 *
 * V4L2_FORCE_FORMAT_FIELD
 *
 */

/* -----------demo-----------
int main(int argc, char **argv)
{
    static char *dev_eye1 = "/dev/video4";

    static int fd         = -1;

    struct buffer *buffers;

    open_device(dev_eye1, &fd);

    init_device(dev_eye1, fd, &buffers);

    start_capturing(fd, buffers);

    while(1){
        if (read_frame(fd, buffers) == 1) break;
    }

    stop_capturing(fd);

    uninit_device(buffers);

    close_device(fd);

    return 0;
}
*/

#ifndef __V4L2_DEVICE_DRIVER_H__
#define __V4L2_DEVICE_DRIVER_H__

enum io_method {
        IO_METHOD_READ,
        IO_METHOD_MMAP,
        IO_METHOD_USERPTR,
};

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

#define METALSEED_TAG 		1  // 1 print log, 0 don't print
#define V4L2_IO_METHOD 		IO_METHOD_MMAP
#define FRAME_QUEUE_LENGTH 	4 //frame queue length

#define V4L2_FORCE_FORMAT 	1
#define V4L2_FORCE_FORMAT_WIDTH 1280
#define V4L2_FORCE_FORMAT_HIGHT 960
#define V4L2_FORCE_FORMAT_PIXEL_FORMAT V4L2_PIX_FMT_YUYV
#define V4L2_FORCE_FORMAT_FIELD V4L2_FIELD_INTERLACED

//You can save the frame to file_output by fwrite(frame_pointer, size, 1, file_output);
static void process_image(const void *frame_pointer, int frame_size);

static int read_frame(int file_descriptor, struct buffer *buffers);

static void stop_capturing(int file_descriptor);

static void start_capturing(int file_descriptor, struct buffer *buffers);

static void init_read(struct buffer **buffers, unsigned int buffer_size);

static void init_mmap(char *dev_name, int file_descriptor, struct buffer **buffers);

static void init_userp(struct buffer **buffers, unsigned int buffer_size, char *dev_name, int file_descriptor);

static void init_device(char *dev_name, int file_descriptor, struct buffer **buffers);

static void uninit_device(struct buffer *buffers);

static void open_device(char *dev_name, int *file_descriptor);

static void close_device(int file_descriptor);

#endif //__V4L2_DEVICE_DRIVER_H__

v4l2_lib.c

/*
 *  V4L2 video capture driver
 *
 *  This program can be used and distributed without restrictions.
 *
 *  This program is provided with the V4L2 API
 *
 *  This program is optimized by MetalSeed([email protected])
 */

#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 <asm/types.h>

#include <linux/videodev2.h>

#include "v4l2_lib.h"
// #include <malloc.h>
// #include <pthread.h>
#define CLEAR(x) memset(&(x), 0, sizeof(x))

static unsigned int     n_buffers;

/*=== set io method ===*/
#ifdef V4L2_IO_METHOD
    static enum io_method io = V4L2_IO_METHOD;
#endif

#ifndef V4L2_IO_METHOD
    static enum io_method io = IO_METHOD_MMAP;
#endif

/*=== set force format switcher ===*/
#ifdef V4L2_FORCE_FORMAT
    static int force_format = V4L2_FORCE_FORMAT;
#endif

#ifndef V4L2_FORCE_FORMAT
    static int force_format = 0;
#endif

/*
 *
 *
 */
static void errno_exit(const char *s)
{
        fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno));
        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;
}

/*
 * one operation
 * step1 : VIDIOC_STREAMOFF
 */
static void stop_capturing(int fd)
{
        enum v4l2_buf_type type;

        switch (io) {
        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;
        }
#if(METALSEED_TAG == 1)
        {
            printf("[ V4L2 CLUE ] : Stop capturing successfully\n");
        }
#endif
}

/* tow operations
 * step1 : VIDIOC_QBUF(insert buffer to queue)
 * step2 : VIDIOC_STREAMOFF
 */
static void start_capturing(int fd, struct buffer *buffers)
{
        unsigned int i;
        enum v4l2_buf_type type;

        switch (io) {
        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");
                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");
                break;
        }
#if(METALSEED_TAG == 1)
        {
            printf("[ V4L2 CLUE ] : Start capturing successfully\n");
        }
#endif
}

/* two operations
 * step1 : munmap buffers
 * steo2 : free buffers
 */
static void uninit_device(struct buffer *buffers)
{
    unsigned int i;
    switch (io) {
    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);

#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Uninit device successfully\n");
    }
#endif
}

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

        if (!(*buffers)) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }

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

        if (!(*buffers)[0].start) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }
#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Initialize read successfully\n");
    }
#endif
}

static void init_mmap(char *dev_name, int fd, struct buffer **buffers)
{
        struct v4l2_requestbuffers req;

        CLEAR(req);

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

        if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s does not support "
                                 "memory mapping\n", dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_REQBUFS");
                }
        }

        if (req.count < 2) {
                fprintf(stderr, "Insufficient buffer memory on %s\n",
                         dev_name);
                exit(EXIT_FAILURE);
        }

        *buffers = calloc(req.count, sizeof(**buffers));
        if (!(*buffers)) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }

        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");
        }
#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Initialize memory mapping successfully\n");
    }
#endif
}

static void init_userp(struct buffer **buffers, unsigned int buffer_size, char *dev_name, int fd)
{
        struct v4l2_requestbuffers req;

        CLEAR(req);

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

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

        *buffers = calloc(FRAME_QUEUE_LENGTH, sizeof(struct buffer));

        if (!(*buffers)) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }

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

                if (!(*buffers)[n_buffers].start) {
                        fprintf(stderr, "Out of memory\n");
                        exit(EXIT_FAILURE);
                }
        }

#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Initialize user pointer successfully\n");
    }
#endif
}

/* six operations
 * step1 : cap :query camera's capability and check it(is a video device? is it support read? is it support streaming?)
 * step2 : cropcap:set cropcap's type and get cropcap by VIDIOC_CROPCAP
 * step3 : set crop parameter by VIDIOC_S_CROP (such as frame type and angle)
 * step4 : set image format
 * step5 : set stream parameter
 * step6 : mmap
 */
static void init_device(char *dev_name, int fd, struct buffer **buffers)
{
        struct v4l2_capability cap;
        struct v4l2_cropcap cropcap;
        struct v4l2_crop crop;
        struct v4l2_format fmt;
        struct v4l2_streamparm parm;
        unsigned int min;

        if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s is no V4L2 device\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_QUERYCAP");
                }
        }
        if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
                fprintf(stderr, "%s is no video capture device\n",
                         dev_name);
                exit(EXIT_FAILURE);
        }

        switch (io) {
        case IO_METHOD_READ:
                if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
                        fprintf(stderr, "%s does not support read i/o\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;

        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
                        fprintf(stderr, "%s does not support streaming i/o\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;
        }
#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Get %s's capabilities successfully.\n", dev_name);
        printf("[ V4L2 CLUE ] : Driver Name : %s\n[ V4L2 CLUE ] : Card Name : %s\n[ V4L2 CLUE ] : Bus info : %s\n[ V4L2 CLUE ] : Driver Version : %u.%u.%u\n",cap.driver, cap.card, cap.bus_info,(cap.version >> 16) & 0XFF, (cap.version >> 8) & 0XFF, cap.version & 0XFF);
    }
#endif

        /* not all capture support crop */
        /* Select video input, video standard and tune here. */

        CLEAR(cropcap);

        cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        /* if device support cropcap's type then set crop */
        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. */
        }

#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Set cropcap successfully.\n");
        //could add some cropcap log.
    }
#endif

#if(METALSEED_TAG == 1)
    {
        struct v4l2_fmtdesc fmtdesc;
        fmtdesc.index = 0;
        fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        printf("[ V4L2 CLUE ] : Format that this device supported:\n");

        while(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) != -1)
        {
            printf("[ V4L2 CLUE ] : \t%d.%s\n", fmtdesc.index + 1, fmtdesc.description);
            fmtdesc.index++;
        }
    }
#endif

        CLEAR(fmt);

        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (force_format) {
                fmt.fmt.pix.width       = V4L2_FORCE_FORMAT_WIDTH;
                fmt.fmt.pix.height      = V4L2_FORCE_FORMAT_HIGHT;
                fmt.fmt.pix.pixelformat = V4L2_FORCE_FORMAT_PIXEL_FORMAT;
                fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;

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

#if(METALSEED_TAG == 1)
    {
                printf("[ V4L2 CLUE ] : Set format by force successfully.\n");
                printf("[ V4L2 CLUE ] : Width = %d\n" , fmt.fmt.pix.width);
                printf("[ V4L2 CLUE ] : Height = %d\n" , fmt.fmt.pix.height);
    }
#endif
                /* 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");
        }

        /* 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;

#if(METALSEED_TAG == 1)
{
        printf("[ V4L2 CLUE ] : Image size = %d\n" , fmt.fmt.pix.sizeimage);
        printf("[ V4L2 CLUE ] : Bytes per line = %d\n" , fmt.fmt.pix.bytesperline);
}
#endif

        CLEAR(parm);
        parm.type                                  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        parm.parm.capture.capturemode              = 0;
        parm.parm.capture.capability               = V4L2_CAP_TIMEPERFRAME;
        parm.parm.capture.timeperframe.denominator = 30; //鏃堕棿闂撮殧鍒嗘瘝
        parm.parm.capture.timeperframe.numerator   = 1;  //鍒嗗瓙
        if(-1 == xioctl(fd, VIDIOC_S_PARM, &parm))
        {
            errno_exit("VIDIOC_S_PARM");
        }

 #if(METALSEED_TAG == 1)
 {
        printf("[ V4L2 CLUE ] : Set stream parameter successfully\n");
        printf("[ V4L2 CLUE ] : Stream capability =  V4L2_CAP_TIMEPERFRAME\n");
        printf("[ V4L2 CLUE ] : Stream timeperframe's donominator = %d\n", parm.parm.capture.timeperframe.denominator);
        printf("[ V4L2 CLUE ] : Stream timeperframe's numerator = %d\n", parm.parm.capture.timeperframe.numerator );
 }
 #endif

        switch (io) {
        case IO_METHOD_READ:
                init_read(buffers, fmt.fmt.pix.sizeimage);
                break;

        case IO_METHOD_MMAP:
                init_mmap(dev_name, fd, buffers);
                break;

        case IO_METHOD_USERPTR:
                init_userp(buffers, fmt.fmt.pix.sizeimage, dev_name, fd);
                break;
        }
}

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

        fd = -1;
#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Close device successfully\n");
    }
#endif
}

/* three operations
 * step 1 : check dev_name and st_mode
 * step 2 : open(device)
 */
static void open_device(char *dev_name, int *fd)
{
        struct stat st;

        if (-1 == stat(dev_name, &st)) {
                fprintf(stderr, "Cannot identify '%s': %d, %s\n",
                         dev_name, errno, strerror(errno));
                exit(EXIT_FAILURE);
        }

        if (!S_ISCHR(st.st_mode)) {
                fprintf(stderr, "%s is no device\n", dev_name);
                exit(EXIT_FAILURE);
        }

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

        if (-1 == *fd) {
                fprintf(stderr, "Cannot open '%s': %d, %s\n",
                         dev_name, errno, strerror(errno));
                exit(EXIT_FAILURE);
        }
#if(METALSEED_TAG == 1)
    {
        printf("[ V4L2 CLUE ] : Open %s successfully. fd = %d\n", dev_name, fd);
    }
#endif
}

static void process_image(const void *frame_pointer, int size)
{
        //fwrite(frame_pointer, size, 1, file_output); save this frame to file_output

        puts("An image has been process over!");
#if(METALSEED_TAG == 1)
        {
            printf("\n[ V4L2 CLUE ] : Process inmage successfully\n");
        }
#endif
}
static ctr = 0;
static int read_frame(int fd, struct buffer *buffers)
{
        struct v4l2_buffer buf;
        unsigned int i;
        switch (io) {
        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;
        }

#if(METALSEED_TAG == 1)
        {
            printf("\n[ V4L2 CLUE ] : Read frame successfully\n");
        }
#endif
        return 1;
}
时间: 2024-10-10 11:03:52

linux v4l2 api的相关文章

Video for Linux Two API Specification revision0.24【转】

转自:http://blog.csdn.net/jmq_0000/article/details/7536805#t136 Video for Linux Two API Specification Revision 0.24 Michael H Schimek <[email protected]> Bill Dirks Hans Verkuil Martin Rubli Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,

Video for Linux Two API Specification Revision 2.6.32【转】

转自:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html Video for Linux Two API Specification Revision 2.6.32 Michael H Schimek <[email protected]> Bill Dirks Original author of the V4L2 API and documentation. Hans

python Socket编程-python API 与 Linux Socket API之间的关系

python socket编程 服务端 #!/usr/bin/env python # coding=utf-8 from socket import * HOST = '' PORT = 2345 BUFSIZE = 1024 ADDR = (HOST,PORT) #创建AF_INET地址族,TCP的套接字 with socket(AF_INET,SOCK_STREAM) as tcpSerSock: #绑定ip和端口 tcpSerSock.bind(ADDR) #监听端口,是否有请求 tcp

GO网络编程和Linux Socket API的关系

先展示一下简单的go程序,然后分析GO的API和Linux API的关系.像简单的socket概念等就不在这里介绍了,不懂的去百度一下. server.go package main import "net" import "fmt" import "bufio" import "strings" // only needed below for sample processing func main() { fmt.Prin

一个hello/hi的简单的网络聊天程序和python Socket API与Linux Socket API之间的关系

1.Socket概述 套接字(socket)是一个抽象层,应用程序可以通过它发送或接收数据,可对其进行像对文件一样的打开.读写和关闭等操作.套接字允许应用程序将I/O插入到网络中,并与网络中的其他应用程序进行通信.网络套接字是IP地址与端口的组合. 套接字可以看成是两个网络应用程序进行通信时,各自通信连接中的一个端点.通信时,其中的一个网络应用程序将要传输的一段信息写入它所在主机的Socket中,该Socket通过网络接口卡的传输介质将这段信息发送给另一台主机的Socket中,使这段信息能传送到

通过基于java实现的网络聊天程序分析java中网络API和Linux Socket API关系

1. 引言 socket网络编程,可以指定不同的通信协议,在这里,我们使用TCP协议实现基于java的C/S模式下“hello/hi”网络聊天程序 2. 目标 1). 通过该网络聊天程序,了解java Socket API接口的基本用法 2). java Socket API简要介绍 3). linux socket API 简单分析 4). tcp协议的连接和终止 5). 探究java socket API 和 linux socket api之间的关系 3. linux socket API

Java Socket编程以及与Linux Socket API关系

Socket 编程(基于Linux) Socket独立于具体协议的网络编程接口,在ISO模型中,主要位于会话层和传输层之间:在通用的计算机网络五层模型中,主要位于应用层和传输层之间. Linux Socket 基本上就是BSD Socket 需要使用的头文件 数据类型:#include <sys/types.h> 函数定义:#include <sys/socket.h> Socket类型 套接字是一种通信机制,通信两方的一种约定,用套接字中的相关函数来完成通信过程.根据传输内容分为

Linux系统编程(第2版)笔记 (本书基本上就是Linux C API的简单使用说明,入门级别的)

Linux系统编程(第2版) 跳转至: 导航. 搜索 目录 1 入门和基本概念 2 文件I/O 3 缓冲I/O 4 高级文件I/O 5 进程管理 6 高级进程管理 7 线程 8 文件和目录管理 9 内存管理 10 信号 11 时间(这里谈不上系统编程了,就是C库API) 12 附录A C语言的GCC扩展 13 附录B 参考书目 入门和基本概念 文件I/O read(): EINTR EAGAIN 其他错误:EBADF EFAULT EINVAL EIO Append模式:每次write之前的文件

windows 和linux 同步api对比

初始化临界区 (win) InitializeCriticalSection(RTL_CRITICAL_SECTION &rtl_critial_section) (linux) pthread_mutexattr_init(&(mutex)->attr); pthread_mutexattr_settype(&(mutex)->attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&(mutex)->mtx