207
207
unsigned char * pCaptureBuffer = (unsigned char*)m_vBuffers[buf.index].start;
209
IntPoint size = getImgSize();
211
210
switch (getCamPF()) {
213
lineLen = size.x*1.5;
212
lineLen = m_ImgSize.x*1.5;
215
lineLen = m_ImgSize.x;
219
lineLen = size.x*Bitmap::getBytesPerPixel(getCamPF());
218
lineLen = m_ImgSize.x*getBytesPerPixel(getCamPF());
221
BitmapPtr pCamBmp(new Bitmap(size, getCamPF(), pCaptureBuffer, lineLen,
220
BitmapPtr pCamBmp(new Bitmap(m_ImgSize, getCamPF(), pCaptureBuffer, lineLen,
222
221
false, "TempCameraBmp"));
224
223
BitmapPtr pDestBmp = convertCamFrameToDestPF(pCamBmp);
372
371
setFeature(V4L2_CID_BLUE_BALANCE, v);
374
int dumpCameras_open(int j)
376
stringstream minorDeviceNumber;
377
minorDeviceNumber << j;
378
string address = "/dev/video";
379
string result = address + minorDeviceNumber.str();
380
int fd = ::open(result.c_str(), O_RDWR /* required */ | O_NONBLOCK, 0);
384
v4l2_capability dumpCameraCapabilities(int fd)
386
v4l2_capability capability;
387
memset(&capability, 0, sizeof(capability));
388
int rc = ioctl(fd, VIDIOC_QUERYCAP, &capability);
390
cout << capability.card << ":" << endl;
391
cout << " Driver: " << capability.driver << endl;
392
cout << " Location: " << capability.bus_info;
393
cout << endl << endl;
398
void dumpSupportedImgFormats(int fd)
400
cout << "Suported Image Formats:" << endl;
401
for (int i = 0;; i++) {
402
v4l2_fmtdesc fmtDesc;
403
memset(&fmtDesc, 0, sizeof(fmtDesc));
405
fmtDesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
406
int rc = ioctl(fd, VIDIOC_ENUM_FMT, &fmtDesc);
410
v4l2_frmsizeenum frmSizeEnum;
411
memset(&frmSizeEnum, 0, sizeof (frmSizeEnum));
412
frmSizeEnum.index = 0;
413
frmSizeEnum.pixel_format = fmtDesc.pixelformat;
414
bool bSupported = false;
415
while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmSizeEnum) == 0) {
416
string sAvgPixelformat;
417
switch (fmtDesc.pixelformat) {
418
case v4l2_fourcc('Y','U','Y','V'):
419
sAvgPixelformat = "YUYV422";
422
case v4l2_fourcc('U','Y','V','Y'):
423
sAvgPixelformat = "YUV422";
426
case v4l2_fourcc('G','R','E','Y'):
427
sAvgPixelformat = "I8";
430
case v4l2_fourcc('Y','1','6',' '):
431
sAvgPixelformat = "I16";
434
case v4l2_fourcc('R','G','B','3'):
435
sAvgPixelformat = "RGB";
438
case v4l2_fourcc('B','G','R','3'):
439
sAvgPixelformat = "BGR";
447
v4l2_frmivalenum frmIvalEnum;
448
cout << " " << sAvgPixelformat << " ";
449
cout << " (" << frmSizeEnum.discrete.width << ", ";
450
cout << frmSizeEnum.discrete.height << ")";
452
memset (&frmIvalEnum, 0, sizeof (frmIvalEnum));
453
frmIvalEnum.index = 0;
454
frmIvalEnum.pixel_format = frmSizeEnum.pixel_format;
455
frmIvalEnum.width = frmSizeEnum.discrete.width;
456
frmIvalEnum.height = frmSizeEnum.discrete.height;
457
while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmIvalEnum) == 0) {
458
cout << frmIvalEnum.discrete.denominator << "/";
468
void dumpCameraControls(int fd)
470
cout << endl << "Camera Controls:" << endl;
471
v4l2_queryctrl queryCtrl;
472
for (queryCtrl.id = V4L2_CID_BASE; queryCtrl.id < V4L2_CID_LASTP1; queryCtrl.id++) {
473
int rc = ioctl (fd, VIDIOC_QUERYCTRL, &queryCtrl);
475
if (queryCtrl.flags & V4L2_CTRL_FLAG_DISABLED) {
478
cout << " " << queryCtrl.name << ":" << endl;
479
cout << " Min: " << queryCtrl.minimum << " | ";
480
cout << "Max: " << queryCtrl.maximum << " | ";
481
cout << "Default: "<< queryCtrl.default_value << endl;
483
if (errno != EINVAL) {
484
perror("VIDIOC_QUERYCTRL");
375
491
void V4LCamera::dumpCameras()
493
for(int j = 0; j < 256; j++){
494
int fd = dumpCameras_open(j);
496
cout << "------------------------Video4linux Camera-------------------------";
498
cout << "/dev/video" << j << " ";
499
v4l2_capability capability = dumpCameraCapabilities(fd);
500
if (capability.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
501
dumpSupportedImgFormats(fd);
502
dumpCameraControls(fd);
504
cout << "-------------------------------------------------------------------";
379
511
void V4LCamera::setFeature(CameraFeature feature, int value, bool bIgnoreOldValue)
381
513
// ignore -1 coming from default unbiased cameranode parameters
471
603
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
472
fmt.fmt.pix.width = getImgSize().x;
473
fmt.fmt.pix.height = getImgSize().y;
604
fmt.fmt.pix.width = m_ImgSize.x;
605
fmt.fmt.pix.height = m_ImgSize.y;
474
606
fmt.fmt.pix.pixelformat = m_v4lPF;
475
607
fmt.fmt.pix.field = V4L2_FIELD_ANY;
477
if (xioctl(m_Fd, VIDIOC_S_FMT, &fmt) == -1) {
608
int rc = xioctl(m_Fd, VIDIOC_S_FMT, &fmt);
609
if (int(fmt.fmt.pix.width) != m_ImgSize.x || int(fmt.fmt.pix.height) != m_ImgSize.y
478
612
throw(Exception(AVG_ERR_CAMERA_NONFATAL,
479
613
string("Unable to set V4L camera image format: '")
481
+"'. Try using v4l-info to find out what the device supports."));
615
+"'. Try using avg_showcamera.py --dump to find out what the device supports."));
484
618
CLEAR(StreamParam);
486
620
StreamParam.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
487
621
StreamParam.parm.capture.timeperframe.numerator = 1;
488
622
StreamParam.parm.capture.timeperframe.denominator = (int) m_FrameRate;
489
if (xioctl(m_Fd, VIDIOC_S_PARM, &StreamParam) == -1) {
623
rc = xioctl(m_Fd, VIDIOC_S_PARM, &StreamParam);
624
if (m_FrameRate != StreamParam.parm.capture.timeperframe.denominator || rc == -1) {
490
625
throw(Exception(AVG_ERR_CAMERA_NONFATAL,
491
626
string("Unable to set V4L camera framerate: '")
493
+"'. Try using v4l-info to find out what the device supports."));
628
+"'. Try using avg_showcamera.py --dump to find out what the device supports."));
495
630
m_FrameRate = (double)StreamParam.parm.capture.timeperframe.denominator / \
496
631
(double)StreamParam.parm.capture.timeperframe.numerator;