Skip to contentSkip to conversation

OpenGL render for qv4l2

PATCH Superseded Bård Eirik Winther 2 participants 8 messages Jul 16, 2013 Media (V4L/DVB)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#3 lore raw

PATCH 3/4 qv4l2: fix CaptureWin mimimum size to match video fram size

In reply to Bård Eirik Winther

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.

---
 utils/qv4l2/capture-win.cpp | 26 ++++++++++++++++++++++++++
 utils/qv4l2/capture-win.h   |  1 +
 2 files changed, 27 insertions(+)
utils/qv4l2/capture-win.cpp +26 -0
index a94c73d..7ac3fa1 100644
@@ -21,6 +21,8 @@
 #include <QImage>
 #include <QVBoxLayout>
 #include <QCloseEvent>
+#include <QApplication>
+#include <QDesktopWidget>
 
 #include "qv4l2.h"
 #include "capture-win.h"
@@ -36,6 +38,10 @@ CaptureWin::CaptureWin()
 	vbox->addWidget(m_label);
 	vbox->addWidget(m_msg);
 
+	int l, t, r, b;
+	vbox->getContentsMargins(&l, &t, &r, &b);
+	vbox->setSpacing(b);
+
 	hotkeyClose = new QShortcut(Qt::CTRL+Qt::Key_W, this);
 	QObject::connect(hotkeyClose, SIGNAL(activated()), this, SLOT(close()));
 }
@@ -45,6 +51,26 @@ CaptureWin::~CaptureWin()
 	delete hotkeyClose;
 }
 
+void CaptureWin::setMinimumSize(int minw, int minh)
+{
+	QDesktopWidget *screen = QApplication::desktop();
+	QRect resolution = screen->screenGeometry();
+
+	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 (minh > resolution.height())
+		minh = resolution.height();
+
+	QWidget::setMinimumSize(minw, minh);
+	resize(minw, minh);
+}
+
 void CaptureWin::setImage(const QImage &image, const QString &status)
 {
 	m_label->setPixmap(QPixmap::fromImage(image));
utils/qv4l2/capture-win.h +1 -0
index 4115d56..3de3447 100644
@@ -35,6 +35,7 @@ public:
 	CaptureWin();
 	~CaptureWin();
 
+	virtual void setMinimumSize(int minw, int minh);
 	void setImage(const QImage &image, const QString &status);
 
 protected:
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/4 qv4l2: move function ctrlEvent

In reply to Bård Eirik Winther

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
index de9b154..a8fcc65 100644
@@ -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
#0 lore raw

cover OpenGL render for qv4l2

qv4l2:

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 performing color space conversion.

The OpenGL implementation requires the QtOpenGL library as well as an OpenGL driver. If OpenGL support is not present, then the program will fall back to using the CPU to display.

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.

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
#2 lore raw

PATCH 2/4 qv4l2: add hotkeys for common operations

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.

---
 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
index 6798252..a94c73d 100644
@@ -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
index e861b12..4115d56 100644
@@ -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
index a8fcc65..bb1d84f 100644
@@ -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
#4 lore raw

PATCH 4/4 qv4l2: add OpenGL video render

In reply to Bård Eirik Winther

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 performing color space conversion.

---
 configure.ac                |   8 +-
 utils/qv4l2/Makefile.am     |   9 +-
 utils/qv4l2/capture-win.cpp | 559 ++++++++++++++++++++++++++++++++++++++++++--
 utils/qv4l2/capture-win.h   |  81 ++++++-
 utils/qv4l2/qv4l2.cpp       | 173 +++++++++++---
 utils/qv4l2/qv4l2.h         |   8 +
 6 files changed, 782 insertions(+), 56 deletions(-)
configure.ac +7 -1
index e249546..97a0dfc 100644
@@ -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(QTOGL, [QtOpenGL >= 4.4 gl], [qt_pkgconfig_ogl=true], [qt_pkgconfig_ogl=false])
+if test "x$qt_pkgconfig_ogl" = "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_OGL_COMPILE], [test WITH_QV4L2 -a ${qt_pkgconfig_ogl} = 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 -2
index 1f5a49f..86bf786 100644
@@ -4,8 +4,14 @@ qv4l2_SOURCES = qv4l2.cpp general-tab.cpp ctrl-tab.cpp vbi-tab.cpp v4l2-api.cpp
   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_OGL_COMPILE
+qv4l2_CPPFLAGS = $(QTOGL_CFLAGS) -DENABLE_OGL
+qv4l2_LDFLAGS = $(QTOGL_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 \
@@ -37,5 +43,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"
\ No newline at end of file
utils/qv4l2/capture-win.cpp +541 -18

596 lines not on this page · raw message

utils/qv4l2/capture-win.h +76 -5

104 lines not on this page · raw message

utils/qv4l2/qv4l2.cpp +143 -30

292 lines not on this page · raw message

utils/qv4l2/qv4l2.h +8 -0
index 8634948..27cb72d 100644
@@ -91,6 +91,9 @@ private:
 	void stopCapture();
 	void startOutput(unsigned buffer_size);
 	void stopOutput();
+	bool isSupportedFormatCPU(v4l2_pix_format &format, QImage::Format &dstFmt);
+	bool isSupportedFormatOGL(v4l2_pix_format &format);
+
 	struct buffer *m_buffers;
 	struct v4l2_format m_capSrcFormat;
 	struct v4l2_format m_capDestFormat;
@@ -108,6 +111,7 @@ private slots:
 	void snapshot();
 	void capVbiFrame();
 	void saveRaw(bool);
+	void setPreviewMode();
 
 	// gui
 private slots:
@@ -186,6 +190,10 @@ private:
 	unsigned m_fps;
 	struct timeval m_tv;
 	QFile m_saveRaw;
+#ifdef ENABLE_OGL
+	QAction *m_previewAct;
+#endif
+
 };
 
 extern ApplicationWindow *g_mw;
Signature · 1 line
1.8.3.2
#5 lore raw

Re: [PATCH 4/4] qv4l2: add OpenGL video render

Hi Bård,

Thank you for the patches.

Quoted 5 lines · On Tuesday 16 July 2013 13:24:08 Bård Eirik Winther wrote:

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 performing color space conversion.

Quoted 8 lines
---
 configure.ac                |   8 +-
 utils/qv4l2/Makefile.am     |   9 +-
 utils/qv4l2/capture-win.cpp | 559 +++++++++++++++++++++++++++++++++++++++--
 utils/qv4l2/capture-win.h   |  81 ++++++-
 utils/qv4l2/qv4l2.cpp       | 173 +++++++++++---
 utils/qv4l2/qv4l2.h         |   8 +
 6 files changed, 782 insertions(+), 56 deletions(-)

Is there a chance you could split the OpenGL code to separate classes, in a separate source file ? This would allow implementing other renderers, such as KMS planes on embedded devices.

Signature · 3 lines
Regards,

Laurent Pinchart
#6 lore raw

Re: [PATCH 4/4] qv4l2: add OpenGL video render

Quoted 19 lines · you

Hi Bård,

Thank you for the patches.

Quoted 5 lines · On Tuesday 16 July 2013 13:24:08 Bård Eirik Winther wrote:

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 performing color space conversion.

Quoted 8 lines
---
 configure.ac                |   8 +-
 utils/qv4l2/Makefile.am     |   9 +-
 utils/qv4l2/capture-win.cpp | 559 +++++++++++++++++++++++++++++++++++++++--
 utils/qv4l2/capture-win.h   |  81 ++++++-
 utils/qv4l2/qv4l2.cpp       | 173 +++++++++++---
 utils/qv4l2/qv4l2.h         |   8 +
 6 files changed, 782 insertions(+), 56 deletions(-)
Quoted 4 lines

Is there a chance you could split the OpenGL code to separate classes, in a separate source file ? This would allow implementing other renderers, such as KMS planes on embedded devices.

Hi.

Do you mean to separate the GL class only or all the different shaders/renderes as well?

Bård Winther

#7 lore raw

Re: [PATCH 4/4] qv4l2: add OpenGL video render

Hi Bård,

Quoted 26 lines · On Tuesday 16 July 2013 14:59:04 Bard Eirik Winther wrote:
Quoted 20 lines · you

Hi Bård,

Thank you for the patches.

Quoted 7 lines · On Tuesday 16 July 2013 13:24:08 Bård Eirik Winther wrote:

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 performing color space conversion.

---

Quoted 7 lines
 configure.ac                |   8 +-
 utils/qv4l2/Makefile.am     |   9 +-
 utils/qv4l2/capture-win.cpp | 559 +++++++++++++++++++++++++++++++++++--
 utils/qv4l2/capture-win.h   |  81 ++++++-
 utils/qv4l2/qv4l2.cpp       | 173 +++++++++++---
 utils/qv4l2/qv4l2.h         |   8 +
 6 files changed, 782 insertions(+), 56 deletions(-)
Quoted 4 lines

Is there a chance you could split the OpenGL code to separate classes, in a
separate source file ? This would allow implementing other renderers, such as KMS planes on embedded devices.

Quoted 4 lines

Hi.

Do you mean to separate the GL class only or all the different shaders/renderes as well?

Basically, what would be nice to get is an easy way to extend qv4l2 with different renderers. OpenGL is fine on the desktop, but for embedded devices a KMS planes backend would work best given the mess that the embedded GPU situation is. Instead of adding #ifdef ENABLE_OGL and if (use_ogl) through the code, abstracting the rendering code in a separate base class that renderers could inherit from would make the code simpler to read, maintain and extend.

I haven't looked at the details so I'm not sure how much work that would be, but if the effort is reasonable I think it would be a nice improvement.

Signature · 3 lines
Regards,

Laurent Pinchart