common.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 StarFive Technology Co., Ltd.
  4. */
  5. #ifndef __COMMON_H__
  6. #define __COMMON_H__
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <stdint.h>
  11. #include <sys/stat.h>
  12. #include <sys/types.h>
  13. #include <sys/time.h>
  14. #include <time.h>
  15. #include <asm/types.h>
  16. #include <linux/videodev2.h>
  17. #include <linux/fb.h>
  18. #include <string.h>
  19. #include <errno.h>
  20. #include <assert.h>
  21. #include <fcntl.h>
  22. #include <malloc.h>
  23. #ifndef TEST_VERSION
  24. #define TEST_VERSION "v0.0.1"
  25. #endif
  26. #define BUFCOUNT 4
  27. #define CLEAR(x) memset (&(x), 0, sizeof (x))
  28. #define PCLEAR(x) memset ((x), 0, sizeof (*x))
  29. struct buffer {
  30. void* start;
  31. size_t length;
  32. int dmabuf_fd;
  33. int index;
  34. };
  35. enum COLOR_FORMAT{
  36. COLOR_YUV422_UYVY = 0, // 00={Y1,V0,Y0,U0}
  37. COLOR_YUV422_VYUY = 1, // 01={Y1,U0,Y0,V0}
  38. COLOR_YUV422_YUYV = 2, // 10={V0,Y1,U0,Y0}
  39. COLOR_YUV422_YVYU = 3, // 11={U0,Y1,V0,Y0}
  40. COLOR_YUV420P, // 4
  41. COLOR_YUV420_NV21, // 5
  42. COLOR_YUV420_NV12, // 6
  43. COLOR_RGB888_ARGB, // 7
  44. COLOR_RGB888_ABGR, // 8
  45. COLOR_RGB888_RGBA, // 9
  46. COLOR_RGB888_BGRA, // 10
  47. COLOR_RGB565, // 11
  48. };
  49. typedef enum IOMethod {
  50. IO_METHOD_MMAP,
  51. IO_METHOD_USERPTR,
  52. IO_METHOD_DMABUF,
  53. IO_METHOD_READ
  54. } IOMethod;
  55. typedef enum STF_DISP_TYPE {
  56. STF_DISP_NONE = 0, // Not display
  57. // STF_DISP_FB, // Use framebuffer framework display
  58. STF_DISP_DRM // Use drm framework display
  59. } STF_DISP_TYPE;
  60. extern void dump_fourcc(uint32_t fourcc);
  61. extern int v4l2fmt_to_fbfmt(uint32_t format);
  62. extern uint32_t v4l2fmt_to_drmfmt(uint32_t v4l2_fmt);
  63. extern uint32_t ffmpegfmt_to_drmfmt(uint32_t ffmpeg_fmt);
  64. extern void errno_exit(const char* s);
  65. extern void errno_print(const char *s);
  66. extern int write_file(char * filename, const unsigned char *image_buffer, int size);
  67. // extern void jpegWrite(unsigned char* img, char* jpegFilename);
  68. extern void jpegWrite(unsigned char* img, char* jpegFilename,
  69. uint32_t width, uint32_t height, int jpegQuality);
  70. extern int write_JPEG_file(char * filename,unsigned char *image_buffer,
  71. int image_width, int image_height, int quality);
  72. // inline int clip(int value, int min, int max) {
  73. // return (value > max ? max : value < min ? min : value);
  74. // }
  75. #endif // __COMMON_H__