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_us;
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
usb_cam::AbstractV4LUSBCam::AbstractV4LUSBCam
AbstractV4LUSBCam()
Definition: camera_driver.cpp:491
usb_cam::AbstractV4LUSBCam::set_v4l_parameter
static bool set_v4l_parameter(const std::string &param, const std::string &value)
Definition: camera_driver.cpp:898
usb_cam::AbstractV4LUSBCam::supported_formats
static std::vector< capture_format_t > supported_formats
Definition: camera_driver.h:67
usb_cam::AbstractV4LUSBCam::full_ffmpeg_log
static bool full_ffmpeg_log
Definition: camera_driver.h:51
usb_cam::AbstractV4LUSBCam::monochrome
static bool monochrome
Definition: camera_driver.h:46
usb_cam::AbstractV4LUSBCam::color_format
static color_format_t color_format
Definition: camera_driver.h:45
types.h
usb_cam::AbstractV4LUSBCam::v4l_query_controls
static void v4l_query_controls()
Definition: camera_driver.cpp:932
usb_cam
Definition: camera_driver.h:35
usb_cam::AbstractV4LUSBCam::run_grabber
static void run_grabber(unsigned int &buffer_size)
Definition: camera_driver.cpp:637
usb_cam::AbstractV4LUSBCam::buffers
static buffer * buffers
Definition: camera_driver.h:52
usb_cam::AbstractV4LUSBCam::avframe_rgb
static AVFrame * avframe_rgb
Definition: camera_driver.h:55
usb_cam::AbstractV4LUSBCam::avpkt
static AVPacket * avpkt
Definition: camera_driver.h:56
usb_cam::AbstractV4LUSBCam::~AbstractV4LUSBCam
virtual ~AbstractV4LUSBCam()
Definition: camera_driver.cpp:225
usb_cam::AbstractV4LUSBCam::buffers_count
static unsigned int buffers_count
Definition: camera_driver.h:53
usb_cam::camera_image_t
Definition: types.h:112
usb_cam::AbstractV4LUSBCam::streaming_status
static bool streaming_status
Definition: camera_driver.h:70
usb_cam::AbstractV4LUSBCam::avframe_rgb_size
static int avframe_rgb_size
Definition: camera_driver.h:62
usb_cam::AbstractV4LUSBCam::framerate
static int framerate
Definition: camera_driver.h:77
usb_cam::AbstractV4LUSBCam::image
static camera_image_t * image
Definition: camera_driver.h:65
usb_cam::AbstractV4LUSBCam::io_method_name
static std::string io_method_name
Definition: camera_driver.h:72
usb_cam::AbstractV4LUSBCam::controls
static std::vector< camera_control_t > controls
Definition: camera_driver.h:78
usb_cam::AbstractV4LUSBCam::release_device
static void release_device()
Definition: camera_driver.cpp:458
usb_cam::AbstractV4LUSBCam::init_decoder
static bool init_decoder()
Definition: camera_driver.cpp:252
usb_cam::AbstractV4LUSBCam::decode_ffmpeg
static bool decode_ffmpeg(const void *src, int len, camera_image_t *dest)
Definition: camera_driver.cpp:756
usb_cam::AbstractV4LUSBCam::avframe_camera
static AVFrame * avframe_camera
Definition: camera_driver.h:54
usb_cam::AbstractV4LUSBCam::color_format_name
static std::string color_format_name
Definition: camera_driver.h:74
usb_cam::AbstractV4LUSBCam::set_v4l_parameter
static bool set_v4l_parameter(const std::string &param, long value)
Definition: camera_driver.h:101
usb_cam::AbstractV4LUSBCam::avframe_camera_size
static int avframe_camera_size
Definition: camera_driver.h:61
usb_cam::AbstractV4LUSBCam::image_width
static int image_width
Definition: camera_driver.h:75
usb_cam::AbstractV4LUSBCam::set_v4l_parameter
static bool set_v4l_parameter(const std::string &param, int value)
Definition: camera_driver.h:100
usb_cam::AbstractV4LUSBCam::pixel_format
static pixel_format_t pixel_format
Definition: camera_driver.h:43
usb_cam::AbstractV4LUSBCam::close_handlers
static void close_handlers()
Definition: camera_driver.cpp:483
usb_cam::AbstractV4LUSBCam::io_method
static io_method_t io_method
Definition: camera_driver.h:42
usb_cam::AbstractV4LUSBCam::get_supported_formats
static std::vector< capture_format_t > & get_supported_formats()
Definition: camera_driver.cpp:830
usb_cam::AbstractV4LUSBCam::suspend
static bool suspend()
Definition: camera_driver.cpp:433
usb_cam::AbstractV4LUSBCam::start
static bool start()
Definition: camera_driver.cpp:90
usb_cam::AbstractV4LUSBCam::_image
camera_image_t _image
Definition: camera_driver.h:64
usb_cam::AbstractV4LUSBCam::epoch_time_shift_us
static const time_t epoch_time_shift_us
Definition: camera_driver.h:48
usb_cam::color_format_t
color_format_t
Definition: types.h:98
usb_cam::AbstractV4LUSBCam::image_height
static int image_height
Definition: camera_driver.h:76
usb_cam::AbstractV4LUSBCam::adjust_camera
static void adjust_camera()
Definition: camera_driver.cpp:1003
usb_cam::buffer
Definition: types.h:106
usb_cam::AbstractV4LUSBCam::video_device_name
static std::string video_device_name
Definition: camera_driver.h:71
usb_cam::pixel_format_t
pixel_format_t
Definition: types.h:83
usb_cam::AbstractV4LUSBCam::start_capture
static bool start_capture()
Definition: camera_driver.cpp:375
usb_cam::AbstractV4LUSBCam::v4l_pixel_format
static unsigned int v4l_pixel_format
Definition: camera_driver.h:44
usb_cam::io_method_t
io_method_t
Definition: types.h:74
param
T param(const std::string &param_name, const T &default_val)
usb_cam::AbstractV4LUSBCam::init
static bool init()
Definition: camera_driver.cpp:53
usb_cam::AbstractV4LUSBCam::ignore_controls
static std::set< std::string > ignore_controls
Definition: camera_driver.h:79
usb_cam::AbstractV4LUSBCam::avoptions
static AVDictionary * avoptions
Definition: camera_driver.h:59
converters.h
usb_cam::AbstractV4LUSBCam::avcodec
static AVCodec * avcodec
Definition: camera_driver.h:57
usb_cam::AbstractV4LUSBCam::pixel_format_name
static std::string pixel_format_name
Definition: camera_driver.h:73
usb_cam::AbstractV4LUSBCam::video_sws
static struct SwsContext * video_sws
Definition: camera_driver.h:63
usb_cam::AbstractV4LUSBCam::file_dev
static int file_dev
Definition: camera_driver.h:47
util.h
usb_cam::AbstractV4LUSBCam
Definition: camera_driver.h:38
usb_cam::AbstractV4LUSBCam::read_frame
static camera_image_t * read_frame()
Definition: camera_driver.cpp:495
usb_cam::AbstractV4LUSBCam::codec_id
static AVCodecID codec_id
Definition: camera_driver.h:58
usb_cam::AbstractV4LUSBCam::set_v4l_parameter
static bool set_v4l_parameter(const std::string &param, bool value)
Definition: camera_driver.h:102
usb_cam::AbstractV4LUSBCam::process_image
static bool process_image(const void *src, int len, camera_image_t *dest)
Definition: camera_driver.cpp:872
usb_cam::AbstractV4LUSBCam::capturing
static bool capturing
Definition: camera_driver.h:66
usb_cam::AbstractV4LUSBCam::avcodec_context
static AVCodecContext * avcodec_context
Definition: camera_driver.h:60


usb_cam
Author(s): Benjamin Pitzer
autogenerated on Sun Sep 3 2023 02:44:54