JeVois
1.22
JeVois Smart Embedded Machine Vision Toolkit
|
|
#include <jevois/Core/Gadget.H>
JeVois gadget driver - exposes a uvcvideo interface to host computer connected over USB.
Gadget is a user-space interface to the Linux kernel's gadget driver implemented by JeVois. A USB gadget driver is a USB driver that runs on a device, as opposed to a USB driver that runs on a host computer. Gadget drivers implement USB functions such as USB printers, USB modems, or USB cameras. In JeVois, the Gadget driver makes the JeVois hardware platform appear as a UVC (USB Video Class) camera. Because UVC has been standardized, no special driver is needed on the host computer to start using the UVC device, as virtually all modern operating systems already provide a built-in driver for UVC-compliant cameras.
The internal operation of Gadget is quite complex, especially due to its tight interaction with the kernel-side UVC gadget driver. Yet, for users, Gadget is just another VideoOutput device: One can set its format, obtain blank image buffers from it using get(), paint results into those buffers, and send them to the host computer when complete using send().
Gadget implements a zero-copy, zero-wait access to output video frames, that is:
Most programmers will never use Gadget directly, instead using Engine and OutputFrame.
Public Member Functions | |
Gadget (std::string const &devname, VideoInput *camera, Engine *engine, size_t const nbufs=0, bool multicam=false) | |
Construct and open the device. | |
virtual | ~Gadget () |
Close the device and free all resources. | |
void | setFormat (jevois::VideoMapping const &m) override |
Set the video format and frame rate. | |
void | get (RawImage &img) override |
Get a pre-allocated image so that we can fill the pixel data and later send out over USB using send() | |
void | send (RawImage const &img) override |
Send an image out over USB to the host computer. | |
void | streamOn () override |
Start streaming. | |
void | abortStream () override |
Abort streaming. | |
void | streamOff () override |
Stop streaming. | |
Public Member Functions inherited from jevois::VideoOutput | |
virtual | ~VideoOutput () |
Virtual destructor for safe inheritance. | |
jevois::Gadget::Gadget | ( | std::string const & | devname, |
jevois::VideoInput * | camera, | ||
jevois::Engine * | engine, | ||
size_t const | nbufs = 0 , |
||
bool | multicam = false |
||
) |
Construct and open the device.
A vaid non-null camera is required for this gadget to work. To avoid testing for a non-null camera on each operation of the gadget, we only test once at construction and then assume the camera will remain operational for the lifetime of the gadget. Use 0 for nbufs to set it automatically.
Definition at line 139 of file Gadget.C.
References jevois::async_little(), jevois::Engine::getDefaultVideoMapping(), JEVOIS_TRACE, LFATAL, LINFO, PLFATAL, UVC_EVENT_DATA, UVC_EVENT_SETUP, UVC_EVENT_STREAMOFF, UVC_EVENT_STREAMON, and XIOCTL.
|
virtual |
Close the device and free all resources.
Definition at line 185 of file Gadget.C.
References JEVOIS_TRACE, PLERROR, and jevois::warnAndIgnoreException().
|
overridevirtual |
Abort streaming.
This only cancels future get() and done() calls, one should still call streamOff() to turn off streaming.
Implements jevois::VideoOutput.
Definition at line 777 of file Gadget.C.
References JEVOIS_TRACE.
|
overridevirtual |
Get a pre-allocated image so that we can fill the pixel data and later send out over USB using send()
May throw if not buffer is available, i.e., all have been queued to send to the host but have not yet been sent. Application code must balance exactly one send() for each get().
Implements jevois::VideoOutput.
Definition at line 813 of file Gadget.C.
References jevois::RawImage::bufindex, JEVOIS_TRACE, LDEBUG, and LFATAL.
|
overridevirtual |
Send an image out over USB to the host computer.
May throw if the format is incorrect or std::overflow_error if we have not yet consumed the previous image.
Implements jevois::VideoOutput.
Definition at line 856 of file Gadget.C.
References jevois::RawImage::bufindex, jevois::RawImage::fmt, jevois::RawImage::height, JEVOIS_TRACE, LDEBUG, LFATAL, and jevois::RawImage::width.
|
overridevirtual |
Set the video format and frame rate.
Implements jevois::VideoOutput.
Definition at line 201 of file Gadget.C.
References jevois::fccstr(), jevois::VideoMapping::fpsToV4l2(), JEVOIS_TIMED_LOCK, JEVOIS_TRACE, LINFO, jevois::VideoMapping::ofmt, jevois::VideoMapping::ofps, jevois::VideoMapping::oh, jevois::VideoMapping::osize(), jevois::VideoMapping::ow, XIOCTL, and XIOCTL_QUIET.
|
overridevirtual |
Stop streaming.
Implements jevois::VideoOutput.
Definition at line 785 of file Gadget.C.
References JEVOIS_TIMED_LOCK, JEVOIS_TRACE, LDEBUG, and XIOCTL_QUIET.
|
overridevirtual |
Start streaming.
Implements jevois::VideoOutput.
Definition at line 721 of file Gadget.C.
References jevois::RawImage::buf, jevois::RawImage::bufindex, jevois::RawImage::fmt, jevois::RawImage::fps, jevois::RawImage::height, JEVOIS_TIMED_LOCK, JEVOIS_TRACE, LDEBUG, LERROR, LINFO, jevois::v4l2ImageSize(), jevois::RawImage::width, and XIOCTL.