You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.4 KiB

  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
  5. Starting with kernel versions 3.16, (DE)Queing of buffers has been fixed
  6. after it was leaking data for ages. in the struct v4l2_buffer is the
  7. bytesused element which indicates the size of the buffer. This however
  8. gets cleared whenever the buffer gets requeued and is thus no longer
  9. valid.
  10. This patch copies the bytesused variable so it is available until the
  11. next frame captured again.
  12. Signed-off-by: Olliver Schinagl <o.schinagl@ultimaker.com>
  13. ---
  14. plugins/input_uvc/input_uvc.c | 6 +++---
  15. plugins/input_uvc/v4l2uvc.c | 2 ++
  16. plugins/input_uvc/v4l2uvc.h | 1 +
  17. 3 files changed, 6 insertions(+), 3 deletions(-)
  18. diff --git a/plugins/input_uvc/input_uvc.c b/plugins/input_uvc/input_uvc.c
  19. index e6c74fd..64f66cb 100644
  20. --- a/plugins/input_uvc/input_uvc.c
  21. +++ b/plugins/input_uvc/input_uvc.c
  22. @@ -482,7 +482,7 @@ void *cam_thread(void *arg)
  23. exit(EXIT_FAILURE);
  24. }
  25. - //DBG("received frame of size: %d from plugin: %d\n", pcontext->videoIn->buf.bytesused, pcontext->id);
  26. + //DBG("received frame of size: %d from plugin: %d\n", pcontext->videoIn->tmpbytesused, pcontext->id);
  27. /*
  28. * Workaround for broken, corrupted frames:
  29. @@ -491,7 +491,7 @@ void *cam_thread(void *arg)
  30. * For example a VGA (640x480) webcam picture is normally >= 8kByte large,
  31. * corrupted frames are smaller.
  32. */
  33. - if(pcontext->videoIn->buf.bytesused < minimum_size) {
  34. + if(pcontext->videoIn->tmpbytesused < minimum_size) {
  35. DBG("dropping too small frame, assuming it as broken\n");
  36. continue;
  37. }
  38. @@ -529,7 +529,7 @@ void *cam_thread(void *arg)
  39. } else {
  40. #endif
  41. //DBG("copying frame from input: %d\n", (int)pcontext->id);
  42. - pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->buf.bytesused);
  43. + pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->tmpbytesused);
  44. #ifndef NO_LIBJPEG
  45. }
  46. #endif
  47. diff --git a/plugins/input_uvc/v4l2uvc.c b/plugins/input_uvc/v4l2uvc.c
  48. index c5a5aa4..d11510c 100644
  49. --- a/plugins/input_uvc/v4l2uvc.c
  50. +++ b/plugins/input_uvc/v4l2uvc.c
  51. @@ -532,6 +532,7 @@ int uvcGrab(struct vdIn *vd)
  52. */
  53. memcpy(vd->tmpbuffer, vd->mem[vd->buf.index], vd->buf.bytesused);
  54. + vd->tmpbytesused = vd->buf.bytesused;
  55. if(debug)
  56. fprintf(stderr, "bytes in used %d \n", vd->buf.bytesused);
  57. @@ -570,6 +571,7 @@ int close_v4l2(struct vdIn *vd)
  58. if(vd->tmpbuffer)
  59. free(vd->tmpbuffer);
  60. vd->tmpbuffer = NULL;
  61. + vd->tmpbytesused = 0;
  62. free(vd->framebuffer);
  63. vd->framebuffer = NULL;
  64. free(vd->videodevice);
  65. diff --git a/plugins/input_uvc/v4l2uvc.h b/plugins/input_uvc/v4l2uvc.h
  66. index 022c57e..2c7c8ba 100644
  67. --- a/plugins/input_uvc/v4l2uvc.h
  68. +++ b/plugins/input_uvc/v4l2uvc.h
  69. @@ -83,6 +83,7 @@ struct vdIn {
  70. struct v4l2_requestbuffers rb;
  71. void *mem[NB_BUFFER];
  72. unsigned char *tmpbuffer;
  73. + int tmpbytesused;
  74. unsigned char *framebuffer;
  75. streaming_state streamingState;
  76. int grabmethod;
  77. --
  78. 1.9.1