aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-07-21 10:23:20 (GMT)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-07-23 17:57:52 (GMT)
commit8a7bdf9d3b48ca50186864faae9e56928594286d (patch)
tree004abc0609501e56bdf00b9a0a3afbbf1f5ae729
parentaa973596fd61d4e91f66cf53ab51cbed9042be30 (diff)
Ignore pad bytes on camera streams
On a perfect world, the memory mapped buffer would contain the exact frame image. However, due to hardware constraints (typically at their DMA engines), sometimes there are pad bytes after the end of each line. So, change the memcpy algorithm to take it into account.
-rw-r--r--src/v4l.c12
-rw-r--r--src/v4l.h2
2 files changed, 10 insertions, 4 deletions
diff --git a/src/v4l.c b/src/v4l.c
index b6483a4..f265512 100644
--- a/src/v4l.c
+++ b/src/v4l.c
@@ -384,10 +384,11 @@ void start_streaming(cam * cam)
}
}
-void capture_buffers(cam * cam, char *outbuf, int len)
+void capture_buffers(cam * cam, unsigned char *outbuf, int len)
{
char *msg;
- int r;
+ unsigned char *inbuf;
+ int r, y;
fd_set fds;
struct v4l2_buffer buf;
struct timeval tv;
@@ -418,7 +419,12 @@ void capture_buffers(cam * cam, char *outbuf, int len)
if (len > buf.bytesused)
len = buf.bytesused;
- memcpy(outbuf, cam->buffers[buf.index].start, len);
+ inbuf = cam->buffers[buf.index].start;
+ for (y = 0; y < cam->height; y++) {
+ memcpy(outbuf, inbuf, cam->width * cam->depth / 8);
+ outbuf += cam->width * cam->depth / 8;
+ inbuf += cam->bytesperline;
+ }
v4l2_ioctl(cam->dev, VIDIOC_QBUF, &buf);
}
diff --git a/src/v4l.h b/src/v4l.h
index c0abaa3..ca2739c 100644
--- a/src/v4l.h
+++ b/src/v4l.h
@@ -90,7 +90,7 @@ void set_win_info (cam * cam);
void get_pic_info (cam *);
void get_win_info (cam *);
void start_streaming(cam * cam);
-void capture_buffers(cam * cam, char *outbuf, int len);
+void capture_buffers(cam * cam, unsigned char *outbuf, int len);
void stop_streaming(cam * cam);
#endif /* !CAMORAMA_V4L_H */

Privacy Policy