这个程序耗费我一天的时间,才得以解决一个问题!原来在arm linux上的程序最好不要放在/usr目录下,我这个程序就是,开始我就把程序放在这个目录下,摄像头采集一会就不采集数据了,一直找不到原因所在,开始还以为内存耗尽了, 但是始终找不到耗尽的原因!郁闷了我好久!今天得以解决,解决了我毕业设计的一大隐患!就担心这个地方出问题,造成毕业设计失败!
明天开始写网络传输模块的程序!
以后有时间会把这个程序进一步封装,更加模块化!
头文件:capture.h
#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;
bool open_video() ;//open video
char *NextFrame() ;//capture one frame data
void close_video() ;//close video and free resource
bool capture_run() ;//create capture thread
void *thread_capture() ;//capture thread function
bool encode_jpeg(char *lpbuf,int width ,int height) ;//jpeg encode
#endif
程序文件capture.c
#include "capture.h"
//定义视频扑捉相应的结构体
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 ;
//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_RGB565;
//conrresponding to thread
pthread_t hthread_capture ;//capture thread!
bool open_video()
{
int ret =-1 ;
//open device
deviceHandle=open(deviceName,O