Commit ee10dc36 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

media: cropcap/g_selection split

If g_selection is implemented, then the v4l2-ioctl cropcap code assumes
that cropcap just implements the pixelaspect part and that g_selection
provides the crop bounds and default rectangles.

There are still some drivers that only implement cropcap and not
g_selection. Split up cropcap into a cropcap and g_selection for those
drivers.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 98af278b
...@@ -1089,14 +1089,43 @@ static int cobalt_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cc) ...@@ -1089,14 +1089,43 @@ static int cobalt_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cc)
timings = cea1080p60; timings = cea1080p60;
else else
err = v4l2_subdev_call(s->sd, video, g_dv_timings, &timings); err = v4l2_subdev_call(s->sd, video, g_dv_timings, &timings);
if (!err) { if (!err)
cc->bounds.width = cc->defrect.width = timings.bt.width;
cc->bounds.height = cc->defrect.height = timings.bt.height;
cc->pixelaspect = v4l2_dv_timings_aspect_ratio(&timings); cc->pixelaspect = v4l2_dv_timings_aspect_ratio(&timings);
}
return err; return err;
} }
static int cobalt_g_selection(struct file *file, void *fh,
struct v4l2_selection *sel)
{
struct cobalt_stream *s = video_drvdata(file);
struct v4l2_dv_timings timings;
int err = 0;
if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
if (s->input == 1)
timings = cea1080p60;
else
err = v4l2_subdev_call(s->sd, video, g_dv_timings, &timings);
if (err)
return err;
switch (sel->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
sel->r.top = 0;
sel->r.left = 0;
sel->r.width = timings.bt.width;
sel->r.height = timings.bt.height;
break;
default:
return -EINVAL;
}
return 0;
}
static const struct v4l2_ioctl_ops cobalt_ioctl_ops = { static const struct v4l2_ioctl_ops cobalt_ioctl_ops = {
.vidioc_querycap = cobalt_querycap, .vidioc_querycap = cobalt_querycap,
.vidioc_g_parm = cobalt_g_parm, .vidioc_g_parm = cobalt_g_parm,
...@@ -1104,6 +1133,7 @@ static const struct v4l2_ioctl_ops cobalt_ioctl_ops = { ...@@ -1104,6 +1133,7 @@ static const struct v4l2_ioctl_ops cobalt_ioctl_ops = {
.vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamon = vb2_ioctl_streamon,
.vidioc_streamoff = vb2_ioctl_streamoff, .vidioc_streamoff = vb2_ioctl_streamoff,
.vidioc_cropcap = cobalt_cropcap, .vidioc_cropcap = cobalt_cropcap,
.vidioc_g_selection = cobalt_g_selection,
.vidioc_enum_input = cobalt_enum_input, .vidioc_enum_input = cobalt_enum_input,
.vidioc_g_input = cobalt_g_input, .vidioc_g_input = cobalt_g_input,
.vidioc_s_input = cobalt_s_input, .vidioc_s_input = cobalt_s_input,
......
...@@ -677,17 +677,34 @@ static int vidioc_cropcap(struct file *file, void *priv, ...@@ -677,17 +677,34 @@ static int vidioc_cropcap(struct file *file, void *priv,
if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
cc->bounds.left = 0;
cc->bounds.top = 0;
cc->bounds.width = 720;
cc->bounds.height = norm_maxh(dev->tvnorm);
cc->defrect = cc->bounds;
cc->pixelaspect.numerator = is_50hz ? 54 : 11; cc->pixelaspect.numerator = is_50hz ? 54 : 11;
cc->pixelaspect.denominator = is_50hz ? 59 : 10; cc->pixelaspect.denominator = is_50hz ? 59 : 10;
return 0; return 0;
} }
static int vidioc_g_selection(struct file *file, void *fh,
struct v4l2_selection *sel)
{
struct cx23885_dev *dev = video_drvdata(file);
if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
switch (sel->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
sel->r.top = 0;
sel->r.left = 0;
sel->r.width = 720;
sel->r.height = norm_maxh(dev->tvnorm);
break;
default:
return -EINVAL;
}
return 0;
}
static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id) static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
{ {
struct cx23885_dev *dev = video_drvdata(file); struct cx23885_dev *dev = video_drvdata(file);
...@@ -1123,6 +1140,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = { ...@@ -1123,6 +1140,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
.vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamon = vb2_ioctl_streamon,
.vidioc_streamoff = vb2_ioctl_streamoff, .vidioc_streamoff = vb2_ioctl_streamoff,
.vidioc_cropcap = vidioc_cropcap, .vidioc_cropcap = vidioc_cropcap,
.vidioc_g_selection = vidioc_g_selection,
.vidioc_s_std = vidioc_s_std, .vidioc_s_std = vidioc_s_std,
.vidioc_g_std = vidioc_g_std, .vidioc_g_std = vidioc_g_std,
.vidioc_enum_input = vidioc_enum_input, .vidioc_enum_input = vidioc_enum_input,
......
...@@ -2091,13 +2091,6 @@ static int vpfe_cropcap(struct file *file, void *priv, ...@@ -2091,13 +2091,6 @@ static int vpfe_cropcap(struct file *file, void *priv,
if (vpfe->std_index >= ARRAY_SIZE(vpfe_standards)) if (vpfe->std_index >= ARRAY_SIZE(vpfe_standards))
return -EINVAL; return -EINVAL;
memset(crop, 0, sizeof(struct v4l2_cropcap));
crop->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
crop->defrect.width = vpfe_standards[vpfe->std_index].width;
crop->bounds.width = crop->defrect.width;
crop->defrect.height = vpfe_standards[vpfe->std_index].height;
crop->bounds.height = crop->defrect.height;
crop->pixelaspect = vpfe_standards[vpfe->std_index].pixelaspect; crop->pixelaspect = vpfe_standards[vpfe->std_index].pixelaspect;
return 0; return 0;
...@@ -2108,12 +2101,17 @@ vpfe_g_selection(struct file *file, void *fh, struct v4l2_selection *s) ...@@ -2108,12 +2101,17 @@ vpfe_g_selection(struct file *file, void *fh, struct v4l2_selection *s)
{ {
struct vpfe_device *vpfe = video_drvdata(file); struct vpfe_device *vpfe = video_drvdata(file);
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
vpfe->std_index >= ARRAY_SIZE(vpfe_standards))
return -EINVAL;
switch (s->target) { switch (s->target) {
case V4L2_SEL_TGT_CROP_BOUNDS: case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT: case V4L2_SEL_TGT_CROP_DEFAULT:
s->r.left = s->r.top = 0; s->r.left = 0;
s->r.width = vpfe->crop.width; s->r.top = 0;
s->r.height = vpfe->crop.height; s->r.width = vpfe_standards[vpfe->std_index].width;
s->r.height = vpfe_standards[vpfe->std_index].height;
break; break;
case V4L2_SEL_TGT_CROP: case V4L2_SEL_TGT_CROP:
......
...@@ -1627,19 +1627,34 @@ static int vidioc_cropcap(struct file *file, void *priv, ...@@ -1627,19 +1627,34 @@ static int vidioc_cropcap(struct file *file, void *priv,
dprintk(1, "%s called std_set %d dev_state %ld\n", __func__, dprintk(1, "%s called std_set %d dev_state %ld\n", __func__,
dev->std_set_in_tuner_core, dev->dev_state); dev->std_set_in_tuner_core, dev->dev_state);
cc->bounds.left = 0;
cc->bounds.top = 0;
cc->bounds.width = dev->width;
cc->bounds.height = dev->height;
cc->defrect = cc->bounds;
cc->pixelaspect.numerator = 54; cc->pixelaspect.numerator = 54;
cc->pixelaspect.denominator = 59; cc->pixelaspect.denominator = 59;
return 0; return 0;
} }
static int vidioc_g_selection(struct file *file, void *priv,
struct v4l2_selection *s)
{
struct au0828_dev *dev = video_drvdata(file);
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
switch (s->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
s->r.left = 0;
s->r.top = 0;
s->r.width = dev->width;
s->r.height = dev->height;
break;
default:
return -EINVAL;
}
return 0;
}
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
static int vidioc_g_register(struct file *file, void *priv, static int vidioc_g_register(struct file *file, void *priv,
struct v4l2_dbg_register *reg) struct v4l2_dbg_register *reg)
...@@ -1763,6 +1778,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = { ...@@ -1763,6 +1778,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
.vidioc_g_audio = vidioc_g_audio, .vidioc_g_audio = vidioc_g_audio,
.vidioc_s_audio = vidioc_s_audio, .vidioc_s_audio = vidioc_s_audio,
.vidioc_cropcap = vidioc_cropcap, .vidioc_cropcap = vidioc_cropcap,
.vidioc_g_selection = vidioc_g_selection,
.vidioc_reqbufs = vb2_ioctl_reqbufs, .vidioc_reqbufs = vb2_ioctl_reqbufs,
.vidioc_create_bufs = vb2_ioctl_create_bufs, .vidioc_create_bufs = vb2_ioctl_create_bufs,
......
...@@ -479,24 +479,25 @@ static int cpia2_g_fmt_vid_cap(struct file *file, void *fh, ...@@ -479,24 +479,25 @@ static int cpia2_g_fmt_vid_cap(struct file *file, void *fh,
* *
*****************************************************************************/ *****************************************************************************/
static int cpia2_cropcap(struct file *file, void *fh, struct v4l2_cropcap *c) static int cpia2_g_selection(struct file *file, void *fh,
struct v4l2_selection *s)
{ {
struct camera_data *cam = video_drvdata(file); struct camera_data *cam = video_drvdata(file);
if (c->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
c->bounds.left = 0;
c->bounds.top = 0;
c->bounds.width = cam->width;
c->bounds.height = cam->height;
c->defrect.left = 0;
c->defrect.top = 0;
c->defrect.width = cam->width;
c->defrect.height = cam->height;
c->pixelaspect.numerator = 1;
c->pixelaspect.denominator = 1;
switch (s->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
s->r.left = 0;
s->r.top = 0;
s->r.width = cam->width;
s->r.height = cam->height;
break;
default:
return -EINVAL;
}
return 0; return 0;
} }
...@@ -1047,7 +1048,7 @@ static const struct v4l2_ioctl_ops cpia2_ioctl_ops = { ...@@ -1047,7 +1048,7 @@ static const struct v4l2_ioctl_ops cpia2_ioctl_ops = {
.vidioc_try_fmt_vid_cap = cpia2_try_fmt_vid_cap, .vidioc_try_fmt_vid_cap = cpia2_try_fmt_vid_cap,
.vidioc_g_jpegcomp = cpia2_g_jpegcomp, .vidioc_g_jpegcomp = cpia2_g_jpegcomp,
.vidioc_s_jpegcomp = cpia2_s_jpegcomp, .vidioc_s_jpegcomp = cpia2_s_jpegcomp,
.vidioc_cropcap = cpia2_cropcap, .vidioc_g_selection = cpia2_g_selection,
.vidioc_reqbufs = cpia2_reqbufs, .vidioc_reqbufs = cpia2_reqbufs,
.vidioc_querybuf = cpia2_querybuf, .vidioc_querybuf = cpia2_querybuf,
.vidioc_qbuf = cpia2_qbuf, .vidioc_qbuf = cpia2_qbuf,
......
...@@ -1510,17 +1510,35 @@ static int vidioc_cropcap(struct file *file, void *priv, ...@@ -1510,17 +1510,35 @@ static int vidioc_cropcap(struct file *file, void *priv,
if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
cc->bounds.left = 0;
cc->bounds.top = 0;
cc->bounds.width = dev->ts1.width;
cc->bounds.height = dev->ts1.height;
cc->defrect = cc->bounds;
cc->pixelaspect.numerator = is_50hz ? 54 : 11; cc->pixelaspect.numerator = is_50hz ? 54 : 11;
cc->pixelaspect.denominator = is_50hz ? 59 : 10; cc->pixelaspect.denominator = is_50hz ? 59 : 10;
return 0; return 0;
} }
static int vidioc_g_selection(struct file *file, void *priv,
struct v4l2_selection *s)
{
struct cx231xx_fh *fh = priv;
struct cx231xx *dev = fh->dev;
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
switch (s->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
s->r.left = 0;
s->r.top = 0;
s->r.width = dev->ts1.width;
s->r.height = dev->ts1.height;
break;
default:
return -EINVAL;
}
return 0;
}
static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm) static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm)
{ {
struct cx231xx_fh *fh = file->private_data; struct cx231xx_fh *fh = file->private_data;
...@@ -1866,6 +1884,7 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = { ...@@ -1866,6 +1884,7 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
.vidioc_s_input = cx231xx_s_input, .vidioc_s_input = cx231xx_s_input,
.vidioc_s_ctrl = vidioc_s_ctrl, .vidioc_s_ctrl = vidioc_s_ctrl,
.vidioc_cropcap = vidioc_cropcap, .vidioc_cropcap = vidioc_cropcap,
.vidioc_g_selection = vidioc_g_selection,
.vidioc_querycap = cx231xx_querycap, .vidioc_querycap = cx231xx_querycap,
.vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
.vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
......
...@@ -1492,17 +1492,35 @@ static int vidioc_cropcap(struct file *file, void *priv, ...@@ -1492,17 +1492,35 @@ static int vidioc_cropcap(struct file *file, void *priv,
if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
cc->bounds.left = 0;
cc->bounds.top = 0;
cc->bounds.width = dev->width;
cc->bounds.height = dev->height;
cc->defrect = cc->bounds;
cc->pixelaspect.numerator = is_50hz ? 54 : 11; cc->pixelaspect.numerator = is_50hz ? 54 : 11;
cc->pixelaspect.denominator = is_50hz ? 59 : 10; cc->pixelaspect.denominator = is_50hz ? 59 : 10;
return 0; return 0;
} }
static int vidioc_g_selection(struct file *file, void *priv,
struct v4l2_selection *s)
{
struct cx231xx_fh *fh = priv;
struct cx231xx *dev = fh->dev;
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
switch (s->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
s->r.left = 0;
s->r.top = 0;
s->r.width = dev->width;
s->r.height = dev->height;
break;
default:
return -EINVAL;
}
return 0;
}
static int vidioc_streamon(struct file *file, void *priv, static int vidioc_streamon(struct file *file, void *priv,
enum v4l2_buf_type type) enum v4l2_buf_type type)
{ {
...@@ -2094,6 +2112,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = { ...@@ -2094,6 +2112,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
.vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
.vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
.vidioc_cropcap = vidioc_cropcap, .vidioc_cropcap = vidioc_cropcap,
.vidioc_g_selection = vidioc_g_selection,
.vidioc_reqbufs = vidioc_reqbufs, .vidioc_reqbufs = vidioc_reqbufs,
.vidioc_querybuf = vidioc_querybuf, .vidioc_querybuf = vidioc_querybuf,
.vidioc_qbuf = vidioc_qbuf, .vidioc_qbuf = vidioc_qbuf,
......
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