Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2150705
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2015-08-07 14:08:40

一. 源码编译及目标
1.luvcview源码下载 
  1. cong@msi:/tmp$ sudo apt-cache showsrc luvcview //a.查看有没有这个源码包
  2. cong@msi:/tmp$ sudo apt-get source luvcview //b. 这就在当前目录下
  3. cong@msi:/tmp$ ls
  4.   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
2. luvcview编译
  1. cong@msi:/work/test/busytest/luvcview-0.2.6$ make                  //直接make就可以了
  2. Package libv4l2 was not found in the pkg-config search path.       //提示libv4l2包没有找到
  3. Perhaps you should add the directory containing `libv4l2.pc'
  4. No package 'libv4l2' found
  5. v4l2uvc.c:28:21: fatal error: libv4l2.h: No such file or directory   //缺少libv4l2头文件
  6.  #include <libv4l2.h>
  7. cong@msi:/work/test/busytest/luvcview-0.2.6$ sudo apt-cache search libv4l2   //查找libv4l2包
  8.   libv4l-dev - Collection of video4linux support libraries (development files)
  9. cong@msi:/work/test/busytest/luvcview-0.2.6$ sudo apt-get install libv4l-dev  //安装libv4l2-dev
安装好libv4l2之后就可以编译出libvucview了
3. libv4l库的编译
  1. libv4l的库源码下载地址:
  2. http://people.atrpms.net/~hdegoede/

  3. cong@msi:/work/libv4l2/libv4l-0.6.1$ ls
  4. include libv4l2 libv4lconvert Makefile README

  5. cong@msi:/work/libv4l2/libv4l-0.6.1$ make LINKTYPE=static //直接make就可以了,这儿是编成静态库
4. libv4l库的使用
  1. Makefile中:
  2. CFLAGS=-g -O0 -I/work/test/uvcview/libv4l2/libv4l-0.6.1/include               //添加include路径
  3. V4L2LIBS = -L/work/test/uvcview/libv4l2/libv4l-0.6.1/libv4l2 -lv4l2 \         //添加库的链接路径
  4.            -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所支持的视频格式
  1. cong@msi:/work/test/uvcview/1check$ cat check.c
  2. #include "utils.h"
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <linux/videodev2.h>

  7. #define VIDEO_DEVICE "/dev/video0"
  8. int main ( int argc, char *argv[] )
  9. {
  10.     int fd;
  11.     int ret = 0;
  12.     struct v4l2_capability cap;
  13.     struct v4l2_fmtdesc fmt;
  14.     if( (fd = v4l2_open(VIDEO_DEVICE,O_RDWR)) == -1)       //打开设备
  15.     {
  16.         dbmsg("error: %s", strerror(errno));
  17.         return 0;
  18.     }
  19.     memset(&cap, 0, sizeof(struct v4l2_capability));       
  20.     if( (ret = v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0)//查询设备属性
  21.     {
  22.         dbmsg("error: %s", strerror(errno));
  23.         return 0;
  24.     }
  25.     //接下来就可以进行一系列的判断了
  26.     //cap.capabilities & V4L2_CAP_VIDEO_CAPTURE    //判断是否支持图像获取
  27.     //cap.capabilities & V4L2_CAP_STREAMING        //是否具有数据流控制模式
  28.     //cap.capabilities & V4L2_CAP_READWRITE        //是否支持 read和write I/O操作函数
  29.     memset(&fmt, 0, sizeof(struct v4l2_fmtdesc));
  30.     fmt.index = 0;
  31.     fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  32.     while ((ret = v4l2_ioctl(fd, VIDIOC_ENUM_FMT, &fmt)) == 0) {    //获取当前视频设备支持的视频格式
  33.             printf("{ pixelformat = '%c%c%c%c', description = '%s' }\n",
  34.                     fmt.pixelformat & 0xFF, (fmt.pixelformat >> 8) & 0xFF,
  35.                     (fmt.pixelformat >> 16) & 0xFF, (fmt.pixelformat >> 24) & 0xFF,
  36.                     fmt.description);
  37.             if(ret != 0)
  38.                 printf(" Unable to enumerate frame sizes.\n");
  39.         fmt.index++;
  40.     }
  41.     return EXIT_SUCCESS;
  42. }
b. Makefile
  1. cong@msi:/work/test/uvcview/1check$ cat Makefile
  2. EXE=check
  3. CC=gcc
  4. SRC=$(wildcard *.c)
  5. #OBJ=$(SRC:.c=.o)
  6. OBJ=$(patsubst %.c,%.o,$(SRC))
  7. DEP=$(patsubst %.c,.%.d,$(SRC))
  8. CFLAGS=-g -O0 -I/work/test/uvcview/libv4l2/libv4l-0.6.1/include
  9. #V4L2LIBS = $(shell pkg-config --libs libv4l2)
  10. V4L2LIBS = -L/work/test/uvcview/libv4l2/libv4l-0.6.1/libv4l2 -lv4l2 \
  11.          -L/work/test/uvcview/libv4l2/libv4l-0.6.1/libv4lconvert/ -lv4lconvert \
  12.          -lrt -lm
  13. $(EXE):$(OBJ)
  14.     $(CC) $(CFLAGS) $^ -o $@ $(V4L2LIBS)

  15. $(DEP):.%.d:%.c
  16.     @set -e; rm -f $@; \
  17.     $(CC) -MM $< > $@.$$$$; \
  18.     sed 's,/($*/)/.o[ :]*,/1.o $@ : ,g' < $@.$$$$ > $@; \
  19.     rm -f $@.$$$$

  20. -include $(DEP)
  21. clean:
  22.     @rm $(EXE) $(OBJ) $(DEP) -f
1check.rar (下载后改名为1check.tar.gz)
c.运行结果
  1. cong@msi:/work/test/uvcview/1check$ ./check
  2. libv4l2.c:v4l2_open[477]:        //v4l2库打印的
  3. libv4lconvert: warning more framesizes then I can   //v4l2库打印的
  4. libv4lconvert: warning more framesizes then I can   //v4l2库打印的
  5. { pixelformat = 'YUYV', description = 'YUV 4:2:2 (YUYV)' }
  6. { pixelformat = 'MJPG', description = 'MJPEG' }
  7. { pixelformat = 'RGB3', description = 'RGB3' }
  8. { pixelformat = 'BGR3', description = 'BGR3' }
  9. { pixelformat = 'YU12', description = 'YU12' }
  10. { pixelformat = 'YV12', description = 'YV12' }

阅读(7957) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~