当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 2 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 大家好!今天编译与video4linux相关的程序出现了一个问题!特向大 家请教!
帖子发表于 : 2009-09-16 21:46 

注册: 2009-04-11 21:54
帖子: 7
送出感谢: 0 次
接收感谢: 0 次
大家好!今天编译了一个程序出现了一个问题!特向大 家请教!错误是:
iquan@ubuntu:/media/study/通信程序/test2$ gcc v4l_test.c -o v4l_test
weiquan@ubuntu:/media/study/通信程序/test2$ ./v4l_test
v4l_get_channels:: Invalid argument
device_init:failed...: Invalid argument


程序有v4l.h,v4l.c,v4l_test.c. 相信大家都有v4l.h,v4l.c,所以下面就给出v4l_test.c的程序.请大家不吝赐教,先谢谢啦!
//de_south send me!09.9.15
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "v4l.h"
#include "v4l.c"

#define norm VIDEO_MODE_NTSC
#define DEFAULT_FILE_NAME "/mnt/cap.jpeg" //抓图后图片的存放位置,自己定义即可

/*typedef struct _v4l_struct v4l_device;*/
v4l_device vd;
int device_init(char *dev)
{
if(dev==NULL) {
dev="/dev/video0";
}
if(v4l_open(dev,&vd)) return -1;
printf("the pointer is key!");
if(v4l_get_channels(&vd)) return -1;
printf("%s: initialization ok... %s\n"
"%d: channels \n"
"%d: audios\n\n",
dev,vd.capability.name,vd.capability.channels,vd.capability.audios);

v4l_close(&vd);
return 0;
}

int main()
{
if(device_init("/dev/video0")==-1) {
perror("device_init:failed...");
exit(1);
}else{printf("ok!\n");}
exit(0);
}
//正常编译,执行结果:
//v4l_get_channel:: Invalid argument
//device_init:failed...: Invalid argument

//注释了:if(v4l_get_channels(&vd)) return -1; 后的执行结果:
// /dev/video0: initialization ok... CNF7237&CNF7238
// 1: channels
// 0: audios

// ok!


页首
 用户资料  
 
2 楼 
 文章标题 : Re: 大家好!今天编译与video4linux相关的程序出现了一个问题!特向大 家请教!
帖子发表于 : 2009-09-17 9:11 

注册: 2009-04-11 21:54
帖子: 7
送出感谢: 0 次
接收感谢: 0 次
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <assert.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <linux/videodev.h>
#include "v4l.h"
/*
struct video_capability
{
char name[32];
int type;
int channels; /* Num channels
int audios; /* Num audio devices
int maxwidth; /* Supported width *
int maxheight; /* And height *
int minwidth; /* Supported width *
int minheight; /* And height *
};capability结构它包括了视频设备的名称,频道数,音频设备数,支持的最大最小宽度和高度等信息。
struct video_picture
{
__u16 brightness;
__u16 hue;
__u16 colour;
__u16 contrast;
__u16 whiteness; /* Black and white only *
__u16 depth; /* Capture depth *
__u16 palette; /* Palette in use *
}picture*/


#define DEFAULT_DEVICE "/dev/video0"

int v4l_open(char *dev, v4l_device *vd)
{
if (!dev)
dev = DEFAULT_DEVICE;

if ((vd->fd = open(dev, O_RDWR)) < 0) {
perror("v4l_open:");
return -1;
}

if (v4l_get_capability(vd))
return -1;

if (v4l_get_picture(vd))
return -1;

return 0;
}

int v4l_grab_picture(v4l_device *vd, unsigned int size)
{
if (read(vd->fd, &(vd->map), size) == 0) return -1;
return 0;
}

int v4l_get_capability(v4l_device *vd)
{
if (ioctl(vd->fd, VIDIOCGCAP, &(vd->capability)) < 0) {
perror("v4l_get_capability:");
return -1;
}

return 0;
}

/*
norm: VIDEO_MODE_PAL | VIDEO_MODE_NTSC | VIDEO_MODE_SECAM | VIDEO_MODE_AUTO
(see videodev.h)
*/
int v4l_set_norm(v4l_device *vdd, int norm)
{
int i;

for (i = 0; i < vdd->capability.channels; i++) {
vdd->channel[i].norm = norm;
//vd->channel[i].type = VIDEO_TYPE_TV; //default (VIDEO_TYPE_TV | VIDEO_TYPE_CAMERA)
}

if (v4l_get_capability(vdd)) {
perror("v4l_set_norm");
return -1;
}
if (v4l_get_picture(vdd)) {
perror("v4l_set_norm");
}
return 0;
}

int v4l_get_channels(v4l_device *vd)
{
int i;
printf("first is ok!");
for (i = 0; i < vd->capability.channels; i++) {
vd->channel[i].channel = i;
printf("second is ok!");
if (ioctl(vd->fd, VIDIOCGCHAN, &(vd->channel[i])) < 0) {
perror("v4l_get_channel:");
printf("third time!\n");
return -1;
}
}
return 0;
}


/*
* v4l_switch_channel - select (switch) the video source
*
* c: the channel number
*/
int v4l_switch_channel(v4l_device *vd, int c)
{
if (ioctl(vd->fd, VIDIOCSCHAN, &(vd->channel[c])) < 0) {
perror("v4l_switch_channel:");
return -1;
}
return 0;
}

int v4l_get_audios(v4l_device *vd)
{
int i;

for (i = 0; i < vd->capability.audios; i++) {
vd->audio[i].audio = i;

if (ioctl(vd->fd, VIDIOCGAUDIO, &(vd->audio[i])) < 0) {
perror("v4l_get_audio:");
return -1;
}
}
return 0;
}

int v4l_get_picture(v4l_device *vd)
{
if (ioctl(vd->fd, VIDIOCGPICT, &(vd->picture)) < 0) {
perror("v4l_get_picture");
return -1;
}
return 0;
}

/* ...may be not necessarily... */
int v4l_set_picture(v4l_device *vd, int br, int hue, int col, int cont,
int white)
{
if (br) vd->picture.brightness = br;
if (hue) vd->picture.hue = hue;
if (col) vd->picture.colour = col;
if (cont) vd->picture.contrast = cont;
if (white) vd->picture.whiteness = white;

if(ioctl(vd->fd, VIDIOCSPICT, &(vd->picture)) < 0) {
perror("v4l_set_picture");
return -1;
}

return 0;
}

int v4l_close(v4l_device *vd)
{
close(vd->fd);
return 0;
}

int v4l_get_mbuf(v4l_device *vd)
{
if (ioctl(vd->fd, VIDIOCGMBUF, &(vd->mbuf)) < 0) {
perror("v4l_get_mbuf");
return -1;
}
return 0;
}

int v4l_mmap_init(v4l_device *vd)
{
//vd->mbuf.size = 0x151000;
//vd->mbuf.offsets[0] = 0;

if (v4l_get_mbuf(vd) < 0)
return -1;

if ((vd->map = mmap(0, vd->mbuf.size, PROT_READ|PROT_WRITE, MAP_SHARED, vd->fd, 0)) < 0) {
perror("v4l_mmap_init:mmap");
return -1; /*yangdaqian add * before vd->map in this statement */
}
return 0;
}

/*
* v4l_grab_init - initalizate mmap buffer
*
* width: width of mmap's buffer
* height: width of mmap's buffer
*/
int v4l_grab_init(v4l_device *vd, int width, int height)
{
vd->mmap.width = width; //width;
vd->mmap.height = height; //height;
vd->mmap.format = vd->picture.palette;

vd->frame_current = 0;
vd->frame_using[0] = FALSE;
vd->frame_using[1] = FALSE;

return v4l_grab_frame(vd, 0);
}

/*
* v4l_grab_frame - activate capturing
*
* frame: frame number to store image data
*/
int v4l_grab_frame(v4l_device *vd, int frame)
{
if (vd->frame_using[frame]) {
fprintf(stderr, "v4l_grab_frame: frame %d is already used.\n", frame);
return -1;
}

vd->mmap.frame = frame;
if (ioctl(vd->fd, VIDIOCMCAPTURE, &(vd->mmap)) < 0) {
perror("v4l_grab_frame");
return -1;
}
vd->frame_using[frame] = TRUE;
vd->frame_current = frame;
return 0;
}

int v4l_grab_sync(v4l_device *vd)
{
if (ioctl(vd->fd, VIDIOCSYNC, &(vd->frame_current)) < 0) {
perror("v4l_grab_sync");
}
vd->frame_using[vd->frame_current] = FALSE;
return 0;
}

int v4l_get_buffer(v4l_device *vd)
{
if (ioctl(vd->fd, VIDIOCGFBUF, &(vd->buffer)) < 0) {
perror("v4l_get_buffer");
}
return 0;
}

int v4l_set_buffer(v4l_device *vd)
{
if (ioctl(vd->fd, VIDIOCSFBUF, &(vd->buffer)) < 0) {
perror("v4l_set_buffer");
return -1;
}
return 0;
}

int v4l_set_palette(v4l_device *vd, int pal, int dep)
{
vd->picture.palette = pal;
vd->picture.depth = dep;

vd->mmap.format =pal;
if (ioctl(vd->fd, VIDIOCSPICT, &(vd->picture)) < 0) {
perror("v4l_set_palette");
return -1;
}
return 0;
}


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 2 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译