qv4l2: avoid empty titles for the video control tabs
PATCH 1/1 qv4l2: avoid empty titles for the video control tabs
The video control class names are used as titles for the GUI-tabs. The current code relies on the driver enumerating the control classes properly when using V4L2_CTRL_FLAG_NEXT_CTRL.
But the UVC-driver (and likely others, too) don't do that, so we can end up with an empty class name string.
Make sure we always have a control class title:
If the driver didn't enumrate a class along with the controls, call VIDIOC_QUERYCTRL for the class explicitly.
If that fails, fall back to an internal string list.
--- utils/qv4l2/ctrl-tab.cpp | 15 ++++++++++++++- utils/qv4l2/v4l2-api.cpp | 25 +++++++++++++++++++++++++ utils/qv4l2/v4l2-api.h | 3 +++ 3 files changed, 42 insertions(+), 1 deletions(-)
utils/qv4l2/ctrl-tab.cpp +14 -1
@@ -133,7 +133,20 @@ void ApplicationWindow::addTabs() m_col = m_row = 0; m_cols = 4; - const v4l2_queryctrl &qctrl = m_ctrlMap[id]; + v4l2_queryctrl &qctrl = m_ctrlMap[id]; + /* No real control, it's just the control class description. + Verify that the driver did enumerate the class properly + and add the class name if missing */ + if (!strlen((char *)qctrl.name)) + { + /* Try to request control class name from API */ + qctrl.id = id; + qctrl.type = V4L2_CTRL_TYPE_CTRL_CLASS; + if (!queryctrl(qctrl) || !strlen((char *)qctrl.name)) + /* Fall back to a local string list */ + strcpy((char *)qctrl.name, ctrl_class_name(ctrl_class).toAscii()); + } + QWidget *t = new QWidget(m_tabs); QVBoxLayout *vbox = new QVBoxLayout(t); QWidget *w = new QWidget(t);
utils/qv4l2/v4l2-api.cpp +25 -0
@@ -638,3 +638,28 @@ bool v4l2::get_interval(v4l2_fract &interval) return false; } + +QString v4l2::ctrl_class_name(__u32 ctrl_class) +{ + switch (ctrl_class) { + case V4L2_CTRL_CLASS_USER: + return "User Controls"; + case V4L2_CTRL_CLASS_MPEG: + return "MPEG-compression Controls"; + case V4L2_CTRL_CLASS_CAMERA: + return "Camera Controls"; + case V4L2_CTRL_CLASS_FM_TX: + return "FM Transmitter Controls"; + case V4L2_CTRL_CLASS_FLASH: + return "Flash Device Controls"; + case V4L2_CTRL_CLASS_JPEG: + return "JPEG-compression Controls"; + case V4L2_CTRL_CLASS_IMAGE_SOURCE: + return "Image Source Controls"; + case V4L2_CTRL_CLASS_IMAGE_PROC: + return "Image Processing Controls"; + case V4L2_CTRL_CLASS_DV: + return "Digital Video Controls"; + } + return "Controls (unknown class)"; +}
utils/qv4l2/v4l2-api.h +3 -0
@@ -163,6 +163,9 @@ public:bool set_interval (v4l2_fract interval); bool get_interval(v4l2_fract &interval); + +QString ctrl_class_name (__u32 ctrl_class); + private: void clear() { error(QString()); }
Signature · 1 line
1.7.7
Hans Verkuil
NAKQuoted 10 lines · On Tue October 9 2012 16:46:04 Frank Schäfer wrote:
The video control class names are used as titles for the GUI-tabs. The current code relies on the driver enumerating the control classes properly when using
V4L2_CTRL_FLAG_NEXT_CTRL.
But the UVC-driver (and likely others, too) don't do that, so we can end up with an empty class name string.Make sure we always have a control class title:
If the driver didn't enumrate a class along with the controls, callVIDIOC_QUERYCTRLfor the class explicitly.
If that fails, fall back to an internal string list.
NACK.
qv4l2 is for testing drivers, so I *want* to see if a driver doesn't provide the control class name. They really should provide it, and it is not something that should be papered over.
Regards,
Hans
Quoted 82 lines
Signed-off-by Frank Schäfer <[email protected]>--- utils/qv4l2/ctrl-tab.cpp | 15 ++++++++++++++- utils/qv4l2/v4l2-api.cpp | 25 +++++++++++++++++++++++++ utils/qv4l2/v4l2-api.h | 3 +++ 3 files changed, 42 insertions(+), 1 deletions(-)utils/qv4l2/ctrl-tab.cpp +14
-1@@ -133,7 +133,20 @@ void ApplicationWindow::addTabs() m_col = m_row = 0; m_cols = 4; - const v4l2_queryctrl &qctrl = m_ctrlMap[id]; + v4l2_queryctrl &qctrl = m_ctrlMap[id]; + /* No real control, it's just the control class description. + Verify that the driver did enumerate the class properly + and add the class name if missing */ + if (!strlen((char *)qctrl.name)) + { + /* Try to request control class name from API */ + qctrl.id = id; + qctrl.type = V4L2_CTRL_TYPE_CTRL_CLASS; + if (!queryctrl(qctrl) || !strlen((char *)qctrl.name)) + /* Fall back to a local string list */ + strcpy((char *)qctrl.name, ctrl_class_name(ctrl_class).toAscii()); + } + QWidget *t = new QWidget(m_tabs); QVBoxLayout *vbox = new QVBoxLayout(t); QWidget *w = new QWidget(t);utils/qv4l2/v4l2-api.cpp +25
-0@@ -638,3 +638,28 @@ bool v4l2::get_interval(v4l2_fract &interval) return false; } + +QString v4l2::ctrl_class_name(__u32 ctrl_class) +{ + switch (ctrl_class) { + case V4L2_CTRL_CLASS_USER: + return "User Controls"; + case V4L2_CTRL_CLASS_MPEG: + return "MPEG-compression Controls"; + case V4L2_CTRL_CLASS_CAMERA: + return "Camera Controls"; + case V4L2_CTRL_CLASS_FM_TX: + return "FM Transmitter Controls"; + case V4L2_CTRL_CLASS_FLASH: + return "Flash Device Controls"; + case V4L2_CTRL_CLASS_JPEG: + return "JPEG-compression Controls"; + case V4L2_CTRL_CLASS_IMAGE_SOURCE: + return "Image Source Controls"; + case V4L2_CTRL_CLASS_IMAGE_PROC: + return "Image Processing Controls"; + case V4L2_CTRL_CLASS_DV: + return "Digital Video Controls"; + } + return "Controls (unknown class)"; +}utils/qv4l2/v4l2-api.h +3
-0@@ -163,6 +163,9 @@ public:bool set_interval (v4l2_fract interval); bool get_interval(v4l2_fract &interval); + +QString ctrl_class_name (__u32 ctrl_class); + private: void clear() { error(QString()); }
Am 09.10.2012 17:24, schrieb Hans Verkuil:
Quoted 11 lines · On Tue October 9 2012 16:46:04 Frank Schäfer wrote:
Quoted 10 lines
The video control class names are used as titles for the GUI-tabs. The current code relies on the driver enumerating the control classes properly when using
V4L2_CTRL_FLAG_NEXT_CTRL.
But the UVC-driver (and likely others, too) don't do that, so we can end up with an empty class name string.Make sure we always have a control class title:
If the driver didn't enumrate a class along with the controls, callVIDIOC_QUERYCTRLfor the class explicitly.
If that fails, fall back to an internal string list.
Quoted 5 lines
NACK.
qv4l2 is for testing drivers, so I *want* to see if a driver doesn't provide the control class name. They really should provide it, and it is not something that should be papered over.
Hehe, ok.
Then you might want to remove all the "papering-over" code a few lines above, too ? ;)
Regards,
Frank
Quoted 3 lines
Regards,
Hans