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

Reza Arbab arbab at panix.com
Tue Feb 2 18:21:34 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>
---
 stream/stream_pvr.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c
index db02cfd..d24e6e6 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -1021,6 +1021,35 @@ 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;
+  struct v4l2_querymenu qmenu;
+
+  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_DBG2,
+            "%s can't set control %d (unsupported)\n",
+            LOG_LEVEL_ENCODER, qctrl.id);
+    return;
+  }
+
+  if (qctrl.type == V4L2_CTRL_TYPE_MENU)
+  {
+    qmenu.id = id;
+    qmenu.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