Commit 4f5a7444 authored by Trent Piepho's avatar Trent Piepho Committed by Mauro Carvalho Chehab

V4L/DVB (11266): vino: Remove code for things already done by video_ioctl2

The v4l2-ioctl core only allows buffer types for which the corresponding
->vidioc_try_fmt_xxx() methods are defined to be used in vidioc_(g|s)_parm,
vidioc_(q|dq|query)buf, and vidioc_reqbufs.

Remove buffer type checking from vino_g_parm(), vino_s_parm(),
vino_reqbufs(), vino_querybuf(), vino_qbuf(), and vino_dqbuf().  This
reduced the indent level of the code so a few lines can be wrapped better.
Also fixed the C++ type comments.

The v4l2-ioctl core also provides structs that have been pre-zeroed for all
fields that driver is supposed to fill in, so remove zeroing code from
vino_enum_fmt_vid_cap().  Also, the format index is unsigned so it's not
necessary to check if it's less than zero.
Signed-off-by: default avatarTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 2509e1cb
...@@ -3102,22 +3102,14 @@ static int vino_s_std(struct file *file, void *__fh, ...@@ -3102,22 +3102,14 @@ static int vino_s_std(struct file *file, void *__fh,
static int vino_enum_fmt_vid_cap(struct file *file, void *__fh, static int vino_enum_fmt_vid_cap(struct file *file, void *__fh,
struct v4l2_fmtdesc *fd) struct v4l2_fmtdesc *fd)
{ {
enum v4l2_buf_type type = fd->type; dprintk("format index = %d\n", fd->index);
int index = fd->index;
dprintk("format index = %d\n", index); if (fd->index >= VINO_DATA_FMT_COUNT)
if ((fd->index < 0) ||
(fd->index >= VINO_DATA_FMT_COUNT))
return -EINVAL; return -EINVAL;
dprintk("format name = %s\n", dprintk("format name = %s\n", vino_data_formats[fd->index].description);
vino_data_formats[index].description);
fd->pixelformat = vino_data_formats[fd->index].pixelformat;
memset(fd, 0, sizeof(struct v4l2_fmtdesc)); strcpy(fd->description, vino_data_formats[fd->index].description);
fd->index = index;
fd->type = type;
fd->pixelformat = vino_data_formats[index].pixelformat;
strcpy(fd->description, vino_data_formats[index].description);
return 0; return 0;
} }
...@@ -3327,28 +3319,18 @@ static int vino_g_parm(struct file *file, void *__fh, ...@@ -3327,28 +3319,18 @@ static int vino_g_parm(struct file *file, void *__fh,
{ {
struct vino_channel_settings *vcs = video_drvdata(file); struct vino_channel_settings *vcs = video_drvdata(file);
unsigned long flags; unsigned long flags;
struct v4l2_captureparm *cp = &sp->parm.capture;
switch (sp->type) { cp->capability = V4L2_CAP_TIMEPERFRAME;
case V4L2_BUF_TYPE_VIDEO_CAPTURE: { cp->timeperframe.numerator = 1;
struct v4l2_captureparm *cp = &sp->parm.capture;
memset(cp, 0, sizeof(struct v4l2_captureparm));
cp->capability = V4L2_CAP_TIMEPERFRAME; spin_lock_irqsave(&vino_drvdata->input_lock, flags);
cp->timeperframe.numerator = 1;
spin_lock_irqsave(&vino_drvdata->input_lock, flags); cp->timeperframe.denominator = vcs->fps;
cp->timeperframe.denominator = vcs->fps; spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
spin_unlock_irqrestore(&vino_drvdata->input_lock, flags); /* TODO: cp->readbuffers = xxx; */
// TODO: cp->readbuffers = xxx;
break;
}
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
default:
return -EINVAL;
}
return 0; return 0;
} }
...@@ -3358,32 +3340,21 @@ static int vino_s_parm(struct file *file, void *__fh, ...@@ -3358,32 +3340,21 @@ static int vino_s_parm(struct file *file, void *__fh,
{ {
struct vino_channel_settings *vcs = video_drvdata(file); struct vino_channel_settings *vcs = video_drvdata(file);
unsigned long flags; unsigned long flags;
struct v4l2_captureparm *cp = &sp->parm.capture;
switch (sp->type) { spin_lock_irqsave(&vino_drvdata->input_lock, flags);
case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
struct v4l2_captureparm *cp = &sp->parm.capture;
spin_lock_irqsave(&vino_drvdata->input_lock, flags);
if ((cp->timeperframe.numerator == 0) ||
(cp->timeperframe.denominator == 0)) {
/* reset framerate */
vino_set_default_framerate(vcs);
} else {
vino_set_framerate(vcs, cp->timeperframe.denominator /
cp->timeperframe.numerator);
}
spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
// TODO: set buffers according to cp->readbuffers if ((cp->timeperframe.numerator == 0) ||
break; (cp->timeperframe.denominator == 0)) {
} /* reset framerate */
case V4L2_BUF_TYPE_VIDEO_OVERLAY: vino_set_default_framerate(vcs);
default: } else {
return -EINVAL; vino_set_framerate(vcs, cp->timeperframe.denominator /
cp->timeperframe.numerator);
} }
spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
return 0; return 0;
} }
...@@ -3391,42 +3362,35 @@ static int vino_reqbufs(struct file *file, void *__fh, ...@@ -3391,42 +3362,35 @@ static int vino_reqbufs(struct file *file, void *__fh,
struct v4l2_requestbuffers *rb) struct v4l2_requestbuffers *rb)
{ {
struct vino_channel_settings *vcs = video_drvdata(file); struct vino_channel_settings *vcs = video_drvdata(file);
if (vcs->reading) if (vcs->reading)
return -EBUSY; return -EBUSY;
switch (rb->type) { /* TODO: check queue type */
case V4L2_BUF_TYPE_VIDEO_CAPTURE: { if (rb->memory != V4L2_MEMORY_MMAP) {
// TODO: check queue type dprintk("type not mmap\n");
if (rb->memory != V4L2_MEMORY_MMAP) { return -EINVAL;
dprintk("type not mmap\n"); }
return -EINVAL;
}
dprintk("count = %d\n", rb->count); dprintk("count = %d\n", rb->count);
if (rb->count > 0) { if (rb->count > 0) {
if (vino_is_capturing(vcs)) { if (vino_is_capturing(vcs)) {
dprintk("busy, capturing\n"); dprintk("busy, capturing\n");
return -EBUSY; return -EBUSY;
} }
if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) { if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
dprintk("busy, buffers still mapped\n"); dprintk("busy, buffers still mapped\n");
return -EBUSY; return -EBUSY;
} else {
vcs->streaming = 0;
vino_queue_free(&vcs->fb_queue);
vino_queue_init(&vcs->fb_queue, &rb->count);
}
} else { } else {
vcs->streaming = 0; vcs->streaming = 0;
vino_capture_stop(vcs);
vino_queue_free(&vcs->fb_queue); vino_queue_free(&vcs->fb_queue);
vino_queue_init(&vcs->fb_queue, &rb->count);
} }
break; } else {
} vcs->streaming = 0;
case V4L2_BUF_TYPE_VIDEO_OVERLAY: vino_capture_stop(vcs);
default: vino_queue_free(&vcs->fb_queue);
return -EINVAL;
} }
return 0; return 0;
...@@ -3474,35 +3438,27 @@ static int vino_querybuf(struct file *file, void *__fh, ...@@ -3474,35 +3438,27 @@ static int vino_querybuf(struct file *file, void *__fh,
struct v4l2_buffer *b) struct v4l2_buffer *b)
{ {
struct vino_channel_settings *vcs = video_drvdata(file); struct vino_channel_settings *vcs = video_drvdata(file);
struct vino_framebuffer *fb;
if (vcs->reading) if (vcs->reading)
return -EBUSY; return -EBUSY;
switch (b->type) { /* TODO: check queue type */
case V4L2_BUF_TYPE_VIDEO_CAPTURE: { if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
struct vino_framebuffer *fb; dprintk("invalid index = %d\n",
b->index);
// TODO: check queue type return -EINVAL;
if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
dprintk("invalid index = %d\n",
b->index);
return -EINVAL;
}
fb = vino_queue_get_buffer(&vcs->fb_queue,
b->index);
if (fb == NULL) {
dprintk("vino_queue_get_buffer() failed");
return -EINVAL;
}
vino_v4l2_get_buffer_status(vcs, fb, b);
break;
} }
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
default: fb = vino_queue_get_buffer(&vcs->fb_queue,
b->index);
if (fb == NULL) {
dprintk("vino_queue_get_buffer() failed");
return -EINVAL; return -EINVAL;
} }
vino_v4l2_get_buffer_status(vcs, fb, b);
return 0; return 0;
} }
...@@ -3510,36 +3466,28 @@ static int vino_qbuf(struct file *file, void *__fh, ...@@ -3510,36 +3466,28 @@ static int vino_qbuf(struct file *file, void *__fh,
struct v4l2_buffer *b) struct v4l2_buffer *b)
{ {
struct vino_channel_settings *vcs = video_drvdata(file); struct vino_channel_settings *vcs = video_drvdata(file);
struct vino_framebuffer *fb;
int ret;
if (vcs->reading) if (vcs->reading)
return -EBUSY; return -EBUSY;
switch (b->type) { /* TODO: check queue type */
case V4L2_BUF_TYPE_VIDEO_CAPTURE: { if (b->memory != V4L2_MEMORY_MMAP) {
struct vino_framebuffer *fb; dprintk("type not mmap\n");
int ret; return -EINVAL;
}
// TODO: check queue type
if (b->memory != V4L2_MEMORY_MMAP) {
dprintk("type not mmap\n");
return -EINVAL;
}
fb = vino_capture_enqueue(vcs, b->index); fb = vino_capture_enqueue(vcs, b->index);
if (fb == NULL) if (fb == NULL)
return -EINVAL; return -EINVAL;
vino_v4l2_get_buffer_status(vcs, fb, b); vino_v4l2_get_buffer_status(vcs, fb, b);
if (vcs->streaming) { if (vcs->streaming) {
ret = vino_capture_next(vcs, 1); ret = vino_capture_next(vcs, 1);
if (ret) if (ret)
return ret; return ret;
}
break;
}
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
default:
return -EINVAL;
} }
return 0; return 0;
...@@ -3550,73 +3498,63 @@ static int vino_dqbuf(struct file *file, void *__fh, ...@@ -3550,73 +3498,63 @@ static int vino_dqbuf(struct file *file, void *__fh,
{ {
struct vino_channel_settings *vcs = video_drvdata(file); struct vino_channel_settings *vcs = video_drvdata(file);
unsigned int nonblocking = file->f_flags & O_NONBLOCK; unsigned int nonblocking = file->f_flags & O_NONBLOCK;
struct vino_framebuffer *fb;
unsigned int incoming, outgoing;
int err;
if (vcs->reading) if (vcs->reading)
return -EBUSY; return -EBUSY;
switch (b->type) { /* TODO: check queue type */
case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
struct vino_framebuffer *fb; err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
unsigned int incoming, outgoing; if (err) {
int err; dprintk("vino_queue_get_incoming() failed\n");
return -EINVAL;
}
err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
if (err) {
dprintk("vino_queue_get_outgoing() failed\n");
return -EINVAL;
}
// TODO: check queue type dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
err = vino_queue_get_incoming(&vcs->fb_queue, &incoming); if (outgoing == 0) {
if (err) { if (incoming == 0) {
dprintk("vino_queue_get_incoming() failed\n"); dprintk("no incoming or outgoing buffers\n");
return -EINVAL; return -EINVAL;
} }
err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing); if (nonblocking) {
if (err) { dprintk("non-blocking I/O was selected and "
dprintk("vino_queue_get_outgoing() failed\n"); "there are no buffers to dequeue\n");
return -EINVAL; return -EAGAIN;
} }
dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing); err = vino_wait_for_frame(vcs);
if (err) {
if (outgoing == 0) {
if (incoming == 0) {
dprintk("no incoming or outgoing buffers\n");
return -EINVAL;
}
if (nonblocking) {
dprintk("non-blocking I/O was selected and "
"there are no buffers to dequeue\n");
return -EAGAIN;
}
err = vino_wait_for_frame(vcs); err = vino_wait_for_frame(vcs);
if (err) { if (err) {
err = vino_wait_for_frame(vcs); /* interrupted or no frames captured because of
if (err) { * frame skipping */
/* interrupted or /* vino_capture_failed(vcs); */
* no frames captured because return -EIO;
* of frame skipping */
// vino_capture_failed(vcs);
return -EIO;
}
} }
} }
}
fb = vino_queue_remove(&vcs->fb_queue, &b->index); fb = vino_queue_remove(&vcs->fb_queue, &b->index);
if (fb == NULL) { if (fb == NULL) {
dprintk("vino_queue_remove() failed\n"); dprintk("vino_queue_remove() failed\n");
return -EINVAL; return -EINVAL;
} }
err = vino_check_buffer(vcs, fb);
vino_v4l2_get_buffer_status(vcs, fb, b); err = vino_check_buffer(vcs, fb);
if (err) vino_v4l2_get_buffer_status(vcs, fb, b);
return -EIO;
break; if (err)
} return -EIO;
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
default:
return -EINVAL;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment