今天完成了前两个模块的整合调试,基本实现了功能!
把代码贴出来!
下一步考虑压缩为jpeg视频数据流,不保存文件直接传输。
视频采集头文件:
#ifndef _CAPTURE_H_
#define _CAPTURE_H_
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/videodev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <linux/types.h>
#include <jpeglib.h>
#include <setjmp.h>
#define bool int
#define true 1
#define false 0
//#include <sys/times.h>
int errno;
extern pthread_t hthread_capture ;//capture thread!
bool open_video() ;//open video
char *NextFrame() ;//capture one frame data
void close_video() ;//close video and free resource
bool capture_Run(pthread_mutex_t *capture_lock) ;//create capture thread
void *thread_capture(pthread_mutex_t *capture_lock) ;//capture thread function
bool encode_jpeg(char *lpbuf,int width ,int height,pthread_mutex_t *capture_lock) ;//jpeg encode
#endif
视频采集源文件:capture.c
#include "capture.h"
//struct video_capture v_capture ;
//定义视频扑捉相应的结构体
struct video_mbuf v_bufferproperty ;//此结构体利用mmap进行映射帧信息
//实际上是输入到摄像头存储器缓冲区的帧信息
struct video_mmap *v_memorymap ;//用于内存映射
struct video_picture v_imageproperty ;//采集图像的各种属性
struct video_capability v_capability ;//摄像头的基本信息
char *memorymap ;
int bufferIndex=0 ;
//struct v4l vd ;//vidoe4linux
//define the variable
char* deviceName = "/dev/v4l/video0";
char *fname="temp.jpg" ;
int deviceHandle = 0;
int width = 320;
int height = 240;
int depth=16;
int palette=VIDEO_PALETTE_RGB24;
//conrresponding to thread
pthread_t hthread_capture ;//capture thread!
bool open_video()
{
int ret =-1 ;
//open device
deviceHandle=open(deviceName,O_RDWR) ;//read and write mode
if(deviceHandle==-1)
{
printf("Capture:Open failed!/n") ;
printf("Mesg:%s/n",sys_errlist[errno]) ;
return false ;
}
//get the property of capture
ret=ioctl(deviceHandle,VIDIOCGCAP,&v_capability) ;
if(ret == -1)
{
printf("Capture:obtain capability failed!/n") ;
printf("Mesg:%s/n",sys_errlist[errno]) ;
close(deviceHandle) ;//关闭设备文件
return false ;
}
if((v_capability.type&VID_TYPE_CAPTURE)==0)
{
printf("Capture:this device can't capture video to memory!/n") ;
close(deviceHandle) ;//关闭设备文件
return false ;
}
//print the information of capture
printf(v_capability.name);
printf(", Type:%d/n",v_capability.type);
printf("Maxwidth:%d,Maxheight:%d/n",v_capability.maxwidth ,v_capability.maxheight);
printf("Minwidth:%d,Minheight:%d/n",v_capability.minwidth,v_capab