diff options
Diffstat (limited to 'Documentation/video4linux/v4l2-framework.txt')
-rw-r--r-- | Documentation/video4linux/v4l2-framework.txt | 59 |
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 | ||
845 | Below is a short description of the v4l2_fh functions used: | 841 | Below is a short description of the v4l2_fh functions used: |
846 | 842 | ||
847 | int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev) | 843 | void 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 | |||
901 | The V4L2 events provide a generic way to pass events to user space. | 897 | The V4L2 events provide a generic way to pass events to user space. |
902 | The driver must use v4l2_fh to be able to support V4L2 events. | 898 | The driver must use v4l2_fh to be able to support V4L2 events. |
903 | 899 | ||
904 | Useful functions: | 900 | Events are defined by a type and an optional ID. The ID may refer to a V4L2 |
901 | object such as a control ID. If unused, then the ID is 0. | ||
902 | |||
903 | When the user subscribes to an event the driver will allocate a number of | ||
904 | kevent structs for that event. So every (type, ID) event tuple will have | ||
905 | its own set of kevent structs. This guarantees that if a driver is generating | ||
906 | lots of events of one type in a short time, then that will not overwrite | ||
907 | events of another type. | ||
908 | |||
909 | But if you get more events of one type than the number of kevents that were | ||
910 | reserved, then the oldest event will be dropped and the new one added. | ||
911 | |||
912 | Furthermore, the internal struct v4l2_subscribed_event has merge() and | ||
913 | replace() callbacks which drivers can set. These callbacks are called when | ||
914 | a new event is raised and there is no more room. The replace() callback | ||
915 | allows you to replace the payload of the old event with that of the new event, | ||
916 | merging any relevant data from the old payload into the new payload that | ||
917 | replaces it. It is called when this event type has only one kevent struct | ||
918 | allocated. The merge() callback allows you to merge the oldest event payload | ||
919 | into that of the second-oldest event payload. It is called when there are two | ||
920 | or more kevent structs allocated. | ||
905 | 921 | ||
906 | - v4l2_event_alloc() | 922 | This way no status information is lost, just the intermediate steps leading |
923 | up to that state. | ||
907 | 924 | ||
908 | To use events, the driver must allocate events for the file handle. By | 925 | A 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 | 926 | ctrls_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. | 928 | Note: these callbacks can be called from interrupt context, so they must be |
929 | fast. | ||
930 | |||
931 | Useful 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 | ||
938 | Drivers do not initialise events directly. The events are initialised | ||
939 | through v4l2_fh_init() if video_device->ioctl_ops->vidioc_subscribe_event is | ||
940 | non-NULL. This *MUST* be performed in the driver's | ||
941 | v4l2_file_operations->open() handler. | ||
942 | |||
943 | Events are delivered to user space through the poll system call. The driver | 960 | Events are delivered to user space through the poll system call. The driver |
944 | can use v4l2_fh->events->wait wait_queue_head_t as the argument for | 961 | can use v4l2_fh->wait (a wait_queue_head_t) as the argument for poll_wait(). |
945 | poll_wait(). | ||
946 | 962 | ||
947 | There are standard and private events. New standard events must use the | 963 | There are standard and private events. New standard events must use the |
948 | smallest available event type. The drivers must allocate their events from | 964 | smallest 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 | |||
952 | available event type is 'class base + 1'. | 968 | available event type is 'class base + 1'. |
953 | 969 | ||
954 | An example on how the V4L2 events may be used can be found in the OMAP | 970 | An example on how the V4L2 events may be used can be found in the OMAP |
955 | 3 ISP driver available at <URL:http://gitorious.org/omap3camera> as of | 971 | 3 ISP driver (drivers/media/video/omap3isp). |
956 | writing this. | ||