foo
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 14 May 2017 14:16:40 +0000 (17:16 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 14 May 2017 14:16:40 +0000 (17:16 +0300)
vdummy.c

index d107e59..9786d11 100644 (file)
--- a/vdummy.c
+++ b/vdummy.c
@@ -50,7 +50,7 @@ module_exit(shutdown);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("John Tsiombikas");
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("John Tsiombikas");
-MODULE_DESCRIPTION("v4l2 test module");
+MODULE_DESCRIPTION("Dummy V4L2 device");
 
 static struct mutex mutex;
 static struct video_device *vdev;
 
 static struct mutex mutex;
 static struct video_device *vdev;
@@ -173,6 +173,7 @@ static int init(void)
 
 static void shutdown(void)
 {
 
 static void shutdown(void)
 {
+       hrtimer_cancel(&timer);
        video_unregister_device(vdev);
        v4l2_device_unregister(&v4l2_dev);
        kfree(frame);
        video_unregister_device(vdev);
        v4l2_device_unregister(&v4l2_dev);
        kfree(frame);
@@ -181,7 +182,7 @@ static void shutdown(void)
 static int ioctl_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
 {
        strcpy(cap->driver, KBUILD_MODNAME);
 static int ioctl_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
 {
        strcpy(cap->driver, KBUILD_MODNAME);
-       strcpy(cap->card, "Test V4L2 device");
+       strcpy(cap->card, "Dummy 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;
        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;
@@ -355,7 +356,7 @@ static int start_streaming(struct vb2_queue *vbq, unsigned int count)
 
 static void stop_streaming(struct vb2_queue *vbq)
 {
 
 static void stop_streaming(struct vb2_queue *vbq)
 {
-       while(hrtimer_try_to_cancel(&timer) == -1);
+       hrtimer_cancel(&timer);
 
        streaming = 0;
        clear_queue(VB2_BUF_STATE_ERROR);
 
        streaming = 0;
        clear_queue(VB2_BUF_STATE_ERROR);
@@ -410,15 +411,17 @@ static int gen_frame(void)
        spin_unlock(&blist_lock);
 
        if(buf) {
        spin_unlock(&blist_lock);
 
        if(buf) {
-               printk(KERN_INFO "vdummy: copying frame: %d\n", seqno);
-
+               mutex_lock(&mutex);
                memcpy(vb2_plane_vaddr(&buf->vb.vb2_buf, 0), frame, frame_size);
 
                buf->vb.vb2_buf.timestamp = ktime_get_ns();
                memcpy(vb2_plane_vaddr(&buf->vb.vb2_buf, 0), frame, frame_size);
 
                buf->vb.vb2_buf.timestamp = ktime_get_ns();
+               printk(KERN_INFO "vdummy: copying frame: %d ts: %lu\n", seqno,
+                               (unsigned long)buf->vb.vb2_buf.timestamp);
                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);
                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);
+               mutex_unlock(&mutex);
        }
        return 0;
 }
        }
        return 0;
 }