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.txt143
1 files changed, 137 insertions, 6 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index 5155700c206b..e831aaca66f8 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -545,12 +545,11 @@ unregister them:
545This will remove the device nodes from sysfs (causing udev to remove them 545This will remove the device nodes from sysfs (causing udev to remove them
546from /dev). 546from /dev).
547 547
548After video_unregister_device() returns no new opens can be done. 548After video_unregister_device() returns no new opens can be done. However,
549 549in the case of USB devices some application might still have one of these
550However, in the case of USB devices some application might still have one 550device nodes open. So after the unregister all file operations will return
551of these device nodes open. You should block all new accesses to read, 551an error as well, except for the ioctl and unlocked_ioctl file operations:
552write, poll, etc. except possibly for certain ioctl operations like 552those will still be passed on since some buffer ioctls may still be needed.
553queueing buffers.
554 553
555When the last user of the video device node exits, then the vdev->release() 554When the last user of the video device node exits, then the vdev->release()
556callback is called and you can do the final cleanup there. 555callback is called and you can do the final cleanup there.
@@ -609,3 +608,135 @@ scatter/gather method (videobuf-dma-sg), DMA with linear access
609 608
610Please see Documentation/video4linux/videobuf for more information on how 609Please see Documentation/video4linux/videobuf for more information on how
611to use the videobuf layer. 610to use the videobuf layer.
611
612struct v4l2_fh
613--------------
614
615struct v4l2_fh provides a way to easily keep file handle specific data
616that is used by the V4L2 framework. Using v4l2_fh is optional for
617drivers.
618
619The users of v4l2_fh (in the V4L2 framework, not the driver) know
620whether a driver uses v4l2_fh as its file->private_data pointer by
621testing the V4L2_FL_USES_V4L2_FH bit in video_device->flags.
622
623Useful functions:
624
625- v4l2_fh_init()
626
627 Initialise the file handle. This *MUST* be performed in the driver's
628 v4l2_file_operations->open() handler.
629
630- v4l2_fh_add()
631
632 Add a v4l2_fh to video_device file handle list. May be called after
633 initialising the file handle.
634
635- v4l2_fh_del()
636
637 Unassociate the file handle from video_device(). The file handle
638 exit function may now be called.
639
640- v4l2_fh_exit()
641
642 Uninitialise the file handle. After uninitialisation the v4l2_fh
643 memory can be freed.
644
645struct v4l2_fh is allocated as a part of the driver's own file handle
646structure and is set to file->private_data in the driver's open
647function by the driver. Drivers can extract their own file handle
648structure by using the container_of macro. Example:
649
650struct my_fh {
651 int blah;
652 struct v4l2_fh fh;
653};
654
655...
656
657int my_open(struct file *file)
658{
659 struct my_fh *my_fh;
660 struct video_device *vfd;
661 int ret;
662
663 ...
664
665 ret = v4l2_fh_init(&my_fh->fh, vfd);
666 if (ret)
667 return ret;
668
669 v4l2_fh_add(&my_fh->fh);
670
671 file->private_data = &my_fh->fh;
672
673 ...
674}
675
676int my_release(struct file *file)
677{
678 struct v4l2_fh *fh = file->private_data;
679 struct my_fh *my_fh = container_of(fh, struct my_fh, fh);
680
681 ...
682}
683
684V4L2 events
685-----------
686
687The V4L2 events provide a generic way to pass events to user space.
688The driver must use v4l2_fh to be able to support V4L2 events.
689
690Useful functions:
691
692- v4l2_event_alloc()
693
694 To use events, the driver must allocate events for the file handle. By
695 calling the function more than once, the driver may assure that at least n
696 events in total have been allocated. The function may not be called in
697 atomic context.
698
699- v4l2_event_queue()
700
701 Queue events to video device. The driver's only responsibility is to fill
702 in the type and the data fields. The other fields will be filled in by
703 V4L2.
704
705- v4l2_event_subscribe()
706
707 The video_device->ioctl_ops->vidioc_subscribe_event must check the driver
708 is able to produce events with specified event id. Then it calls
709 v4l2_event_subscribe() to subscribe the event.
710
711- v4l2_event_unsubscribe()
712
713 vidioc_unsubscribe_event in struct v4l2_ioctl_ops. A driver may use
714 v4l2_event_unsubscribe() directly unless it wants to be involved in
715 unsubscription process.
716
717 The special type V4L2_EVENT_ALL may be used to unsubscribe all events. The
718 drivers may want to handle this in a special way.
719
720- v4l2_event_pending()
721
722 Returns the number of pending events. Useful when implementing poll.
723
724Drivers do not initialise events directly. The events are initialised
725through v4l2_fh_init() if video_device->ioctl_ops->vidioc_subscribe_event is
726non-NULL. This *MUST* be performed in the driver's
727v4l2_file_operations->open() handler.
728
729Events are delivered to user space through the poll system call. The driver
730can use v4l2_fh->events->wait wait_queue_head_t as the argument for
731poll_wait().
732
733There are standard and private events. New standard events must use the
734smallest available event type. The drivers must allocate their events from
735their own class starting from class base. Class base is
736V4L2_EVENT_PRIVATE_START + n * 1000 where n is the lowest available number.
737The first event type in the class is reserved for future use, so the first
738available event type is 'class base + 1'.
739
740An example on how the V4L2 events may be used can be found in the OMAP
7413 ISP driver available at <URL:http://gitorious.org/omap3camera> as of
742writing this.