1 From 19202b54698b343a0207d7e213448e32b8e58fc3 Mon Sep 17 00:00:00 2001
2 From: Olliver Schinagl <o.schinagl@ultimaker.com>
3 Date: Wed, 29 Oct 2014 09:34:41 +0100
4 Subject: [PATCH 1/7] Buffer the bytesused variable from struct v4l2_buffer
6 Starting with kernel versions 3.16, (DE)Queing of buffers has been fixed
7 after it was leaking data for ages. in the struct v4l2_buffer is the
8 bytesused element which indicates the size of the buffer. This however
9 gets cleared whenever the buffer gets requeued and is thus no longer
12 This patch copies the bytesused variable so it is available until the
13 next frame captured again.
15 Signed-off-by: Olliver Schinagl <o.schinagl@ultimaker.com>
17 plugins/input_uvc/input_uvc.c | 6 +++---
18 plugins/input_uvc/v4l2uvc.c | 2 ++
19 plugins/input_uvc/v4l2uvc.h | 1 +
20 3 files changed, 6 insertions(+), 3 deletions(-)
22 diff --git a/plugins/input_uvc/input_uvc.c b/plugins/input_uvc/input_uvc.c
23 index e6c74fd..64f66cb 100644
24 --- a/plugins/input_uvc/input_uvc.c
25 +++ b/plugins/input_uvc/input_uvc.c
26 @@ -482,7 +482,7 @@ void *cam_thread(void *arg)
30 - //DBG("received frame of size: %d from plugin: %d\n", pcontext->videoIn->buf.bytesused, pcontext->id);
31 + //DBG("received frame of size: %d from plugin: %d\n", pcontext->videoIn->tmpbytesused, pcontext->id);
34 * Workaround for broken, corrupted frames:
35 @@ -491,7 +491,7 @@ void *cam_thread(void *arg)
36 * For example a VGA (640x480) webcam picture is normally >= 8kByte large,
37 * corrupted frames are smaller.
39 - if(pcontext->videoIn->buf.bytesused < minimum_size) {
40 + if(pcontext->videoIn->tmpbytesused < minimum_size) {
41 DBG("dropping too small frame, assuming it as broken\n");
44 @@ -529,7 +529,7 @@ void *cam_thread(void *arg)
47 //DBG("copying frame from input: %d\n", (int)pcontext->id);
48 - pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->buf.bytesused);
49 + pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->tmpbytesused);
53 diff --git a/plugins/input_uvc/v4l2uvc.c b/plugins/input_uvc/v4l2uvc.c
54 index c5a5aa4..d11510c 100644
55 --- a/plugins/input_uvc/v4l2uvc.c
56 +++ b/plugins/input_uvc/v4l2uvc.c
57 @@ -532,6 +532,7 @@ int uvcGrab(struct vdIn *vd)
60 memcpy(vd->tmpbuffer, vd->mem[vd->buf.index], vd->buf.bytesused);
61 + vd->tmpbytesused = vd->buf.bytesused;
64 fprintf(stderr, "bytes in used %d \n", vd->buf.bytesused);
65 @@ -570,6 +571,7 @@ int close_v4l2(struct vdIn *vd)
69 + vd->tmpbytesused = 0;
70 free(vd->framebuffer);
71 vd->framebuffer = NULL;
72 free(vd->videodevice);
73 diff --git a/plugins/input_uvc/v4l2uvc.h b/plugins/input_uvc/v4l2uvc.h
74 index 022c57e..2c7c8ba 100644
75 --- a/plugins/input_uvc/v4l2uvc.h
76 +++ b/plugins/input_uvc/v4l2uvc.h
77 @@ -83,6 +83,7 @@ struct vdIn {
78 struct v4l2_requestbuffers rb;
80 unsigned char *tmpbuffer;
82 unsigned char *framebuffer;
83 streaming_state streamingState;