Re: [RFCv2 PATCH 04/11] v4l2-ctrls: Replace v4l2_ctrl_activate/grab with v4l2_ctrl_flags.

2011-06-04 Thread Hans Verkuil
On Friday, June 03, 2011 21:55:59 Laurent Pinchart wrote:
 Hi Hans,
 
 Thanks for the patch.
 
 On Wednesday 25 May 2011 15:33:48 Hans Verkuil wrote:
  From: Hans Verkuil hans.verk...@cisco.com
  
  This more generic function makes it possible to have a single function
  that takes care of flags handling, in particular with regards to sending
  a control event when the flags change.
  
  Signed-off-by: Hans Verkuil hans.verk...@cisco.com
  ---
 
 [snip]
 
  +/** v4l2_ctrl_flags_lock() - Clear and set flags for a control.
  +  * @ctrl: The control whose flags should be changed.
  +  * @clear_flags:  Mask out these flags.
  +  * @set_flags:Set these flags.
 *
  -  * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
  -  * Does nothing if @ctrl == NULL.
  -  * This will usually be called when starting or stopping streaming in the
  -  * driver.
  +  * This clears and sets flags. Does nothing if @ctrl == NULL.
 *
  -  * This function can be called regardless of whether the control handler
  -  * is locked or not.
  +  * This function expects that the control handler is unlocked and will
  lock +  * it before changing flags.
 */
  -void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
  +void v4l2_ctrl_flags_lock(struct v4l2_ctrl *ctrl, u32 clear_flags, u32
  set_flags);
 
 The v4l2_ctrl_flags_lock() function doesn't seem to be used. Do we need it ?
 
 

It is likely that I will (partially?) revert this patch. The idea for
v4l2_ctrl_flags(_lock) was to simplify changing the READ_ONLY flag on
the fly for autofoo/foo type controls. But I've changed my opinion on that.
See also the mail I sent earlier:

http://www.mail-archive.com/linux-media@vger.kernel.org/msg32332.html

Regards,

Hans
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFCv2 PATCH 04/11] v4l2-ctrls: Replace v4l2_ctrl_activate/grab with v4l2_ctrl_flags.

2011-06-03 Thread Laurent Pinchart
Hi Hans,

Thanks for the patch.

On Wednesday 25 May 2011 15:33:48 Hans Verkuil wrote:
 From: Hans Verkuil hans.verk...@cisco.com
 
 This more generic function makes it possible to have a single function
 that takes care of flags handling, in particular with regards to sending
 a control event when the flags change.
 
 Signed-off-by: Hans Verkuil hans.verk...@cisco.com
 ---

[snip]

 +/** v4l2_ctrl_flags_lock() - Clear and set flags for a control.
 +  * @ctrl:   The control whose flags should be changed.
 +  * @clear_flags:Mask out these flags.
 +  * @set_flags:  Set these flags.
*
 -  * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
 -  * Does nothing if @ctrl == NULL.
 -  * This will usually be called when starting or stopping streaming in the
 -  * driver.
 +  * This clears and sets flags. Does nothing if @ctrl == NULL.
*
 -  * This function can be called regardless of whether the control handler
 -  * is locked or not.
 +  * This function expects that the control handler is unlocked and will
 lock +  * it before changing flags.
*/
 -void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
 +void v4l2_ctrl_flags_lock(struct v4l2_ctrl *ctrl, u32 clear_flags, u32
 set_flags);

The v4l2_ctrl_flags_lock() function doesn't seem to be used. Do we need it ?

-- 
Regards,

Laurent Pinchart
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv2 PATCH 04/11] v4l2-ctrls: Replace v4l2_ctrl_activate/grab with v4l2_ctrl_flags.

2011-05-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This more generic function makes it possible to have a single function
that takes care of flags handling, in particular with regards to sending
a control event when the flags change.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 Documentation/video4linux/v4l2-controls.txt |   28 +++--
 drivers/media/video/cx2341x.c   |   58 --
 drivers/media/video/saa7115.c   |3 +-
 drivers/media/video/v4l2-ctrls.c|   33 ---
 include/media/v4l2-ctrls.h  |   34 +++-
 5 files changed, 76 insertions(+), 80 deletions(-)

diff --git a/Documentation/video4linux/v4l2-controls.txt 
b/Documentation/video4linux/v4l2-controls.txt
index 881e7f4..bc24be4 100644
--- a/Documentation/video4linux/v4l2-controls.txt
+++ b/Documentation/video4linux/v4l2-controls.txt
@@ -381,24 +381,26 @@ Active and Grabbed Controls
 ===
 
 If you get more complex relationships between controls, then you may have to
-activate and deactivate controls. For example, if the Chroma AGC control is
-on, then the Chroma Gain control is inactive. That is, you may set it, but
-the value will not be used by the hardware as long as the automatic gain
-control is on. Typically user interfaces can disable such input fields.
+activate and deactivate controls. For example, depending on the chosen MPEG
+audio codec only the audio bitrate control correspending to that audio codec
+is marked 'active', all other audio bitrate controls will be marked 'inactive'.
+That is, you may set it, but the value will not be used by the hardware.
+Typically user interfaces will disable inactive input fields.
 
-You can set the 'active' status using v4l2_ctrl_activate(). By default all
-controls are active. Note that the framework does not check for this flag.
-It is meant purely for GUIs. The function is typically called from within
-s_ctrl.
+By default all controls are active. Note that the framework does not check
+for this flag. It is meant purely for GUIs.
 
-The other flag is the 'grabbed' flag. A grabbed control means that you cannot
+You may also have to grab controls. A grabbed control means that you cannot
 change it because it is in use by some resource. Typical examples are MPEG
 bitrate controls that cannot be changed while capturing is in progress.
 
-If a control is set to 'grabbed' using v4l2_ctrl_grab(), then the framework
-will return -EBUSY if an attempt is made to set this control. The
-v4l2_ctrl_grab() function is typically called from the driver when it
-starts or stops streaming.
+If a control is set to 'grabbed', then the framework will return -EBUSY if
+an attempt is made to set this control. You typically change the 'grabbed'
+status from the driver when it starts or stops streaming.
+
+You can change the control's status using the v4l2_ctrl_flags() or
+v4l2_ctrl_flags_lock() calls. The first can be called from within s_ctrl,
+the second can be called from elsewhere and will lock first.
 
 
 Control Clusters
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 103ef6b..2781889 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -1307,6 +1307,12 @@ static int cx2341x_try_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static void cx2341x_activate(struct v4l2_ctrl *ctrl, bool activate)
+{
+   v4l2_ctrl_flags(ctrl, V4L2_CTRL_FLAG_INACTIVE,
+   activate ? 0 : V4L2_CTRL_FLAG_INACTIVE);
+}
+
 static int cx2341x_s_ctrl(struct v4l2_ctrl *ctrl)
 {
static const int mpeg_stream_type[] = {
@@ -1380,10 +1386,10 @@ static int cx2341x_s_ctrl(struct v4l2_ctrl *ctrl)
int is_ac3 = hdl-audio_encoding-val ==
V4L2_MPEG_AUDIO_ENCODING_AC3;
 
-   v4l2_ctrl_activate(hdl-audio_ac3_bitrate, is_ac3);
-   v4l2_ctrl_activate(hdl-audio_l2_bitrate, !is_ac3);
+   cx2341x_activate(hdl-audio_ac3_bitrate, is_ac3);
+   cx2341x_activate(hdl-audio_l2_bitrate, !is_ac3);
}
-   v4l2_ctrl_activate(hdl-audio_mode_extension,
+   cx2341x_activate(hdl-audio_mode_extension,
hdl-audio_mode-val == 
V4L2_MPEG_AUDIO_MODE_JOINT_STEREO);
if (cx2341x_neq(hdl-audio_sampling_freq) 
hdl-ops  hdl-ops-s_audio_sampling_freq)
@@ -1413,9 +1419,9 @@ static int cx2341x_s_ctrl(struct v4l2_ctrl *ctrl)
if (err)
return err;
 
-   v4l2_ctrl_activate(hdl-video_bitrate_mode,
+   cx2341x_activate(hdl-video_bitrate_mode,
hdl-video_encoding-val != 
V4L2_MPEG_VIDEO_ENCODING_MPEG_1);
-   v4l2_ctrl_activate(hdl-video_bitrate_peak,
+   cx2341x_activate(hdl-video_bitrate_peak,