[v4l-utils] [PATCH] qv4l2: Use C library file operations with v4lconvert for raw mode devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux