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.txt122
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
562There are a few useful helper functions: 562There are a few useful helper functions:
563 563
564- file/video_device private data
565
564You can set/get driver private data in the video_device struct using: 566You can set/get driver private data in the video_device struct using:
565 567
566void *video_get_drvdata(struct video_device *vdev); 568void *video_get_drvdata(struct video_device *vdev);
@@ -575,8 +577,7 @@ struct video_device *video_devdata(struct file *file);
575 577
576returns the video_device belonging to the file struct. 578returns the video_device belonging to the file struct.
577 579
578The final helper function combines video_get_drvdata with 580The video_drvdata function combines video_get_drvdata with video_devdata:
579video_devdata:
580 581
581void *video_drvdata(struct file *file); 582void *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
585struct v4l2_device *v4l2_dev = vdev->v4l2_dev; 586struct v4l2_device *v4l2_dev = vdev->v4l2_dev;
586 587
588- Device node name
589
590The video_device node kernel name can be retrieved using
591
592const char *video_device_node_name(struct video_device *vdev);
593
594The name is used as a hint by userspace tools such as udev. The function
595should be used where possible instead of accessing the video_device::num and
596video_device::minor fields.
597
598
587video buffer helper functions 599video buffer helper functions
588----------------------------- 600-----------------------------
589 601
590The v4l2 core API provides a standard method for dealing with video 602The v4l2 core API provides a set of standard methods (called "videobuf")
591buffers. Those methods allow a driver to implement read(), mmap() and 603for dealing with video buffers. Those methods allow a driver to implement
592overlay() on a consistent way. 604read(), mmap() and overlay() in a consistent way. There are currently
593 605methods for using video buffers on devices that supports DMA with
594There are currently methods for using video buffers on devices that 606scatter/gather method (videobuf-dma-sg), DMA with linear access
595supports DMA with scatter/gather method (videobuf-dma-sg), DMA with 607(videobuf-dma-contig), and vmalloced buffers, mostly used on USB drivers
596linear access (videobuf-dma-contig), and vmalloced buffers, mostly 608(videobuf-vmalloc).
597used on USB drivers (videobuf-vmalloc). 609
598 610Please see Documentation/video4linux/videobuf for more information on how
599Any driver using videobuf should provide operations (callbacks) for 611to use the videobuf layer.
600four handlers:
601
602ops->buf_setup - calculates the size of the video buffers and avoid they
603 to waste more than some maximum limit of RAM;
604ops->buf_prepare - fills the video buffer structs and calls
605 videobuf_iolock() to alloc and prepare mmaped memory;
606ops->buf_queue - advices the driver that another buffer were
607 requested (by read() or by QBUF);
608ops->buf_release - frees any buffer that were allocated.
609
610In order to use it, the driver need to have a code (generally called at
611interrupt context) that will properly handle the buffer request lists,
612announcing that a new buffer were filled.
613
614The irq handling code should handle the videobuf task lists, in order
615to advice videobuf that a new frame were filled, in order to honor to a
616request. 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
631Those are the videobuffer functions used on drivers, implemented on
632videobuf-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
682The better way to understand it is to take a look at vivi driver. One
683of the main reasons for vivi is to be a videobuf usage example. the
684vivi_thread_tick() does the task that the IRQ callback would do on PCI
685drivers (or the irq callback on USB).