diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-07-02 04:43:34 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-07-06 16:36:46 -0400 |
commit | 4a77a8361fe79b78b741640b484a97c8d47e307f (patch) | |
tree | e862f23184f8764d174dbc7f8d932d70aff0f5c4 /Documentation/video4linux | |
parent | 387c71b262a7a62d271dc9deb00c173264e33357 (diff) |
[media] v4l2-framework.txt: Update the locking documentation
This documents the new queue->lock and how to use it. It also removes the
documentation of v4l2_disable_ioctl_locking: this is only used in gspca and
will be removed once gspca has been converted to vb2.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'Documentation/video4linux')
-rw-r--r-- | Documentation/video4linux/v4l2-framework.txt | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index 1f5905270050..89318be6c1d2 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt | |||
@@ -594,6 +594,15 @@ You should also set these fields: | |||
594 | unlocked_ioctl file operation is called this lock will be taken by the | 594 | unlocked_ioctl file operation is called this lock will be taken by the |
595 | core and released afterwards. See the next section for more details. | 595 | core and released afterwards. See the next section for more details. |
596 | 596 | ||
597 | - queue: a pointer to the struct vb2_queue associated with this device node. | ||
598 | If queue is non-NULL, and queue->lock is non-NULL, then queue->lock is | ||
599 | used for the queuing ioctls (VIDIOC_REQBUFS, CREATE_BUFS, QBUF, DQBUF, | ||
600 | QUERYBUF, PREPARE_BUF, STREAMON and STREAMOFF) instead of the lock above. | ||
601 | That way the vb2 queuing framework does not have to wait for other ioctls. | ||
602 | This queue pointer is also used by the vb2 helper functions to check for | ||
603 | queuing ownership (i.e. is the filehandle calling it allowed to do the | ||
604 | operation). | ||
605 | |||
597 | - prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY. | 606 | - prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY. |
598 | If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device. | 607 | If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device. |
599 | If you want to have a separate priority state per (group of) device node(s), | 608 | If you want to have a separate priority state per (group of) device node(s), |
@@ -647,47 +656,43 @@ manually set the struct media_entity type and name fields. | |||
647 | A reference to the entity will be automatically acquired/released when the | 656 | A reference to the entity will be automatically acquired/released when the |
648 | video device is opened/closed. | 657 | video device is opened/closed. |
649 | 658 | ||
650 | v4l2_file_operations and locking | 659 | ioctls and locking |
651 | -------------------------------- | 660 | ------------------ |
652 | |||
653 | You can set a pointer to a mutex_lock in struct video_device. Usually this | ||
654 | will be either a top-level mutex or a mutex per device node. By default this | ||
655 | lock will be used for unlocked_ioctl, but you can disable locking for | ||
656 | selected ioctls by calling: | ||
657 | |||
658 | void v4l2_disable_ioctl_locking(struct video_device *vdev, unsigned int cmd); | ||
659 | |||
660 | E.g.: v4l2_disable_ioctl_locking(vdev, VIDIOC_DQBUF); | ||
661 | 661 | ||
662 | You have to call this before you register the video_device. | 662 | The V4L core provides optional locking services. The main service is the |
663 | lock field in struct video_device, which is a pointer to a mutex. If you set | ||
664 | this pointer, then that will be used by unlocked_ioctl to serialize all ioctls. | ||
663 | 665 | ||
664 | Particularly with USB drivers where certain commands such as setting controls | 666 | If you are using the videobuf2 framework, then there is a second lock that you |
665 | can take a long time you may want to do your own locking for the buffer queuing | 667 | can set: video_device->queue->lock. If set, then this lock will be used instead |
666 | ioctls. | 668 | of video_device->lock to serialize all queuing ioctls (see the previous section |
669 | for the full list of those ioctls). | ||
667 | 670 | ||
668 | If you want still finer-grained locking then you have to set mutex_lock to NULL | 671 | The advantage of using a different lock for the queuing ioctls is that for some |
669 | and do you own locking completely. | 672 | drivers (particularly USB drivers) certain commands such as setting controls |
673 | can take a long time, so you want to use a separate lock for the buffer queuing | ||
674 | ioctls. That way your VIDIOC_DQBUF doesn't stall because the driver is busy | ||
675 | changing the e.g. exposure of the webcam. | ||
670 | 676 | ||
671 | It is up to the driver developer to decide which method to use. However, if | 677 | Of course, you can always do all the locking yourself by leaving both lock |
672 | your driver has high-latency operations (for example, changing the exposure | 678 | pointers at NULL. |
673 | of a USB webcam might take a long time), then you might be better off with | ||
674 | doing your own locking if you want to allow the user to do other things with | ||
675 | the device while waiting for the high-latency command to finish. | ||
676 | 679 | ||
677 | If a lock is specified then all ioctl commands will be serialized on that | 680 | If you use the old videobuf then you must pass the video_device lock to the |
678 | lock. If you use videobuf then you must pass the same lock to the videobuf | 681 | videobuf queue initialize function: if videobuf has to wait for a frame to |
679 | queue initialize function: if videobuf has to wait for a frame to arrive, then | 682 | arrive, then it will temporarily unlock the lock and relock it afterwards. If |
680 | it will temporarily unlock the lock and relock it afterwards. If your driver | 683 | your driver also waits in the code, then you should do the same to allow other |
681 | also waits in the code, then you should do the same to allow other processes | 684 | processes to access the device node while the first process is waiting for |
682 | to access the device node while the first process is waiting for something. | 685 | something. |
683 | 686 | ||
684 | In the case of videobuf2 you will need to implement the wait_prepare and | 687 | In the case of videobuf2 you will need to implement the wait_prepare and |
685 | wait_finish callbacks to unlock/lock if applicable. In particular, if you use | 688 | wait_finish callbacks to unlock/lock if applicable. If you use the queue->lock |
686 | the lock in struct video_device then you must unlock/lock this mutex in | 689 | pointer, then you can use the helper functions vb2_ops_wait_prepare/finish. |
687 | wait_prepare and wait_finish. | 690 | |
688 | 691 | The implementation of a hotplug disconnect should also take the lock from | |
689 | The implementation of a hotplug disconnect should also take the lock before | 692 | video_device before calling v4l2_device_disconnect. If you are also using |
690 | calling v4l2_device_disconnect. | 693 | video_device->queue->lock, then you have to first lock video_device->queue->lock |
694 | followed by video_device->lock. That way you can be sure no ioctl is running | ||
695 | when you call v4l2_device_disconnect. | ||
691 | 696 | ||
692 | video_device registration | 697 | video_device registration |
693 | ------------------------- | 698 | ------------------------- |