⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videodev.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
static int videodev_proc_read(char *page, char **start, off_t off,			       int count, int *eof, void *data){	char *out = page;	struct video_device *vfd = data;	struct videodev_proc_data *d;	struct list_head *tmp;	int len;	char c = ' ';	list_for_each (tmp, &videodev_proc_list) {		d = list_entry(tmp, struct videodev_proc_data, proc_list);		if (vfd == d->vdev)			break;	}	/* Sanity check */	if (tmp == &videodev_proc_list)		goto skip;		#define PRINT_VID_TYPE(x) do { if (vfd->type & x) \	out += sprintf (out, "%c%s", c, #x); c='|';} while (0)	out += sprintf (out, "name            : %s\n", vfd->name);	out += sprintf (out, "type            :");		PRINT_VID_TYPE(VID_TYPE_CAPTURE);		PRINT_VID_TYPE(VID_TYPE_TUNER);		PRINT_VID_TYPE(VID_TYPE_TELETEXT);		PRINT_VID_TYPE(VID_TYPE_OVERLAY);		PRINT_VID_TYPE(VID_TYPE_CHROMAKEY);		PRINT_VID_TYPE(VID_TYPE_CLIPPING);		PRINT_VID_TYPE(VID_TYPE_FRAMERAM);		PRINT_VID_TYPE(VID_TYPE_SCALES);		PRINT_VID_TYPE(VID_TYPE_MONOCHROME);		PRINT_VID_TYPE(VID_TYPE_SUBCAPTURE);		PRINT_VID_TYPE(VID_TYPE_MPEG_DECODER);		PRINT_VID_TYPE(VID_TYPE_MPEG_ENCODER);		PRINT_VID_TYPE(VID_TYPE_MJPEG_DECODER);		PRINT_VID_TYPE(VID_TYPE_MJPEG_ENCODER);	out += sprintf (out, "\n");	out += sprintf (out, "hardware        : 0x%x\n", vfd->hardware);#if 0	out += sprintf (out, "channels        : %d\n", d->vcap.channels);	out += sprintf (out, "audios          : %d\n", d->vcap.audios);	out += sprintf (out, "maxwidth        : %d\n", d->vcap.maxwidth);	out += sprintf (out, "maxheight       : %d\n", d->vcap.maxheight);	out += sprintf (out, "minwidth        : %d\n", d->vcap.minwidth);	out += sprintf (out, "minheight       : %d\n", d->vcap.minheight);#endifskip:	len = out - page;	len -= off;	if (len < count) {		*eof = 1;		if (len <= 0)			return 0;	} else		len = count;	*start = page + off;	return len;}static void videodev_proc_create(void){	video_proc_entry = create_proc_entry("video", S_IFDIR, &proc_root);	if (video_proc_entry == NULL) {		printk("video_dev: unable to initialise /proc/video\n");		return;	}	video_proc_entry->owner = THIS_MODULE;	video_dev_proc_entry = create_proc_entry("dev", S_IFDIR, video_proc_entry);	if (video_dev_proc_entry == NULL) {		printk("video_dev: unable to initialise /proc/video/dev\n");		return;	}	video_dev_proc_entry->owner = THIS_MODULE;}#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)static void videodev_proc_destroy(void){	if (video_dev_proc_entry != NULL)		remove_proc_entry("dev", video_proc_entry);	if (video_proc_entry != NULL)		remove_proc_entry("video", &proc_root);}#endifstatic void videodev_proc_create_dev (struct video_device *vfd, char *name){	struct videodev_proc_data *d;	struct proc_dir_entry *p;	if (video_dev_proc_entry == NULL)		return;	d = kmalloc (sizeof (struct videodev_proc_data), GFP_KERNEL);	if (!d)		return;	p = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, video_dev_proc_entry);	if (!p)		return;	p->data = vfd;	p->read_proc = videodev_proc_read;	d->proc_entry = p;	d->vdev = vfd;	strcpy (d->name, name);	/* How can I get capability information ? */	list_add (&d->proc_list, &videodev_proc_list);}static void videodev_proc_destroy_dev (struct video_device *vfd){	struct list_head *tmp;	struct videodev_proc_data *d;	list_for_each (tmp, &videodev_proc_list) {		d = list_entry(tmp, struct videodev_proc_data, proc_list);		if (vfd == d->vdev) {			remove_proc_entry(d->name, video_dev_proc_entry);			list_del (&d->proc_list);			kfree(d);			break;		}	}}#endif /* CONFIG_VIDEO_PROC_FS */extern struct file_operations video_fops;/** *	video_register_device - register video4linux devices *	@vfd:  video device structure we want to register *	@type: type of device to register *	@nr:   which device number (0 == /dev/video0, 1 == /dev/video1, ... *             -1 == first free) *	 *	The registration code assigns minor numbers based on the type *	requested. -ENFILE is returned in all the device slots for this *	category are full. If not then the minor field is set and the *	driver initialize function is called (if non %NULL). * *	Zero is returned on success. * *	Valid types are * *	%VFL_TYPE_GRABBER - A frame grabber * *	%VFL_TYPE_VTX - A teletext device * *	%VFL_TYPE_VBI - Vertical blank data (undecoded) * *	%VFL_TYPE_RADIO - A radio card	 */int video_register_device(struct video_device *vfd, int type, int nr){	int i=0;	int base;	int err;	int end;	char *name_base;	char name[16];		switch(type)	{		case VFL_TYPE_GRABBER:			base=0;			end=64;			name_base = "video";			break;		case VFL_TYPE_VTX:			base=192;			end=224;			name_base = "vtx";			break;		case VFL_TYPE_VBI:			base=224;			end=240;			name_base = "vbi";			break;		case VFL_TYPE_RADIO:			base=64;			end=128;			name_base = "radio";			break;		default:			return -1;	}	/* pick a minor number */	down(&videodev_lock);	if (nr >= 0  &&  nr < end-base) {		/* use the one the driver asked for */		i = base+nr;		if (NULL != video_device[i]) {			up(&videodev_lock);			return -ENFILE;		}	} else {		/* use first free */		for(i=base;i<end;i++)			if (NULL == video_device[i])				break;		if (i == end) {			up(&videodev_lock);			return -ENFILE;		}	}	video_device[i]=vfd;	vfd->minor=i;	up(&videodev_lock);	/* The init call may sleep so we book the slot out	   then call */	MOD_INC_USE_COUNT;	if(vfd->initialize) {		err=vfd->initialize(vfd);		if(err<0) {			video_device[i]=NULL;			MOD_DEC_USE_COUNT;			return err;		}	}	sprintf (name, "v4l/%s%d", name_base, i - base);	/*	 *	Start the device root only. Anything else	 *	has serious privacy issues.	 */	vfd->devfs_handle =		devfs_register (NULL, name, DEVFS_FL_DEFAULT,				VIDEO_MAJOR, vfd->minor,				S_IFCHR | S_IRUSR | S_IWUSR,				&video_fops,				NULL);	init_MUTEX(&vfd->lock);	#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)	sprintf (name, "%s%d", name_base, i - base);	videodev_proc_create_dev (vfd, name);#endif	return 0;}/** *	video_unregister_device - unregister a video4linux device *	@vfd: the device to unregister * *	This unregisters the passed device and deassigns the minor *	number. Future open calls will be met with errors. */ void video_unregister_device(struct video_device *vfd){	down(&videodev_lock);	if(video_device[vfd->minor]!=vfd)		panic("videodev: bad unregister");#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)	videodev_proc_destroy_dev (vfd);#endif	devfs_unregister (vfd->devfs_handle);	if (vfd->release)		vfd->release(vfd);	video_device[vfd->minor]=NULL;	MOD_DEC_USE_COUNT;	up(&videodev_lock);}static struct file_operations video_fops={	owner:		THIS_MODULE,	llseek:		no_llseek,	read:		video_read,	write:		video_write,	ioctl:		video_ioctl,	mmap:		video_mmap,	open:		video_open,	release:	video_release,	poll:		video_poll,};/* *	Initialise video for linux */ static int __init videodev_init(void){	printk(KERN_INFO "Linux video capture interface: v1.00\n");	if(devfs_register_chrdev(VIDEO_MAJOR,"video_capture", &video_fops))	{		printk("video_dev: unable to get major %d\n", VIDEO_MAJOR);		return -EIO;	}#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)	videodev_proc_create ();#endif		return 0;}static void __exit videodev_exit(void){#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)	videodev_proc_destroy ();#endif	devfs_unregister_chrdev(VIDEO_MAJOR, "video_capture");}module_init(videodev_init)module_exit(videodev_exit)EXPORT_SYMBOL(video_device_alloc);EXPORT_SYMBOL(video_device_release);EXPORT_SYMBOL(video_register_device);EXPORT_SYMBOL(video_unregister_device);EXPORT_SYMBOL(video_devdata);EXPORT_SYMBOL(video_usercopy);EXPORT_SYMBOL(video_exclusive_open);EXPORT_SYMBOL(video_exclusive_release);MODULE_AUTHOR("Alan Cox");MODULE_DESCRIPTION("Device registrar for Video4Linux drivers");MODULE_LICENSE("GPL");/* * Local variables: * c-basic-offset: 8 * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -