一. 源码编译及目标
1.luvcview源码下载
2. luvcview编译
安装好libv4l2之后就可以编译出libvucview了
3. libv4l库的编译
4. libv4l库的使用
注意:
a. 出现undefined reference to `shm_open',是因为libv4l2库中用到了,需要在编译时加上-lrt
b. 出现undefined reference to `powf',是因为libv4l2库中用到了,需要在编译时加上-lm
c. 为了防止系统中己安装的v4l2库的干扰,把v4l2删掉: sudo apt-get remove libv4l-dev
5. 目标
目标是通过分析luvcview,自己动手写一个luvcview,这不是再次造轮子,而是一个学习并提高的过程。
二. 测试demo
2.1 check
获取camera所支持的视频格式
b. Makefile
1check.rar
(下载后改名为1check.tar.gz)
c.运行结果
1.luvcview源码下载
- cong@msi:/tmp$ sudo apt-cache showsrc luvcview //a.查看有没有这个源码包
- cong@msi:/tmp$ sudo apt-get source luvcview //b. 这就在当前目录下
- cong@msi:/tmp$ ls
- luvcview_0.2.6-6.dsc luvcview-0.2.6 luvcview_0.2.6.orig.tar.gz luvcview_0.2.6-6.debian.tar.gz
- cong@msi:/work/test/busytest/luvcview-0.2.6$ make //直接make就可以了
- Package libv4l2 was not found in the pkg-config search path. //提示libv4l2包没有找到
- Perhaps you should add the directory containing `libv4l2.pc'
- No package 'libv4l2' found
- v4l2uvc.c:28:21: fatal error: libv4l2.h: No such file or directory //缺少libv4l2头文件
- #include <libv4l2.h>
- cong@msi:/work/test/busytest/luvcview-0.2.6$ sudo apt-cache search libv4l2 //查找libv4l2包
- libv4l-dev - Collection of video4linux support libraries (development files)
- cong@msi:/work/test/busytest/luvcview-0.2.6$ sudo apt-get install libv4l-dev //安装libv4l2-dev
3. libv4l库的编译
- libv4l的库源码下载地址:
- http://people.atrpms.net/~hdegoede/
-
- cong@msi:/work/libv4l2/libv4l-0.6.1$ ls
- include libv4l2 libv4lconvert Makefile README
-
- cong@msi:/work/libv4l2/libv4l-0.6.1$ make LINKTYPE=static //直接make就可以了,这儿是编成静态库
- Makefile中:
- CFLAGS=-g -O0 -I/work/test/uvcview/libv4l2/libv4l-0.6.1/include //添加include路径
- V4L2LIBS = -L/work/test/uvcview/libv4l2/libv4l-0.6.1/libv4l2 -lv4l2 \ //添加库的链接路径
- -L/work/test/uvcview/libv4l2/libv4l-0.6.1/libv4lconvert/ -lv4lconvert -lrt -lm
a. 出现undefined reference to `shm_open',是因为libv4l2库中用到了,需要在编译时加上-lrt
b. 出现undefined reference to `powf',是因为libv4l2库中用到了,需要在编译时加上-lm
c. 为了防止系统中己安装的v4l2库的干扰,把v4l2删掉: sudo apt-get remove libv4l-dev
5. 目标
目标是通过分析luvcview,自己动手写一个luvcview,这不是再次造轮子,而是一个学习并提高的过程。
二. 测试demo
2.1 check
获取camera所支持的视频格式
- cong@msi:/work/test/uvcview/1check$ cat check.c
- #include "utils.h"
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <linux/videodev2.h>
-
- #define VIDEO_DEVICE "/dev/video0"
- int main ( int argc, char *argv[] )
- {
- int fd;
- int ret = 0;
- struct v4l2_capability cap;
- struct v4l2_fmtdesc fmt;
- if( (fd = v4l2_open(VIDEO_DEVICE,O_RDWR)) == -1) //打开设备
- {
- dbmsg("error: %s", strerror(errno));
- return 0;
- }
- memset(&cap, 0, sizeof(struct v4l2_capability));
- if( (ret = v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0)) //查询设备属性
- {
- dbmsg("error: %s", strerror(errno));
- return 0;
- }
- //接下来就可以进行一系列的判断了
- //cap.capabilities & V4L2_CAP_VIDEO_CAPTURE //判断是否支持图像获取
- //cap.capabilities & V4L2_CAP_STREAMING //是否具有数据流控制模式
- //cap.capabilities & V4L2_CAP_READWRITE //是否支持 read和write I/O操作函数
- memset(&fmt, 0, sizeof(struct v4l2_fmtdesc));
- fmt.index = 0;
- fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- while ((ret = v4l2_ioctl(fd, VIDIOC_ENUM_FMT, &fmt)) == 0) { //获取当前视频设备支持的视频格式
- printf("{ pixelformat = '%c%c%c%c', description = '%s' }\n",
- fmt.pixelformat & 0xFF, (fmt.pixelformat >> 8) & 0xFF,
- (fmt.pixelformat >> 16) & 0xFF, (fmt.pixelformat >> 24) & 0xFF,
- fmt.description);
- if(ret != 0)
- printf(" Unable to enumerate frame sizes.\n");
- fmt.index++;
- }
- return EXIT_SUCCESS;
- }
- cong@msi:/work/test/uvcview/1check$ cat Makefile
- EXE=check
- CC=gcc
- SRC=$(wildcard *.c)
- #OBJ=$(SRC:.c=.o)
- OBJ=$(patsubst %.c,%.o,$(SRC))
- DEP=$(patsubst %.c,.%.d,$(SRC))
- CFLAGS=-g -O0 -I/work/test/uvcview/libv4l2/libv4l-0.6.1/include
- #V4L2LIBS = $(shell pkg-config --libs libv4l2)
- V4L2LIBS = -L/work/test/uvcview/libv4l2/libv4l-0.6.1/libv4l2 -lv4l2 \
- -L/work/test/uvcview/libv4l2/libv4l-0.6.1/libv4lconvert/ -lv4lconvert \
- -lrt -lm
- $(EXE):$(OBJ)
- $(CC) $(CFLAGS) $^ -o $@ $(V4L2LIBS)
-
- $(DEP):.%.d:%.c
- @set -e; rm -f $@; \
- $(CC) -MM $< > $@.$$$$; \
- sed 's,/($*/)/.o[ :]*,/1.o $@ : ,g' < $@.$$$$ > $@; \
- rm -f $@.$$$$
-
- -include $(DEP)
- clean:
- @rm $(EXE) $(OBJ) $(DEP) -f
c.运行结果
- cong@msi:/work/test/uvcview/1check$ ./check
- libv4l2.c:v4l2_open[477]: //v4l2库打印的
- libv4lconvert: warning more framesizes then I can //v4l2库打印的
- libv4lconvert: warning more framesizes then I can //v4l2库打印的
- { pixelformat = 'YUYV', description = 'YUV 4:2:2 (YUYV)' }
- { pixelformat = 'MJPG', description = 'MJPEG' }
- { pixelformat = 'RGB3', description = 'RGB3' }
- { pixelformat = 'BGR3', description = 'BGR3' }
- { pixelformat = 'YU12', description = 'YU12' }
- { pixelformat = 'YV12', description = 'YV12' }