#include <sys/ioctl.h>
#include <linux/videodev.h>
#include <linux/types.h>
#include <malloc.h>
#include <fcntl.h>
#include <sys/time.h>
#include <pthread.h>
#define FILE_BUFFER_LEN 1024*64
#define CMD_LEN 5 //"start"
#define SERVER_PORT 8880
#define VIDEO_PALETTE_RAW_JPEG 20
#define VIDEO_PALETTE_JPEG 21
#define USB_VIDEO_DEV "/dev/video0"
#define PICTURE_WIDTH 320
#define PICTURE_HEIGHT 240
#define VIDEO_FRAME_LEN (PICTURE_WIDTH * PICTURE_HEIGHT >> 2)
unsigned char *video_buffer = NULL;
int usb_camera_fd = -1;
int init_video(void)//初始化usb摄像头,这里使用read方式读取图像数据
{
struct video_capability video_caps;
struct video_channel video_chan;
struct video_picture video_pic;
struct video_window vid_win;
int usb_camera_fd = -1;
char *usb_video_dev = USB_VIDEO_DEV;
//分配图像数据存储空间
if((video_buffer = (unsigned char *)malloc(VIDEO_FRAME_LEN)) == NULL)
{
fprintf(stderr,"Can not allocate memory :%s",strerror(errno));
return -1;
}
usb_camera_fd = open(usb_video_dev, O_RDWR);
if (usb_camera_fd == -1)
{
fprintf(stderr, "Can't open device %s\n", usb_video_dev);
return -1;
}
/**********************video_capability***************************/
if (ioctl(usb_camera_fd, VIDIOCGCAP, &video_caps) == -1)
{
perror("ioctl (VIDIOCGCAP)");
return -1;
}
/************************video_channel********************************/
video_chan.channel = 1;
if (ioctl(usb_camera_fd, VIDIOCGCHAN, &video_chan) == -1)
{
perror("ioctl (VIDIOCGCAP)");
return -1;
}