All of lore.kernel.org
 help / color / mirror / Atom feed
* [v4l-utils] [PATCH] qv4l2: Use C library file operations with v4lconvert for raw mode devices
@ 2020-01-06 13:25 Laurent Pinchart
  2020-01-06 13:25 ` Laurent Pinchart
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Pinchart @ 2020-01-06 13:25 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, Paul Elder

qv4l2 uses libv4l2 to access the V4L2 device by default, and supports a
raw open mode for direct access to the device through C library file
operations. It also uses libv4lconvert to perform format conversion, and
libv4lconvert accesses the V4L2 device through direct syscalls by
default.

Usage of raw open mode is useful to test direct access to the device,
but also to test LD_PRELOAD wrappers that intercept the C library calls,
such as the libcamera V4L2 compatibility wrapper. The usage of syscalls
in libv4lconvert prevents the latter case from working properly. Fix it
by providing file operations to libv4lconvert that use the C library
file operations when opening the device in raw mode.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/qv4l2/qv4l2.cpp | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/utils/qv4l2/qv4l2.cpp b/utils/qv4l2/qv4l2.cpp
index d42ce9a4bf74..b57178e4237b 100644
--- a/utils/qv4l2/qv4l2.cpp
+++ b/utils/qv4l2/qv4l2.cpp
@@ -60,11 +60,45 @@ extern "C" {
 #include "capture-win-qt.h"
 #include "capture-win-gl.h"
 
+#include <libv4l-plugin.h>
 #include <libv4lconvert.h>
 
 #define SDR_WIDTH 1024
 #define SDR_HEIGHT 512
 
+static void *rawDevInit(int fd)
+{
+	return NULL;
+}
+
+static void rawDevClose(void *dev_ops_priv)
+{
+}
+
+static int rawDevIoctl(void *dev_ops_priv, int fd, unsigned long cmd, void *arg)
+{
+	return ioctl(fd, cmd, arg);
+}
+
+static ssize_t rawDevRead(void *dev_ops_priv, int fd, void *buf, size_t len)
+{
+	return read(fd, buf, len);
+}
+
+static ssize_t rawDevWrite(void *dev_ops_priv, int fd, const void *buf,
+                         size_t len)
+{
+	return write(fd, buf, len);
+}
+
+static const struct libv4l_dev_ops rawDevOps = {
+	.init = rawDevInit,
+	.close = rawDevClose,
+	.ioctl = rawDevIoctl,
+	.read = rawDevRead,
+	.write = rawDevWrite,
+};
+
 static QAction *addSubMenuItem(QActionGroup *grp, QMenu *menu, const QString &text, int val)
 {
 	QAction *a = grp->addAction(menu->addAction(text));
@@ -417,7 +451,10 @@ void ApplicationWindow::setDevice(const QString &device, bool rawOpen)
 	statusBar()->clearMessage();
 	m_tabs->show();
 	m_tabs->setFocus();
-	m_convertData = v4lconvert_create(g_fd());
+	if (rawOpen)
+		m_convertData = v4lconvert_create_with_dev_ops(g_fd(), NULL, &rawDevOps);
+	else
+		m_convertData = v4lconvert_create(g_fd());
 	bool canStream = has_rw() || has_streaming();
 	bool isCapture = v4l_type_is_capture(g_type());
 	m_capStartAct->setEnabled(canStream);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [v4l-utils] [PATCH] qv4l2: Use C library file operations with v4lconvert for raw mode devices
  2020-01-06 13:25 [v4l-utils] [PATCH] qv4l2: Use C library file operations with v4lconvert for raw mode devices Laurent Pinchart
@ 2020-01-06 13:25 ` Laurent Pinchart
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2020-01-06 13:25 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, Paul Elder

qv4l2 uses libv4l2 to access the V4L2 device by default, and supports a
raw open mode for direct access to the device through C library file
operations. It also uses libv4lconvert to perform format conversion, and
libv4lconvert accesses the V4L2 device through direct syscalls by
default.

Usage of raw open mode is useful to test direct access to the device,
but also to test LD_PRELOAD wrappers that intercept the C library calls,
such as the libcamera V4L2 compatibility wrapper. The usage of syscalls
in libv4lconvert prevents the latter case from working properly. Fix it
by providing file operations to libv4lconvert that use the C library
file operations when opening the device in raw mode.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/qv4l2/qv4l2.cpp | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/utils/qv4l2/qv4l2.cpp b/utils/qv4l2/qv4l2.cpp
index d42ce9a4bf74..b57178e4237b 100644
--- a/utils/qv4l2/qv4l2.cpp
+++ b/utils/qv4l2/qv4l2.cpp
@@ -60,11 +60,45 @@ extern "C" {
 #include "capture-win-qt.h"
 #include "capture-win-gl.h"
 
+#include <libv4l-plugin.h>
 #include <libv4lconvert.h>
 
 #define SDR_WIDTH 1024
 #define SDR_HEIGHT 512
 
+static void *rawDevInit(int fd)
+{
+	return NULL;
+}
+
+static void rawDevClose(void *dev_ops_priv)
+{
+}
+
+static int rawDevIoctl(void *dev_ops_priv, int fd, unsigned long cmd, void *arg)
+{
+	return ioctl(fd, cmd, arg);
+}
+
+static ssize_t rawDevRead(void *dev_ops_priv, int fd, void *buf, size_t len)
+{
+	return read(fd, buf, len);
+}
+
+static ssize_t rawDevWrite(void *dev_ops_priv, int fd, const void *buf,
+                         size_t len)
+{
+	return write(fd, buf, len);
+}
+
+static const struct libv4l_dev_ops rawDevOps = {
+	.init = rawDevInit,
+	.close = rawDevClose,
+	.ioctl = rawDevIoctl,
+	.read = rawDevRead,
+	.write = rawDevWrite,
+};
+
 static QAction *addSubMenuItem(QActionGroup *grp, QMenu *menu, const QString &text, int val)
 {
 	QAction *a = grp->addAction(menu->addAction(text));
@@ -417,7 +451,10 @@ void ApplicationWindow::setDevice(const QString &device, bool rawOpen)
 	statusBar()->clearMessage();
 	m_tabs->show();
 	m_tabs->setFocus();
-	m_convertData = v4lconvert_create(g_fd());
+	if (rawOpen)
+		m_convertData = v4lconvert_create_with_dev_ops(g_fd(), NULL, &rawDevOps);
+	else
+		m_convertData = v4lconvert_create(g_fd());
 	bool canStream = has_rw() || has_streaming();
 	bool isCapture = v4l_type_is_capture(g_type());
 	m_capStartAct->setEnabled(canStream);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-06 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-06 13:25 [v4l-utils] [PATCH] qv4l2: Use C library file operations with v4lconvert for raw mode devices Laurent Pinchart
2020-01-06 13:25 ` Laurent Pinchart

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.