qv4l2: add OpenGL render and window fixes
v2 cover qv4l2: add OpenGL render and window fixes
The qv4l2 test utility now supports OpenGL-accelerated display of video. This allows for using the graphics card to render the video content to screen and to perform color space conversion.
The OpenGL implementation requires OpenGL and QtOpenGL libraries as well as an OpenGL driver (typically from the graphics driver). If OpenGL support is not present,
then the program will fall back to using the CPU to display.
Changelog v2:
- Cleaned up the capture win code and classes
- CaptureWin is now a base class that can be used to implement different ways of displaying video.
- setMinimumSize is now more reliable
- Small code tweaks and improvements, including cleaner display flow
- Changed the OpenGL abbreviation from OGL to GL
Some of the changes/improvements:
- Moved the ctrlEvent() function in qv4l2.cpp to be grouped with GUI function and to group capFrame() and capVbiFrame() together.
- OpenGL acceleration for supported systems.
- Option to change between GPU or CPU based rendering.
- CaptureWin's setMinimumSize() sets the minimum size for the video frame viewport and not for the window itself. If the minimum size is larger than the monitor resolution, it will reduce the minimum size to match this.
- Added a new menu option 'Preview' for controlling the CaptureWin's behavior.
- Added a couple of hotkeys:
CTRL + V : When main window is selected start capture.
This gives an option other than the button to start recording, as this is a frequent operation when using the utility.
CTRL + W : When CaptureWin is selected close capture window.
It makes it easier to deal with high resolutions video on small screen, especially when the window close button may
be outside the monitor when repositioning the window.
Known issues:
- Repositioning, scaling or switching windows while the capture is recording will reduce the framerate. This is a limitation of Qt and not OpenGL.
- Using 4 streams of RGB3 1080p60 can at random times cease to render correctly
and reduce the framerate to half. A restart solves this though.
- OpenGL is limited to 60fps. Disabling V-sync might allow for faster framerates.
- Resizing or scaling is not supported, mainly because the YUY2 shader renders the image incorrectly when the canvas size is not equal to the frame size.
- Some of the supported OpenGL formats may use the CPU for colorspace conversion, but this is driver dependant.
Supported formats for OpenGL render:
- Native supported and accelerated:
V4L2_PIX_FMT_RGB32
V4L2_PIX_FMT_BGR32
V4L2_PIX_FMT_RGB24
V4L2_PIX_FMT_BGR24
V4L2_PIX_FMT_RGB565
V4L2_PIX_FMT_RGB555
V4L2_PIX_FMT_YUYV
V4L2_PIX_FMT_YVYU
V4L2_PIX_FMT_UYVY
V4L2_PIX_FMT_VYUY
V4L2_PIX_FMT_YVU420
V4L2_PIX_FMT_YUV420- All formats supported by V4L conversion library,
but they will use the CPU to convert to RGB3 before being displayed with OpenGL.
Performance:
All tests are done on an Intel i7-2600S (with Turbo Boost disabled) using the integrated Intel HD 2000 graphics processor. The mothreboard is an ASUS P8H77-I with 2x2GB CL 9-9-9-24 DDR3 RAM. The capture card is a Cisco test card with 4 HDMI inputs connected using PCIe2.0x8. All video input streams used for testing are progressive HD (1920x1080) with 60fps.
FPS for every input for a given number of streams:
1 STREAM 2 STREAMS 3 STREAMS 4 STREAMS
RGB3 60 60 60 60 BGR3 60 60 60 50 YUYV 60 60 60 48 YU12 60 60 60 52 YV12 60 60 60 52
PATCH v2 1/5 qv4l2: move function ctrlEvent
Moved the ctrlEvent() function in qv4l2.cpp to be grouped with GUI function and to group capFrame() and capVbiFrame() together.
--- utils/qv4l2/qv4l2.cpp | 94 +++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 47 deletions(-)
utils/qv4l2/qv4l2.cpp +47 -47
@@ -202,6 +202,53 @@ void ApplicationWindow::openrawdev() setDevice(d.selectedFiles().first(), true); } +void ApplicationWindow::ctrlEvent() +{ + v4l2_event ev; + + while (dqevent(ev)) { + if (ev.type != V4L2_EVENT_CTRL) + continue; + m_ctrlMap[ev.id].flags = ev.u.ctrl.flags; + m_ctrlMap[ev.id].minimum = ev.u.ctrl.minimum; + m_ctrlMap[ev.id].maximum = ev.u.ctrl.maximum; + m_ctrlMap[ev.id].step = ev.u.ctrl.step; + m_ctrlMap[ev.id].default_value = ev.u.ctrl.default_value; + m_widgetMap[ev.id]->setDisabled(m_ctrlMap[ev.id].flags & CTRL_FLAG_DISABLED); + switch (m_ctrlMap[ev.id].type) { + case V4L2_CTRL_TYPE_INTEGER: + case V4L2_CTRL_TYPE_INTEGER_MENU: + case V4L2_CTRL_TYPE_MENU: + case V4L2_CTRL_TYPE_BOOLEAN: + case V4L2_CTRL_TYPE_BITMASK: + setVal(ev.id, ev.u.ctrl.value); + break; + case V4L2_CTRL_TYPE_INTEGER64: + setVal64(ev.id, ev.u.ctrl.value64); + break; + default: + break; + } + if (m_ctrlMap[ev.id].type != V4L2_CTRL_TYPE_STRING) + continue; + queryctrl(m_ctrlMap[ev.id]); + + struct v4l2_ext_control c; + struct v4l2_ext_controls ctrls; + + c.id = ev.id; + c.size = m_ctrlMap[ev.id].maximum + 1; + c.string = (char *)malloc(c.size); + memset(&ctrls, 0, sizeof(ctrls)); + ctrls.count = 1; + ctrls.ctrl_class = 0; + ctrls.controls = &c; + if (!ioctl(VIDIOC_G_EXT_CTRLS, &ctrls)) + setString(ev.id, c.string); + free(c.string); + } +} + void ApplicationWindow::capVbiFrame() { __u32 buftype = m_genTab->bufType();
@@ -305,53 +352,6 @@ void ApplicationWindow::capVbiFrame() refresh(); } -void ApplicationWindow::ctrlEvent() -{ - v4l2_event ev; - - while (dqevent(ev)) { - if (ev.type != V4L2_EVENT_CTRL) - continue; - m_ctrlMap[ev.id].flags = ev.u.ctrl.flags; - m_ctrlMap[ev.id].minimum = ev.u.ctrl.minimum; - m_ctrlMap[ev.id].maximum = ev.u.ctrl.maximum; - m_ctrlMap[ev.id].step = ev.u.ctrl.step; - m_ctrlMap[ev.id].default_value = ev.u.ctrl.default_value; - m_widgetMap[ev.id]->setDisabled(m_ctrlMap[ev.id].flags & CTRL_FLAG_DISABLED); - switch (m_ctrlMap[ev.id].type) { - case V4L2_CTRL_TYPE_INTEGER: - case V4L2_CTRL_TYPE_INTEGER_MENU: - case V4L2_CTRL_TYPE_MENU: - case V4L2_CTRL_TYPE_BOOLEAN: - case V4L2_CTRL_TYPE_BITMASK: - setVal(ev.id, ev.u.ctrl.value); - break; - case V4L2_CTRL_TYPE_INTEGER64: - setVal64(ev.id, ev.u.ctrl.value64); - break; - default: - break; - } - if (m_ctrlMap[ev.id].type != V4L2_CTRL_TYPE_STRING) - continue; - queryctrl(m_ctrlMap[ev.id]); - - struct v4l2_ext_control c; - struct v4l2_ext_controls ctrls; - - c.id = ev.id; - c.size = m_ctrlMap[ev.id].maximum + 1; - c.string = (char *)malloc(c.size); - memset(&ctrls, 0, sizeof(ctrls)); - ctrls.count = 1; - ctrls.ctrl_class = 0; - ctrls.controls = &c; - if (!ioctl(VIDIOC_G_EXT_CTRLS, &ctrls)) - setString(ev.id, c.string); - free(c.string); - } -} - void ApplicationWindow::capFrame() { __u32 buftype = m_genTab->bufType();
Signature · 1 line
1.8.3.2
PATCH v2 2/5 qv4l2: add hotkeys for common operations
In reply to Bård Eirik WintherCTRL + V : When main window is selected start capture.
This gives an option other than the button to start recording, as this is a frequent operation when using the utility.
CTRL + W : When CaptureWin is selected close capture window
It makes it easier to deal with high resolutions video on small screen, especially when the window close button may be outside the monitor when repositioning the window.
--- utils/qv4l2/capture-win.cpp | 8 ++++++++ utils/qv4l2/capture-win.h | 4 +++- utils/qv4l2/qv4l2.cpp | 1 + 3 files changed, 12 insertions(+), 1 deletion(-)
utils/qv4l2/capture-win.cpp +8 -0
@@ -35,6 +35,14 @@ CaptureWin::CaptureWin() vbox->addWidget(m_label); vbox->addWidget(m_msg); + + hotkeyClose = new QShortcut(Qt::CTRL+Qt::Key_W, this); + QObject::connect(hotkeyClose, SIGNAL(activated()), this, SLOT(close())); +} + +CaptureWin::~CaptureWin() +{ + delete hotkeyClose; } void CaptureWin::setImage(const QImage &image, const QString &status)
utils/qv4l2/capture-win.h +3 -1
@@ -21,6 +21,7 @@#define CAPTURE_WIN_H #include <QWidget> +#include <QShortcut> #include <sys/time.h> class QImage;
@@ -32,7 +33,7 @@ class CaptureWin : public QWidget public:CaptureWin (); - virtual ~CaptureWin() {} + ~CaptureWin (); void setImage(const QImage &image, const QString &status);
@@ -45,6 +46,7 @@ signals: private:QLabel *m_label;QLabel *m_msg; + QShortcut *hotkeyClose; };#endif
utils/qv4l2/qv4l2.cpp +1 -0
@@ -78,6 +78,7 @@ ApplicationWindow::ApplicationWindow() : m_capStartAct->setStatusTip("Start capturing"); m_capStartAct->setCheckable(true); m_capStartAct->setDisabled(true); + m_capStartAct->setShortcut(Qt::CTRL+Qt::Key_V); connect(m_capStartAct, SIGNAL(toggled(bool)), this, SLOT(capStart(bool))); m_snapshotAct = new QAction(QIcon(":/snapshot.png"), "&Make Snapshot", this);
Signature · 1 line
1.8.3.2
PATCH v2 3/5 qv4l2: fix minimum size in capture win to frame size
In reply to Bård Eirik WintherCaptureWin's setMinimumSize() sets the minimum size for the video frame viewport and not for the window itself. If the minimum size is larger than the monitor resolution, it will reduce the minimum size to match this.
--- utils/qv4l2/capture-win.cpp | 29 +++++++++++++++++++++++++++++ utils/qv4l2/capture-win.h | 1 + 2 files changed, 30 insertions(+)
utils/qv4l2/capture-win.cpp +29 -0
@@ -21,6 +21,8 @@ #include <QImage> #include <QVBoxLayout> #include <QCloseEvent> +#include <QApplication> +#include <QDesktopWidget> #include "qv4l2.h" #include "capture-win.h"
@@ -45,6 +47,33 @@ CaptureWin::~CaptureWin() delete hotkeyClose; } +void CaptureWin::setMinimumSize(int minw, int minh) +{ + QDesktopWidget *screen = QApplication::desktop(); + QRect resolution = screen->screenGeometry(); + QSize maxSize = maximumSize(); + + int l, t, r, b; + layout()->getContentsMargins(&l, &t, &r, &b); + minw += l + r; + minh += t + b + m_msg->minimumSizeHint().height() + layout()->spacing(); + + if (minw > resolution.width()) + minw = resolution.width(); + if (minw < 150) + minw = 150; + + if (minh > resolution.height()) + minh = resolution.height(); + if (minh < 100) + minh = 100; + + QWidget::setMinimumSize(minw, minh); + QWidget::setMaximumSize(minw, minh); + updateGeometry(); + QWidget::setMaximumSize(maxSize.width(), maxSize.height()); +} + void CaptureWin::setImage(const QImage &image, const QString &status) { m_label->setPixmap(QPixmap::fromImage(image));
utils/qv4l2/capture-win.h +1 -0
@@ -35,6 +35,7 @@ public:CaptureWin (); ~CaptureWin (); +void setMinimumSize (int minw,int minh); void setImage(const QImage &image, const QString &status); protected:
Signature · 1 line
1.8.3.2
PATCH v2 4/5 qv4l2: new modular capture window design
In reply to Bård Eirik WintherThe display of video has been divided into classes to easier implement other ways to render frames on screen.
--- utils/qv4l2/Makefile.am | 4 +- utils/qv4l2/capture-win-qt.cpp | 89 ++++++++++++++++++++++++++++++++++++ utils/qv4l2/capture-win-qt.h | 48 ++++++++++++++++++++ utils/qv4l2/capture-win.cpp | 45 ++++++++++--------- utils/qv4l2/capture-win.h | 25 ++++++----- utils/qv4l2/qv4l2.cpp | 100 ++++++++++++++++++++--------------------- utils/qv4l2/qv4l2.h | 1 + 7 files changed, 226 insertions(+), 86 deletions(-) create mode 100644 utils/qv4l2/capture-win-qt.cpp create mode 100644 utils/qv4l2/capture-win-qt.h
utils/qv4l2/Makefile.am +2 -2
@@ -1,6 +1,7 @@ bin_PROGRAMS = qv4l2 qv4l2_SOURCES = qv4l2.cpp general-tab.cpp ctrl-tab.cpp vbi-tab.cpp v4l2-api.cpp capture-win.cpp \ + capture-win-qt.cpp capture-win-qt.h \ raw2sliced.cpp qv4l2.h capture-win.h general-tab.h vbi-tab.h v4l2-api.h raw2sliced.h nodist_qv4l2_SOURCES = moc_qv4l2.cpp moc_general-tab.cpp moc_capture-win.cpp moc_vbi-tab.cpp qrc_qv4l2.cpp qv4l2_LDADD = ../../lib/libv4l2/libv4l2.la ../../lib/libv4lconvert/libv4lconvert.la ../libv4l2util/libv4l2util.la
@@ -37,5 +38,4 @@ install-data-local: $(INSTALL_DATA) -D -p "$(srcdir)/qv4l2_24x24.png" "$(DESTDIR)$(datadir)/icons/hicolor/24x24/apps/qv4l2.png" $(INSTALL_DATA) -D -p "$(srcdir)/qv4l2_32x32.png" "$(DESTDIR)$(datadir)/icons/hicolor/32x32/apps/qv4l2.png" $(INSTALL_DATA) -D -p "$(srcdir)/qv4l2_64x64.png" "$(DESTDIR)$(datadir)/icons/hicolor/64x64/apps/qv4l2.png" - $(INSTALL_DATA) -D -p "$(srcdir)/qv4l2.svg" "$(DESTDIR)$(datadir)/icons/hicolor/scalable/apps/qv4l2.svg" - + $(INSTALL_DATA) -D -p "$(srcdir)/qv4l2.svg" "$(DESTDIR)$(datadir)/icons/hicolor/scalable/apps/qv4l2.svg"
utils/qv4l2/capture-win-qt.cpp new file +89 -0
89 lines not on this page · raw message
utils/qv4l2/capture-win-qt.h new file +48 -0
48 lines not on this page · raw message
utils/qv4l2/capture-win.cpp +23 -22
77 lines not on this page · raw message
utils/qv4l2/capture-win.h +15 -10
@@ -20,12 +20,11 @@#ifndef CAPTURE_WIN_H #define CAPTURE_WIN_H +#include "qv4l2.h" +#include <QWidget> #include <QShortcut> -#include <sys/time.h> - -class QImage; -class QLabel; +#include <QLabel> class CaptureWin : public QWidget {
@@ -36,18 +35,24 @@ public: ~CaptureWin ();void setMinimumSize (int minw,int minh); - void setImage(const QImage &image, const QString &status); + virtual void setFrame(int width, int height, __u32 format, + unsigned char *data, const QString &info) = 0; + + virtual void stop() = 0; + virtual bool hasNativeFormat(__u32 format) = 0; +static bool isSupported () {return false; } protected: - virtual void closeEvent(QCloseEvent *event); +void closeEvent (QCloseEvent *event); +void buildWindow (QWidget *videoSurface); + +QLabel m_information; signals:void close (); private: -QLabel *m_label; -QLabel *m_msg; - QShortcut *hotkeyClose; -}; + QShortcut *m_hotkeyClose; +};#endif
utils/qv4l2/qv4l2.cpp +48 -52
204 lines not on this page · raw message
utils/qv4l2/qv4l2.h +1 -0
@@ -33,6 +33,7 @@#include "v4l2-api.h" #include "raw2sliced.h" +#include "capture-win.h" class QComboBox;class QSpinBox;
Signature · 1 line
1.8.3.2
PATCH v2 5/5 qv4l2: add OpenGL video display and render
In reply to Bård Eirik WintherAdds OpenGL-accelerated display of video for the qv4l2 test utility. This allows for using the graphics card to render the video content to screen and to perform color space conversion.
--- configure.ac | 8 +- utils/qv4l2/Makefile.am | 8 +- utils/qv4l2/capture-win-gl.cpp | 556 +++++++++++++++++++++++++++++++++++++++++ utils/qv4l2/capture-win-gl.h | 103 ++++++++ utils/qv4l2/qv4l2.cpp | 52 +++- utils/qv4l2/qv4l2.h | 10 + 6 files changed, 733 insertions(+), 4 deletions(-) create mode 100644 utils/qv4l2/capture-win-gl.cpp create mode 100644 utils/qv4l2/capture-win-gl.h
configure.ac +7 -1
@@ -128,7 +128,12 @@ if test "x$qt_pkgconfig" = "xtrue"; then AC_SUBST(UIC) AC_SUBST(RCC) else - AC_MSG_WARN(Qt4 is not available) + AC_MSG_WARN(Qt4 or higher is not available) +fi + +PKG_CHECK_MODULES(QTGL, [QtOpenGL >= 4.4 gl], [qt_pkgconfig_gl=true], [qt_pkgconfig_gl=false]) +if test "x$qt_pkgconfig_gl" = "xfalse"; then + AC_MSG_WARN(Qt4 OpenGL or higher is not available) fi AC_SUBST([JPEG_LIBS])
@@ -237,6 +242,7 @@ AM_CONDITIONAL([WITH_LIBDVBV5], [test x$enable_libdvbv5 = xyes]) AM_CONDITIONAL([WITH_LIBV4L], [test x$enable_libv4l != xno]) AM_CONDITIONAL([WITH_V4LUTILS], [test x$enable_v4lutils != xno]) AM_CONDITIONAL([WITH_QV4L2], [test ${qt_pkgconfig} = true -a x$enable_qv4l2 != xno]) +AM_CONDITIONAL([WITH_QV4L2_GL], [test WITH_QV4L2 -a ${qt_pkgconfig_gl} = true]) AM_CONDITIONAL([WITH_V4L_PLUGINS], [test x$enable_libv4l != xno -a x$enable_shared != xno]) AM_CONDITIONAL([WITH_V4L_WRAPPERS], [test x$enable_libv4l != xno -a x$enable_shared != xno])
utils/qv4l2/Makefile.am +7 -1
@@ -1,12 +1,18 @@ bin_PROGRAMS = qv4l2 qv4l2_SOURCES = qv4l2.cpp general-tab.cpp ctrl-tab.cpp vbi-tab.cpp v4l2-api.cpp capture-win.cpp \ - capture-win-qt.cpp capture-win-qt.h \ + capture-win-qt.cpp capture-win-qt.h capture-win-gl.cpp capture-win-gl.h \ raw2sliced.cpp qv4l2.h capture-win.h general-tab.h vbi-tab.h v4l2-api.h raw2sliced.h nodist_qv4l2_SOURCES = moc_qv4l2.cpp moc_general-tab.cpp moc_capture-win.cpp moc_vbi-tab.cpp qrc_qv4l2.cpp qv4l2_LDADD = ../../lib/libv4l2/libv4l2.la ../../lib/libv4lconvert/libv4lconvert.la ../libv4l2util/libv4l2util.la + +if WITH_QV4L2_GL +qv4l2_CPPFLAGS = $(QTGL_CFLAGS) -DENABLE_GL +qv4l2_LDFLAGS = $(QTGL_LIBS) +else qv4l2_CPPFLAGS = $(QT_CFLAGS) qv4l2_LDFLAGS = $(QT_LIBS) +endif EXTRA_DIST = exit.png fileopen.png qv4l2_24x24.png qv4l2_64x64.png qv4l2.png qv4l2.svg snapshot.png \ video-television.png fileclose.png qv4l2_16x16.png qv4l2_32x32.png qv4l2.desktop qv4l2.qrc record.png \
utils/qv4l2/capture-win-gl.cpp new file +556 -0
556 lines not on this page · raw message
utils/qv4l2/capture-win-gl.h new file +103 -0
103 lines not on this page · raw message
utils/qv4l2/qv4l2.cpp +50 -2
83 lines not on this page · raw message
utils/qv4l2/qv4l2.h +10 -0
@@ -60,6 +60,11 @@ enum CapMethod {methodUser }; +enum RenderMethod { +QV4L2_RENDER_GL , +QV4L2_RENDER_QT +}; +struct buffer {void *start;size_t length;
@@ -92,6 +97,8 @@ private:void stopCapture ();void startOutput (unsigned buffer_size);void stopOutput (); +void newCaptureWin (); +struct buffer *m_buffers;struct v4l2_format m_capSrcFormat;struct v4l2_format m_capDestFormat;
@@ -101,6 +108,7 @@ private:bool m_mustConvert;CapMethod m_capMethod;bool m_makeSnapshot; +RenderMethod m_renderMethod; private slots:void capStart (bool );
@@ -109,6 +117,7 @@ private slots:void snapshot ();void capVbiFrame ();void saveRaw (bool ); +void setRenderMethod ();// gui private slots:
@@ -166,6 +175,7 @@ private:QAction *m_snapshotAct;QAction *m_saveRawAct;QAction *m_showFramesAct; +QAction *m_useGLAct;QString m_filename;QSignalMapper *m_sigMapper;QTabWidget *m_tabs;
Signature · 1 line
1.8.3.2