Skip to contentSkip to conversation

camorama: Handle properly ERROR buffers

PATCH New Ricardo Ribalda 1 participant 3 messages Sep 2 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

cover camorama: Handle properly ERROR buffers

And now that we are at it, add a missing CONTRIBUTE file.

---
Ricardo Ribalda (2):
v4l: Handle properly ERROR buffers
CONTRIBUTE: Add simple contribution instructions

 .b4-config    |  3 +++
 CONTRIBUTE.md | 23 +++++++++++++++++++
 src/v4l.c     | 73 ++++++++++++++++-------------------------------------------
 src/v4l.h     |  3 +--
 4 files changed, 47 insertions(+), 55 deletions(-)

---
base-commit: 645f7b9072187a5d9a9de520e074dff3be3a2bb9
change-id: 20260902-contribute-e8b6dae82a4e

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
#1 lore raw

PATCH 1/2 v4l: Handle properly ERROR buffers

If a buffers is flagged as erroneus ignore that frame.

Now that we are at it refactor a bit the code to remove code duplication for the usrptr and mmap implementation.

---
 src/v4l.c | 73 +++++++++++++++++----------------------------------------------
 src/v4l.h |  3 +--
 2 files changed, 21 insertions(+), 55 deletions(-)
src/v4l.c +20 -53
index aa706f9..48357cb 100644
@@ -414,9 +414,9 @@ unsigned char *cam_read(cam_t *cam)
 		convert_to_rgb24(cam, cam->tmp);
 	}
     } else if (cam->userptr) {
-            capture_buffers_userptr(cam, cam->pic_buf);
+            capture_buffers(cam, cam->pic_buf, V4L2_MEMORY_USERPTR);
     } else {
-            capture_buffers(cam, cam->pic_buf, cam->bytesperline);
+            capture_buffers(cam, cam->pic_buf, V4L2_MEMORY_MMAP);
     }
     if (ret)
         return NULL;
@@ -1587,14 +1587,10 @@ void start_streaming_userptr(cam_t *cam)
     }
 }
 
-void capture_buffers(cam_t *cam, unsigned char *outbuf, unsigned int len)
+static void deque_buffer(cam_t *cam, struct v4l2_buffer *buf, guint32 memory_type)
 {
-    char *msg;
-    unsigned char *inbuf;
     int r;
-    unsigned int y;
     fd_set fds;
-    struct v4l2_buffer buf;
     struct timeval tv;
 
     do {
@@ -1609,6 +1605,7 @@ void capture_buffers(cam_t *cam, unsigned char *outbuf, unsigned int len)
     } while ((r == -1 && (errno == EINTR)));
 
     if (r == -1) {
+        char *msg;
         msg = g_strdup_printf(_("Timeout while waiting for frames (%s)"),
                               cam->video_dev);
         error_dialog(msg);
@@ -1616,61 +1613,31 @@ void capture_buffers(cam_t *cam, unsigned char *outbuf, unsigned int len)
         exit(0);
     }
 
-    memset(&buf, 0, sizeof(buf));
-    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-    buf.memory = V4L2_MEMORY_MMAP;
-    cam_ioctl(cam, VIDIOC_DQBUF, &buf);
-
-    if (len > buf.bytesused)
-        len = buf.bytesused;
+    memset(buf, 0, sizeof(*buf));
+    buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    buf->memory = memory_type;
+    cam_ioctl(cam, VIDIOC_DQBUF, buf);
 
-    inbuf = cam->buffers[buf.index].start;
-    if (cam->use_libv4l) {
-	    for (y = 0; y < cam->height; y++) {
-		memcpy(outbuf, inbuf, cam->width * cam->bpp / 8);
-		outbuf += cam->width * cam->bpp / 8;
-		inbuf += cam->bytesperline;
-	    }
-    } else {
-	    convert_to_rgb24(cam, inbuf);
-    }
+    return;
+}
 
-    cam_ioctl(cam, VIDIOC_QBUF, &buf);
+static void deque_good_buffer(cam_t *cam, struct v4l2_buffer *buf, guint32 memory_type)
+{
+	while (TRUE) {
+		deque_buffer(cam, buf, memory_type);
+		if (!(buf->flags & V4L2_BUF_FLAG_ERROR))
+			break;
+		cam_ioctl(cam, VIDIOC_QBUF, &buf);
+	}
 }
 
-void capture_buffers_userptr(cam_t *cam, unsigned char *outbuf)
+void capture_buffers(cam_t *cam, unsigned char *outbuf, guint32 memory_type)
 {
-    char *msg;
     unsigned char *inbuf;
-    int r;
     unsigned int y;
-    fd_set fds;
     struct v4l2_buffer buf;
-    struct timeval tv;
-
-    do {
-        FD_ZERO(&fds);
-        FD_SET(cam->dev, &fds);
-
-        /* Timeout. */
-        tv.tv_sec = 2;
-        tv.tv_usec = 0;
-
-        r = select(cam->dev + 1, &fds, NULL, NULL, &tv);
-    } while ((r == -1 && (errno == EINTR)));
-
-    if (r == -1) {
-        msg = g_strdup_printf(_("Timeout while waiting for frames (%s)"),
-                              cam->video_dev);
-        error_dialog(msg);
-        g_free(msg);
-        exit(0);
-    }
 
-    memset(&buf, 0, sizeof(buf));
-    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-    buf.memory = V4L2_MEMORY_USERPTR;
-    cam_ioctl(cam, VIDIOC_DQBUF, &buf);
+    deque_good_buffer(cam, &buf, memory_type);
 
     inbuf = cam->buffers[buf.index].start;
     if (cam->use_libv4l) {
src/v4l.h +1 -2
index cc69875..15ecd6c 100644
@@ -167,10 +167,9 @@ void get_pic_info(cam_t *);
 void get_win_info(cam_t *);
 void get_supported_resolutions(cam_t *cam, gboolean all_supported);
 void start_streaming(cam_t *cam);
-void capture_buffers(cam_t *cam, unsigned char *outbuf, unsigned int len);
+void capture_buffers(cam_t *cam, unsigned char *outbuf, guint32 memory_type);
 void stop_streaming(cam_t *cam);
 void start_streaming_userptr(cam_t *cam);
-void capture_buffers_userptr(cam_t *cam, unsigned char *outbuf);
 void stop_streaming_userptr(cam_t *cam);
 
 #endif                          /* !CAMORAMA_V4L_H */
Signature · 1 line
2.55.0.966.g6673acef38-goog
#2 lore raw

PATCH 2/2 CONTRIBUTE: Add simple contribution instructions

In reply to Ricardo Ribalda

In the media summit we discussed the need of a special prefix for userspace. This helps patchwork and media-ci.

Create a new file with a brief introductions on how to contribute and make the camorama prefix official.

---
 .b4-config    |  3 +++
 CONTRIBUTE.md | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+)
.b4-config new file +3 -0
new file mode 100644
index 0000000..2a0772c
@@ -0,0 +1,3 @@
+[b4]
+  send-series-cc = [email protected]
+  send-prefixes = camorama
CONTRIBUTE.md new file +23 -0
new file mode 100644
index 0000000..d8a8b3c
@@ -0,0 +1,23 @@
+## Repository
+
+camorama official repository is hosted at https://git.linuxtv.org/camorama.git
+
+## Contributions
+
+Patches are welcome! Please send your patches to `[email protected]`
+using the prefix `[PATCH camorama]`. E.g:
+
+```
+git config set format.subjectPrefix "PATCH camorama"
+```
+
+## b4 config
+
+If you use b4[1] for your contributor workflow you can use these options:
+
+```
+git config set b4.send-series-cc [email protected]
+git config set b4.send-prefixes camorama
+```
+
+[1] https://b4.docs.kernel.org/en/latest/contributor/overview.html
Signature · 1 line
2.55.0.966.g6673acef38-goog