camera_v4l2_cuda.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2016,2017, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of NVIDIA CORPORATION nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include <queue>
  29. #include "NvJpegDecoder.h"
  30. #include "NvBufSurface.h"
  31. #define V4L2_BUFFERS_NUM 4
  32. #define INFO(fmt, ...) \
  33. if (ctx->enable_verbose) \
  34. printf("INFO: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);
  35. #define WARN(fmt, ...) \
  36. printf("WARN: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);
  37. #define CHECK_ERROR(cond, label, fmt, ...) \
  38. if (!cond) { \
  39. error = 1; \
  40. printf("ERROR: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
  41. goto label; \
  42. }
  43. #define ERROR_RETURN(fmt, ...) \
  44. do { \
  45. printf("ERROR: %s(): (line:%d) " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
  46. return false; \
  47. } while(0)
  48. typedef struct
  49. {
  50. // Hold the user accessible pointer
  51. unsigned char * start;
  52. // Hold the memory length
  53. unsigned int size;
  54. // Hold the file descriptor of NvBuffer
  55. int dmabuff_fd;
  56. } nv_buffer;
  57. typedef struct
  58. {
  59. // camera v4l2 context
  60. const char * cam_devname;
  61. char cam_file[16];
  62. int cam_fd;
  63. unsigned int cam_pixfmt;
  64. unsigned int cam_w;
  65. unsigned int cam_h;
  66. unsigned int frame;
  67. unsigned int save_n_frame;
  68. // Global buffer ptr
  69. nv_buffer * g_buff;
  70. bool capture_dmabuf;
  71. // EGL renderer
  72. NvEglRenderer *renderer;
  73. int render_dmabuf_fd;
  74. int fps;
  75. // CUDA processing
  76. bool enable_cuda;
  77. EGLDisplay egl_display;
  78. EGLImageKHR egl_image;
  79. // MJPEG decoding
  80. NvJPEGDecoder *jpegdec;
  81. // Verbose option
  82. bool enable_verbose;
  83. } context_t;
  84. // Correlate v4l2 pixel format and NvBuffer color format
  85. typedef struct
  86. {
  87. unsigned int v4l2_pixfmt;
  88. NvBufSurfaceColorFormat nvbuff_color;
  89. } nv_color_fmt;