A class for handle a video device. More...
#include <vidl_v4l2_device.h>
Classes | |
| struct | buffer |
Public Member Functions | |
| vidl_v4l2_device (const char *file) | |
| Constructor. | |
| ~vidl_v4l2_device () | |
| vcl_string | device_file () const |
| Name of the associated file device (same as constructor). | |
| vcl_string | card_name () const |
| Friendly name of the device. | |
| unsigned int | n_inputs () const |
| Number of inputs in device. | |
| unsigned int | current_input () const |
| Inputs been used (0 to ninputs-1). | |
| const vidl_v4l2_input & | input (int i) const |
| Return input number i (0 ..\ ninputs-1). | |
| bool | set_input (unsigned int i) |
| Select input i. | |
| bool | set_v4l2_format (unsigned int fourcode, int width, int height, double fps=0.0) |
| Select a new format. | |
| bool | try_formats (int width=640, int height=480) |
| Try several formats implemented in vidl. | |
| bool | format_is_set () const |
| Return if the format is set. | |
| unsigned int | get_v4l2_format () const |
| Get pixel format of type of compression. | |
| int | get_width () const |
| Return Image width in pixels. | |
| int | get_height () const |
| Return Image height in pixels. | |
| double | get_frame_rate () const |
| Return Current frame rate. | |
| void | reset_controls () |
| Reset controls to default. | |
| int | n_controls () const |
| Get number of controls. | |
| vidl_v4l2_control * | get_control (int i) const |
| Get control. | |
| vidl_v4l2_control * | get_control_id (int id) const |
| Get control from driver id. | |
| vidl_v4l2_control_integer * | get_control_integer_id (int id) const |
| Get control from driver id. | |
| vidl_v4l2_control_menu * | get_control_menu_id (int id) const |
| Get control from driver id. | |
| vidl_v4l2_control_boolean * | get_control_boolean_id (int id) const |
| Get control from driver id. | |
| vidl_v4l2_control_button * | get_control_button_id (int id) const |
| Get control from driver id. | |
| bool | start_capturing () |
| Start capturing. | |
| bool | is_capturing () const |
| Return if device is capturing. | |
| bool | stop_capturing () |
| Stop capturing. | |
| bool | read_frame () |
| Read next frame. | |
| bool | set_number_of_buffers (unsigned int nb) |
| Set numbers of buffers. | |
| unsigned int | get_number_of_buffers () const |
| Get numbers of buffers. | |
| void * | current_buffer () const |
| Return the last used buffer. | |
| unsigned int | current_buffer_length () const |
| Return length of the last used buffer. | |
| void * | ibuffer (unsigned int i) const |
| Return buffer number i. | |
| unsigned int | sequence () const |
| bool | time_available () const |
| Return if driver has time associated to the captured frame. | |
| v4l2_timecode | time () const |
| Time from last frame. | |
| operator safe_bool () const | |
| Cast to bool is true if video device is working ok. | |
| bool | operator! () const |
| Return false if video device is not working ok. | |
| vcl_string | get_error () const |
| Return last error if device is in a bad state. Empty if ok. | |
| void | ref () |
| Increment reference count. | |
| void | unref () |
| Decrement reference count. | |
| int | ref_count () const |
| Number of objects referring to this data. | |
Private Member Functions | |
| void | update_controls () |
| void | reset () |
| bool | open () |
| bool | initialize_device () |
| bool | init_mmap (int reqbuf) |
| bool | uninit_mmap () |
| bool | close () |
| bool | is_open () const |
| bool | is_prepared_for_capturing () const |
| bool | good () const |
| vidl_v4l2_device (const vidl_v4l2_device &) | |
| vidl_v4l2_device & | operator= (const vidl_v4l2_device &) |
Private Attributes | |
| VCL_SAFE_BOOL_DEFINE | |
| int | fd |
| unsigned int | pre_nbuffers |
| struct buffer * | buffers |
| unsigned int | n_buffers |
| int | last_buffer |
| struct v4l2_format | fmt |
| double | frame_rate |
| vcl_string | dev_name_ |
| vcl_string | card_name_ |
| vcl_string | last_error |
| bool | capturing |
| vcl_vector< vidl_v4l2_input > | inputs_ |
| vcl_vector< vidl_v4l2_control * > | controls_ |
| int | ref_count_ |
A class for handle a video device.
This class is designed to be vidl independent, although it is very easy to create a vidl istream from it. It has not been fully tested, although it has been proven to capture images from multiple webcams with a single buffer (default) and has worked properly. Generally, the steps to be made for a capture are as follows:
Definition at line 57 of file vidl_v4l2_device.h.
| vidl_v4l2_device::vidl_v4l2_device | ( | const vidl_v4l2_device & | ) | [private] |
| vidl_v4l2_device::vidl_v4l2_device | ( | const char * | file | ) |
Constructor.
After construction, device is closed (device is not busy). You can use device as a boolean expression to test if device is ok.
| file | device name (for example, "/dev/video") |
| file | device name (for example, "/dev/video") |
Definition at line 103 of file vidl_v4l2_device.cxx.
| vidl_v4l2_device::~vidl_v4l2_device | ( | ) |
Definition at line 145 of file vidl_v4l2_device.cxx.
| vcl_string vidl_v4l2_device::card_name | ( | ) | const [inline] |
Friendly name of the device.
Definition at line 114 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::close | ( | void | ) | [private] |
Definition at line 579 of file vidl_v4l2_device.cxx.
| void* vidl_v4l2_device::current_buffer | ( | ) | const [inline] |
Return the last used buffer.
Definition at line 257 of file vidl_v4l2_device.h.
| unsigned int vidl_v4l2_device::current_buffer_length | ( | ) | const [inline] |
Return length of the last used buffer.
Definition at line 263 of file vidl_v4l2_device.h.
| unsigned int vidl_v4l2_device::current_input | ( | ) | const |
Inputs been used (0 to ninputs-1).
if equal to ninputs, indicates unknown
Definition at line 599 of file vidl_v4l2_device.cxx.
| vcl_string vidl_v4l2_device::device_file | ( | ) | const [inline] |
Name of the associated file device (same as constructor).
Definition at line 112 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::format_is_set | ( | ) | const [inline] |
Return if the format is set.
Normally, a format is automatically selected or user call set_v4l2_format. User can use this function to know if a format is selected before calling start_capturing.
Definition at line 149 of file vidl_v4l2_device.h.
| vidl_v4l2_control* vidl_v4l2_device::get_control | ( | int | i | ) | const [inline] |
Get control.
The user must downcast the pointer -depending on type- to use all functionality.
| i | indicates the control to be extracted, from 0 to n_controls-1 |
Definition at line 185 of file vidl_v4l2_device.h.
| vidl_v4l2_control_boolean* vidl_v4l2_device::get_control_boolean_id | ( | int | id | ) | const [inline] |
Get control from driver id.
| id | is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS |
Definition at line 216 of file vidl_v4l2_device.h.
| vidl_v4l2_control_button* vidl_v4l2_device::get_control_button_id | ( | int | id | ) | const [inline] |
Get control from driver id.
| id | is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS |
Definition at line 226 of file vidl_v4l2_device.h.
| vidl_v4l2_control* vidl_v4l2_device::get_control_id | ( | int | id | ) | const [inline] |
Get control from driver id.
The user must downcast the pointer -depending on type- to use all functionality.
| id | is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS |
Definition at line 190 of file vidl_v4l2_device.h.
| vidl_v4l2_control_integer* vidl_v4l2_device::get_control_integer_id | ( | int | id | ) | const [inline] |
Get control from driver id.
| id | is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS |
Definition at line 196 of file vidl_v4l2_device.h.
| vidl_v4l2_control_menu* vidl_v4l2_device::get_control_menu_id | ( | int | id | ) | const [inline] |
Get control from driver id.
| id | is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS |
Definition at line 206 of file vidl_v4l2_device.h.
| vcl_string vidl_v4l2_device::get_error | ( | ) | const [inline] |
Return last error if device is in a bad state. Empty if ok.
Definition at line 305 of file vidl_v4l2_device.h.
| double vidl_v4l2_device::get_frame_rate | ( | ) | const [inline] |
Return Current frame rate.
Definition at line 170 of file vidl_v4l2_device.h.
| int vidl_v4l2_device::get_height | ( | ) | const [inline] |
Return Image height in pixels.
Definition at line 166 of file vidl_v4l2_device.h.
| unsigned int vidl_v4l2_device::get_number_of_buffers | ( | ) | const [inline] |
Get numbers of buffers.
Definition at line 253 of file vidl_v4l2_device.h.
| unsigned int vidl_v4l2_device::get_v4l2_format | ( | ) | const [inline] |
Get pixel format of type of compression.
Definition at line 154 of file vidl_v4l2_device.h.
| int vidl_v4l2_device::get_width | ( | ) | const [inline] |
Return Image width in pixels.
Definition at line 162 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::good | ( | ) | const [inline, private] |
Definition at line 95 of file vidl_v4l2_device.h.
| void* vidl_v4l2_device::ibuffer | ( | unsigned int | i | ) | const [inline] |
Return buffer number i.
Definition at line 270 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::init_mmap | ( | int | reqbuf | ) | [private] |
Definition at line 365 of file vidl_v4l2_device.cxx.
| bool vidl_v4l2_device::initialize_device | ( | ) | [private] |
Definition at line 226 of file vidl_v4l2_device.cxx.
| const vidl_v4l2_input& vidl_v4l2_device::input | ( | int | i | ) | const [inline] |
Return input number i (0 ..\ ninputs-1).
Definition at line 122 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::is_capturing | ( | ) | const [inline] |
Return if device is capturing.
Definition at line 239 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::is_open | ( | ) | const [inline, private] |
Definition at line 93 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::is_prepared_for_capturing | ( | ) | const [inline, private] |
Definition at line 94 of file vidl_v4l2_device.h.
| int vidl_v4l2_device::n_controls | ( | ) | const [inline] |
Get number of controls.
Definition at line 179 of file vidl_v4l2_device.h.
| unsigned int vidl_v4l2_device::n_inputs | ( | ) | const [inline] |
Number of inputs in device.
Definition at line 116 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::open | ( | ) | [private] |
Definition at line 194 of file vidl_v4l2_device.cxx.
| vidl_v4l2_device::operator safe_bool | ( | ) | const [inline] |
Cast to bool is true if video device is working ok.
Definition at line 297 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::operator! | ( | ) | const [inline] |
Return false if video device is not working ok.
Definition at line 301 of file vidl_v4l2_device.h.
| vidl_v4l2_device& vidl_v4l2_device::operator= | ( | const vidl_v4l2_device & | ) | [private] |
| bool vidl_v4l2_device::read_frame | ( | void | ) |
| void vidl_v4l2_device::ref | ( | ) | [inline] |
Increment reference count.
Definition at line 312 of file vidl_v4l2_device.h.
| int vidl_v4l2_device::ref_count | ( | ) | const [inline] |
Number of objects referring to this data.
Definition at line 325 of file vidl_v4l2_device.h.
| void vidl_v4l2_device::reset | ( | ) | [private] |
Definition at line 160 of file vidl_v4l2_device.cxx.
| void vidl_v4l2_device::reset_controls | ( | ) |
Reset controls to default.
Definition at line 93 of file vidl_v4l2_device.cxx.
| unsigned int vidl_v4l2_device::sequence | ( | ) | const [inline] |
Definition at line 275 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::set_input | ( | unsigned int | i | ) |
| bool vidl_v4l2_device::set_number_of_buffers | ( | unsigned int | nb | ) |
| bool vidl_v4l2_device::set_v4l2_format | ( | unsigned int | fourcode, |
| int | width, | ||
| int | height, | ||
| double | fps = 0.0 |
||
| ) |
Select a new format.
Device try automatically different formats (
| fourcode | A four character code defined in v4l2 (see v4l2 specification and vidl_pixel_format.h) indicating pixel encoding |
| width | can be changed by drivers to the closest possible value |
| height | can be changed by drivers to the closest possible value |
| fps | frame rate to try (not garanteed). |
Definition at line 294 of file vidl_v4l2_device.cxx.
| bool vidl_v4l2_device::start_capturing | ( | ) |
| bool vidl_v4l2_device::stop_capturing | ( | ) |
| v4l2_timecode vidl_v4l2_device::time | ( | ) | const [inline] |
| bool vidl_v4l2_device::time_available | ( | ) | const [inline] |
Return if driver has time associated to the captured frame.
Definition at line 284 of file vidl_v4l2_device.h.
| bool vidl_v4l2_device::try_formats | ( | int | width = 640, |
| int | height = 480 |
||
| ) |
Try several formats implemented in vidl.
| width | can be changed by drivers to the closest possible value |
| height | can be changed by drivers to the closest possible value |
| fps | frame rate to try (not garanteed). |
Definition at line 263 of file vidl_v4l2_device.cxx.
| bool vidl_v4l2_device::uninit_mmap | ( | ) | [private] |
Definition at line 566 of file vidl_v4l2_device.cxx.
| void vidl_v4l2_device::unref | ( | ) | [inline] |
Decrement reference count.
Definition at line 315 of file vidl_v4l2_device.h.
| void vidl_v4l2_device::update_controls | ( | ) | [private] |
Definition at line 56 of file vidl_v4l2_device.cxx.
struct buffer* vidl_v4l2_device::buffers [private] |
Definition at line 68 of file vidl_v4l2_device.h.
bool vidl_v4l2_device::capturing [private] |
Definition at line 77 of file vidl_v4l2_device.h.
vcl_string vidl_v4l2_device::card_name_ [private] |
Definition at line 75 of file vidl_v4l2_device.h.
vcl_vector<vidl_v4l2_control *> vidl_v4l2_device::controls_ [private] |
Definition at line 79 of file vidl_v4l2_device.h.
vcl_string vidl_v4l2_device::dev_name_ [private] |
Definition at line 74 of file vidl_v4l2_device.h.
int vidl_v4l2_device::fd [private] |
Definition at line 60 of file vidl_v4l2_device.h.
struct v4l2_format vidl_v4l2_device::fmt [private] |
Definition at line 71 of file vidl_v4l2_device.h.
double vidl_v4l2_device::frame_rate [private] |
Definition at line 72 of file vidl_v4l2_device.h.
vcl_vector<vidl_v4l2_input> vidl_v4l2_device::inputs_ [private] |
Definition at line 78 of file vidl_v4l2_device.h.
int vidl_v4l2_device::last_buffer [private] |
Definition at line 70 of file vidl_v4l2_device.h.
vcl_string vidl_v4l2_device::last_error [mutable, private] |
Definition at line 76 of file vidl_v4l2_device.h.
unsigned int vidl_v4l2_device::n_buffers [private] |
Definition at line 69 of file vidl_v4l2_device.h.
unsigned int vidl_v4l2_device::pre_nbuffers [private] |
Definition at line 67 of file vidl_v4l2_device.h.
int vidl_v4l2_device::ref_count_ [private] |
Definition at line 328 of file vidl_v4l2_device.h.
vidl_v4l2_device::VCL_SAFE_BOOL_DEFINE [private] |
Definition at line 59 of file vidl_v4l2_device.h.
1.7.5.1