aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2011-06-29 07:56:22 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-07-27 16:53:34 -0400
commit60c0732244164f14e376cfae493dba368f761514 (patch)
tree104e04777d3239dabb1c4dba20ec17a7b1089c86
parent3ad57c33846d884cfeed770238b27f3dcf3742f1 (diff)
[media] v4l2-ctrls.c: add support for V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK
Normally no control events will go to the filehandle that called the VIDIOC_S_CTRL/VIDIOC_S_EXT_CTRLS ioctls. This is to prevent a feedback loop. This can now be overridden by setting the new V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK flag. Based on suggestions from Mauro Carvalho Chehab <mchehab@redhat.com> and Laurent Pinchart <laurent.pinchart@ideasonboard.com>. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml36
-rw-r--r--drivers/media/video/v4l2-ctrls.c3
-rw-r--r--include/linux/videodev2.h3
3 files changed, 33 insertions, 9 deletions
diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index 039a9694fd1d..25471e8e5da5 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -114,25 +114,28 @@
114 <row> 114 <row>
115 <entry><constant>V4L2_EVENT_CTRL</constant></entry> 115 <entry><constant>V4L2_EVENT_CTRL</constant></entry>
116 <entry>3</entry> 116 <entry>3</entry>
117 <entry>This event requires that the <structfield>id</structfield> 117 <entry><para>This event requires that the <structfield>id</structfield>
118 matches the control ID from which you want to receive events. 118 matches the control ID from which you want to receive events.
119 This event is triggered if the control's value changes, if a 119 This event is triggered if the control's value changes, if a
120 button control is pressed or if the control's flags change. 120 button control is pressed or if the control's flags change.
121 This event has a &v4l2-event-ctrl; associated with it. This struct 121 This event has a &v4l2-event-ctrl; associated with it. This struct
122 contains much of the same information as &v4l2-queryctrl; and 122 contains much of the same information as &v4l2-queryctrl; and
123 &v4l2-control;. 123 &v4l2-control;.</para>
124 124
125 If the event is generated due to a call to &VIDIOC-S-CTRL; or 125 <para>If the event is generated due to a call to &VIDIOC-S-CTRL; or
126 &VIDIOC-S-EXT-CTRLS;, then the event will not be sent to 126 &VIDIOC-S-EXT-CTRLS;, then the event will <emphasis>not</emphasis> be sent to
127 the file handle that called the ioctl function. This prevents 127 the file handle that called the ioctl function. This prevents
128 nasty feedback loops. 128 nasty feedback loops. If you <emphasis>do</emphasis> want to get the
129 event, then set the <constant>V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK</constant>
130 flag.
131 </para>
129 132
130 This event type will ensure that no information is lost when 133 <para>This event type will ensure that no information is lost when
131 more events are raised than there is room internally. In that 134 more events are raised than there is room internally. In that
132 case the &v4l2-event-ctrl; of the second-oldest event is kept, 135 case the &v4l2-event-ctrl; of the second-oldest event is kept,
133 but the <structfield>changes</structfield> field of the 136 but the <structfield>changes</structfield> field of the
134 second-oldest event is ORed with the <structfield>changes</structfield> 137 second-oldest event is ORed with the <structfield>changes</structfield>
135 field of the oldest event. 138 field of the oldest event.</para>
136 </entry> 139 </entry>
137 </row> 140 </row>
138 <row> 141 <row>
@@ -157,6 +160,25 @@
157 that are triggered by a status change such as <constant>V4L2_EVENT_CTRL</constant>. 160 that are triggered by a status change such as <constant>V4L2_EVENT_CTRL</constant>.
158 Other events will ignore this flag.</entry> 161 Other events will ignore this flag.</entry>
159 </row> 162 </row>
163 <row>
164 <entry><constant>V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK</constant></entry>
165 <entry>0x0002</entry>
166 <entry><para>If set, then events directly caused by an ioctl will also be sent to
167 the filehandle that called that ioctl. For example, changing a control using
168 &VIDIOC-S-CTRL; will cause a V4L2_EVENT_CTRL to be sent back to that same
169 filehandle. Normally such events are suppressed to prevent feedback loops
170 where an application changes a control to a one value and then another, and
171 then receives an event telling it that that control has changed to the first
172 value.</para>
173
174 <para>Since it can't tell whether that event was caused by another application
175 or by the &VIDIOC-S-CTRL; call it is hard to decide whether to set the
176 control to the value in the event, or ignore it.</para>
177
178 <para>Think carefully when you set this flag so you won't get into situations
179 like that.</para>
180 </entry>
181 </row>
160 </tbody> 182 </tbody>
161 </tgroup> 183 </tgroup>
162 </table> 184 </table>
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index a037739868e0..37a50e57f222 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -590,7 +590,8 @@ static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
590 fill_event(&ev, ctrl, changes); 590 fill_event(&ev, ctrl, changes);
591 591
592 list_for_each_entry(sev, &ctrl->ev_subs, node) 592 list_for_each_entry(sev, &ctrl->ev_subs, node)
593 if (sev->fh && sev->fh != fh) 593 if (sev->fh && (sev->fh != fh ||
594 (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK)))
594 v4l2_event_queue_fh(sev->fh, &ev); 595 v4l2_event_queue_fh(sev->fh, &ev);
595} 596}
596 597
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index baafe2f2e02a..2c4e83796301 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -1832,7 +1832,8 @@ struct v4l2_event {
1832 __u32 reserved[8]; 1832 __u32 reserved[8];
1833}; 1833};
1834 1834
1835#define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0) 1835#define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0)
1836#define V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK (1 << 1)
1836 1837
1837struct v4l2_event_subscription { 1838struct v4l2_event_subscription {
1838 __u32 type; 1839 __u32 type;