[media] v4l2-ctrls: add v4l2_fh pointer to the set control functions
authorHans Verkuil <hans.verkuil@cisco.com>
Tue, 7 Jun 2011 09:47:18 +0000 (06:47 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 27 Jul 2011 20:53:19 +0000 (17:53 -0300)
When an application changes a control you want to generate an event.
However, you want to avoid sending such an event back to the application
(file handle) that caused the change.

Add the filehandle to the various set control functions.

The filehandle isn't used yet, but the control event patches will need
this.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/v4l2-ctrls.c
drivers/media/video/v4l2-ioctl.c
drivers/media/video/v4l2-subdev.c
include/media/v4l2-ctrls.h

index 30b0b4609b361f4e5fc2d65347f528cb1ab2ca77..70dbeeef6a2ee03820b249c5138518dacf505865 100644 (file)
@@ -657,7 +657,8 @@ static int ctrl_is_volatile(struct v4l2_ext_control *c,
 }
 
 /* Copy the new value to the current value. */
-static void new_to_cur(struct v4l2_ctrl *ctrl, bool update_inactive)
+static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
+                                               bool update_inactive)
 {
        if (ctrl == NULL)
                return;
@@ -1717,7 +1718,8 @@ EXPORT_SYMBOL(v4l2_ctrl_g_ctrl);
 /* Core function that calls try/s_ctrl and ensures that the new value is
    copied to the current value on a set.
    Must be called with ctrl->handler->lock held. */
-static int try_or_set_control_cluster(struct v4l2_ctrl *master, bool set)
+static int try_or_set_control_cluster(struct v4l2_fh *fh,
+                                       struct v4l2_ctrl *master, bool set)
 {
        bool update_flag;
        bool try = !set;
@@ -1768,12 +1770,13 @@ static int try_or_set_control_cluster(struct v4l2_ctrl *master, bool set)
 
        update_flag = is_cur_manual(master) != is_new_manual(master);
        for (i = 0; i < master->ncontrols; i++)
-               new_to_cur(master->cluster[i], update_flag && i > 0);
+               new_to_cur(fh, master->cluster[i], update_flag && i > 0);
        return 0;
 }
 
 /* Try or set controls. */
-static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
+static int try_or_set_ext_ctrls(struct v4l2_fh *fh,
+                               struct v4l2_ctrl_handler *hdl,
                                struct v4l2_ext_controls *cs,
                                struct ctrl_helper *helpers,
                                bool set)
@@ -1818,7 +1821,7 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
                ret = cluster_walk(i, cs, helpers, user_to_new);
 
                if (!ret)
-                       ret = try_or_set_control_cluster(master, set);
+                       ret = try_or_set_control_cluster(fh, master, set);
 
                /* Copy the new values back to userspace. */
                if (!ret)
@@ -1831,7 +1834,7 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
 }
 
 /* Try or try-and-set controls */
-static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
+static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
                             struct v4l2_ext_controls *cs,
                             bool set)
 {
@@ -1858,7 +1861,7 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
 
        /* First 'try' all controls and abort on error */
        if (!ret)
-               ret = try_or_set_ext_ctrls(hdl, cs, helpers, false);
+               ret = try_or_set_ext_ctrls(NULL, hdl, cs, helpers, false);
        /* If this is a 'set' operation and the initial 'try' failed,
           then set error_idx to count to tell the application that no
           controls changed value yet. */
@@ -1868,7 +1871,7 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
                /* Reset 'handled' state */
                for (i = 0; i < cs->count; i++)
                        helpers[i].handled = false;
-               ret = try_or_set_ext_ctrls(hdl, cs, helpers, true);
+               ret = try_or_set_ext_ctrls(fh, hdl, cs, helpers, true);
        }
 
        if (cs->count > ARRAY_SIZE(helper))
@@ -1878,30 +1881,31 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
 
 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs)
 {
-       return try_set_ext_ctrls(hdl, cs, false);
+       return try_set_ext_ctrls(NULL, hdl, cs, false);
 }
 EXPORT_SYMBOL(v4l2_try_ext_ctrls);
 
-int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs)
+int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
+                                       struct v4l2_ext_controls *cs)
 {
-       return try_set_ext_ctrls(hdl, cs, true);
+       return try_set_ext_ctrls(fh, hdl, cs, true);
 }
 EXPORT_SYMBOL(v4l2_s_ext_ctrls);
 
 int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs)
 {
-       return try_set_ext_ctrls(sd->ctrl_handler, cs, false);
+       return try_set_ext_ctrls(NULL, sd->ctrl_handler, cs, false);
 }
 EXPORT_SYMBOL(v4l2_subdev_try_ext_ctrls);
 
 int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs)
 {
-       return try_set_ext_ctrls(sd->ctrl_handler, cs, true);
+       return try_set_ext_ctrls(NULL, sd->ctrl_handler, cs, true);
 }
 EXPORT_SYMBOL(v4l2_subdev_s_ext_ctrls);
 
 /* Helper function for VIDIOC_S_CTRL compatibility */
-static int set_ctrl(struct v4l2_ctrl *ctrl, s32 *val)
+static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, s32 *val)
 {
        struct v4l2_ctrl *master = ctrl->cluster[0];
        int ret;
@@ -1916,15 +1920,16 @@ static int set_ctrl(struct v4l2_ctrl *ctrl, s32 *val)
 
        ctrl->val = *val;
        ctrl->is_new = 1;
-       ret = try_or_set_control_cluster(master, false);
+       ret = try_or_set_control_cluster(NULL, master, false);
        if (!ret)
-               ret = try_or_set_control_cluster(master, true);
+               ret = try_or_set_control_cluster(fh, master, true);
        *val = ctrl->cur.val;
        v4l2_ctrl_unlock(ctrl);
        return ret;
 }
 
-int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control)
+int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
+                                       struct v4l2_control *control)
 {
        struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
 
@@ -1934,13 +1939,13 @@ int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control)
        if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
                return -EACCES;
 
-       return set_ctrl(ctrl, &control->value);
+       return set_ctrl(fh, ctrl, &control->value);
 }
 EXPORT_SYMBOL(v4l2_s_ctrl);
 
 int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control)
 {
-       return v4l2_s_ctrl(sd->ctrl_handler, control);
+       return v4l2_s_ctrl(NULL, sd->ctrl_handler, control);
 }
 EXPORT_SYMBOL(v4l2_subdev_s_ctrl);
 
@@ -1948,6 +1953,6 @@ int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
 {
        /* It's a driver bug if this happens. */
        WARN_ON(!type_is_int(ctrl));
-       return set_ctrl(ctrl, &val);
+       return set_ctrl(NULL, ctrl, &val);
 }
 EXPORT_SYMBOL(v4l2_ctrl_s_ctrl);
index 36a4a475ab22959c0e9d0d2179293b5271eb1b11..29f7a7df34c35ec18ebf0e7e762af073ec2bbe8c 100644 (file)
@@ -1483,11 +1483,11 @@ static long __video_do_ioctl(struct file *file,
                dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
 
                if (vfh && vfh->ctrl_handler) {
-                       ret = v4l2_s_ctrl(vfh->ctrl_handler, p);
+                       ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
                        break;
                }
                if (vfd->ctrl_handler) {
-                       ret = v4l2_s_ctrl(vfd->ctrl_handler, p);
+                       ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
                        break;
                }
                if (ops->vidioc_s_ctrl) {
@@ -1532,9 +1532,9 @@ static long __video_do_ioctl(struct file *file,
                        break;
                v4l_print_ext_ctrls(cmd, vfd, p, 1);
                if (vfh && vfh->ctrl_handler)
-                       ret = v4l2_s_ext_ctrls(vfh->ctrl_handler, p);
+                       ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
                else if (vfd->ctrl_handler)
-                       ret = v4l2_s_ext_ctrls(vfd->ctrl_handler, p);
+                       ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
                else if (check_ext_ctrls(p, 0))
                        ret = ops->vidioc_s_ext_ctrls(file, fh, p);
                break;
index f396cc3f32afeb31164eddaec2d1b11a9490b432..fd5dccaf3519a989a711e6489bd0976a75a4020c 100644 (file)
@@ -164,13 +164,13 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
                return v4l2_g_ctrl(vfh->ctrl_handler, arg);
 
        case VIDIOC_S_CTRL:
-               return v4l2_s_ctrl(vfh->ctrl_handler, arg);
+               return v4l2_s_ctrl(vfh, vfh->ctrl_handler, arg);
 
        case VIDIOC_G_EXT_CTRLS:
                return v4l2_g_ext_ctrls(vfh->ctrl_handler, arg);
 
        case VIDIOC_S_EXT_CTRLS:
-               return v4l2_s_ext_ctrls(vfh->ctrl_handler, arg);
+               return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, arg);
 
        case VIDIOC_TRY_EXT_CTRLS:
                return v4l2_try_ext_ctrls(vfh->ctrl_handler, arg);
index 56323e341e02a1910eb17c22d0082e64dcc1393e..e720f11a56fd2d64b21f1b3a33ef8dd79ae4a0b6 100644 (file)
@@ -28,6 +28,7 @@
 /* forward references */
 struct v4l2_ctrl_handler;
 struct v4l2_ctrl;
+struct v4l2_fh;
 struct video_device;
 struct v4l2_subdev;
 
@@ -485,15 +486,16 @@ s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
   */
 int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
 
-
 /* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
-int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
+int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
+                                               struct v4l2_control *ctrl);
 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
-int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
+int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
+                                               struct v4l2_ext_controls *c);
 
 /* Helpers for subdevices. If the associated ctrl_handler == NULL then they
    will all return -EINVAL. */