[question] v4l read() operation

3 messages, 2 authors, 2012-02-28 · open the first message on its own page

[question] v4l read() operation

From: Ezequiel García <hidden>
Date: 2012-02-25 22:29:53

Hi,

If I register a video device with this fops:

static const struct v4l2_file_operations v4l2_fops = {
        .owner      = THIS_MODULE,
        .open        = xxx_open,
        .unlocked_ioctl = xxx_unlocked_ioctl,
        .poll           = xxx_poll,
        .mmap      = xxx_mmap,
};

then if I "cat" the device

$ cat /dev/video0

Who is supporting read() ?

I thought it could be v4l2_read(),
however this function seems to return EINVAL:

static ssize_t v4l2_read(struct file *filp, char __user *buf,
                size_t sz, loff_t *off)
{
        struct video_device *vdev = video_devdata(filp);
        int ret = -ENODEV;

        if (!vdev->fops->read)
                return -EINVAL;
        if (vdev->lock && mutex_lock_interruptible(vdev->lock))
                return -ERESTARTSYS;
        if (video_is_registered(vdev))
                ret = vdev->fops->read(filp, buf, sz, off);
        if (vdev->lock)
                mutex_unlock(vdev->lock);
        return ret;
}

Thanks,
Ezequiel.

Re: [question] v4l read() operation

From: Dave Hylands <hidden>
Date: 2012-02-25 23:14:37

Hi Ezequiel

2012/2/25 Ezequiel Garc?a [off-list ref]:
Hi,

If I register a video device with this fops:

static const struct v4l2_file_operations v4l2_fops = {
? ? ? ?.owner ? ? ?= THIS_MODULE,
? ? ? ?.open ? ? ? ?= xxx_open,
? ? ? ?.unlocked_ioctl = xxx_unlocked_ioctl,
? ? ? ?.poll ? ? ? ? ? = xxx_poll,
? ? ? ?.mmap ? ? ?= xxx_mmap,
};

then if I "cat" the device

$ cat /dev/video0

Who is supporting read() ?

I thought it could be v4l2_read(),
however this function seems to return EINVAL:

static ssize_t v4l2_read(struct file *filp, char __user *buf,
? ? ? ? ? ? ? ?size_t sz, loff_t *off)
{
? ? ? ?struct video_device *vdev = video_devdata(filp);
? ? ? ?int ret = -ENODEV;

? ? ? ?if (!vdev->fops->read)
? ? ? ? ? ? ? ?return -EINVAL;
? ? ? ?if (vdev->lock && mutex_lock_interruptible(vdev->lock))
? ? ? ? ? ? ? ?return -ERESTARTSYS;
? ? ? ?if (video_is_registered(vdev))
? ? ? ? ? ? ? ?ret = vdev->fops->read(filp, buf, sz, off);
? ? ? ?if (vdev->lock)
? ? ? ? ? ? ? ?mutex_unlock(vdev->lock);
? ? ? ?return ret;
}
I'm not all that familiar with v4l, but based on what you've posted,
you need to populate the read routine in your v4l2_fops structure to
support read.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com

Re: [question] v4l read() operation

From: Ezequiel García <hidden>
Date: 2012-02-28 00:11:30

Hi Dave,

2012/2/25 Dave Hylands [off-list ref]:
I'm not all that familiar with v4l, but based on what you've posted,
you need to populate the read routine in your v4l2_fops structure to
support read.
My bad! You are totally right: I forgot about my webcam.
When I did:

$ cat /dev/video0

I was actually getting data from my webcam (which supports read),
and not from the easycap device, which is /dev/video1.

So, everything makes sense now:

$ cat /dev/video1

...
open("/dev/video1", O_RDONLY|O_LARGEFILE) = 3
...
read(3, 0x8835000, 32768)               = -1 EINVAL (Invalid argument)

This is clearly shown by the piece of code mentioned before.

Thanks and sorry for the noise,
Ezequiel.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help