aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/video4linux/v4l2-framework.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/video4linux/v4l2-framework.txt')
-rw-r--r--Documentation/video4linux/v4l2-framework.txt59
1 files changed, 37 insertions, 22 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index cf21f7aae97..f8dcabf7852 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -817,11 +817,7 @@ int my_open(struct file *file)
817 817
818 ... 818 ...
819 819
820 ret = v4l2_fh_init(&my_fh->fh, vfd); 820 v4l2_fh_init(&my_fh->fh, vfd);
821 if (ret) {
822 kfree(my_fh);
823 return ret;
824 }
825 821
826 ... 822 ...
827 823
@@ -844,7 +840,7 @@ int my_release(struct file *file)
844 840
845Below is a short description of the v4l2_fh functions used: 841Below is a short description of the v4l2_fh functions used:
846 842
847int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev) 843void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
848 844
849 Initialise the file handle. This *MUST* be performed in the driver's 845 Initialise the file handle. This *MUST* be performed in the driver's
850 v4l2_file_operations->open() handler. 846 v4l2_file_operations->open() handler.
@@ -901,14 +897,38 @@ V4L2 events
901The V4L2 events provide a generic way to pass events to user space. 897The V4L2 events provide a generic way to pass events to user space.
902The driver must use v4l2_fh to be able to support V4L2 events. 898The driver must use v4l2_fh to be able to support V4L2 events.
903 899
904Useful functions: 900Events are defined by a type and an optional ID. The ID may refer to a V4L2
901object such as a control ID. If unused, then the ID is 0.
902
903When the user subscribes to an event the driver will allocate a number of
904kevent structs for that event. So every (type, ID) event tuple will have
905its own set of kevent structs. This guarantees that if a driver is generating
906lots of events of one type in a short time, then that will not overwrite
907events of another type.
908
909But if you get more events of one type than the number of kevents that were
910reserved, then the oldest event will be dropped and the new one added.
911
912Furthermore, the internal struct v4l2_subscribed_event has merge() and
913replace() callbacks which drivers can set. These callbacks are called when
914a new event is raised and there is no more room. The replace() callback
915allows you to replace the payload of the old event with that of the new event,
916merging any relevant data from the old payload into the new payload that
917replaces it. It is called when this event type has only one kevent struct
918allocated. The merge() callback allows you to merge the oldest event payload
919into that of the second-oldest event payload. It is called when there are two
920or more kevent structs allocated.
905 921
906- v4l2_event_alloc() 922This way no status information is lost, just the intermediate steps leading
923up to that state.
907 924
908 To use events, the driver must allocate events for the file handle. By 925A good example of these replace/merge callbacks is in v4l2-event.c:
909 calling the function more than once, the driver may assure that at least n 926ctrls_replace() and ctrls_merge() callbacks for the control event.
910 events in total have been allocated. The function may not be called in 927
911 atomic context. 928Note: these callbacks can be called from interrupt context, so they must be
929fast.
930
931Useful functions:
912 932
913- v4l2_event_queue() 933- v4l2_event_queue()
914 934
@@ -920,7 +940,9 @@ Useful functions:
920 940
921 The video_device->ioctl_ops->vidioc_subscribe_event must check the driver 941 The video_device->ioctl_ops->vidioc_subscribe_event must check the driver
922 is able to produce events with specified event id. Then it calls 942 is able to produce events with specified event id. Then it calls
923 v4l2_event_subscribe() to subscribe the event. 943 v4l2_event_subscribe() to subscribe the event. The last argument is the
944 size of the event queue for this event. If it is 0, then the framework
945 will fill in a default value (this depends on the event type).
924 946
925- v4l2_event_unsubscribe() 947- v4l2_event_unsubscribe()
926 948
@@ -935,14 +957,8 @@ Useful functions:
935 957
936 Returns the number of pending events. Useful when implementing poll. 958 Returns the number of pending events. Useful when implementing poll.
937 959
938Drivers do not initialise events directly. The events are initialised
939through v4l2_fh_init() if video_device->ioctl_ops->vidioc_subscribe_event is
940non-NULL. This *MUST* be performed in the driver's
941v4l2_file_operations->open() handler.
942
943Events are delivered to user space through the poll system call. The driver 960Events are delivered to user space through the poll system call. The driver
944can use v4l2_fh->events->wait wait_queue_head_t as the argument for 961can use v4l2_fh->wait (a wait_queue_head_t) as the argument for poll_wait().
945poll_wait().
946 962
947There are standard and private events. New standard events must use the 963There are standard and private events. New standard events must use the
948smallest available event type. The drivers must allocate their events from 964smallest available event type. The drivers must allocate their events from
@@ -952,5 +968,4 @@ The first event type in the class is reserved for future use, so the first
952available event type is 'class base + 1'. 968available event type is 'class base + 1'.
953 969
954An example on how the V4L2 events may be used can be found in the OMAP 970An example on how the V4L2 events may be used can be found in the OMAP
9553 ISP driver available at <URL:http://gitorious.org/omap3camera> as of 9713 ISP driver (drivers/media/video/omap3isp).
956writing this.