pub struct V4LCaptureDevice<'a> { /* private fields */ }Expand description
The backend struct that interfaces with V4L2.
To see what this does, please see CaptureBackendTrait.
§Quirks
- Calling
set_resolution(),set_frame_rate(), orset_frame_format()each internally callsset_camera_format().
Implementations§
Source§impl<'a> V4LCaptureDevice<'a>
impl<'a> V4LCaptureDevice<'a>
Sourcepub fn new(
index: &CameraIndex,
cam_fmt: RequestedFormat<'_>,
) -> Result<V4LCaptureDevice<'a>, NokhwaError>
pub fn new( index: &CameraIndex, cam_fmt: RequestedFormat<'_>, ) -> Result<V4LCaptureDevice<'a>, NokhwaError>
Creates a new capture device using the V4L2 backend. Indexes are gives to devices by the OS, and usually numbered by order of discovery.
§Errors
This function will error if the camera is currently busy or if V4L2 can’t read device information.
Sourcepub fn new_with(
index: CameraIndex,
width: u32,
height: u32,
fps: u32,
fourcc: FrameFormat,
) -> Result<V4LCaptureDevice<'a>, NokhwaError>
👎Deprecated since 0.10.0: please use new instead.
pub fn new_with( index: CameraIndex, width: u32, height: u32, fps: u32, fourcc: FrameFormat, ) -> Result<V4LCaptureDevice<'a>, NokhwaError>
please use new instead.
Create a new V4L2 Camera with desired settings. This may or may not work.
§Errors
This function will error if the camera is currently busy or if V4L2 can’t read device information.
Sourcepub fn force_refresh_camera_format(&mut self) -> Result<(), NokhwaError>
pub fn force_refresh_camera_format(&mut self) -> Result<(), NokhwaError>
Force refreshes the inner CameraFormat state.
§Errors
If the internal representation in the driver is invalid, this will error.
Trait Implementations§
Source§impl<'a> CaptureBackendTrait for V4LCaptureDevice<'a>
impl<'a> CaptureBackendTrait for V4LCaptureDevice<'a>
Source§fn backend(&self) -> ApiBackend
fn backend(&self) -> ApiBackend
Returns the current backend used.
Source§fn camera_info(&self) -> &CameraInfo
fn camera_info(&self) -> &CameraInfo
Gets the camera information such as Name and Index as a
CameraInfo.Source§fn refresh_camera_format(&mut self) -> Result<(), NokhwaError>
fn refresh_camera_format(&mut self) -> Result<(), NokhwaError>
Forcefully refreshes the stored camera format, bringing it into sync with “reality” (current camera state) Read more
Source§fn camera_format(&self) -> CameraFormat
fn camera_format(&self) -> CameraFormat
Gets the current
CameraFormat. This will force refresh to the current latest if it has changed.Source§fn set_camera_format(
&mut self,
new_fmt: CameraFormat,
) -> Result<(), NokhwaError>
fn set_camera_format( &mut self, new_fmt: CameraFormat, ) -> Result<(), NokhwaError>
Will set the current
CameraFormat
This will reset the current stream if used while stream is opened. Read moreSource§fn compatible_list_by_resolution(
&mut self,
fourcc: FrameFormat,
) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>
fn compatible_list_by_resolution( &mut self, fourcc: FrameFormat, ) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>
A hashmap of
Resolutions mapped to framerates. Not sorted! Read moreSource§fn compatible_fourcc(&mut self) -> Result<Vec<FrameFormat>, NokhwaError>
fn compatible_fourcc(&mut self) -> Result<Vec<FrameFormat>, NokhwaError>
A Vector of compatible
FrameFormats. Will only return 2 elements at most. Read moreSource§fn resolution(&self) -> Resolution
fn resolution(&self) -> Resolution
Gets the current camera resolution (See:
Resolution, CameraFormat). This will force refresh to the current latest if it has changed.Source§fn set_resolution(&mut self, new_res: Resolution) -> Result<(), NokhwaError>
fn set_resolution(&mut self, new_res: Resolution) -> Result<(), NokhwaError>
Will set the current
Resolution
This will reset the current stream if used while stream is opened. Read moreSource§fn frame_rate(&self) -> u32
fn frame_rate(&self) -> u32
Gets the current camera framerate (See:
CameraFormat). This will force refresh to the current latest if it has changed.Source§fn set_frame_rate(&mut self, new_fps: u32) -> Result<(), NokhwaError>
fn set_frame_rate(&mut self, new_fps: u32) -> Result<(), NokhwaError>
Will set the current framerate
This will reset the current stream if used while stream is opened. Read more
Source§fn frame_format(&self) -> FrameFormat
fn frame_format(&self) -> FrameFormat
Gets the current camera’s frame format (See:
FrameFormat, CameraFormat). This will force refresh to the current latest if it has changed.Source§fn set_frame_format(&mut self, fourcc: FrameFormat) -> Result<(), NokhwaError>
fn set_frame_format(&mut self, fourcc: FrameFormat) -> Result<(), NokhwaError>
Will set the current
FrameFormat
This will reset the current stream if used while stream is opened. Read moreSource§fn camera_control(
&self,
control: KnownCameraControl,
) -> Result<CameraControl, NokhwaError>
fn camera_control( &self, control: KnownCameraControl, ) -> Result<CameraControl, NokhwaError>
Gets the value of
KnownCameraControl. Read moreSource§fn camera_controls(&self) -> Result<Vec<CameraControl>, NokhwaError>
fn camera_controls(&self) -> Result<Vec<CameraControl>, NokhwaError>
Gets the current supported list of
KnownCameraControl Read moreSource§fn set_camera_control(
&mut self,
id: KnownCameraControl,
value: ControlValueSetter,
) -> Result<(), NokhwaError>
fn set_camera_control( &mut self, id: KnownCameraControl, value: ControlValueSetter, ) -> Result<(), NokhwaError>
Sets the control to
control in the camera.
Usually, the pipeline is calling camera_control(), getting a camera control that way
then calling value() to get a ControlValueSetter and setting the value that way. Read moreSource§fn open_stream(&mut self) -> Result<(), NokhwaError>
fn open_stream(&mut self) -> Result<(), NokhwaError>
Will open the camera stream with set parameters. This will be called internally if you try and call
frame() before you call open_stream(). Read moreSource§fn is_stream_open(&self) -> bool
fn is_stream_open(&self) -> bool
Checks if stream if open. If it is, it will return true.
Source§fn frame(&mut self) -> Result<Buffer, NokhwaError>
fn frame(&mut self) -> Result<Buffer, NokhwaError>
Will get a frame from the camera as a
Buffer. Depending on the backend, if you have not called open_stream() before you called this,
it will either return an error. Read moreSource§fn frame_raw(&mut self) -> Result<Cow<'_, [u8]>, NokhwaError>
fn frame_raw(&mut self) -> Result<Cow<'_, [u8]>, NokhwaError>
Will get a frame from the camera without any processing applied, meaning you will usually get a frame you need to decode yourself. Read more
Source§fn stop_stream(&mut self) -> Result<(), NokhwaError>
fn stop_stream(&mut self) -> Result<(), NokhwaError>
Will drop the stream. Read more
Source§fn compatible_camera_formats(
&mut self,
) -> Result<Vec<CameraFormat>, NokhwaError>
fn compatible_camera_formats( &mut self, ) -> Result<Vec<CameraFormat>, NokhwaError>
Gets the compatible
CameraFormat of the camera Read moreSource§fn decoded_buffer_size(&self, alpha: bool) -> usize
fn decoded_buffer_size(&self, alpha: bool) -> usize
The minimum buffer size needed to write the current frame. If
alpha is true, it will instead return the minimum size of the buffer with an alpha channel as well.
This assumes that you are decoding to RGB/RGBA for FrameFormat::MJPEG or FrameFormat::YUYV and Luma8/LumaA8 for FrameFormat::GRAYAuto Trait Implementations§
impl<'a> Freeze for V4LCaptureDevice<'a>
impl<'a> RefUnwindSafe for V4LCaptureDevice<'a>
impl<'a> Send for V4LCaptureDevice<'a>
impl<'a> Sync for V4LCaptureDevice<'a>
impl<'a> Unpin for V4LCaptureDevice<'a>
impl<'a> UnsafeUnpin for V4LCaptureDevice<'a>
impl<'a> !UnwindSafe for V4LCaptureDevice<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more