X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vdummy;a=blobdiff_plain;f=vdummy.c;h=9848db63438ec41b19135c4aa23aa2e48792f2c8;hp=bf04eec46722b0c8ad7cf7ec22c9ea31445bfb5f;hb=9571424cab6f4f6c2d0711782f715e54310dcb81;hpb=019a9d6eb5da203b03caa54bcc30ab2507606cbe diff --git a/vdummy.c b/vdummy.c index bf04eec..9848db6 100644 --- a/vdummy.c +++ b/vdummy.c @@ -5,13 +5,16 @@ #include #include #include +#include #include #include #include #include +#include +#include struct buffer { - struct vb2_buffer vb; + struct vb2_v4l2_buffer vb; struct buffer *next; }; @@ -73,6 +76,7 @@ static int init(void) } mutex_init(&mutex); + spin_lock_init(&blist_lock); vbops.queue_setup = queue_setup; vbops.buf_prepare = buf_prepare; @@ -101,12 +105,16 @@ static int init(void) if(!(vdev = video_device_alloc())) { return -ENOMEM; } + memset(vdev, 0, sizeof *vdev); vdev->release = video_device_release; strcpy(vdev->name, KBUILD_MODNAME); vdev->fops = &fops; vdev->ioctl_ops = &iops; vdev->vfl_type = VFL_TYPE_GRABBER; + vdev->vfl_dir = VFL_DIR_RX; vdev->v4l2_dev = &v4l2_dev; + vdev->lock = &mutex; + vdev->queue = &vbq; fops.owner = THIS_MODULE; fops.open = v4l2_fh_open; @@ -131,6 +139,9 @@ static int init(void) iops.vidioc_expbuf = vb2_ioctl_expbuf; iops.vidioc_streamon = vb2_ioctl_streamon; iops.vidioc_streamoff = vb2_ioctl_streamoff; + iops.vidioc_log_status = v4l2_ctrl_log_status; + iops.vidioc_subscribe_event = v4l2_ctrl_subscribe_event; + iops.vidioc_unsubscribe_event = v4l2_event_unsubscribe; if((res = video_register_device(vdev, VFL_TYPE_GRABBER, -1)) != 0) { printk(KERN_ALERT "vdummy: failed to register video device\n"); @@ -160,7 +171,7 @@ static void shutdown(void) static int ioctl_querycap(struct file *file, void *fh, struct v4l2_capability *cap) { strcpy(cap->driver, KBUILD_MODNAME); - strcpy(cap->card, "dummy v4l2 dev"); + strcpy(cap->card, "Test V4L2 device"); strcpy(cap->bus_info, "nobus"); cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; @@ -257,7 +268,6 @@ static int buf_prepare(struct vb2_buffer *vb) printk(KERN_ALERT "vdummy: buffer too small\n"); return -EINVAL; } - vb2_set_plane_payload(vb, 0, frame_size); return 0; } @@ -282,7 +292,7 @@ static void clear_queue(enum vb2_buffer_state st) while(buflist) { struct buffer *buf = buflist; buflist = buflist->next; - vb2_buffer_done(&buf->vb, st); + vb2_buffer_done(&buf->vb.vb2_buf, st); } buflist = buflist_tail = 0; spin_unlock(&blist_lock); @@ -352,12 +362,13 @@ static int gen_frame(void) spin_unlock(&blist_lock); if(buf) { - memcpy(vb2_plane_vaddr(&buf->vb, 0), frame, frame_size); + memcpy(vb2_plane_vaddr(&buf->vb.vb2_buf, 0), frame, frame_size); - /*v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp); - buf->vb.v4l2_buf.sequence = seqno++; - buf->vb.v4l2_buf.field = V4L2_FIELD_NONE;*/ - vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE); + buf->vb.vb2_buf.timestamp = ktime_get_ns(); + buf->vb.sequence = seqno++; + buf->vb.field = V4L2_FIELD_NONE; + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); + vb2_set_plane_payload(&buf->vb.vb2_buf, 0, frame_size); } return 0;