25 #include <sys/types.h>
29 #include <sys/ioctl.h>
37 #include "VideoSource_V4L.hh"
38 #include "VideoSourceCapabilities.hh"
39 #include <Base/Common/FileHandling.hh>
40 #include <Base/Debug/Exception.hh>
41 #include <Image/Camera.hh>
42 #include <Base/Image/ImageIO.hh>
44 #define CLEAR(x) memset(&(x), 0, sizeof(x));
67 BEXCEPTION(
"error initializing mutex");
81 BIASDOUT(D_V4L,
"Contructor finished");
91 BIASDOUT(D_V4L,
"Destructor finished");
100 BIASDOUT(D_V4L,
"GetAllDevices()");
105 for (
unsigned int i=0;i<devs.size(); i++){
106 struct v4l2_capability cap;
108 if ((
fd = open(devs[i].c_str(), O_RDWR))>0) {
109 if (xioctl_(
fd, (
int)VIDIOC_QUERYCAP, &cap)>=0) {
116 BIASERR(
"Enumerating devices, query capabilities failed for "<<devs[i]<<
": "<<strerror(errno));
120 BIASERR(
"Enumerating devices, open() failed for "<<devs[i]<<
": "<<strerror(errno));
124 return devices.size();
140 BIASDOUT(D_V4L,
string(
"GetCapabilities() for device ")+device);
143 if (device[0] !=
'/') {
145 if (usedev ==
"")
return -2;
148 if ((
fd = open(usedev.c_str(), O_RDWR))<0) {
150 BEXCEPTION(
"Failed to open device: "<<usedev<<
" "<<strerror(errno));
156 BEXCEPTION(
"Failed to query capabilities: "<<strerror(errno));
164 if (
capability2.capabilities & V4L2_CAP_VIDEO_CAPTURE)
165 cout<<
"The device supports the video capture interface."<<endl;
166 if (
capability2.capabilities & V4L2_CAP_VIDEO_OUTPUT)
167 cout<<
"The device supports the video output interface."<<endl;
168 if (
capability2.capabilities &V4L2_CAP_VIDEO_OVERLAY)
169 cout<<
"The device supports the video overlay interface. Overlay "
170 "typically stores captured images directly in the video memory "
171 "of a graphics card, with support for clipping."<<endl;
172 if (
capability2.capabilities & V4L2_CAP_VBI_CAPTURE)
173 cout<<
"The device supports the VBI capture interface"<<endl;
175 cout<<
"The device has a tuner of some form"<<endl;
177 cout<<
"The device has audio inputs or outputs."<<endl;
179 cout<<
"The device supports the read() and/or write() I/O methods."<<endl;
181 cout<<
"The device supports the asynchronous I/O methods."<<endl;
183 cout<<
"The device supports the streaming I/O method."<<endl;
186 int index=0, current=-1;
187 struct v4l2_input input;
188 memset (&input, 0,
sizeof (input));
190 if (xioctl_(
fd,(
int)VIDIOC_G_INPUT, ¤t)!=0){
191 perror(
"couldn't get current active input number");
194 while (xioctl_(
fd, (
int)VIDIOC_ENUMINPUT, &input)==0) {
197 InpDesc.
name = (
char*)input.name;
198 if (input.type == V4L2_INPUT_TYPE_CAMERA)
201 if (input.type == V4L2_INPUT_TYPE_TUNER)
209 if (index==current) {
211 if (input.status & V4L2_IN_ST_NO_POWER) InpDesc.
NoPower =
true;
213 if (input.status & V4L2_IN_ST_NO_SIGNAL) InpDesc.
NoSignal =
true;
215 if (input.status & V4L2_IN_ST_NO_COLOR) InpDesc.
NoColor =
true;
218 else InpDesc.
Active =
false;
229 cerr<<
"No Input found. Error:";
230 if (errno==EBUSY) cout<<
"EBUSY"<<endl;
231 if (errno==EINVAL) cout<<
"EINVAL"<<endl;
232 else cout<<errno<<endl;
236 struct v4l2_fmtdesc fmtdesc;
237 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
240 while (xioctl_(
fd,(
int)VIDIOC_ENUM_FMT,&fmtdesc) ==0 ) {
242 switch(fmtdesc.pixelformat) {
254 memcpy(tmp, (
char*)&fmtdesc.pixelformat,4);
263 struct v4l2_frmsizeenum frmsizeenum;
264 frmsizeenum.index = 0;
265 frmsizeenum.pixel_format = fmtdesc.pixelformat;
266 bool interlace =
true;
267 switch(fmtdesc.pixelformat)
269 case V4L2_FIELD_NONE:
274 case V4L2_FIELD_TOP :
275 case V4L2_FIELD_BOTTOM :
276 case V4L2_FIELD_INTERLACED:
277 case V4L2_FIELD_SEQ_TB:
278 case V4L2_FIELD_SEQ_BT:
279 case V4L2_FIELD_ALTERNATE:
280 case V4L2_FIELD_INTERLACED_TB :
281 case V4L2_FIELD_INTERLACED_BT:
292 while (-1 != xioctl_(
fd,(
int)VIDIOC_ENUM_FRAMESIZES,&frmsizeenum)) {
293 cout <<
" Framesize type: "<<frmsizeenum.type<<endl;
294 switch (frmsizeenum.type)
296 case V4L2_FRMSIZE_TYPE_DISCRETE: {
297 struct v4l2_frmivalenum frmivalenum;
298 frmivalenum.pixel_format = fmtdesc.pixelformat;
299 frmivalenum.width = frmsizeenum.discrete.width;
300 frmivalenum.height = frmsizeenum.discrete.height;
301 frmivalenum.index = 0;
304 while (xioctl_(
fd,(
int)VIDIOC_ENUM_FRAMEINTERVALS, &frmivalenum) ==0) {
305 switch (frmivalenum.type) {
306 case V4L2_FRMIVAL_TYPE_DISCRETE:
307 fps = (float)frmivalenum.discrete.denominator/(
float)frmivalenum.discrete.numerator;
308 caps.
AddMode(frmsizeenum.discrete.width,frmsizeenum.discrete.height,fps,cm,interlace);
309 cout<<
"Adding Mode:"<<frmsizeenum.discrete.width<<
","<<frmsizeenum.discrete.height<<endl;
311 case V4L2_FRMIVAL_TYPE_STEPWISE:
313 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
316 frmivalenum.index ++;
320 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
321 BIASERR(
"VideoSourceCapabilities can not handle continuous frame sizes");
323 case V4L2_FRMSIZE_TYPE_STEPWISE:
324 BIASERR(
"VideoSourceCapabilities can not handle continuous frame sizes");
327 cout<<
"we found :"<<frmsizeenum.index<<
" valid configurations."<<endl;
358 if (device[0] !=
'/') {
362 device = tmp[0].c_str();
364 cout<<
"Device in OpenDevice:"<<device<<endl;
366 if (usedev ==
"") BEXCEPTION(
"Unknown device "<<device);
367 BIASDOUT(D_V4L,
string(
"OpenDevice(")+device+
") will use "+usedev);
371 BIASDOUT(D_V4L,
string(
"OpenDevice() will use ")+usedev);
374 cout<<
"Opening device :"<<usedev<<endl;
376 if ((
fd = open(usedev.c_str(), O_RDWR))<0){
377 BIASERR(
"Failed to open device: "<<usedev<<
" "<<strerror(errno));
382 BIASERR(
"Failed query capabilities: "<<strerror(errno));
397 struct v4l2_input input;
399 res=ioctl(
fd, VIDIOC_S_INPUT, &index);
401 perror(
"VIDIOC_S_INPUT: couldn't set active input:");
404 while (!found && res==0) {
406 memset (&input, 0,
sizeof (input));
409 if (ioctl(
fd, VIDIOC_ENUMINPUT, &input)==0) {
410 if (input.status==0) {
418 res=xioctl_(
fd, (
int)VIDIOC_S_INPUT, &index);
420 cerr<<
"VIDIOC_S_INPUT: couldn't set active input:"<<index<<endl;
426 BIASERR(
"No valid input signal found on all "<<index+1<<
" channels");
431 if (res!=0)
return res;
434 if (res!=0)
return res;
438 #ifdef BIAS_HAVE_LIBJPEG
441 BIASERR(
"Could not initialize JPEG-compression!!!");
444 else cout<<
"Initialized jpeg decompressor."<<endl;
446 #else //BIAS_HAVE_LIBJPEG
448 BIASERR(
"Compression mode not available without LIBJPEG!");
450 #endif //BIAS_HAVE_LIBJPEG
464 sprintf(dev,
"/dev/video%d", device);
471 BIASDOUT(D_V4L,
"Closing device");
481 BIASERR(
"UninitMMap_() Failed ");
485 if (-1 == close(
fd)){
486 cerr <<
"error calling close()\n";
501 if (!
Active_) BEXCEPTION(
"VideoSource Object not active, use PreGrab()");
502 if (
Grabbing_) BEXCEPTION(
"VideoSource Object is already grabbing()");
526 <<
"target buffer has size: "<<image.
GetSizeByte());
537 if (xioctl_(
fd, (
int)VIDIOC_QBUF, &
buffer_)!=0) {
538 perror(
"ioctl: freeing the buffer memory\n");
545 while ( (errno!=EINVAL) &&
546 (xioctl_(
fd, (
int)VIDIOC_DQBUF, &
buffer_)!=0) ) {
550 BIASERR(
"Error while waiting for a new frame: "<<strerror(errno));
574 BIASDOUT(D_V4L,
"PreGrab()");
576 int res = StartCapturing_();
578 BIASERR(
"StartCapturing_() failed");
581 pthread_attr_t attributes;
582 pthread_attr_init(&attributes);
584 pthread_attr_getdetachstate(&attributes,&detachstate);
587 pthread_attr_setdetachstate(&attributes,PTHREAD_CREATE_JOINABLE);
596 BIASDOUT(D_V4L,
"PostGrab()");
602 BIASERR(
"VideoSource_V4L::PostGrab() pthread_join unsucessfull: "
607 res = StopCapturing_();
608 if (res!=0) BIASERR(
"StopCapturing_() failed");
617 if (
Identifier_.find(
"UVC Camera") != string::npos) {
618 cout <<
"This is an UVC-Camera on USB, Identifier: "<<
Identifier_<<endl;
627 vector<string> possibleMapFiles;
629 possibleMapFiles.push_back(
"/var/lib/misc/usb.ids");
630 for (
unsigned f=0; f<possibleMapFiles.size(); f++ ) {
631 ifstream ifs(possibleMapFiles[f].c_str());
633 mapfile = possibleMapFiles[f];
638 if ( mapfile ==
"" )
return;
640 string vendorID = USBID.substr(0,4);
641 string productID = USBID.substr(5,4);
644 ifstream ifs(mapfile.c_str());
645 if (!ifs) cerr <<
"Cannot open file: " << mapfile << endl;
649 while ( !ifs.eof() ) {
652 if ( tmp.substr(0,4) == vendorID ) {
653 int vendorStart = tmp.find_first_not_of(
" ", 4);
654 identifier = tmp.substr(vendorStart);
662 while ( !ifs.eof() ) {
665 int productIDStart = tmp.find_first_not_of(
"\t ");
666 if ( productIDStart == 0 ) {
670 if ( tmp.substr(productIDStart, 4) == productID ) {
671 tmp = tmp.substr(productIDStart);
672 int productIDEnd = tmp.find_first_of(
" ");
673 int productStart = tmp.find_first_not_of(
" ", productIDEnd);
674 if ( identifier !=
"" ) identifier +=
" ";
675 identifier += tmp.substr(productStart);
686 if ( identifier !=
"" ) {
710 FD_SET (obj->
fd, &fds);
716 r = select(obj->
fd + 1, &fds, NULL, NULL, &tv);
728 cerr <<
"select timeout\n";
733 if ( obj->ReadFrame_() != 0 ) {
734 cerr <<
"lost camera\n";
741 cout <<
"finished grab thread"<<endl;
747 int VideoSource_V4L::
751 struct v4l2_requestbuffers req;
755 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
756 req.memory = V4L2_MEMORY_MMAP;
758 if (-1 == xioctl_(
fd, (
int)VIDIOC_REQBUFS, &req)) {
760 BEXCEPTION(
"Device does not support memory mapping:"<<strerror(errno))
762 BEXCEPTION("Failed to request buffers: "<<strerror(errno));
766 BEXCEPTION("Insufficient buffer memory, need at least 2 buffers"<<strerror(errno));
770 for (
unsigned i = 0; i < req.count; ++i) {
771 struct v4l2_buffer buf;
775 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
776 buf.memory = V4L2_MEMORY_MMAP;
779 if (-1 == xioctl_(
fd, (
int)VIDIOC_QUERYBUF, &buf))
780 BEXCEPTION(
"Failed to query buffer: "<<strerror(errno));
786 PROT_READ | PROT_WRITE ,
790 if (MAP_FAILED ==
Buffers_[i].start)
791 BEXCEPTION(
"Failed to map memory: "<<strerror(errno));
797 int VideoSource_V4L::
798 xioctl_(
int fd,
int request,
void *arg)
801 do r = ioctl(fd, request, arg);
802 while (-1 == r && EINTR == errno);
808 int VideoSource_V4L::
811 enum v4l2_buf_type type;
813 const unsigned num_buf =
Buffers_.size();
814 for (
unsigned i = 0; i < num_buf; ++i) {
815 struct v4l2_buffer buf;
819 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
820 buf.memory = V4L2_MEMORY_MMAP;
823 if (-1 == xioctl_(fd, (
int)VIDIOC_QBUF, &buf)){
824 BIASERR(
"error: ioctl VIDIOC_QBUF:"<<strerror(errno));
829 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
831 if (-1 == xioctl_(fd, VIDIOC_STREAMON, &type)){
833 BIASERR(
"Failed to activate streaming from device :"<<strerror(errno));
839 int VideoSource_V4L::
842 enum v4l2_buf_type type;
843 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
845 if (-1 == xioctl_(fd, VIDIOC_STREAMOFF, &type))
846 BEXCEPTION(
"Failed to deactivate streaming from device :"<<strerror(errno))
857 const unsigned num_bufs =
Buffers_.size();
858 for (
unsigned i = 0; i < num_bufs; ++i){
860 BEXCEPTION(
"Failed unmap memory :"<<strerror(errno))
866 int VideoSource_V4L::
869 struct v4l2_buffer buf;
873 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
874 buf.memory = V4L2_MEMORY_MMAP;
876 if (-1 == xioctl_(fd, (
int)VIDIOC_DQBUF, &buf)) {
879 cerr <<
"cannot DQBUF\n";
885 perror(
"ioctl: VIDIOC_DQBUF");
889 assert(buf.index <
Buffers_.size());
899 if (num !=
Buffers_[buf.index].length){
903 #ifdef BIAS_HAVE_LIBJPEG
920 BIASERR(
"Decompression failed!");
930 cerr <<
"buffer and image size mismatch: "<<num<<
"\t"
931 <<Buffers_[buf.index].length<<endl;
932 BIASASSERT(num <= Buffers_[buf.index].length);
937 CopyIn_NoInit((
unsigned char*)Buffers_[buf.index].start);
946 if (-1 == xioctl_(fd, (
int)VIDIOC_QBUF, &buf)){
947 cerr <<
"ioctl: VIDIOC_QBUF\n";
948 perror(
"ioctl: VIDIOC_QBUF");
956 int VideoSource_V4L::
959 struct v4l2_capability cap;
960 struct v4l2_cropcap cropcap;
961 struct v4l2_crop crop;
962 struct v4l2_format fmt;
965 if (-1 == xioctl_(fd, (
int)VIDIOC_QUERYCAP, &cap)) {
966 if (EINVAL == errno) {
967 perror(
"not a V4L2 device");
970 perror(
"InitDevice_() ioctl: VIDIOC_QUERYCAP");
977 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
978 BEXCEPTION(
"No video capture device");
980 if (!(cap.capabilities & V4L2_CAP_STREAMING))
981 BEXCEPTION(
"This device does not support streaming i/o");
986 cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
988 if (0 == xioctl_(fd, (
int)VIDIOC_CROPCAP, &cropcap)) {
989 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
990 crop.c = cropcap.defrect;
992 if (-1 == xioctl_(fd, VIDIOC_S_CROP, &crop)) {
1009 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1010 fmt.fmt.pix.width =
Width_;
1016 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_GREY;
1019 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1022 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
1025 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR24;
1028 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR32;
1031 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SGBRG8;
1034 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
1037 BEXCEPTION(
"Unsupported color model: "<<
ColorMode_);
1045 if (-1 == xioctl_(fd, (
int)VIDIOC_TRY_FMT, &fmt)){
1046 BIASERR(
"Unable to set video device to requested format, "
1047 "falling back to 640x480 YUYV");
1049 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1050 fmt.fmt.pix.width = 640;
1051 fmt.fmt.pix.height = 480;
1052 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1053 fmt.fmt.pix.field = V4L2_FIELD_ANY;
1056 if (-1 == xioctl_(fd, (
int)VIDIOC_S_FMT, &fmt))
1057 BEXCEPTION(
"Failed to set video format: "<<strerror(errno));
1063 min = fmt.fmt.pix.width * 2;
1064 if (fmt.fmt.pix.bytesperline < min)
1065 fmt.fmt.pix.bytesperline = min;
1066 min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
1067 if (fmt.fmt.pix.sizeimage < min)
1068 fmt.fmt.pix.sizeimage = min;
1070 Width_ = fmt.fmt.pix.width;
1074 switch (fmt.fmt.pix.pixelformat){
1075 case V4L2_PIX_FMT_GREY:
1079 case V4L2_PIX_FMT_YUYV:
1083 case V4L2_PIX_FMT_RGB24:
1087 case V4L2_PIX_FMT_BGR24:
1091 case V4L2_PIX_FMT_BGR32:
1092 cout<<
"Set color mode to BGRA"<<endl;
1096 case V4L2_PIX_FMT_SGBRG8:
1097 cout<<
"Thats it Bayer GBRG"<<endl;
1101 case V4L2_PIX_FMT_JPEG:
1102 cout<<
"Thats it JPEG/JFIF"<<endl;
1105 struct v4l2_jpegcompression compression;
1106 if (xioctl_(fd, (
int)VIDIOC_G_JPEGCOMP, &compression)==0) {
1107 cout<<
"Got jpeg compression params"<<endl;
1108 cout<<
"compression.quality:"<<compression.quality<<endl;
1109 cout<<
"compression.APPn:"<<compression.APPn<<endl;
1110 cout<<
"compression.APP_len:"<<compression.APP_len<<endl;
1111 cout<<
"compression.COM_len:"<<compression.COM_len<<endl;
1114 else BIASERR(
"Could not get jpeg compression parameters.");
1118 BIASERR(
"unknown color model:"<<fmt.fmt.pix.pixelformat);
1123 struct v4l2_queryctrl controls;
1126 for (controls.id=V4L2_CID_BASE; controls.id<V4L2_CID_LASTP1-23;
1128 unsigned int tmpID = controls.id;
1129 if(controls.id == V4L2_CID_BASE+4)
continue;
1130 if(controls.id == V4L2_CID_BASE+5)
continue;
1134 if (xioctl_(fd, (
int)VIDIOC_QUERYCTRL, &controls)==0) {
1136 cout <<
"control valid: V4L2_CID_BASE+"<<controls.id-V4L2_CID_BASE
1137 <<
" name: "<<controls.name<<endl;
1139 switch (controls.id){
1140 case V4L2_CID_BRIGHTNESS:
1143 case V4L2_CID_CONTRAST:
1149 case V4L2_CID_EXPOSURE:
1152 case V4L2_CID_AUTOGAIN:
1159 if(tmpID != controls.id){
1160 BIASERR(
"xioctl_ destroyed struct at ID: " << tmpID <<
" BaseID: " << V4L2_CID_BASE <<
" EndID: " << V4L2_CID_LASTP1 <<
" ID-BaseID: " << tmpID-V4L2_CID_BASE << endl);
1202 formatRGB_.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
1214 struct v4l2_control ctrl;
1219 float val = (g /100.0f) * (max-min) + min;
1220 ctrl.value = (int) rint(val);
1222 if (xioctl_(fd, (
int)VIDIOC_S_CTRL, &ctrl)<0) {
1226 else cout <<
"Set Brightness to: "<<ctrl.value<<endl;
1236 struct v4l2_control ctrl;
1238 if (xioctl_(fd, (
int)VIDIOC_G_CTRL, &ctrl)<0) {
1244 float val = ctrl.value;
1248 val = ((val-min) / (max-min))*100.0f;
1280 struct v4l2_control ctrl;
1285 float val = (g/100.0f) * (max-min) + min;
1286 ctrl.value = (int) rint(val);
1288 if (xioctl_(fd, (
int)VIDIOC_S_CTRL, &ctrl)<0) {
1289 perror(
"SetBrightness");
1300 struct v4l2_control ctrl;
1302 if (xioctl_(fd, (
int)VIDIOC_G_CTRL, &ctrl)<0) {
1303 perror(
"GetBrightness");
1307 float val = ctrl.value;
1310 val = ((val-min) / (max-min))*100.0f;
1319 struct v4l2_control ctrl;
1324 float val = (g/100.0f) * (max-min) + min;
1325 ctrl.value = (int) rint(val);
1327 if (xioctl_(fd, (
int)VIDIOC_S_CTRL, &ctrl)<0) {
1328 perror(
"SetContrast");
1340 struct v4l2_control ctrl;
1342 if (xioctl_(fd, (
int)VIDIOC_G_CTRL, &ctrl)<0) {
1343 perror(
"GetContrast");
1346 float val = ctrl.value;
1350 val = ((val-min) / (max-min))*100.0f;
1359 struct v4l2_control ctrl;
1364 float val = (g/1.0f) * (max-min) + min;
1365 ctrl.value = (int) rint(val);
1367 if (xioctl_(fd, (
int)VIDIOC_S_CTRL, &ctrl)<0) {
1368 perror(
"SetShutter");
1380 struct v4l2_control ctrl;
1382 if (xioctl_(fd, (
int)VIDIOC_G_CTRL, &ctrl)<0) {
1383 perror(
"GetShutter");
1386 float val = ctrl.value;
1390 val = ((val-min) / (max-min))*1.0f;
EColorModel
These are the most often used color models.
YUYV422, 2 channels, full luminance Y, subsampled half U,V.
virtual int InitImage(BIAS::ImageBase &Image)
float GetBrightness()
Get brightness as value in interval [0, 100]. */.
float GetContrast()
Get contrast as value in interval [0, 100]. */.
bool HasControlBrightness()
pthread_mutex_t ActiveFrameMutex_
Defines a common interface to different devices.
void GetDeviceChannelNames(std::vector< std::string > &names)
if more than one channel is present names can are returned here.
bool IsControllable_
Must be initialized be the derived classes.
struct v4l2_buffer buffer_
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
const char * DefaultDevice_
Device name.
unsigned int GetSizeByte() const
returns the nr.
v4l2_field interlaceMode_
BIAS::ImageBase::EColorModel ColorMode_
Color mode used by camera.
int SetShutter(float g)
Set shutter (exposure time) in seconds.
std::vector< BIAS::Camera< unsigned char > > Frame_
void AddInput(InputDescriptor id)
int DeviceChannel_
Device channel.
struct v4l2_format formatRGB_
bool WaitForNew_
Wait for new frames in GrabSingle()
float BytesPerPixel_
BytesPerPixel cannot be int (e.g. it is 1.5 for YUV420p)
void FixIdentifierString_()
void ResetPanTiltZoom()
Reset digital zoom, pan and tilt to defaults to ensure compliance with calibration.
static int GetDirectoryContent(const std::string &Dir, const std::string &prefix, const std::string &suffix, std::vector< std::string > &content, const bool GetFullPath=false)
Read all files in.
float GetShutter()
Get shutter (exposure time) in seconds.
virtual int OpenDevice()
selects the first available device to open (e.g.
float GetGain()
Get gain in dB.
bool CompleteInitialized_
Complete_initialized_ is set when OpenDevice(), UseChannel() etc. are done.
struct v4l2_queryctrl ControlContrast_
struct v4l2_queryctrl ControlShutter_
color values, 3 channels, order: blue,green,red
int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
struct v4l2_queryctrl ControlAutoGain_
virtual int GrabSingle(BIAS::Camera< unsigned char > &image)
blocks until a new frame arrives from the cam, if dont want blocking set waitForNew() to false ...
Bayer_BGGR, 1 channel RGB image Bayer tile.
int SetBrightness(float g)
Set brightness as value in interval [0, 100]. */.
int SetGain(float g)
Set gain in dB.
Bayer_GBRG, 1 channel RGB image Bayer tile.
std::string Identifier_
Verbose camera descriptor.
struct v4l2_format format2_
int GetAllDevices(std::vector< std::string > &devices)
bool Grabbing_
Grabbing flag is set and unset in GrabSingle() methods.
BIAS::JpegHandler Decompressor_
std::map< std::string, std::string > ModelNameToDevice_
color values, 3 channels, order: red,green,blue
void SetDebugLevel(const long int lv)
int Decompress(BIAS::Image< unsigned char > &destImg, bool readComment=false)
Start decompression of previously given data (from ReadJPEG() or SetCompressedData()), results will be stored in destination image.
UYVY422, 2 channels, full luminance Y, subsampled half U,V inverse order.
struct v4l2_queryctrl ControlBrightness_
pthread_t ContinousThread_
bool Active_
Active flag is set in PreGrab() und unset in PostGrab()
struct v4l2_queryctrl ControlGain_
int SetContrast(float g)
Set contrast as value in interval [0, 100]. */.
void InvalidateUID()
sets the image's uid to invalid
BIAS::Camera< unsigned char > jpegImg_
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
void SetUID(const BIAS::UUID &id)
virtual ~VideoSource_V4L()
void AddMode(unsigned int width, unsigned int height, float fps, ImageBase::EColorModel colormodel, bool interlaced=false)
void SetCompressedData(void *data, long length)
Copy memory area in which compressed data can be found and set its length in byte.
std::vector< std::string > deviceChannelNames_
int Init(long size=10485760)
Initialize object with standard values and limit shared memory area to given size (in byte...
invalid (not set) image format
Checks for VideoSource capabilities.
bool HasControlContrast()
struct v4l2_capability capability2
void SetTime(unsigned long long int sec, unsigned long long int usec)
Set time and ensure correct format (seconds and useconds after 'sec')
void SetName(const std::string &name)
This class extends VideoSource for the use of Video4Linux supported devices like framegrabber, USB cameras.
int PostGrab()
Stop anything started in PreGrab()
virtual int CloseDevice()
int GetCapabilities(VideoSourceCapabilities &caps)
Use this method to learn something about the capabilities of the source (only useful for V4L sources...
static UUID GenerateUUID(const bool &consecutively=DEFAULT_UUID_CONSECUTIVELY)
static function which simply produces a uuid and returns
std::vector< struct buffer > Buffers_
static void * GrabContThread_(void *arg)
BGRA color values, 4 channels, order: blue,green,red,alpha.
void SetAutoShutter(bool b)