V4L2 Framework

Peter Teoh htmldeveloper at gmail.com
Sat Feb 23 19:37:34 EST 2013


Q1:

1.   go to your linux kernel source driver/media/video directory.
2.   ls *v4l* and u can see all the v4l related kernel sources.
3.   one of these is v4l2-ioctl.c which implement the interface when
userspace program makes an ioctl() call.
4.   all the parameters that userspace ioctl() can pass in are defined in,
for eg:

/* debug help functions                                               */
static const char *v4l2_ioctls[] = {
        [_IOC_NR(VIDIOC_QUERYCAP)]         = "VIDIOC_QUERYCAP",
        [_IOC_NR(VIDIOC_RESERVED)]         = "VIDIOC_RESERVED",
        [_IOC_NR(VIDIOC_ENUM_FMT)]         = "VIDIOC_ENUM_FMT",
        [_IOC_NR(VIDIOC_G_FMT)]            = "VIDIOC_G_FMT",
        [_IOC_NR(VIDIOC_S_FMT)]            = "VIDIOC_S_FMT",
        [_IOC_NR(VIDIOC_REQBUFS)]          = "VIDIOC_REQBUFS",
        [_IOC_NR(VIDIOC_QUERYBUF)]         = "VIDIOC_QUERYBUF",
        [_IOC_NR(VIDIOC_G_FBUF)]           = "VIDIOC_G_FBUF",
        [_IOC_NR(VIDIOC_S_FBUF)]           = "VIDIOC_S_FBUF",
        [_IOC_NR(VIDIOC_OVERLAY)]          = "VIDIOC_OVERLAY",
        [_IOC_NR(VIDIOC_QBUF)]             = "VIDIOC_QBUF",
        [_IOC_NR(VIDIOC_DQBUF)]            = "VIDIOC_DQBUF",
        [_IOC_NR(VIDIOC_STREAMON)]         = "VIDIOC_STREAMON",
        [_IOC_NR(VIDIOC_STREAMOFF)]        = "VIDIOC_STREAMOFF",
        [_IOC_NR(VIDIOC_G_PARM)]           = "VIDIOC_G_PARM",
        [_IOC_NR(VIDIOC_S_PARM)]           = "VIDIOC_S_PARM",
        [_IOC_NR(VIDIOC_G_STD)]            = "VIDIOC_G_STD",
        [_IOC_NR(VIDIOC_S_STD)]            = "VIDIOC_S_STD",
        [_IOC_NR(VIDIOC_ENUMSTD)]          = "VIDIOC_ENUMSTD",
        [_IOC_NR(VIDIOC_ENUMINPUT)]        = "VIDIOC_ENUMINPUT",
        [_IOC_NR(VIDIOC_G_CTRL)]           = "VIDIOC_G_CTRL",
        [_IOC_NR(VIDIOC_S_CTRL)]           = "VIDIOC_S_CTRL",
        [_IOC_NR(VIDIOC_G_TUNER)]          = "VIDIOC_G_TUNER",
        [_IOC_NR(VIDIOC_S_TUNER)]          = "VIDIOC_S_TUNER",
        [_IOC_NR(VIDIOC_G_AUDIO)]          = "VIDIOC_G_AUDIO",
        [_IOC_NR(VIDIOC_S_AUDIO)]          = "VIDIOC_S_AUDIO",

etc etc.

and for eg, the first item in the list - the userspace example are:

http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-querycap.html

(or more generally, http://linuxtv.org/downloads/v4l-dvb-apis/)

and another example is the v4l libraries:

libv4l-dev

and the whole series of V4L2 articles  (kernel) is here:

http://lwn.net/Articles/203924/   (your interests in ioctl() is here:
http://lwn.net/Articles/206765/)

and here (kernel+userspace):

http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/Intro-to-V4L2/

and this (userspace):

http://linuxtv.org/wiki/index.php/V4L2_Userspace_Library

and your question on buffer management in the kernel:

http://lwn.net/Articles/363349/

which also contains the answer to your question (NO, it is not the generic
layer for ALL devices - only some radio + video + dvb devices).

Q2:

dont quite understand u, but definitely capture and output buffer are
different, and memcpy operation can happened independently.

in videobuf2-core.c are defined all the core buffer operation:

EXPORT_SYMBOL(vb2_querybuf);
EXPORT_SYMBOL_GPL(vb2_reqbufs);
EXPORT_SYMBOL_GPL(vb2_create_bufs);
EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
EXPORT_SYMBOL_GPL(vb2_plane_cookie);
EXPORT_SYMBOL_GPL(vb2_buffer_done);
EXPORT_SYMBOL_GPL(vb2_prepare_buf);
EXPORT_SYMBOL_GPL(vb2_qbuf);
EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
EXPORT_SYMBOL_GPL(vb2_dqbuf);
EXPORT_SYMBOL_GPL(vb2_streamon);
EXPORT_SYMBOL_GPL(vb2_streamoff);
EXPORT_SYMBOL_GPL(vb2_mmap);
EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
EXPORT_SYMBOL_GPL(vb2_poll);
EXPORT_SYMBOL_GPL(vb2_queue_init);
EXPORT_SYMBOL_GPL(vb2_queue_release);
EXPORT_SYMBOL_GPL(vb2_read);
EXPORT_SYMBOL_GPL(vb2_write);

and v4l2-mem2mem.c:

EXPORT_SYMBOL(v4l2_m2m_get_vq);
EXPORT_SYMBOL_GPL(v4l2_m2m_next_buf);
EXPORT_SYMBOL_GPL(v4l2_m2m_buf_remove);
EXPORT_SYMBOL(v4l2_m2m_get_curr_priv);
EXPORT_SYMBOL(v4l2_m2m_job_finish);
EXPORT_SYMBOL_GPL(v4l2_m2m_reqbufs);
EXPORT_SYMBOL_GPL(v4l2_m2m_querybuf);
EXPORT_SYMBOL_GPL(v4l2_m2m_qbuf);
EXPORT_SYMBOL_GPL(v4l2_m2m_dqbuf);
EXPORT_SYMBOL_GPL(v4l2_m2m_streamon);
EXPORT_SYMBOL_GPL(v4l2_m2m_streamoff);
EXPORT_SYMBOL_GPL(v4l2_m2m_poll);
EXPORT_SYMBOL(v4l2_m2m_mmap);
EXPORT_SYMBOL_GPL(v4l2_m2m_init);
EXPORT_SYMBOL_GPL(v4l2_m2m_release);
EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_init);
EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_release);
EXPORT_SYMBOL_GPL(v4l2_m2m_buf_queue);

memcopy operation is vb2_mmap() or v4l2_m2m_mmap() for eg.

and for DMA it can be videobuf_dma_mmap() (for scatter-gather operation)
etc etc.   Search the same directories for how these are used by the
different drivers.

Q3:   device to device mapping, I think will be the "mem2mem" files in the
kernel source:

mem2mem_testdev.c    v4l2-mem2mem.c

and all the APIs u can use (inside kernel drivers) are listed above (as
EXPORT symbol).


On Mon, Feb 18, 2013 at 12:29 PM, Kaushal Billore <
kaushalbillore at hotmail.com> wrote:

> I have some doubt regarding Linux kernel V4l2 API's.
> When capture application calls Reqbuff ioctl to allocate n no of buffer
> which would belongs to v4l2 layer and display application calls the Reqbuff
> ioctl to allocate N no of buffer which would also belongs to device memory.
>
> Question:
> 1. V4l2 maintains the generic layer for all devices in which buffers can
> be allocated by any device and can be handle by any device?
>
> 2. If not then while capturing the data from capture device can capture
> device allocated buffer gets filled and while displaying the same data
> there memory copy happens between capture buffer and output buffers?
>
> 3. If not then I want to capture data from capture device and display onto
> display device through the v4l2 framework layer.
>
> Awaiting for responce!
>
> Thanks in advance
> Kaushal
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>


-- 
Regards,
Peter Teoh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130224/8539e1e9/attachment.html 


More information about the Kernelnewbies mailing list