camera_driver.h
Go to the documentation of this file.
1 #ifndef USB_CAM_CAMERA_DRIVER_H
2 #define USB_CAM_CAMERA_DRIVER_H
3 
4 #include <string>
5 #include <iostream>
6 #include <algorithm>
7 #include <set>
8 extern "C"
9 {
10 // Legacy FFMPEG workaround
11 #include <libavcodec/version.h>
12 #if LIBAVCODEC_VERSION_MAJOR < 55
13  #define AV_CODEC_ID_MJPEG CODEC_ID_MJPEG
14 #endif
15 #include <libavcodec/avcodec.h>
16 #include <libswscale/swscale.h>
17 #define __STDC_CONSTANT_MACROS // Required for libavutil
18 #include <libavutil/imgutils.h>
19 #include <libavutil/frame.h>
20 #include <libavutil/mem.h>
21 }
22 
23 #include <fcntl.h> // for O_* constants
24 #include <unistd.h> // for getpagesize()
25 #include <malloc.h> // for memalign
26 #include <sys/mman.h> // for mmap
27 #include <sys/stat.h> // for stat
28 
29 #include <opencv2/imgproc.hpp>
30 
31 #include "usb_cam/types.h"
32 #include "usb_cam/util.h"
33 #include "usb_cam/converters.h"
34 
35 namespace usb_cam
36 {
37 
39 {
40 protected:
41  /* V4L/HARDWARE */
42  static io_method_t io_method; // io_
44  static unsigned int v4l_pixel_format;
46  static bool monochrome;
47  static int file_dev; // fd_
48  static const time_t epoch_time_shift;
49 
50  /* FFMPEG */
51  static bool full_ffmpeg_log;
52  static buffer* buffers;
53  static unsigned int buffers_count; // n_buffers_
54  static AVFrame * avframe_camera;
55  static AVFrame * avframe_rgb;
56  static AVPacket* avpkt;
57  static AVCodec * avcodec;
58  static AVCodecID codec_id;
59  static AVDictionary * avoptions;
60  static AVCodecContext * avcodec_context;
61  static int avframe_camera_size;
62  static int avframe_rgb_size;
63  static struct SwsContext * video_sws;
66  static bool capturing;
67  static std::vector<capture_format_t> supported_formats;
68 
69  /* V4L camera parameters */
70  static bool streaming_status;
71  static std::string video_device_name;
72  static std::string io_method_name;
73  static std::string pixel_format_name;
74  static std::string color_format_name;
75  static int image_width;
76  static int image_height;
77  static int framerate;
78  static std::vector<camera_control_t>controls;
79  static std::set<std::string> ignore_controls;
80  /*
81  static int exposure;
82  static int brightness;
83  static int contrast;
84  static int saturation;
85  static int sharpness;
86  static int focus;
87  static int white_balance;
88  static int gain;
89  static bool autofocus;
90  static bool autoexposure;
91  static bool auto_white_balance;
92  */
93 
94  /* Internal functions */
95  static bool init();
96  static bool start();
97  static bool init_decoder();
98  static void run_grabber(unsigned int& buffer_size);
99  static bool set_v4l_parameter(const std::string & param, const std::string & value);
100  static inline bool set_v4l_parameter(const std::string & param, int value){return set_v4l_parameter(param, std::to_string(value));}
101  static inline bool set_v4l_parameter(const std::string & param, long value){return set_v4l_parameter(param, std::to_string(value));}
102  static inline bool set_v4l_parameter(const std::string & param, bool value){return set_v4l_parameter(param, value ? 1 : 0);}
103  static void v4l_query_controls();
104  static void adjust_camera();
105  static bool start_capture();
106  static camera_image_t* read_frame();
107  static bool decode_ffmpeg(const void *src, int len, camera_image_t *dest);
108  static bool process_image(const void * src, int len, camera_image_t * dest);
109  static bool suspend();
110  static void release_device();
111  static void close_handlers();
113  AbstractV4LUSBCam(const AbstractV4LUSBCam& root) = delete;
114 
115 public:
116  virtual ~AbstractV4LUSBCam();
117  static std::vector<capture_format_t>& get_supported_formats();
118 };
119 
120 } // namespace usb_cam
121 
122 #endif // USB_CAM_CAMERA_DRIVER_H
static bool set_v4l_parameter(const std::string &param, bool value)
static bool process_image(const void *src, int len, camera_image_t *dest)
static camera_image_t * read_frame()
static const time_t epoch_time_shift
Definition: camera_driver.h:48
static AVCodecContext * avcodec_context
Definition: camera_driver.h:60
static AVPacket * avpkt
Definition: camera_driver.h:56
static color_format_t color_format
Definition: camera_driver.h:45
static void run_grabber(unsigned int &buffer_size)
static bool decode_ffmpeg(const void *src, int len, camera_image_t *dest)
static AVFrame * avframe_rgb
Definition: camera_driver.h:55
static AVFrame * avframe_camera
Definition: camera_driver.h:54
static std::string color_format_name
Definition: camera_driver.h:74
static io_method_t io_method
Definition: camera_driver.h:42
static std::string io_method_name
Definition: camera_driver.h:72
static unsigned int buffers_count
Definition: camera_driver.h:53
static std::vector< camera_control_t > controls
Definition: camera_driver.h:78
static std::vector< capture_format_t > & get_supported_formats()
static pixel_format_t pixel_format
Definition: camera_driver.h:43
static bool set_v4l_parameter(const std::string &param, long value)
static camera_image_t * image
Definition: camera_driver.h:65
pixel_format_t
Definition: types.h:83
static unsigned int v4l_pixel_format
Definition: camera_driver.h:44
static bool set_v4l_parameter(const std::string &param, int value)
static AVDictionary * avoptions
Definition: camera_driver.h:59
static std::set< std::string > ignore_controls
Definition: camera_driver.h:79
io_method_t
Definition: types.h:74
static AVCodecID codec_id
Definition: camera_driver.h:58
static std::string video_device_name
Definition: camera_driver.h:71
static AVCodec * avcodec
Definition: camera_driver.h:57
static std::string pixel_format_name
Definition: camera_driver.h:73
static struct SwsContext * video_sws
Definition: camera_driver.h:63
static bool set_v4l_parameter(const std::string &param, const std::string &value)
static std::vector< capture_format_t > supported_formats
Definition: camera_driver.h:67
color_format_t
Definition: types.h:98


usb_cam
Author(s): Benjamin Pitzer
autogenerated on Sat May 27 2023 02:53:04