camera.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include <linux/v4l2-subdev.h>
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. typedef enum {
  6. MP_PIXEL_FMT_UNSUPPORTED,
  7. MP_PIXEL_FMT_BGGR8,
  8. MP_PIXEL_FMT_GBRG8,
  9. MP_PIXEL_FMT_GRBG8,
  10. MP_PIXEL_FMT_RGGB8,
  11. MP_PIXEL_FMT_BGGR10P,
  12. MP_PIXEL_FMT_GBRG10P,
  13. MP_PIXEL_FMT_GRBG10P,
  14. MP_PIXEL_FMT_RGGB10P,
  15. MP_PIXEL_FMT_UYVY,
  16. MP_PIXEL_FMT_YUYV,
  17. MP_PIXEL_FMT_MAX,
  18. } MPPixelFormat;
  19. MPPixelFormat mp_pixel_format_from_str(const char *str);
  20. const char *mp_pixel_format_to_str(MPPixelFormat pixel_format);
  21. MPPixelFormat mp_pixel_format_from_v4l_pixel_format(uint32_t v4l_pixel_format);
  22. MPPixelFormat mp_pixel_format_from_v4l_bus_code(uint32_t v4l_bus_code);
  23. uint32_t mp_pixel_format_to_v4l_pixel_format(MPPixelFormat pixel_format);
  24. uint32_t mp_pixel_format_to_v4l_bus_code(MPPixelFormat pixel_format);
  25. uint32_t mp_pixel_format_bits_per_pixel(MPPixelFormat pixel_format);
  26. uint32_t mp_pixel_format_width_to_bytes(MPPixelFormat pixel_format, uint32_t width);
  27. uint32_t mp_pixel_format_width_to_colors(MPPixelFormat pixel_format, uint32_t width);
  28. uint32_t mp_pixel_format_height_to_colors(MPPixelFormat pixel_format, uint32_t height);
  29. typedef struct {
  30. MPPixelFormat pixel_format;
  31. struct v4l2_fract frame_interval;
  32. uint32_t width;
  33. uint32_t height;
  34. } MPCameraMode;
  35. bool mp_camera_mode_is_equivalent(const MPCameraMode *m1, const MPCameraMode *m2);
  36. typedef struct {
  37. uint32_t pixel_format;
  38. uint32_t width;
  39. uint32_t height;
  40. uint8_t *data;
  41. } MPImage;
  42. typedef struct _MPCamera MPCamera;
  43. MPCamera *mp_camera_new(int video_fd, int subdev_fd);
  44. void mp_camera_free(MPCamera *camera);
  45. bool mp_camera_is_subdev(MPCamera *camera);
  46. int mp_camera_get_video_fd(MPCamera *camera);
  47. int mp_camera_get_subdev_fd(MPCamera *camera);
  48. const MPCameraMode *mp_camera_get_mode(const MPCamera *camera);
  49. bool mp_camera_try_mode(MPCamera *camera, MPCameraMode *mode);
  50. bool mp_camera_set_mode(MPCamera *camera, MPCameraMode *mode);
  51. bool mp_camera_start_capture(MPCamera *camera);
  52. bool mp_camera_stop_capture(MPCamera *camera);
  53. bool mp_camera_is_capturing(MPCamera *camera);
  54. bool mp_camera_capture_image(MPCamera *camera, void (*callback)(MPImage, void *), void *user_data);
  55. typedef struct _MPCameraModeList MPCameraModeList;
  56. MPCameraModeList *mp_camera_list_supported_modes(MPCamera *camera);
  57. MPCameraModeList *mp_camera_list_available_modes(MPCamera *camera);
  58. MPCameraMode *mp_camera_mode_list_get(MPCameraModeList *list);
  59. MPCameraModeList *mp_camera_mode_list_next(MPCameraModeList *list);
  60. void mp_camera_mode_list_free(MPCameraModeList *list);