vidl_v4l2_device Class Reference

#include <vidl_v4l2_device.h>

List of all members.


Detailed Description

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:

  1. Select input
  2. Select format
  3. Select number of buffers.
  4. Start capturing
  5. Stop capturing When a devide is opened, a input and format are selected by default (see vidl_v4l2_device::try_formats function). Then if you start capturing, you will probably get 640x480 frames, from input 0, using just one buffer with a unknown format (the first one valid for the driver).
    See also:
    vidl_v4l2_devices

Definition at line 50 of file vidl_v4l2_device.h.


Public Member Functions

 vidl_v4l2_device (const char *file)
 Constructor.
 ~vidl_v4l2_device ()
void reset ()
 Reset the device to a initial state.
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_inputinput (int i) const
 Return input number i (0 .
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 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_controlget_control (int i) const
 Get control.
vidl_v4l2_controlget_control_id (int id) const
 Get control from driver id.
vidl_v4l2_control_integerget_control_integer_id (int id) const
 Get control from driver id.
vidl_v4l2_control_menuget_control_menu_id (int id) const
 Get control from driver id.
vidl_v4l2_control_booleanget_control_boolean_id (int id) const
 Get control from driver id.
vidl_v4l2_control_buttonget_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 ()
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
bool try_formats ()
 vidl_v4l2_device (const vidl_v4l2_device &)
vidl_v4l2_deviceoperator= (const vidl_v4l2_device &)

Private Attributes

 VCL_SAFE_BOOL_DEFINE
int fd
unsigned int pre_nbuffers
bufferbuffers
unsigned int n_buffers
int last_buffer
v4l2_format fmt
double frame_rate
vcl_string dev_name_
vcl_string card_name_
vcl_string last_error
bool capturing
vcl_vector< vidl_v4l2_inputinputs_
vcl_vector< vidl_v4l2_control * > controls_
int ref_count_

Classes

struct  buffer

Constructor & Destructor Documentation

vidl_v4l2_device::vidl_v4l2_device ( const vidl_v4l2_device  )  [private]

vidl_v4l2_device::vidl_v4l2_device ( const char *  file  ) 

Constructor.

Parameters:
file device name (for example, "/dev/video")

Definition at line 100 of file vidl_v4l2_device.cxx.

vidl_v4l2_device::~vidl_v4l2_device (  ) 

Definition at line 141 of file vidl_v4l2_device.cxx.


Member Function Documentation

void vidl_v4l2_device::update_controls (  )  [private]

Definition at line 55 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::open (  )  [private]

Definition at line 181 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::initialize_device (  )  [private]

Definition at line 213 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::init_mmap ( int  reqbuf  )  [private]

Definition at line 339 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::uninit_mmap (  )  [private]

Definition at line 539 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::close (  )  [private]

Definition at line 552 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::is_open (  )  const [inline, private]

Definition at line 81 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::is_prepared_for_capturing (  )  const [inline, private]

Definition at line 82 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::good (  )  const [inline, private]

Definition at line 83 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::try_formats (  )  [private]

Definition at line 250 of file vidl_v4l2_device.cxx.

vidl_v4l2_device& vidl_v4l2_device::operator= ( const vidl_v4l2_device  )  [private]

void vidl_v4l2_device::reset (  ) 

Reset the device to a initial state.

Definition at line 153 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 102 of file vidl_v4l2_device.h.

vcl_string vidl_v4l2_device::card_name (  )  const [inline]

Friendly name of the device.

Definition at line 104 of file vidl_v4l2_device.h.

unsigned int vidl_v4l2_device::n_inputs (  )  const [inline]

Number of inputs in device.

Definition at line 106 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

See also:
ninputs

Definition at line 562 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 112 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::set_input ( unsigned int  i  ) 

Select input i.

Returns:
if successful

Definition at line 577 of file vidl_v4l2_device.cxx.

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 (

See also:
try_formats()). Then this function could be ignored if you don't mind the format. Usually, user wants a concrete pixel format or, simply, change width and height.
Parameters:
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
Returns:
if successful
See also:
format_is_set

Definition at line 281 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::format_is_set (  )  const [inline]

Return if the format is set.

Normally, a format is automatically selected of user call set_v4l2_format. User can use this function to know if a format is selected before calling start_capturing.

See also:
set_v4l2_format

Definition at line 130 of file vidl_v4l2_device.h.

unsigned int vidl_v4l2_device::get_v4l2_format (  )  const [inline]

Get pixel format of type of compression.

Returns:
the four character code which is being used by driver(see v4l2 specification and vidl_pixel_format.h) or 0 if not set
See also:
set_v4l2_format

Definition at line 135 of file vidl_v4l2_device.h.

int vidl_v4l2_device::get_width (  )  const [inline]

Return Image width in pixels.

Note:
You can use this function to know the width selected by driver after calling set_v4l2_format
See also:
set_v4l2_format

Definition at line 143 of file vidl_v4l2_device.h.

int vidl_v4l2_device::get_height (  )  const [inline]

Return Image height in pixels.

Note:
You can use this function to know the height selected by driver after calling set_v4l2_format
See also:
set_v4l2_format

Definition at line 147 of file vidl_v4l2_device.h.

double vidl_v4l2_device::get_frame_rate (  )  const [inline]

Return Current frame rate.

See also:
set_v4l2_format

Definition at line 151 of file vidl_v4l2_device.h.

void vidl_v4l2_device::reset_controls (  ) 

Reset controls to default.

Definition at line 90 of file vidl_v4l2_device.cxx.

int vidl_v4l2_device::n_controls (  )  const [inline]

Get number of controls.

Returns:
the number of detected controls (control not disabled and not inactive).

Definition at line 160 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 funcionality.

Parameters:
i indicates the control to be extracted, from 0 to n_controls-1
Returns:
pointer to control
See also:
n_controls

Definition at line 166 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 funcionality.

Parameters:
id is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS
Returns:
pointer to control or 0 if does not exist

Definition at line 171 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.

Parameters:
id is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS
Returns:
pointer to control. Null if doesn't exist or is not of type V4L2_CTRL_TYPE_INTEGER

Definition at line 177 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.

Parameters:
id is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS
Returns:
pointer to control. Null if doesn't exist or is not of type V4L2_CTRL_TYPE_MENU

Definition at line 187 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.

Parameters:
id is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS
Returns:
pointer to control. Null if doesn't exist or is not of type V4L2_CTRL_TYPE_BOOLEAN

Definition at line 197 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.

Parameters:
id is control ID from v4l2 specification. For example, V4L2_CID_BRIGHTNESS
Returns:
pointer to control. Null if doesn't exist or is not of type V4L2_CTRL_TYPE_BUTTON

Definition at line 207 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::start_capturing (  ) 

Start capturing.

Returns:
if successful

Definition at line 428 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::is_capturing (  )  const [inline]

Return if device is capturing.

Definition at line 221 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::stop_capturing (  ) 

Stop capturing.

Returns:
if successful

Definition at line 521 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::read_frame (  ) 

Read next frame.

Returns:
if successful

Definition at line 463 of file vidl_v4l2_device.cxx.

bool vidl_v4l2_device::set_number_of_buffers ( unsigned int  nb  ) 

Set numbers of buffers.

Returns:
if successful

Definition at line 415 of file vidl_v4l2_device.cxx.

unsigned int vidl_v4l2_device::get_number_of_buffers (  )  const [inline]

Get numbers of buffers.

Definition at line 236 of file vidl_v4l2_device.h.

void* vidl_v4l2_device::current_buffer (  )  const [inline]

Return the last used buffer.

Precondition:
device is capturing

Definition at line 240 of file vidl_v4l2_device.h.

unsigned int vidl_v4l2_device::current_buffer_length (  )  const [inline]

Return length of the last used buffer.

Precondition:
device is capturing

Definition at line 246 of file vidl_v4l2_device.h.

void* vidl_v4l2_device::ibuffer ( unsigned int  i  )  const [inline]

Return buffer number i.

Precondition:
device is capturing
See also:
get_number_of_buffers

Definition at line 253 of file vidl_v4l2_device.h.

unsigned int vidl_v4l2_device::sequence (  )  const [inline]

Definition at line 258 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::time_available (  )  const [inline]

Return if driver has time associated to the captured frame.

Precondition:
device is capturing

Definition at line 268 of file vidl_v4l2_device.h.

v4l2_timecode vidl_v4l2_device::time (  )  const [inline]

Time from last frame.

See also:
time_available

Definition at line 274 of file vidl_v4l2_device.h.

vidl_v4l2_device::operator safe_bool (  )  const [inline]

Cast to bool is true if video device is working ok.

Definition at line 281 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 285 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 289 of file vidl_v4l2_device.h.

void vidl_v4l2_device::ref (  )  [inline]

Increment reference count.

Definition at line 297 of file vidl_v4l2_device.h.

void vidl_v4l2_device::unref (  )  [inline]

Decrement reference count.

Definition at line 300 of file vidl_v4l2_device.h.

int vidl_v4l2_device::ref_count (  )  const [inline]

Number of objects referring to this data.

Definition at line 310 of file vidl_v4l2_device.h.


Member Data Documentation

vidl_v4l2_device::VCL_SAFE_BOOL_DEFINE [private]

Definition at line 52 of file vidl_v4l2_device.h.

int vidl_v4l2_device::fd [private]

Definition at line 53 of file vidl_v4l2_device.h.

unsigned int vidl_v4l2_device::pre_nbuffers [private]

Definition at line 60 of file vidl_v4l2_device.h.

struct buffer* vidl_v4l2_device::buffers [private]

Definition at line 61 of file vidl_v4l2_device.h.

unsigned int vidl_v4l2_device::n_buffers [private]

Definition at line 62 of file vidl_v4l2_device.h.

int vidl_v4l2_device::last_buffer [private]

Definition at line 63 of file vidl_v4l2_device.h.

struct v4l2_format vidl_v4l2_device::fmt [private]

Definition at line 64 of file vidl_v4l2_device.h.

double vidl_v4l2_device::frame_rate [private]

Definition at line 65 of file vidl_v4l2_device.h.

vcl_string vidl_v4l2_device::dev_name_ [private]

Definition at line 67 of file vidl_v4l2_device.h.

vcl_string vidl_v4l2_device::card_name_ [private]

Definition at line 68 of file vidl_v4l2_device.h.

vcl_string vidl_v4l2_device::last_error [mutable, private]

Definition at line 69 of file vidl_v4l2_device.h.

bool vidl_v4l2_device::capturing [private]

Definition at line 70 of file vidl_v4l2_device.h.

vcl_vector<vidl_v4l2_input> vidl_v4l2_device::inputs_ [private]

Definition at line 71 of file vidl_v4l2_device.h.

vcl_vector<vidl_v4l2_control *> vidl_v4l2_device::controls_ [private]

Definition at line 72 of file vidl_v4l2_device.h.

int vidl_v4l2_device::ref_count_ [private]

Definition at line 313 of file vidl_v4l2_device.h.


The documentation for this class was generated from the following files:
Generated on Mon Mar 8 05:10:37 2010 for core/vidl by  doxygen 1.5.1