[MPlayer-dev-eng] [PATCH v2 2/5] stream_pvr: validate extended v4l2 controls before setting them

Reza Arbab arbab at panix.com
Wed Feb 10 17:19:49 CET 2016


An hdpvr device does not support the extended v4l2 controls

	V4L2_CID_MPEG_VIDEO_ASPECT
	V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
	V4L2_CID_MPEG_AUDIO_L1_BITRATE
	V4L2_CID_MPEG_AUDIO_L2_BITRATE
	V4L2_CID_MPEG_AUDIO_L3_BITRATE
	V4L2_CID_MPEG_AUDIO_MODE

Also, it supports only a subset of the menu options for

	V4L2_CID_MPEG_AUDIO_ENCODING
	V4L2_CID_MPEG_STREAM_TYPE

This results in the mplayer error

	[encoder] Error setting MPEG controls (Invalid argument).

Change add_v4l2_ext_control to do basic validation of a control/value pair
before adding it.

Signed-off-by: Reza Arbab <arbab at panix.com>
---
v2:
 * Move qmenu declaration into the block that uses it.
 * Use designated struct initializers for qctrl and qmenu.
 * Change MSGL_DBG2 to MSGL_V.

 stream/stream_pvr.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c
index db02cfd..ecce2c5 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -1021,6 +1021,31 @@ static void
 add_v4l2_ext_control (struct v4l2_ext_controls *ctrls, struct pvr_t *pvr,
                       uint32_t id, int32_t value)
 {
+  struct v4l2_query_ext_ctrl qctrl = { .id = id };
+
+  /* add only if the device supports this control */
+  if (ioctl (pvr->dev_fd, VIDIOC_QUERY_EXT_CTRL, &qctrl) < 0)
+  {
+    mp_msg (MSGT_OPEN, MSGL_V,
+            "%s can't set control %d (unsupported)\n",
+            LOG_LEVEL_ENCODER, qctrl.id);
+    return;
+  }
+
+  if (qctrl.type == V4L2_CTRL_TYPE_MENU)
+  {
+    struct v4l2_querymenu qmenu = { .id = id, .index = value };
+
+    /* add only if the value is a valid menu choice */
+    if (ioctl (pvr->dev_fd, VIDIOC_QUERYMENU, &qmenu) < 0)
+    {
+      mp_msg (MSGT_OPEN, MSGL_ERR,
+              "%s can't set %s to %d (invalid menu choice)\n",
+              LOG_LEVEL_ENCODER, qctrl.name, value);
+      return;
+    }
+  }
+
   ctrls->controls[ctrls->count].id = id;
   ctrls->controls[ctrls->count].value = value;
   ctrls->count++;
-- 
2.5.0



More information about the MPlayer-dev-eng mailing list