From ed4e3e54d662b46bec3b0b8269e2e60728c75460 Mon Sep 17 00:00:00 2001 From: klemek Date: Sun, 21 Sep 2025 23:51:37 +0200 Subject: [PATCH] trying to work with v4l2 loopback but not implemented --- src/types.h | 1 + src/video.c | 30 +++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/types.h b/src/types.h index 30dc711..4e3dbb7 100644 --- a/src/types.h +++ b/src/types.h @@ -92,6 +92,7 @@ typedef struct VideoDevice { unsigned int height; unsigned int pixelformat; unsigned int bytesperline; + bool output; struct v4l2_buffer buf; EGLImageKHR dma_image; } VideoDevice; diff --git a/src/video.c b/src/video.c index 18438c4..db85cb8 100644 --- a/src/video.c +++ b/src/video.c @@ -94,6 +94,8 @@ static bool set_device_format(VideoDevice *device, unsigned int preferred_width, unsigned int preferred_height) { struct v4l2_format fmt; + device->output = false; + memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -103,8 +105,15 @@ static bool set_device_format(VideoDevice *device, unsigned int preferred_width, fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; if (ioctl(device->fd, VIDIOC_S_FMT, &fmt) == -1) { - ioctl_error(device, "VIDIOC_S_FMT", "Requested buffer type not supported"); - return false; + fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; + + device->output = true; + + if (ioctl(device->fd, VIDIOC_S_FMT, &fmt) == -1) { + ioctl_error(device, "VIDIOC_S_FMT", + "Requested buffer type not supported"); + return false; + } } device->width = fmt.fmt.pix.width; @@ -126,7 +135,8 @@ static bool request_buffers(VideoDevice *device) { memset(&reqbuf, 0, sizeof(reqbuf)); - reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + reqbuf.type = + device->output ? V4L2_BUF_TYPE_VIDEO_OUTPUT : V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.count = 1; @@ -148,8 +158,9 @@ static bool export_buffer(VideoDevice *device) { memset(&expbuf, 0, sizeof(expbuf)); - expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - expbuf.index = 0; /// '0' for one buffer + expbuf.type = + device->output ? V4L2_BUF_TYPE_VIDEO_OUTPUT : V4L2_BUF_TYPE_VIDEO_CAPTURE; + expbuf.index = 0; expbuf.flags = O_RDONLY; if (ioctl(device->fd, VIDIOC_EXPBUF, &expbuf) == -1) { @@ -180,7 +191,8 @@ static bool open_stream(VideoDevice *device) { static void create_image_buffer(VideoDevice *device) { memset(&device->buf, 0, sizeof(device->buf)); - device->buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + device->buf.type = + device->output ? V4L2_BUF_TYPE_VIDEO_OUTPUT : V4L2_BUF_TYPE_VIDEO_CAPTURE; device->buf.memory = V4L2_MEMORY_MMAP; device->buf.index = 0; @@ -209,9 +221,9 @@ VideoDevice video_init(char *name, unsigned int preferred_width, return device; } - // if (!request_buffers(&device)) { - // return device; - // } + if (!request_buffers(&device)) { + return device; + } if (!export_buffer(&device)) { return device;