diff options
Diffstat (limited to 'Documentation/video4linux/v4l2-framework.txt')
-rw-r--r-- | Documentation/video4linux/v4l2-framework.txt | 122 |
1 files changed, 24 insertions, 98 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index b806edaf3e75..5155700c206b 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt | |||
@@ -561,6 +561,8 @@ video_device helper functions | |||
561 | 561 | ||
562 | There are a few useful helper functions: | 562 | There are a few useful helper functions: |
563 | 563 | ||
564 | - file/video_device private data | ||
565 | |||
564 | You can set/get driver private data in the video_device struct using: | 566 | You can set/get driver private data in the video_device struct using: |
565 | 567 | ||
566 | void *video_get_drvdata(struct video_device *vdev); | 568 | void *video_get_drvdata(struct video_device *vdev); |
@@ -575,8 +577,7 @@ struct video_device *video_devdata(struct file *file); | |||
575 | 577 | ||
576 | returns the video_device belonging to the file struct. | 578 | returns the video_device belonging to the file struct. |
577 | 579 | ||
578 | The final helper function combines video_get_drvdata with | 580 | The video_drvdata function combines video_get_drvdata with video_devdata: |
579 | video_devdata: | ||
580 | 581 | ||
581 | void *video_drvdata(struct file *file); | 582 | void *video_drvdata(struct file *file); |
582 | 583 | ||
@@ -584,102 +585,27 @@ You can go from a video_device struct to the v4l2_device struct using: | |||
584 | 585 | ||
585 | struct v4l2_device *v4l2_dev = vdev->v4l2_dev; | 586 | struct v4l2_device *v4l2_dev = vdev->v4l2_dev; |
586 | 587 | ||
588 | - Device node name | ||
589 | |||
590 | The video_device node kernel name can be retrieved using | ||
591 | |||
592 | const char *video_device_node_name(struct video_device *vdev); | ||
593 | |||
594 | The name is used as a hint by userspace tools such as udev. The function | ||
595 | should be used where possible instead of accessing the video_device::num and | ||
596 | video_device::minor fields. | ||
597 | |||
598 | |||
587 | video buffer helper functions | 599 | video buffer helper functions |
588 | ----------------------------- | 600 | ----------------------------- |
589 | 601 | ||
590 | The v4l2 core API provides a standard method for dealing with video | 602 | The v4l2 core API provides a set of standard methods (called "videobuf") |
591 | buffers. Those methods allow a driver to implement read(), mmap() and | 603 | for dealing with video buffers. Those methods allow a driver to implement |
592 | overlay() on a consistent way. | 604 | read(), mmap() and overlay() in a consistent way. There are currently |
593 | 605 | methods for using video buffers on devices that supports DMA with | |
594 | There are currently methods for using video buffers on devices that | 606 | scatter/gather method (videobuf-dma-sg), DMA with linear access |
595 | supports DMA with scatter/gather method (videobuf-dma-sg), DMA with | 607 | (videobuf-dma-contig), and vmalloced buffers, mostly used on USB drivers |
596 | linear access (videobuf-dma-contig), and vmalloced buffers, mostly | 608 | (videobuf-vmalloc). |
597 | used on USB drivers (videobuf-vmalloc). | 609 | |
598 | 610 | Please see Documentation/video4linux/videobuf for more information on how | |
599 | Any driver using videobuf should provide operations (callbacks) for | 611 | to use the videobuf layer. |
600 | four handlers: | ||
601 | |||
602 | ops->buf_setup - calculates the size of the video buffers and avoid they | ||
603 | to waste more than some maximum limit of RAM; | ||
604 | ops->buf_prepare - fills the video buffer structs and calls | ||
605 | videobuf_iolock() to alloc and prepare mmaped memory; | ||
606 | ops->buf_queue - advices the driver that another buffer were | ||
607 | requested (by read() or by QBUF); | ||
608 | ops->buf_release - frees any buffer that were allocated. | ||
609 | |||
610 | In order to use it, the driver need to have a code (generally called at | ||
611 | interrupt context) that will properly handle the buffer request lists, | ||
612 | announcing that a new buffer were filled. | ||
613 | |||
614 | The irq handling code should handle the videobuf task lists, in order | ||
615 | to advice videobuf that a new frame were filled, in order to honor to a | ||
616 | request. The code is generally like this one: | ||
617 | if (list_empty(&dma_q->active)) | ||
618 | return; | ||
619 | |||
620 | buf = list_entry(dma_q->active.next, struct vbuffer, vb.queue); | ||
621 | |||
622 | if (!waitqueue_active(&buf->vb.done)) | ||
623 | return; | ||
624 | |||
625 | /* Some logic to handle the buf may be needed here */ | ||
626 | |||
627 | list_del(&buf->vb.queue); | ||
628 | do_gettimeofday(&buf->vb.ts); | ||
629 | wake_up(&buf->vb.done); | ||
630 | |||
631 | Those are the videobuffer functions used on drivers, implemented on | ||
632 | videobuf-core: | ||
633 | |||
634 | - Videobuf init functions | ||
635 | videobuf_queue_sg_init() | ||
636 | Initializes the videobuf infrastructure. This function should be | ||
637 | called before any other videobuf function on drivers that uses DMA | ||
638 | Scatter/Gather buffers. | ||
639 | |||
640 | videobuf_queue_dma_contig_init | ||
641 | Initializes the videobuf infrastructure. This function should be | ||
642 | called before any other videobuf function on drivers that need DMA | ||
643 | contiguous buffers. | ||
644 | |||
645 | videobuf_queue_vmalloc_init() | ||
646 | Initializes the videobuf infrastructure. This function should be | ||
647 | called before any other videobuf function on USB (and other drivers) | ||
648 | that need a vmalloced type of videobuf. | ||
649 | |||
650 | - videobuf_iolock() | ||
651 | Prepares the videobuf memory for the proper method (read, mmap, overlay). | ||
652 | |||
653 | - videobuf_queue_is_busy() | ||
654 | Checks if a videobuf is streaming. | ||
655 | |||
656 | - videobuf_queue_cancel() | ||
657 | Stops video handling. | ||
658 | |||
659 | - videobuf_mmap_free() | ||
660 | frees mmap buffers. | ||
661 | |||
662 | - videobuf_stop() | ||
663 | Stops video handling, ends mmap and frees mmap and other buffers. | ||
664 | |||
665 | - V4L2 api functions. Those functions correspond to VIDIOC_foo ioctls: | ||
666 | videobuf_reqbufs(), videobuf_querybuf(), videobuf_qbuf(), | ||
667 | videobuf_dqbuf(), videobuf_streamon(), videobuf_streamoff(). | ||
668 | |||
669 | - V4L1 api function (corresponds to VIDIOCMBUF ioctl): | ||
670 | videobuf_cgmbuf() | ||
671 | This function is used to provide backward compatibility with V4L1 | ||
672 | API. | ||
673 | |||
674 | - Some help functions for read()/poll() operations: | ||
675 | videobuf_read_stream() | ||
676 | For continuous stream read() | ||
677 | videobuf_read_one() | ||
678 | For snapshot read() | ||
679 | videobuf_poll_stream() | ||
680 | polling help function | ||
681 | |||
682 | The better way to understand it is to take a look at vivi driver. One | ||
683 | of the main reasons for vivi is to be a videobuf usage example. the | ||
684 | vivi_thread_tick() does the task that the IRQ callback would do on PCI | ||
685 | drivers (or the irq callback on USB). | ||