From: John Tsiombikas Date: Tue, 16 May 2017 06:08:07 +0000 (+0300) Subject: Merge branch 'master' of goat:git/vdummy X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vdummy;a=commitdiff_plain;h=1f8e4783af5e5ba3406af8d732c680179dedd0c3;hp=-c Merge branch 'master' of goat:git/vdummy --- 1f8e4783af5e5ba3406af8d732c680179dedd0c3 diff --combined vdummy.c index 565a6b8,a4d05b8..b434b6f --- a/vdummy.c +++ b/vdummy.c @@@ -7,7 -7,6 +7,6 @@@ #include #include #include - #include #include #include #include @@@ -25,6 -24,7 +24,7 @@@ static void shutdown(void) static int ioctl_querycap(struct file *file, void *fh, struct v4l2_capability *cap); static int ioctl_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *fdesc); + static int ioctl_enum_framesz(struct file *file, void *fh, struct v4l2_frmsizeenum *fsz); static int ioctl_get_fmt(struct file *file, void *fh, struct v4l2_format *fmt); static int ioctl_set_fmt(struct file *file, void *fh, struct v4l2_format *fmt); static int ioctl_try_fmt(struct file *file, void *fh, struct v4l2_format *fmt); @@@ -33,7 -33,7 +33,7 @@@ static int ioctl_set_parm(struct file * static int ioctl_queryctl(struct file *file, void *fh, struct v4l2_queryctrl *ctl); static int queue_setup(struct vb2_queue *vbq, unsigned int *nbuf, - unsigned int *nplanes, unsigned int *sizes, void **alloc_ctx); + unsigned int *nplanes, unsigned int *sizes, struct device **alloc_ctx); static int buf_prepare(struct vb2_buffer *vb); static void buf_queue(struct vb2_buffer *vb); static int start_streaming(struct vb2_queue *vbq, unsigned int count); @@@ -132,6 -132,7 +132,7 @@@ static int init(void iops.vidioc_querycap = ioctl_querycap; iops.vidioc_enum_fmt_vid_cap = ioctl_enum_fmt; + iops.vidioc_enum_framesizes = ioctl_enum_framesz; iops.vidioc_g_fmt_vid_cap = ioctl_get_fmt; iops.vidioc_s_fmt_vid_cap = ioctl_set_fmt; iops.vidioc_try_fmt_vid_cap = ioctl_try_fmt; @@@ -167,7 -168,7 +168,7 @@@ return res; } - printk(KERN_INFO "vdummy device initialized\n"); + printk(KERN_INFO "vdummy: initialized\n"); return 0; } @@@ -200,6 -201,18 +201,18 @@@ static int ioctl_enum_fmt(struct file * return 0; } + static int ioctl_enum_framesz(struct file *file, void *fh, struct v4l2_frmsizeenum *fsz) + { + if(fsz->index != 0) { + return -EINVAL; + } + fsz->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; + fsz->stepwise.min_width = fsz->stepwise.min_height = 1; + fsz->stepwise.max_width = fsz->stepwise.max_height = 8192; + fsz->stepwise.step_width = fsz->stepwise.step_height = 1; + return 0; + } + static int ioctl_get_fmt(struct file *file, void *fh, struct v4l2_format *fmt) { if(fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { @@@ -288,7 -301,7 +301,7 @@@ static int ioctl_queryctl(struct file * } static int queue_setup(struct vb2_queue *vbq, unsigned int *nbuf, - unsigned int *nplanes, unsigned int *sizes, void **alloc_ctx) + unsigned int *nplanes, unsigned int *sizes, struct device **alloc_ctx) { if(vbq->num_buffers + *nbuf < 2) { *nbuf = 2 - vbq->num_buffers; @@@ -314,7 -327,6 +327,7 @@@ static void buf_queue(struct vb2_buffe 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; @@@ -327,20 -339,14 +340,20 @@@ 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) @@@ -357,15 -363,12 +370,15 @@@ 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) { + printk(KERN_INFO "vdummy: stop streaming\n"); hrtimer_cancel(&timer); streaming = 0; @@@ -411,19 -414,17 +424,19 @@@ static int update_frame(int xsz, int ys static int gen_frame(void) { struct buffer *buf = 0; + unsigned long flags; + printk(KERN_INFO "vdummy: gen_frame\n"); + - spin_lock(&blist_lock); + spin_lock_irqsave(&blist_lock, flags); if(buflist) { buf = buflist; buflist = buflist->next; if(!buflist) buflist_tail = 0; } - spin_unlock(&blist_lock); + spin_unlock_irqrestore(&blist_lock, flags); if(buf) { - mutex_lock(&mutex); memcpy(vb2_plane_vaddr(&buf->vb.vb2_buf, 0), frame, frame_size); buf->vb.vb2_buf.timestamp = ktime_get_ns(); @@@ -433,14 -434,12 +446,13 @@@ 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; }