C++ reference

This is for the most part identical to the Python reference, so much of the descriptions are not here, The descriptions are mostly for the parts that differ from the Python interface.

Devices

Device

class Device

Subclassed by qamlib::StreamingDevice

Public Functions

std::map<std::string, std::shared_ptr<Control>> list_controls()
virtual void set_control(const std::string &name, int value)

Set named control to value

void set_control(uint32_t id, int value)

Set control of id to value

int get_control(const std::string &name)
int get_control(uint32_t id)
void set_ext_control(const std::string &name, ControlValue &value)
std::unique_ptr<ControlValue> get_ext_control(const std::string &name, bool default_value = false)
std::map<std::string, std::unique_ptr<ControlValue>> get_controls(std::vector<std::string> names, bool default_value = false)
void set_controls(std::map<std::string, ControlValue*> values)
inline virtual ~Device()

Public Members

DeviceInfo device_info

StreamingDevice

class StreamingDevice : public qamlib::Device

Subclassed by qamlib::Camera

Public Functions

virtual void start()
virtual void stop()
std::tuple<uint32_t, uint32_t> get_resolution()
std::tuple<uint32_t, uint32_t> set_resolution(uint32_t newWidth, uint32_t newHeight)
std::vector<Rectangle> get_crop()
void set_crop(int left, int top, uint32_t width, uint32_t height)
void set_crop(Rectangle rectangle)
void set_crop(std::vector<Rectangle> rectangles)
Rectangle get_crop_default()
Rectangle get_crop_bounds()
std::map<std::string, ImageFormat> list_formats()

Camera

class Camera : public qamlib::StreamingDevice

Class for interacting with a V4L2 capture device.

Public Functions

inline Camera(const std::string &device, std::optional<uint32_t> buffers = std::nullopt, bool overflow_exception = true)
inline Camera(uint32_t device_num, std::optional<uint32_t> buffers = std::nullopt, bool overflow_exception = true)
inline Camera(bool overflow_exception = true)
inline ~Camera() override
virtual void start() override

Start streaming from the camera

virtual void stop() override

Stop streaming from the camera

std::tuple<struct FrameMetadata, cv::Mat> get_frame(std::optional<double> timeout = std::nullopt, bool buffered = false)

Get latest frame from the camera as a OpenCV Mat object.

Parameters:
  • timeout – Time in seconds to wait before throwing a TimeoutException. If 0 then there is no timeout.

  • buffered – If true then the first frame in the buffer is returned, if false then the latest frame is returned.

std::unique_ptr<Format> get_format()
std::unique_ptr<Format> set_format(Format &format)
std::unique_ptr<Format> set_format(const std::string &format, bool big_endian = false)
std::unique_ptr<FrameRate> get_framerates()
std::unique_ptr<FrameRate> get_framerates(uint32_t width, uint32_t height)
std::unique_ptr<FrameRate> get_framerates(uint32_t width, uint32_t height, const std::string &format, bool big_endian = false)
double get_framerate()
double set_framerate(double value)

Controls

Control

class Control

Subclassed by qamlib::ValueControl

Public Functions

inline Control(v4l2_query_ext_ctrl *query)
virtual ~Control() = default
virtual std::string to_string() const
virtual json to_json() const

Public Members

uint32_t id
std::string name
uint32_t type
ControlFlags flags
uint32_t elem_size
uint32_t elems
std::vector<uint32_t> dimensions

ValueControl

class ValueControl : public qamlib::Control

Subclassed by qamlib::IntegerMenuControl, qamlib::MenuControl

Public Functions

inline ValueControl(v4l2_query_ext_ctrl *query)
virtual std::string to_string() const override
virtual json to_json() const override

Public Members

int64_t min
int64_t max
int64_t default_value
uint64_t step

IntegerMenuControl

class IntegerMenuControl : public qamlib::ValueControl

Public Functions

inline IntegerMenuControl(v4l2_query_ext_ctrl *query, std::map<uint32_t, int64_t> items)
virtual std::string to_string() const override
virtual json to_json() const override

Public Members

std::map<uint32_t, int64_t> items

ControlFlags

class ControlFlags

Public Functions

inline ControlFlags(uint32_t flags)
flag_function(disabled, V4L2_CTRL_FLAG_DISABLED)
flag_function(grabbed, V4L2_CTRL_FLAG_GRABBED)
flag_function(read_only, V4L2_CTRL_FLAG_READ_ONLY)
flag_function(update, V4L2_CTRL_FLAG_UPDATE)
flag_function(inactive, V4L2_CTRL_FLAG_INACTIVE)
flag_function(slider, V4L2_CTRL_FLAG_SLIDER)
flag_function(write_only, V4L2_CTRL_FLAG_WRITE_ONLY)
flag_function(is_volatile, V4L2_CTRL_FLAG_VOLATILE)
flag_function(has_payload, V4L2_CTRL_FLAG_HAS_PAYLOAD)
flag_function(execute_on_write, V4L2_CTRL_FLAG_EXECUTE_ON_WRITE)
flag_function(modify_layout, V4L2_CTRL_FLAG_MODIFY_LAYOUT)
flag_function(dynamic_array, V4L2_CTRL_FLAG_DYNAMIC_ARRAY)
std::string to_string() const
json to_json() const

Public Members

uint32_t flags

ControlValue classes

IntegerControlValue

class IntegerControlValue : public qamlib::ControlValue

Public Functions

inline IntegerControlValue(uint32_t type)

Internal qamlib function not to be used otherwise

inline IntegerControlValue(int64_t value)
inline IntegerControlValue(int32_t value)
int64_t get_value() const
virtual void check_value(std::shared_ptr<Control> ctrl) override

Internal qamlib function not to be used otherwise

virtual void ready_control(v4l2_ext_control &ctrl) override

Internal qamlib function not to be used otherwise

virtual void update_value(v4l2_ext_control &ctrl) override

Internal qamlib function not to be used otherwise

virtual std::string to_string() const override
virtual json to_json() const override

StringControlValue

class StringControlValue : public qamlib::ControlValue

Public Functions

inline StringControlValue(uint32_t max_size)

Internal qamlib function not to be used otherwise

inline StringControlValue(std::string &val)
virtual void check_value(std::shared_ptr<Control> ctrl) override

Internal qamlib function not to be used otherwise

virtual void ready_control(v4l2_ext_control &ctrl) override

Internal qamlib function not to be used otherwise

inline ~StringControlValue() override
virtual std::string to_string() const override
virtual json to_json() const override

ArrayControlValue

class ArrayControlValue : public qamlib::ControlValue

Public Functions

inline ArrayControlValue(uint32_t elements, uint32_t element_size, std::vector<uint32_t> dims, bool sign = false)
inline ArrayControlValue(cv::Mat array)
cv::Mat get_array() const
virtual void check_value(std::shared_ptr<Control> ctrl) override

Internal qamlib function not to be used otherwise

virtual void ready_control(v4l2_ext_control &ctrl) override

Internal qamlib function not to be used otherwise

inline ~ArrayControlValue() override
virtual std::string to_string() const override
virtual json to_json() const override

Formats

ImageFormat

class ImageFormat

Public Functions

inline ImageFormat(struct v4l2_fmtdesc *fmt)
std::string to_string() const
json to_json() const

Public Members

uint32_t index
ImageFormatFlags flags
std::string description
PixelFormat pixelformat

ImageFormatFlags

class ImageFormatFlags

Public Functions

inline ImageFormatFlags(uint32_t flags)
flag_function(compressed, V4L2_FMT_FLAG_COMPRESSED)
flag_function(emulated, V4L2_FMT_FLAG_EMULATED)
flag_function(continuous_bytestream, V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM)
flag_function(dyn_resolution, V4L2_FMT_FLAG_DYN_RESOLUTION)
flag_function(enc_cap_frame_interval, V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL)
flag_function(csc_colorspace, V4L2_FMT_FLAG_CSC_COLORSPACE)
flag_function(csc_xfer_func, V4L2_FMT_FLAG_CSC_XFER_FUNC)
flag_function(csc_ycbcr_enc, V4L2_FMT_FLAG_CSC_YCBCR_ENC)
flag_function(csc_hsv_enc, V4L2_FMT_FLAG_CSC_HSV_ENC)
flag_function(csc_quantization, V4L2_FMT_FLAG_CSC_QUANTIZATION)
std::string to_string() const
json to_json() const

Public Members

uint32_t flags

Format

class Format

Subclassed by qamlib::SinglePlaneFormat

Public Functions

inline Format(v4l2_buf_type type)
virtual ~Format() = default

Public Members

v4l2_buf_type type

SinglePlaneFormat

class SinglePlaneFormat : public qamlib::Format

Public Functions

inline SinglePlaneFormat(struct v4l2_pix_format *fmt, v4l2_buf_type type)
std::string to_string() const
json to_json() const

Public Members

uint32_t width
uint32_t height
PixelFormat pixelformat
v4l2_field field
uint32_t bytesperline
uint32_t sizeimage
v4l2_colorspace colorspace
bool priv
PixelFormatFlags flags
v4l2_quantization quantization
v4l2_xfer_func xfer_func

PixelFormat

class PixelFormat

Public Functions

inline PixelFormat(uint32_t code)
inline PixelFormat(const std::string &fourcc, bool big_endian)
inline PixelFormat(const std::string &fourcc)
std::string get_fourcc() const
void set_fourcc(std::string &new_name)
uint32_t get_code() const
std::string to_string() const

Public Members

bool big_endian = false

PixelFormatFlags

class PixelFormatFlags

Public Functions

inline PixelFormatFlags(uint32_t flags)
flag_function(premul_alpha, V4L2_PIX_FMT_FLAG_PREMUL_ALPHA)
flag_function(set_csc, V4L2_PIX_FMT_FLAG_SET_CSC)
std::string to_string() const
json to_json() const

Public Members

uint32_t flags

Framerates

FrameRate

class FrameRate

Subclassed by qamlib::ContinuousFrameRate, qamlib::DiscreteFrameRate

Public Functions

virtual ~FrameRate() = default

Public Members

v4l2_frmivaltypes type

DiscreteFrameRate

class DiscreteFrameRate : public qamlib::FrameRate

Public Functions

inline DiscreteFrameRate(std::vector<double> values)
std::string to_string() const
json to_json() const

Public Members

std::vector<double> values

ContinuousFrameRate

class ContinuousFrameRate : public qamlib::FrameRate

Subclassed by qamlib::StepwiseFrameRate

Public Functions

inline ContinuousFrameRate(double min, double max)
std::string to_string() const
json to_json() const

Public Members

double min
double max

StepwiseFrameRate

class StepwiseFrameRate : public qamlib::ContinuousFrameRate

Public Functions

inline StepwiseFrameRate(double min, double max, double step)
std::string to_string() const
json to_json() const

Public Members

double step

Events

BaseEvent

class BaseEvent

Subclassed by qamlib::ControlEvent, qamlib::SourceEvent

Public Functions

inline BaseEvent(v4l2_event &event)
virtual ~BaseEvent() = default
std::string to_string() const

Public Members

EventType type
uint32_t pending
uint32_t sequence
double timestamp
uint32_t id

ControlEvent

class ControlEvent : public qamlib::BaseEvent

Public Functions

inline ControlEvent(v4l2_event &event)
std::string to_string() const

Public Members

ControlChangesFlags changes
uint32_t control_type
int64_t value
ControlFlags flags
int min
int max
int step
int default_value

EventType

enum qamlib::EventType

Values:

enumerator ALL
enumerator VSYNC
enumerator EOS
enumerator CTRL
enumerator FRAME_SYNC
enumerator SOURCE_CHANGE
enumerator MOTION_DET

ControlChangesFlags

class ControlChangesFlags

Public Functions

inline ControlChangesFlags(uint32_t flags)
flag_function(value, V4L2_EVENT_CTRL_CH_VALUE)
flag_function(ch_flags, V4L2_EVENT_CTRL_CH_FLAGS)
flag_function(range, V4L2_EVENT_CTRL_CH_RANGE)
std::string to_string() const

Misc

FrameMetadata

class FrameMetadata

Metadata for a frame. time is in machine clock with clock specifying which clock is used sequence is the framenumber since the stream was started

Public Functions

std::string to_string()

Function to “pretty-print” the FrameMetadata struct

Public Members

double time
clockid_t clock
uint32_t sequence

Rectangle

class Rectangle

Public Functions

inline Rectangle()
inline Rectangle(int left, int top, uint32_t width, uint32_t height)
inline std::string to_string()
inline std::vector<int> as_vector()
inline bool operator==(const Rectangle &rhs) const
inline bool operator!=(const Rectangle &rhs) const

Public Members

int left = 0
int top = 0
uint32_t width = 0
uint32_t height = 0

Exceptions

V4L2Exception

class V4L2Exception : public std::exception

Subclassed by qamlib::V4L2BusyException

Public Functions

inline V4L2Exception(const std::string &msg, int err_num)
inline V4L2Exception(const std::string &msg)
inline V4L2Exception(const std::string &name, const std::string &msg)
inline const char *what() const noexcept override
virtual ~V4L2Exception() = default

TimeoutException

class TimeoutException : public std::exception

Public Functions

inline TimeoutException()
inline const char *what() const noexcept override

DroppedFrameException

class DroppedFrameException : public std::exception

Public Functions

inline DroppedFrameException()
inline const char *what() const noexcept override