V4L2 file handles and event interface
v3 cover V4L2 file handles and event interface
Hi,
Here's the fifth version of the V4L2 file handle and event interface patchset.
The first patch adds the V4L2 file handle support and the rest are for V4L2 events.
The patchset has been tested with the OMAP 3 ISP driver. Patches for OMAP 3 ISP are not part of this patchset but are available in Gitorious (branch is called event):
git://gitorious.org/omap3camera/mainline.git event
So, for this patchset I've baked in comments from Hans. What has changed:
- v4l2_fh_init -> v4l2_fhs_init
- v4l2_fh_add has been split to v4l2_fh_init and v4l2_fh_add. Similarly for del/exit.
- Forward declaration for struct v4l2_event in v4l2_fh.h
- No more struct v4l2_fhs. The fields are directly in struct video_device now.
- v4l2_event_alloc now returns an error code if it fails for some reason.
- The number of maximum events allocatable by the driver is now limited by events->max_events.
- Possibly something else I don't happen to remember just now.
Comments are welcome as always.
Cheers,
Signature · 2 lines
Sakari Ailus [email protected]
PATCH v3 1/7 V4L: File handles
This patch adds a list of v4l2_fh structures to every video_device. It allows using file handle related information in V4L2. The event interface is one example of such use.
Video device drivers should use the v4l2_fh pointer as their file->private_data.
--- drivers/media/video/Makefile | 3 +- drivers/media/video/v4l2-dev.c | 2 + drivers/media/video/v4l2-fh.c | 65 ++++++++++++++++++++++++++++++++++++++++ include/media/v4l2-dev.h | 6 ++++ include/media/v4l2-fh.h | 47 +++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+), 1 deletions(-) create mode 100644 drivers/media/video/v4l2-fh.c create mode 100644 include/media/v4l2-fh.h
drivers/media/video/Makefile +2 -1
@@ -10,7 +10,8 @@ stkwebcam-objs := stk-webcam.o stk-sensor.o omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o -videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-subdev.o +videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-subdev.o \ + v4l2-fh.o # V4L2 core modules
drivers/media/video/v4l2-dev.c +2 -0
@@ -423,6 +423,8 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,if (!vdev->release)return -EINVAL ; +v4l2_fhs_init (vdev); +/* Part 1: check device type */ switch (type) {case VFL_TYPE_GRABBER :
drivers/media/video/v4l2-fh.c new file +65 -0
65 lines not on this page · raw message
include/media/v4l2-dev.h +6 -0
@@ -18,6 +18,8 @@#include <media/media-entity.h> +#include <media/v4l2-fh.h> +#define VIDEO_MAJOR 81#define VFL_TYPE_GRABBER 0
@@ -82,6 +84,10 @@ struct video_device/* attribute to differentiate multiple indices on one physical device */ int index; +/* V4L2 file handles */ +spinlock_t fh_lock;/* Lock for all v4l2_fhs */ +struct list_head fh_list;/* List of struct v4l2_fh */ +int debug;/* Activates debug level*/ /* Video standard vars */
include/media/v4l2-fh.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH v3 2/7 V4L: Events: Add new ioctls for events
This patch adds a set of new ioctls to the V4L2 API. The ioctls conform to V4L2 Events RFC version 2.3:
<URL:http://www.spinics.net/lists/linux-media/msg12033.html>
--- drivers/media/video/v4l2-compat-ioctl32.c | 3 +++ drivers/media/video/v4l2-ioctl.c | 3 +++ include/linux/videodev2.h | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 0 deletions(-)
drivers/media/video/v4l2-compat-ioctl32.c +3 -0
@@ -1077,6 +1077,9 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)case VIDIOC_DBG_G_REGISTER :case VIDIOC_DBG_G_CHIP_IDENT :case VIDIOC_S_HW_FREQ_SEEK : +case VIDIOC_DQEVENT : +case VIDIOC_SUBSCRIBE_EVENT : +case VIDIOC_UNSUBSCRIBE_EVENT : ret =do_video_ioctl (file, cmd, arg);break ;
drivers/media/video/v4l2-ioctl.c +3 -0
@@ -283,6 +283,9 @@ static const char *v4l2_ioctls[] = { [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT", [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK", + [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT", + [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT", + [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT", #endif };#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
include/linux/videodev2.h +23 -0
@@ -1536,6 +1536,26 @@ struct v4l2_streamparm { };/* +* E V E N T S +*/ + +struct v4l2_event { +__u32 count; +__u32 type; +__u32 sequence; +struct timespec timestamp; +__u32 reserved[9 ]; +__u8 data[64 ]; +}; + +struct v4l2_event_subscription { +__u32 type; +__u32 reserved[7 ]; +}; + +#define V4L2_EVENT_PRIVATE_START 0x08000000 + +/* * A D V A N C E D D E B U G G I N G * * NOTE: EXPERIMENTAL API, NEVER RELY ON THIS IN APPLICATIONS!
@@ -1651,6 +1671,9 @@ struct v4l2_dbg_chip_ident {#endif #define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek) +#define VIDIOC_DQEVENT _IOR('V', 83, struct v4l2_event) +#define VIDIOC_SUBSCRIBE_EVENT _IOW('V', 84, struct v4l2_event_subscription) +#define VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 85, struct v4l2_event_subscription)/* Reminder: when adding new ioctls please add support for them to drivers/media/video/v4l2-compat-ioctl32.c as well! */
Signature · 1 line
1.5.6.5
PATCH v3 3/7 V4L: Events: Support event handling in do_ioctl
Add support for event handling to do_ioctl.
--- drivers/media/video/Makefile | 2 +- drivers/media/video/v4l2-ioctl.c | 48 ++++++++++++++++++++++++++++++++++++++ include/media/v4l2-ioctl.h | 9 +++++++ 3 files changed, 58 insertions(+), 1 deletions(-)
drivers/media/video/Makefile +1 -1
@@ -11,7 +11,7 @@ stkwebcam-objs := stk-webcam.o stk-sensor.o omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-subdev.o \ - v4l2-fh.o + v4l2-fh.o v4l2-event.o # V4L2 core modules
drivers/media/video/v4l2-ioctl.c +48 -0
55 lines not on this page · raw message
include/media/v4l2-ioctl.h +9 -0
@@ -21,6 +21,8 @@#include <linux/videodev2.h> #endif +struct v4l2_fh ; +struct v4l2_ioctl_ops {/* ioctl callbacks */
@@ -239,6 +241,13 @@ struct v4l2_ioctl_ops {int (*vidioc_enum_frameintervals) (struct file *file,void *fh,struct v4l2_frmivalenum *fival); +int (*vidioc_dqevent) (struct v4l2_fh *fh, +struct v4l2_event *ev); +int (*vidioc_subscribe_event) (struct v4l2_fh *fh, +struct v4l2_event_subscription *sub); +int (*vidioc_unsubscribe_event)(struct v4l2_fh *fh, +struct v4l2_event_subscription *sub); +/* For other private ioctls */ long (*vidioc_default) (struct file *file,void *fh,int cmd,void *arg);
Signature · 1 line
1.5.6.5
PATCH v3 4/7 V4L: Events: Add backend
Add event handling backend to V4L2. The backend handles event subscription and delivery to file handles. Event subscriptions are based on file handle. Events may be delivered to all subscribed file handles on a device independent of where they originate from.
--- drivers/media/video/v4l2-event.c | 258 ++++++++++++++++++++++++++++++++++++++ drivers/media/video/v4l2-fh.c | 4 + include/media/v4l2-event.h | 64 ++++++++++ include/media/v4l2-fh.h | 2 + 4 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/v4l2-event.c create mode 100644 include/media/v4l2-event.h
drivers/media/video/v4l2-event.c new file +258 -0
@@ -0,0 +1,258 @@ +/* +* drivers/media/video/v4l2-event.c +* +* V4L2 events. +* +* Copyright (C) 2009 Nokia Corporation. +* +* Contact: Sakari Ailus <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +*/ + +#include <media/v4l2-dev.h> +#include <media/v4l2-event.h> + +#include <linux/sched.h> + +/* In error case, return number of events *not* allocated. */ +int v4l2_event_alloc (struct v4l2_fh *fh,unsigned int n) +{ +struct v4l2_events *events = fh->events; +unsigned long flags; + +for (; n >0 ; n--) { +struct v4l2_kevent *kev; + + kev =kzalloc (sizeof (*kev),GFP_KERNEL ); +if (kev ==NULL ) +return -ENOMEM ; + +spin_lock_irqsave (&fh->vdev->fh_lock, flags); +list_add_tail (&kev->list, &events->free); +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); + } + +return n; +} +EXPORT_SYMBOL_GPL (v4l2_event_alloc); + +#define list_kfree (list, type, member) \ + while (!list_empty(list)) { \ + type *hi; \ + hi = list_first_entry(list, type, member); \ + list_del(&hi->member); \ + kfree(hi); \ + } + +void v4l2_event_exit (struct v4l2_fh *fh) +{ +struct v4l2_events *events = fh->events; + +if (!events) +return ; + + list_kfree(&events->free, struct v4l2_kevent, list); + list_kfree(&events->available, struct v4l2_kevent, list); + list_kfree(&events->subscribed, struct v4l2_subscribed_event, list); + +kfree (events); + fh->events =NULL ; +} +EXPORT_SYMBOL_GPL (v4l2_event_exit); + +int v4l2_event_init (struct v4l2_fh *fh,unsigned int n) +{ +int ret; + + fh->events =kzalloc (sizeof (*fh->events),GFP_KERNEL ); +if (fh->events ==NULL ) +return -ENOMEM ; + +init_waitqueue_head (&fh->events->wait); + +INIT_LIST_HEAD (&fh->events->free); +INIT_LIST_HEAD (&fh->events->available); +INIT_LIST_HEAD (&fh->events->subscribed); + + ret =v4l2_event_alloc (fh, n); +if (ret <0 ) +v4l2_event_exit (fh); + +return ret; +} +EXPORT_SYMBOL_GPL (v4l2_event_init); + +int v4l2_event_dequeue (struct v4l2_fh *fh,struct v4l2_event *event) +{ +struct v4l2_events *events = fh->events; +struct v4l2_kevent *kev; +unsigned long flags; + +spin_lock_irqsave (&fh->vdev->fh_lock, flags); + +if (list_empty (&events->available)) { +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); +return -ENOENT ; + } + + kev = list_first_entry(&events->available, struct v4l2_kevent, list); +list_move (&kev->list, &events->free); + + kev->event.count = !list_empty (&events->available); + + *event = kev->event; + +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (v4l2_event_dequeue); + +static struct v4l2_subscribed_event *__v4l2_event_subscribed ( +struct v4l2_fh *fh,u32 type) +{ +struct v4l2_events *events = fh->events; +struct v4l2_subscribed_event *sev; + +list_for_each_entry (sev, &events->subscribed, list) { +if (sev->type == type) +return sev; + } + +return NULL ; +} + +struct v4l2_subscribed_event *v4l2_event_subscribed ( +struct v4l2_fh *fh,u32 type) +{ +struct v4l2_subscribed_event *sev; +unsigned long flags; + +spin_lock_irqsave (&fh->vdev->fh_lock, flags); + + sev =__v4l2_event_subscribed (fh, type); + +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); + +return sev; +} +EXPORT_SYMBOL_GPL (v4l2_event_subscribed); + +void v4l2_event_queue (struct video_device *vdev,struct v4l2_event *ev) +{ +struct v4l2_fh *fh; +unsigned long flags; + +spin_lock_irqsave (&vdev->fh_lock, flags); + +list_for_each_entry (fh, &vdev->fh_list, list) { +struct v4l2_events *events = fh->events; +struct v4l2_kevent *kev; + +/* Do we have any free events and are we subscribed? */ +if (list_empty (&events->free) || + !__v4l2_event_subscribed (fh, ev->type)) +continue ; + +/* Take one and fill it. */ + kev = list_first_entry(&events->free, struct v4l2_kevent, list); + kev->event = *ev; +list_move_tail (&kev->list, &events->available); + +wake_up_all (&events->wait); + } + +spin_unlock_irqrestore (&vdev->fh_lock, flags); +} +EXPORT_SYMBOL_GPL (v4l2_event_queue); + +int v4l2_event_pending (struct v4l2_fh *fh) +{ +struct v4l2_events *events = fh->events; +unsigned long flags; +int ret; + +spin_lock_irqsave (&fh->vdev->fh_lock, flags); + ret = !list_empty (&events->available); +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); + +return ret; +} +EXPORT_SYMBOL_GPL (v4l2_event_pending); + +int v4l2_event_subscribe (struct v4l2_fh *fh, +struct v4l2_event_subscription *sub) +{ +struct v4l2_events *events = fh->events; +struct v4l2_subscribed_event *sev; +unsigned long flags; +int ret =0 ; + +/* Allow subscribing to valid events only. */ +if (sub->type <V4L2_EVENT_PRIVATE_START ) +switch (sub->type) { +default : +return -EINVAL ; + } + + sev =kmalloc (sizeof (*sev),GFP_KERNEL ); +if (!sev) +return -ENOMEM ; + +spin_lock_irqsave (&fh->vdev->fh_lock, flags); + +if (__v4l2_event_subscribed (fh, sub->type) !=NULL ) { + ret = -EBUSY ; + goto out; + } + +INIT_LIST_HEAD (&sev->list); + sev->type = sub->type; + +list_add (&sev->list, &events->subscribed); + +out: +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); + +if (ret) +kfree (sev); + +return ret; +} +EXPORT_SYMBOL_GPL (v4l2_event_subscribe); + +int v4l2_event_unsubscribe (struct v4l2_fh *fh, +struct v4l2_event_subscription *sub) +{ +struct v4l2_subscribed_event *sev; +unsigned long flags; + +spin_lock_irqsave (&fh->vdev->fh_lock, flags); + + sev =__v4l2_event_subscribed (fh, sub->type); + +if (sev ==NULL ) { +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); +return -EINVAL ; + } + +list_del (&sev->list); + +spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (v4l2_event_unsubscribe);
drivers/media/video/v4l2-fh.c +4 -0
@@ -24,6 +24,7 @@#include <media/v4l2-dev.h> #include <media/v4l2-fh.h> +#include <media/v4l2-event.h> void v4l2_fh_init (struct video_device *vdev,struct v4l2_fh *fh) {
@@ -54,6 +55,9 @@ EXPORT_SYMBOL_GPL(v4l2_fh_del);void v4l2_fh_exit (struct v4l2_fh *fh) {BUG_ON (fh->vdev ==NULL ); + +v4l2_event_exit (fh); + fh->vdev =NULL ; }EXPORT_SYMBOL_GPL (v4l2_fh_exit);
include/media/v4l2-event.h new file +64 -0
64 lines not on this page · raw message
include/media/v4l2-fh.h +2 -0
@@ -31,10 +31,12 @@#include <asm/atomic.h> struct video_device ; +struct v4l2_events ;struct v4l2_fh {struct list_head list;struct video_device *vdev; +struct v4l2_events *events;/* events, pending and subscribed */ };void v4l2_fh_init (struct video_device *vdev,struct v4l2_fh *fh);
Signature · 1 line
1.5.6.5
PATCH v3 5/7 V4L: Events: Count event queue length
Update the count field properly by setting it to exactly to number of further available events.
--- drivers/media/video/v4l2-event.c | 27 +++++++++++++++------------ include/media/v4l2-event.h | 6 +++++- 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/media/video/v4l2-event.c +15 -12
@@ -36,6 +36,9 @@ int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n)for (; n >0 ; n--) {struct v4l2_kevent *kev; +if (atomic_read (&events->max_events) <=0 ) +return -ENOMEM ; + kev =kzalloc (sizeof (*kev),GFP_KERNEL );if (kev ==NULL )return -ENOMEM ;
@@ -43,9 +46,10 @@ int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n)spin_lock_irqsave (&fh->vdev->fh_lock, flags);list_add_tail (&kev->list, &events->free);spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); +atomic_dec (&events->max_events); } -return n; +return 0 ; }EXPORT_SYMBOL_GPL (v4l2_event_alloc);
@@ -73,7 +77,7 @@ void v4l2_event_exit(struct v4l2_fh *fh) }EXPORT_SYMBOL_GPL (v4l2_event_exit); -int v4l2_event_init (struct v4l2_fh *fh,unsigned int n) +int v4l2_event_init (struct v4l2_fh *fh,unsigned int n,unsigned int max_events) {int ret;
@@ -87,6 +91,9 @@ int v4l2_event_init(struct v4l2_fh *fh, unsigned int n)INIT_LIST_HEAD (&fh->events->available);INIT_LIST_HEAD (&fh->events->subscribed); +atomic_set (&fh->events->navailable,0 ); +atomic_set (&fh->events->max_events, max_events); + ret =v4l2_event_alloc (fh, n);if (ret <0 )v4l2_event_exit (fh);
@@ -108,10 +115,12 @@ int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event)return -ENOENT ; } +BUG_ON (&events->navailable ==0 ); + kev = list_first_entry(&events->available, struct v4l2_kevent, list);list_move (&kev->list, &events->free); - kev->event.count = !list_empty (&events->available); + kev->event.count =atomic_dec_return (&events->navailable); *event = kev->event;
@@ -172,6 +181,8 @@ void v4l2_event_queue(struct video_device *vdev, struct v4l2_event *ev) kev->event = *ev;list_move_tail (&kev->list, &events->available); +atomic_inc (&events->navailable); +wake_up_all (&events->wait); }
@@ -181,15 +192,7 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue);int v4l2_event_pending (struct v4l2_fh *fh) { -struct v4l2_events *events = fh->events; -unsigned long flags; -int ret; - -spin_lock_irqsave (&fh->vdev->fh_lock, flags); - ret = !list_empty (&events->available); -spin_unlock_irqrestore (&fh->vdev->fh_lock, flags); - -return ret; +return atomic_read (&fh->events->navailable); }EXPORT_SYMBOL_GPL (v4l2_event_pending);
include/media/v4l2-event.h +5 -1
@@ -28,6 +28,8 @@#include <linux/types.h> #include <linux/videodev2.h> +#include <asm/atomic.h> +struct v4l2_fh ;struct video_device ;
@@ -45,11 +47,13 @@ struct v4l2_events {wait_queue_head_t wait;struct list_head subscribed;/* Subscribed events */ struct list_head available;/* Dequeueable event */ +atomic_t navailable; +atomic_t max_events;/* Never allocate more. */ struct list_head free;/* Events ready for use */ };int v4l2_event_alloc (struct v4l2_fh *fh,unsigned int n); -int v4l2_event_init (struct v4l2_fh *fh,unsigned int n); +int v4l2_event_init (struct v4l2_fh *fh,unsigned int n,unsigned int max_alloc);void v4l2_event_exit (struct v4l2_fh *fh);int v4l2_event_dequeue (struct v4l2_fh *fh,struct v4l2_event *event); struct v4l2_subscribed_event *v4l2_event_subscribed(
Signature · 1 line
1.5.6.5
PATCH v3 6/7 V4L: Events: Sequence numbers
Add sequence numbers to events.
--- drivers/media/video/v4l2-event.c | 15 ++++++++++++--- include/media/v4l2-event.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/media/video/v4l2-event.c +12 -3
@@ -93,6 +93,7 @@ int v4l2_event_init(struct v4l2_fh *fh, unsigned int n, unsigned int max_events)atomic_set (&fh->events->navailable,0 );atomic_set (&fh->events->max_events, max_events); +atomic_set (&fh->events->sequence,-1 ); ret =v4l2_event_alloc (fh, n);if (ret <0 )
@@ -170,15 +171,23 @@ void v4l2_event_queue(struct video_device *vdev, struct v4l2_event *ev)list_for_each_entry (fh, &vdev->fh_list, list) {struct v4l2_events *events = fh->events;struct v4l2_kevent *kev; +u32 sequence; -/* Do we have any free events and are we subscribed? */ -if (list_empty (&events->free) || - !__v4l2_event_subscribed (fh, ev->type)) +/* Are we subscribed? */ +if (!__v4l2_event_subscribed (fh, ev->type)) +continue ; + +/* Increase event sequence number on fh. */ + sequence =atomic_inc_return (&events->sequence); + +/* Do we have any free events? */ +if (list_empty (&events->free))continue ;/* Take one and fill it. */ kev = list_first_entry(&events->free, struct v4l2_kevent, list); kev->event = *ev; + kev->event.sequence = sequence;list_move_tail (&kev->list, &events->available);atomic_inc (&events->navailable);
include/media/v4l2-event.h +1 -0
@@ -50,6 +50,7 @@ struct v4l2_events {atomic_t navailable;atomic_t max_events;/* Never allocate more. */ struct list_head free;/* Events ready for use */ +atomic_t sequence; };int v4l2_event_alloc (struct v4l2_fh *fh,unsigned int n);
Signature · 1 line
1.5.6.5
PATCH v3 7/7 V4L: Events: Support all events
Add support for subscribing all events with a special id V4L2_EVENT_ALL. If V4L2_EVENT_ALL is subscribed, no other events may be subscribed. Otherwise V4L2_EVENT_ALL is considered just as any other event.
--- drivers/media/video/v4l2-event.c | 13 ++++++++++++- include/linux/videodev2.h | 1 + 2 files changed, 13 insertions(+), 1 deletions(-)
drivers/media/video/v4l2-event.c +12 -1
@@ -137,6 +137,14 @@ static struct v4l2_subscribed_event *__v4l2_event_subscribed(struct v4l2_events *events = fh->events;struct v4l2_subscribed_event *sev; +if (list_empty (&events->subscribed)) +return NULL ; + + sev =list_entry (events->subscribed.next, + struct v4l2_subscribed_event, list); +if (sev->type ==V4L2_EVENT_ALL ) +return sev; +list_for_each_entry (sev, &events->subscribed, list) {if (sev->type == type)return sev;
@@ -216,6 +224,8 @@ int v4l2_event_subscribe(struct v4l2_fh *fh,/* Allow subscribing to valid events only. */ if (sub->type <V4L2_EVENT_PRIVATE_START )switch (sub->type) { +case V4L2_EVENT_ALL : +break ;default :return -EINVAL ; }
@@ -256,7 +266,8 @@ int v4l2_event_unsubscribe(struct v4l2_fh *fh, sev =__v4l2_event_subscribed (fh, sub->type); -if (sev ==NULL ) { +if (sev ==NULL || + (sub->type !=V4L2_EVENT_ALL && sev->type ==V4L2_EVENT_ALL )) {spin_unlock_irqrestore (&fh->vdev->fh_lock, flags);return -EINVAL ; }
include/linux/videodev2.h +1 -0
@@ -1553,6 +1553,7 @@ struct v4l2_event_subscription {__u32 reserved[7 ]; }; +#define V4L2_EVENT_ALL 0#define V4L2_EVENT_PRIVATE_START 0x08000000/*
Signature · 1 line
1.5.6.5