Skip to contentSkip to conversation

qv4l2: remove unused local variables 'QString what'

PATCH New Peter Seiderer 1 participant 4 messages Nov 16, 2023 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 qv4l2: remove unused local variables 'QString what'

---
 utils/qv4l2/ctrl-tab.cpp | 2 --
 1 file changed, 2 deletions(-)
utils/qv4l2/ctrl-tab.cpp +0 -2
index cfdecdeb..dcf014a8 100644
@@ -704,7 +704,6 @@ void ApplicationWindow::refresh()
 void ApplicationWindow::setWhat(QWidget *w, unsigned id, const QString &v)
 {
 	const v4l2_query_ext_ctrl &qec = m_ctrlMap[id];
-	QString what;
 	QString flags = getCtrlFlags(qec.flags);
 
 	switch (qec.type) {
@@ -725,7 +724,6 @@ void ApplicationWindow::setWhat(QWidget *w, unsigned id, const QString &v)
 void ApplicationWindow::setWhat(QWidget *w, unsigned id, long long v)
 {
 	const v4l2_query_ext_ctrl &qec = m_ctrlMap[id];
-	QString what;
 	QString flags = getCtrlFlags(qec.flags);
 
 	switch (qec.type) {
Signature · 1 line
2.42.1
#1 lore raw

PATCH 2/4 qv4l2: enable Qt6 compile with Qt OpenGL support

---
 utils/qv4l2/capture-win-gl.cpp | 125 ++++++++++++++++++++++++++++++---
 utils/qv4l2/capture-win-gl.h   |  17 +++++
 utils/qv4l2/qv4l2.cpp          |   4 ++
 utils/qv4l2/qv4l2.pro          |   3 +
 4 files changed, 138 insertions(+), 11 deletions(-)
utils/qv4l2/capture-win-gl.cpp +114 -11
index 6cbeb426..7e993e3b 100644
@@ -151,7 +151,9 @@ CaptureWinGLEngine::CaptureWinGLEngine() :
 	m_min_filter(GL_NEAREST)
 {
 	makeCurrent();
+#if QT_VERSION < 0x060000
 	m_glfunction.initializeGLFunctions(context());
+#endif
 }
 
 CaptureWinGLEngine::~CaptureWinGLEngine()
@@ -285,6 +287,9 @@ void CaptureWinGLEngine::stop()
 
 void CaptureWinGLEngine::initializeGL()
 {
+#if QT_VERSION >= 0x060000
+	initializeOpenGLFunctions();
+#endif
 	glShadeModel(GL_FLAT);
 	glEnable(GL_TEXTURE_2D);
 	glEnable(GL_BLEND);
@@ -337,7 +342,11 @@ void CaptureWinGLEngine::setFrame(int width, int height, int WCrop, int HCrop,
 	m_frameData = data;
 	m_frameData2 = data2 ? data2 : data;
 	m_frameData3 = data3 ? data3 : data;
+#if QT_VERSION < 0x060000
 	updateGL();
+#else
+	update();
+#endif
 }
 
 void CaptureWinGLEngine::checkError(const char *msg)
@@ -431,8 +440,13 @@ bool CaptureWinGLEngine::hasNativeFormat(__u32 format)
 		0
 	};
 
+#if QT_VERSION < 0x060000
 	if (!m_glfunction.hasOpenGLFeature(QGLFunctions::Shaders))
 		return false;
+#else
+	if (!hasOpenGLFeature(QOpenGLFunctions::Shaders))
+		return false;
+#endif
 
 	for (int i = 0; supported_fmts[i]; i++)
 		if (supported_fmts[i] == format)
@@ -449,7 +463,11 @@ void CaptureWinGLEngine::changeShader()
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
 	glOrtho(0, m_frameWidth, m_frameHeight, 0, 0, 1);
+#if QT_VERSION < 0x060000
 	resizeGL(QGLWidget::width(), QGLWidget::height());
+#else
+	resizeGL(QOpenGLWidget::width(), QOpenGLWidget::height());
+#endif
 	checkError("Render settings.\n");
 
 	switch (m_frameFormat) {
@@ -1010,7 +1028,12 @@ void CaptureWinGLEngine::shader_YUV(__u32 format)
 			   codeSuffix;
 
 	bool src_c = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, codeHead + codeTail);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				codeHead + codeTail);
 
 	if (!src_c)
 		fprintf(stderr, "OpenGL Error: YUV shader compilation failed.\n");
@@ -1053,7 +1076,11 @@ void CaptureWinGLEngine::render_YUV(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1061,7 +1088,11 @@ void CaptureWinGLEngine::render_YUV(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint U = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "utex");
+#else
+	GLint U = glGetUniformLocation(m_shaderProgram.programId(), "utex");
+#endif
 	glUniform1i(U, 1);
 	switch (format) {
 	case V4L2_PIX_FMT_YUV422P:
@@ -1087,7 +1118,11 @@ void CaptureWinGLEngine::render_YUV(__u32 format)
 
 	glActiveTexture(GL_TEXTURE2);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[2]);
+#if QT_VERSION < 0x060000
 	GLint V = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "vtex");
+#else
+	GLint V = glGetUniformLocation(m_shaderProgram.programId(), "vtex");
+#endif
 	glUniform1i(V, 2);
 	switch (format) {
 	case V4L2_PIX_FMT_YUV422P:
@@ -1189,7 +1224,11 @@ void CaptureWinGLEngine::shader_NV12(__u32 format)
 			   codeSuffix;
 
 	bool src_c = m_shaderProgram.addShaderFromSourceCode(
+#if QT_VERSION < 0x060000
 				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
 				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_c)
@@ -1211,7 +1250,11 @@ void CaptureWinGLEngine::render_NV12(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1219,7 +1262,11 @@ void CaptureWinGLEngine::render_NV12(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint U = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#else
+	GLint U = glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#endif
 	glUniform1i(U, 1);
 	switch (format) {
 	case V4L2_PIX_FMT_NV12:
@@ -1307,7 +1354,11 @@ void CaptureWinGLEngine::shader_NV24(__u32 format)
 			   codeSuffix;
 
 	bool src_c = m_shaderProgram.addShaderFromSourceCode(
+#if QT_VERSION < 0x060000
 				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
 				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_c)
@@ -1327,7 +1378,11 @@ void CaptureWinGLEngine::render_NV24(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1335,7 +1390,11 @@ void CaptureWinGLEngine::render_NV24(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint U = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#else
+	GLint U = glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#endif
 	glUniform1i(U, 1);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRedGreen, GL_UNSIGNED_BYTE,
@@ -1419,8 +1478,12 @@ void CaptureWinGLEngine::shader_NV16(__u32 format)
 			   codeSuffix;
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2%3").arg(codeHead, codeBody, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: NV16 shader compilation failed.\n");
@@ -1440,7 +1503,11 @@ void CaptureWinGLEngine::render_NV16(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "ytex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
 			m_glRed, GL_UNSIGNED_BYTE, m_frameData);
@@ -1448,7 +1515,11 @@ void CaptureWinGLEngine::render_NV16(__u32 format)
 
 	glActiveTexture(GL_TEXTURE1);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]);
+#if QT_VERSION < 0x060000
 	GLint UV = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#else
+	GLint UV = glGetUniformLocation(m_shaderProgram.programId(), "uvtex");
+#endif
 	glUniform1i(UV, 1);
 	switch (format) {
 	case V4L2_PIX_FMT_NV16:
@@ -1559,8 +1630,12 @@ void CaptureWinGLEngine::shader_YUY2(__u32 format)
 			   codeSuffix;
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2%3").arg(codeHead, codeBody, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2%3").arg(codeHead, codeBody, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: YUY2 shader compilation failed.\n");
@@ -1580,7 +1655,11 @@ void CaptureWinGLEngine::render_YUY2(__u32 format)
 
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth / 2, m_frameHeight,
 			GL_RGBA, GL_UNSIGNED_BYTE, m_frameData);
@@ -1785,8 +1864,12 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
 		    (hasAlpha ? codeSuffixWithAlpha : codeSuffix);
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2").arg(codeHead, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2").arg(codeHead, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: RGB shader compilation failed.\n");
@@ -1798,7 +1881,11 @@ void CaptureWinGLEngine::render_RGB(__u32 format)
 {
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	int idx = glGetUniformLocation(m_shaderProgram.programId(), "tex_h"); // Texture height
 	glUniform1f(idx, m_frameHeight);
@@ -2016,8 +2103,12 @@ void CaptureWinGLEngine::shader_Bayer(__u32 format)
 		    codeSuffix;
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2").arg(codeHead, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2").arg(codeHead, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: Bayer shader compilation failed.\n");
@@ -2029,7 +2120,11 @@ void CaptureWinGLEngine::render_Bayer(__u32 format)
 {
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	int idx = glGetUniformLocation(m_shaderProgram.programId(), "tex_h"); // Texture height
 	glUniform1f(idx, m_frameHeight);
@@ -2146,8 +2241,12 @@ void CaptureWinGLEngine::shader_YUV_packed(__u32 format)
 			   (hasAlpha ? codeSuffixWithAlpha : codeSuffix);
 
 	bool src_ok = m_shaderProgram.addShaderFromSourceCode(
-				QGLShader::Fragment, QString("%1%2").arg(codeHead, codeTail)
-				);
+#if QT_VERSION < 0x060000
+				QGLShader::Fragment,
+#else
+				QOpenGLShader::Fragment,
+#endif
+				QString("%1%2").arg(codeHead, codeTail));
 
 	if (!src_ok)
 		fprintf(stderr, "OpenGL Error: Packed YUV shader compilation failed.\n");
@@ -2159,7 +2258,11 @@ void CaptureWinGLEngine::render_YUV_packed(__u32 format)
 {
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]);
+#if QT_VERSION < 0x060000
 	GLint Y = m_glfunction.glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#else
+	GLint Y = glGetUniformLocation(m_shaderProgram.programId(), "tex");
+#endif
 	glUniform1i(Y, 0);
 	int idx = glGetUniformLocation(m_shaderProgram.programId(), "tex_h"); // Texture height
 	glUniform1f(idx, m_frameHeight);
utils/qv4l2/capture-win-gl.h +17 -0
index e27b2b3f..96376934 100644
@@ -10,10 +10,17 @@
 #define GL_GLEXT_PROTOTYPES
 #define QT_NO_OPENGL_ES_2
 
+#include <QtCore>
+#if QT_VERSION < 0x060000
 #include <QGLWidget>
 #include <QGLShader>
 #include <QGLShaderProgram>
 #include <QGLFunctions>
+#else
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions>
+#include <QOpenGLShaderProgram>
+#endif
 #endif
 
 #include "qv4l2.h"
@@ -26,7 +33,11 @@
 // This must be equal to the max number of textures that any shader uses
 #define MAX_TEXTURES_NEEDED 3
 
+#if QT_VERSION < 0x060000
 class CaptureWinGLEngine : public QGLWidget
+#else
+class CaptureWinGLEngine : public QOpenGLWidget, protected QOpenGLFunctions
+#endif
 {
 public:
 	CaptureWinGLEngine();
@@ -102,11 +113,17 @@ private:
 	bool m_formatChange;
 	__u32 m_frameFormat;
 	GLuint m_screenTexture[MAX_TEXTURES_NEEDED];
+#if QT_VERSION < 0x060000
 	QGLFunctions m_glfunction;
+#endif
 	unsigned char *m_frameData;
 	unsigned char *m_frameData2;
 	unsigned char *m_frameData3;
+#if QT_VERSION < 0x060000
 	QGLShaderProgram m_shaderProgram;
+#else
+	QOpenGLShaderProgram m_shaderProgram;
+#endif
 	bool m_haveFramebufferSRGB;
 	bool m_hasGLRed;
 	unsigned m_glRed;
utils/qv4l2/qv4l2.cpp +4 -0
index e37ee87f..534bedb2 100644
@@ -401,7 +401,11 @@ void ApplicationWindow::setDevice(const QString &device, bool rawOpen)
 {
 	closeDevice();
 	m_sigMapper = new QSignalMapper(this);
+#if QT_VERSION < 0x060000
 	connect(m_sigMapper, SIGNAL(mapped(int)), this, SLOT(ctrlAction(int)));
+#else
+	connect(m_sigMapper, &QSignalMapper::mappedInt, this, &ApplicationWindow::ctrlAction);
+#endif
 
 	s_direct(rawOpen);
 
utils/qv4l2/qv4l2.pro +3 -0
index 1ea07374..a9343c89 100644
@@ -8,6 +8,9 @@ CONFIG += debug
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
+# opengl: to disable opengl suppport on Qt6 comment out the
+# following line
+greaterThan(QT_MAJOR_VERSION, 5): QT += openglwidgets
 
 # adjust to your local meson build path
 MESON_BUILD_PATH = $$PWD/build-meson
Signature · 1 line
2.42.1
#2 lore raw

PATCH 3/4 qvidcap: fix v4l2_convert_hook (add PRE_TARGETDEPS)

In reply to Peter Seiderer

Force early v4l2-convert.h creation by adding the v4l2_convert_hook to PRE_TARGETDEPS.

Fixes:

../qvidcap/paint.cpp:318:10: fatal error: v4l2-convert.h: No such file or directory 318 | #include "v4l2-convert.h"

---
 utils/qvidcap/qvidcap.pro | 1 +
 1 file changed, 1 insertion(+)
utils/qvidcap/qvidcap.pro +1 -0
index db948611..cf7d3ca5 100644
@@ -25,6 +25,7 @@ INCLUDEPATH += $$PWD/../v4l2-compliance
 v4l2_convert_hook.depends = $$PWD/v4l2-convert.pl $$PWD/v4l2-convert.glsl
 v4l2_convert_hook.commands = perl $$PWD/v4l2-convert.pl < $$PWD/v4l2-convert.glsl > v4l2-convert.h
 QMAKE_EXTRA_TARGETS += v4l2_convert_hook
+PRE_TARGETDEPS += v4l2_convert_hook
 
 # Input
 HEADERS += capture.h
Signature · 1 line
2.42.1
#3 lore raw

PATCH 4/4 qvidcap: enable Qt6 compile with Qt OpenGL support

In reply to Peter Seiderer

- update qmake project file for Qt6 (openglwidgets)
- fix includes for Qt6 (QOpenGLShaderProgram instead of QtGui/QOpenGLShaderProgram and QOpenGLPaintDevice instead of QtGui/QOpenGLPaintDevice)

---
 utils/qvidcap/capture.cpp | 4 ++++
 utils/qvidcap/capture.h   | 4 ++++
 utils/qvidcap/paint.cpp   | 4 ++++
 utils/qvidcap/qvidcap.pro | 1 +
 4 files changed, 13 insertions(+)
utils/qvidcap/capture.cpp +4 -0
index 0b4c4115..1e3597b0 100644
@@ -13,7 +13,11 @@
 #include <QtCore/QTextStream>
 #include <QtCore/QCoreApplication>
 #include <QtGui/QOpenGLContext>
+#if QT_VERSION < 0x060000
 #include <QtGui/QOpenGLPaintDevice>
+#else
+#include <QOpenGLPaintDevice>
+#endif
 #include <QtGui/QContextMenuEvent>
 #include <QtGui/QKeyEvent>
 #include <QtGui/QPainter>
utils/qvidcap/capture.h +4 -0
index 37f5bfc5..8ebe76a9 100644
@@ -16,7 +16,11 @@
 #include <QAction>
 #include <QActionGroup>
 #include <QScrollArea>
+#if QT_VERSION < 0x060000
 #include <QtGui/QOpenGLShaderProgram>
+#else
+#include <QOpenGLShaderProgram>
+#endif
 
 #include "qvidcap.h"
 
utils/qvidcap/paint.cpp +4 -0
index c5aadb09..0246de60 100644
@@ -13,7 +13,11 @@
 #include <QtCore/QTextStream>
 #include <QtCore/QCoreApplication>
 #include <QtGui/QOpenGLContext>
+#if QT_VERSION < 0x060000
 #include <QtGui/QOpenGLPaintDevice>
+#else
+#include <QOpenGLPaintDevice>
+#endif
 #include <QtGui/QContextMenuEvent>
 #include <QtGui/QKeyEvent>
 #include <QtGui/QPainter>
utils/qvidcap/qvidcap.pro +1 -0
index cf7d3ca5..d08f0059 100644
@@ -7,6 +7,7 @@ INCLUDEPATH += . ../libv4l2util ../../lib/include ../../include
 CONFIG += debug
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+greaterThan(QT_MAJOR_VERSION, 5): QT += openglwidgets
 
 # adjust to your local meson build path
 MESON_BUILD_PATH = $$PWD/build-meson
Signature · 1 line
2.42.1