Skip to content

Commit 34a6b7d

Browse files
Hans VerkuilMauro Carvalho Chehab
authored andcommitted
[media] v4l2-ctrls: add a filter function to v4l2_ctrl_add_handler
With a filter function you can control more precisely which controls are added. This is useful in particular for radio device nodes for combined TV/Radio cards where you want to show just the radio-specific controls and not controls like brightness. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent a4f6440 commit 34a6b7d

8 files changed

Lines changed: 50 additions & 9 deletions

File tree

‎Documentation/video4linux/v4l2-controls.txt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,11 @@ handler and finally add the first handler to the second. For example:
594594
v4l2_ctrl_new_std(&radio_ctrl_handler, &radio_ops, V4L2_CID_AUDIO_MUTE, ...);
595595
v4l2_ctrl_new_std(&video_ctrl_handler, &video_ops, V4L2_CID_BRIGHTNESS, ...);
596596
v4l2_ctrl_new_std(&video_ctrl_handler, &video_ops, V4L2_CID_CONTRAST, ...);
597-
v4l2_ctrl_add_handler(&video_ctrl_handler, &radio_ctrl_handler);
597+
v4l2_ctrl_add_handler(&video_ctrl_handler, &radio_ctrl_handler, NULL);
598+
599+
The last argument to v4l2_ctrl_add_handler() is a filter function that allows
600+
you to filter which controls will be added. Set it to NULL if you want to add
601+
all controls.
598602

599603
Or you can add specific controls to a handler:
600604

‎drivers/media/pci/cx88/cx88-blackbird.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
12361236
err = cx2341x_handler_init(&dev->cxhdl, 36);
12371237
if (err)
12381238
goto fail_core;
1239-
v4l2_ctrl_add_handler(&dev->cxhdl.hdl, &core->video_hdl);
1239+
v4l2_ctrl_add_handler(&dev->cxhdl.hdl, &core->video_hdl, NULL);
12401240

12411241
/* blackbird stuff */
12421242
printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n",

‎drivers/media/pci/cx88/cx88-video.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
17951795
if (vc->id == V4L2_CID_CHROMA_AGC)
17961796
core->chroma_agc = vc;
17971797
}
1798-
v4l2_ctrl_add_handler(&core->video_hdl, &core->audio_hdl);
1798+
v4l2_ctrl_add_handler(&core->video_hdl, &core->audio_hdl, NULL);
17991799

18001800
/* load and configure helper modules */
18011801

‎drivers/media/platform/s5p-fimc/fimc-capture.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ int fimc_capture_ctrls_create(struct fimc_dev *fimc)
472472
return ret;
473473

474474
return v4l2_ctrl_add_handler(&vid_cap->ctx->ctrls.handler,
475-
fimc->pipeline.subdevs[IDX_SENSOR]->ctrl_handler);
475+
fimc->pipeline.subdevs[IDX_SENSOR]->ctrl_handler, NULL);
476476
}
477477

478478
static int fimc_capture_set_default_format(struct fimc_dev *fimc);

‎drivers/media/platform/soc_camera/soc_camera.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
11841184
sd->grp_id = soc_camera_grp_id(icd);
11851185
v4l2_set_subdev_hostdata(sd, icd);
11861186

1187-
if (v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler))
1187+
if (v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler, NULL))
11881188
goto ectrl;
11891189

11901190
/* At this point client .probe() should have run already */

‎drivers/media/v4l2-core/v4l2-ctrls.c‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,8 @@ EXPORT_SYMBOL(v4l2_ctrl_add_ctrl);
16871687

16881688
/* Add the controls from another handler to our own. */
16891689
int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
1690-
struct v4l2_ctrl_handler *add)
1690+
struct v4l2_ctrl_handler *add,
1691+
bool (*filter)(const struct v4l2_ctrl *ctrl))
16911692
{
16921693
struct v4l2_ctrl_ref *ref;
16931694
int ret = 0;
@@ -1707,6 +1708,9 @@ int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
17071708
/* And control classes */
17081709
if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
17091710
continue;
1711+
/* Filter any unwanted controls */
1712+
if (filter && !filter(ctrl))
1713+
continue;
17101714
ret = handler_new_ref(hdl, ctrl);
17111715
if (ret)
17121716
break;
@@ -1716,6 +1720,25 @@ int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
17161720
}
17171721
EXPORT_SYMBOL(v4l2_ctrl_add_handler);
17181722

1723+
bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl)
1724+
{
1725+
if (V4L2_CTRL_ID2CLASS(ctrl->id) == V4L2_CTRL_CLASS_FM_TX)
1726+
return true;
1727+
switch (ctrl->id) {
1728+
case V4L2_CID_AUDIO_MUTE:
1729+
case V4L2_CID_AUDIO_VOLUME:
1730+
case V4L2_CID_AUDIO_BALANCE:
1731+
case V4L2_CID_AUDIO_BASS:
1732+
case V4L2_CID_AUDIO_TREBLE:
1733+
case V4L2_CID_AUDIO_LOUDNESS:
1734+
return true;
1735+
default:
1736+
break;
1737+
}
1738+
return false;
1739+
}
1740+
EXPORT_SYMBOL(v4l2_ctrl_radio_filter);
1741+
17191742
/* Cluster controls */
17201743
void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
17211744
{

‎drivers/media/v4l2-core/v4l2-device.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
166166
}
167167

168168
/* This just returns 0 if either of the two args is NULL */
169-
err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler);
169+
err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler, NULL);
170170
if (err) {
171171
if (sd->internal_ops && sd->internal_ops->unregistered)
172172
sd->internal_ops->unregistered(sd);

‎include/media/v4l2-ctrls.h‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,28 @@ struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
384384
* @hdl: The control handler.
385385
* @add: The control handler whose controls you want to add to
386386
* the @hdl control handler.
387+
* @filter: This function will filter which controls should be added.
387388
*
388-
* Does nothing if either of the two is a NULL pointer.
389+
* Does nothing if either of the two handlers is a NULL pointer.
390+
* If @filter is NULL, then all controls are added. Otherwise only those
391+
* controls for which @filter returns true will be added.
389392
* In case of an error @hdl->error will be set to the error code (if it
390393
* wasn't set already).
391394
*/
392395
int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
393-
struct v4l2_ctrl_handler *add);
396+
struct v4l2_ctrl_handler *add,
397+
bool (*filter)(const struct v4l2_ctrl *ctrl));
394398

399+
/** v4l2_ctrl_radio_filter() - Standard filter for radio controls.
400+
* @ctrl: The control that is filtered.
401+
*
402+
* This will return true for any controls that are valid for radio device
403+
* nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
404+
* transmitter class controls.
405+
*
406+
* This function is to be used with v4l2_ctrl_add_handler().
407+
*/
408+
bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
395409

396410
/** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster.
397411
* @ncontrols: The number of controls in this cluster.

0 commit comments

Comments
 (0)