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;
return res;
}
- printk(KERN_INFO "vdummy device initialized\n");
+ printk(KERN_INFO "vdummy: initialized\n");
return 0;
}
static void shutdown(void)
{
+ hrtimer_cancel(&timer);
video_unregister_device(vdev);
v4l2_device_unregister(&v4l2_dev);
kfree(frame);
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;
struct buffer *buf = (struct buffer*)((char*)vb - offsetof(struct buffer, vb));
spin_lock(&blist_lock);
+ printk(KERN_INFO "vdummy: enqueue buffer\n");
if(buflist) {
buflist_tail->next = buf;
buflist_tail = buf;
static void clear_queue(enum vb2_buffer_state st)
{
+ struct buffer *list;
+
+ printk(KERN_INFO "vdummy: clear_queue\n");
+
spin_lock(&blist_lock);
- while(buflist) {
- struct buffer *buf = buflist;
- buflist = buflist->next;
- vb2_buffer_done(&buf->vb.vb2_buf, st);
- }
+ list = buflist;
buflist = buflist_tail = 0;
spin_unlock(&blist_lock);
+
+ while(list) {
+ struct buffer *buf = list;
+ list = list->next;
+ vb2_buffer_done(&buf->vb.vb2_buf, st);
+ }
}
static int start_streaming(struct vb2_queue *vbq, unsigned int count)
frame_interval = ktime_set(0, 1000000000ul / (unsigned long)framerate);
}
+ printk(KERN_INFO "vdummy: start streaming (interval: %ld ms)\n",
+ (long)ktime_to_ms(frame_interval));
hrtimer_start(&timer, frame_interval, HRTIMER_MODE_REL);
return 0;
}
static void stop_streaming(struct vb2_queue *vbq)
{
- while(hrtimer_try_to_cancel(&timer) == -1);
+ printk(KERN_INFO "vdummy: stop streaming\n");
+ hrtimer_cancel(&timer);
streaming = 0;
clear_queue(VB2_BUF_STATE_ERROR);
{
struct buffer *buf = 0;
+ printk(KERN_INFO "vdummy: gen_frame\n");
+
spin_lock(&blist_lock);
if(buflist) {
buf = buflist;
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();
+ 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);
+ mutex_unlock(&mutex);
}
return 0;
}
enum hrtimer_restart timer_func(struct hrtimer *timer)
{
- gen_frame();
+ printk(KERN_INFO "vdummy: timer!\n");
+ //gen_frame();
return streaming ? HRTIMER_RESTART : HRTIMER_NORESTART;
}