parent
fccdc0eed7
commit
46d67f624c
@ -0,0 +1,107 @@
|
|||||||
|
|
||||||
|
#include "convert.h"
|
||||||
|
#include "videodev-svbcam.h"
|
||||||
|
|
||||||
|
VideoDev_SVBCam::VideoDev_SVBCam() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
VideoDev_SVBCam::~VideoDev_SVBCam() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
if (running > 0) CaptureStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return a list of /dev/video* devices found on the system, and read out its human friendly name
|
||||||
|
* output will be a lit of: "V4L2 /dev/videoX [Name]"
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::GetDeviceList(std::list<std::string> *list) {
|
||||||
|
std::string device;
|
||||||
|
int devnum;
|
||||||
|
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
|
||||||
|
if (list == NULL) return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open Device
|
||||||
|
* prepare the buffer, InitMMAP and read all controls
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::Open() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Close Device
|
||||||
|
* Free videobuffer
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::Close() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************************************
|
||||||
|
* VideoGrabbing
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* send the start capture signal to the cam
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::CaptureStart() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int VideoDev_SVBCam::CaptureStop() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* try to grab one frame and convert it into RGB32.
|
||||||
|
* If something goes wrong return an error code.
|
||||||
|
* Return code VDEV_STATUS_AGAIN is not an error. There was no video image ready to read.
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::Grab(VideoFrame *vf) {
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************************************
|
||||||
|
* Controls
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set video control identified by id
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::SetDevCtrl(unsigned int id, int value) {
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get video control identified by id
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::GetDevCtrl(unsigned int id, int *value) {
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
#ifndef _H_VIDEODEV_V4L2_H_
|
||||||
|
#define _H_VIDEODEV_V4L2_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <linux/videodev2.h>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
#include "convert.h"
|
||||||
|
#include "gui.h"
|
||||||
|
#include "videodev.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
IOMODE_READ,
|
||||||
|
IOMODE_MMAP
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class VideoDev_SVBCam: public VideoDev {
|
||||||
|
private:
|
||||||
|
ConvertData cdata;
|
||||||
|
|
||||||
|
int Grab(VideoFrame *vf);
|
||||||
|
int Open();
|
||||||
|
int Close();
|
||||||
|
int CaptureStart();
|
||||||
|
int CaptureStop();
|
||||||
|
int SetDevCtrl(unsigned int id, int value);
|
||||||
|
int GetDevCtrl(unsigned int id, int *value);
|
||||||
|
public:
|
||||||
|
VideoDev_SVBCam();
|
||||||
|
~VideoDev_SVBCam();
|
||||||
|
int GetDeviceList(std::list<std::string> *list);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,306 @@
|
|||||||
|
/*
|
||||||
|
* module to read video data from SVBcams.
|
||||||
|
* maybe you have to add something like: /etc/udev.d/90-svbony.rules to get read/wirte access for users in 'plugdev'
|
||||||
|
* SUBSYSTEMS=="usb", ATTRS{idVendor}=="f266", ATTRS{idProduct}=="9a0a", GROUP="plugdev", MODE="0660"
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SVBCameraSDK.h>
|
||||||
|
#include "convert.h"
|
||||||
|
#include "videodev-svbcam.h"
|
||||||
|
|
||||||
|
VideoDev_SVBCam::VideoDev_SVBCam() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
camid = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
VideoDev_SVBCam::~VideoDev_SVBCam() {
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
if (running > 0) CaptureStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void VideoDev_SVBCam::print_error(int err) {
|
||||||
|
switch (err) {
|
||||||
|
case SVB_ERROR_INVALID_ID:
|
||||||
|
printf ("SVB_ERROR_INVALID_ID\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_CAMERA_REMOVED:
|
||||||
|
printf ("SVB_ERROR_CAMERA_REMOVED\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_CAMERA_CLOSED:
|
||||||
|
printf ("SVB_ERROR_CAMERA_CLOSED\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_INVALID_SIZE:
|
||||||
|
printf ("SVB_ERROR_INVALID_SIZE\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_INVALID_IMGTYPE:
|
||||||
|
printf ("SVB_ERROR_INVALID_IMGTYPE\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_INVALID_MODE:
|
||||||
|
printf ("SVB_ERROR_INVALID_MODE\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_EXPOSURE_IN_PROGRESS:
|
||||||
|
printf("SVB_ERROR_EXPOSURE_IN_PROGRESS\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_GENERAL_ERROR:
|
||||||
|
printf("SVB_ERROR_GENERAL_ERROR\n");
|
||||||
|
break;
|
||||||
|
case SVB_ERROR_TIMEOUT:
|
||||||
|
printf("SVB_ERROR_TIMEOUT\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf ("unknown %d\n", err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exit (0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check for connected devices and return the result in a lite.
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::GetDeviceList(std::list<std::string> *list) {
|
||||||
|
int iNumofConnectCameras = SVBGetNumOfConnectedCameras();
|
||||||
|
std::string device;
|
||||||
|
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
if (list == NULL) return VDEV_STATUS_ERROR;
|
||||||
|
|
||||||
|
// from sample code
|
||||||
|
SVB_CAMERA_INFO *caminfo = (SVB_CAMERA_INFO *)malloc(sizeof(SVB_CAMERA_INFO)*iNumofConnectCameras);
|
||||||
|
for (int i = 0; i < iNumofConnectCameras; i++) {
|
||||||
|
SVBGetCameraInfo(&caminfo[i], i);
|
||||||
|
device = "SVBCAM " + to_string(caminfo[i].CameraID) + " [" + caminfo[i].FriendlyName + "]";
|
||||||
|
list->push_back(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open Device
|
||||||
|
* prepare the buffer
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::Open() {
|
||||||
|
int camnumcontrols, err;
|
||||||
|
SVB_CONTROL_CAPS *camcontrols = NULL;
|
||||||
|
SVB_CAMERA_PROPERTY camprop;
|
||||||
|
VideoDevCtrl vctl;
|
||||||
|
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
|
||||||
|
camid = atoi (conf_device.c_str());
|
||||||
|
printf ("%s:%d %s opening cam %d\n", __FILE__, __LINE__, __FUNCTION__, camid);
|
||||||
|
|
||||||
|
if ((err = SVBOpenCamera(camid)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// get cam property
|
||||||
|
if ((err = SVBGetCameraProperty(camid, &camprop)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
Close();
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
printf ("%s:%d %s height: %ld width: %ld\n", __FILE__, __LINE__, __FUNCTION__, camprop.MaxHeight, camprop.MaxWidth);
|
||||||
|
|
||||||
|
for(int i=0; i < 8 && camprop.SupportedVideoFormat[i] == SVB_IMG_END; i++) {
|
||||||
|
printf ("%s:%d %s VideoFormat Index:%d ", __FILE__, __LINE__, __FUNCTION__, i);
|
||||||
|
switch (camprop.SupportedVideoFormat[i]) {
|
||||||
|
case SVB_IMG_RAW8:
|
||||||
|
printf("\t\tSVB_IMG_RAW8\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_RAW10:
|
||||||
|
printf("\t\tSVB_IMG_RAW10\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_RAW12:
|
||||||
|
printf("\t\tSVB_IMG_RAW12\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_RAW14:
|
||||||
|
printf("\t\tSVB_IMG_RAW14\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_RAW16:
|
||||||
|
printf("\t\tSVB_IMG_RAW16\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_Y8:
|
||||||
|
printf("\t\tSVB_IMG_Y8\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_Y10:
|
||||||
|
printf("\t\tSVB_IMG_Y10\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_Y12:
|
||||||
|
printf("\t\tSVB_IMG_Y12\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_Y14:
|
||||||
|
printf("\t\tSVB_IMG_Y14\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_Y16:
|
||||||
|
printf("\t\tSVB_IMG_Y16\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_RGB24:
|
||||||
|
printf("\t\tSVB_IMG_RGB24\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_RGB32:
|
||||||
|
printf("\t\tSVB_IMG_RGB32\n");
|
||||||
|
break;
|
||||||
|
case SVB_IMG_END:
|
||||||
|
printf("\t\tSVB_IMG_END\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf ("\t\tunbekannt\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// get controls
|
||||||
|
vidctrls.clear();
|
||||||
|
if ((err = SVBGetNumOfControls(camid, &camnumcontrols)) != SVB_SUCCESS) print_error(err);
|
||||||
|
camcontrols = (SVB_CONTROL_CAPS*) malloc (sizeof(SVB_CONTROL_CAPS) * camnumcontrols);
|
||||||
|
for (int i = 0; i < camnumcontrols; i++) {
|
||||||
|
if ((err = SVBGetControlCaps(camid, i, &camcontrols[i])) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
printf ("%s:%d %s Got Control idx: %d name:%s desc:%s\n", __FILE__, __LINE__, __FUNCTION__,
|
||||||
|
i, camcontrols[i].Name, camcontrols[i].Description);
|
||||||
|
vctl.name = (char*)camcontrols[i].Name;
|
||||||
|
vctl.id = i;
|
||||||
|
vctl.min = camcontrols[i].MinValue;
|
||||||
|
vctl.max = camcontrols[i].MaxValue;
|
||||||
|
GetDevCtrl(i, &vctl.value);
|
||||||
|
vidctrls.push_back(vctl);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// set ROI (region of interest)
|
||||||
|
if ((err = SVBSetROIFormat(camid, 0, 0, camprop.MaxWidth, camprop.MaxHeight, 1)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Mode and IMG Format
|
||||||
|
if ((err = SVBSetCameraMode(camid, SVB_MODE_NORMAL)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
if ((err = SVBSetOutputImageType(camid, SVB_IMG_RGB24)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// preprare buffer
|
||||||
|
LockMutex();
|
||||||
|
threaddata.vf.SetSize(camprop.MaxWidth, camprop.MaxHeight);
|
||||||
|
UnLockMutex();
|
||||||
|
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Close Device
|
||||||
|
* Free videobuffer
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::Close() {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
if ((err = SVBCloseCamera(camid)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************************************
|
||||||
|
* VideoGrabbing
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* send the start capture signal to the cam
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::CaptureStart() {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
// start video capture
|
||||||
|
if ((err = SVBStartVideoCapture(camid)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int VideoDev_SVBCam::CaptureStop() {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
if ((err = SVBStopVideoCapture(camid)) != SVB_SUCCESS) {
|
||||||
|
print_error(err);
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* try to grab one frame and convert it into RGB32.
|
||||||
|
* If something goes wrong return an error code.
|
||||||
|
* Return code VDEV_STATUS_AGAIN is not an error. There was no video image ready to read.
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::Grab(VideoFrame *vf) {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
LockMutex();
|
||||||
|
if ((err = SVBGetVideoData(camid, threaddata.vf.data, (long)threaddata.vf.size, 50)) != SVB_SUCCESS) {
|
||||||
|
if (err != SVB_ERROR_TIMEOUT) {
|
||||||
|
print_error(err);
|
||||||
|
UnLockMutex();
|
||||||
|
return VDEV_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UnLockMutex();
|
||||||
|
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************************************
|
||||||
|
* Controls
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set video control identified by id
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::SetDevCtrl(unsigned int id, int value) {
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get video control identified by id
|
||||||
|
*/
|
||||||
|
int VideoDev_SVBCam::GetDevCtrl(unsigned int id, int *value) {
|
||||||
|
*value = 0;
|
||||||
|
return VDEV_STATUS_OK;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
#ifndef _H_VIDEODEV_SVBCAM_H_
|
||||||
|
#define _H_VIDEODEV_SVBCAM_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <linux/videodev2.h>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
#include "convert.h"
|
||||||
|
#include "gui.h"
|
||||||
|
#include "videodev.h"
|
||||||
|
|
||||||
|
|
||||||
|
class VideoDev_SVBCam: public VideoDev {
|
||||||
|
private:
|
||||||
|
VideoFrame vf;
|
||||||
|
|
||||||
|
ConvertData cdata;
|
||||||
|
int camid;
|
||||||
|
|
||||||
|
int Grab(VideoFrame *vf);
|
||||||
|
int Open();
|
||||||
|
int Close();
|
||||||
|
int CaptureStart();
|
||||||
|
int CaptureStop();
|
||||||
|
int SetDevCtrl(unsigned int id, int value);
|
||||||
|
int GetDevCtrl(unsigned int id, int *value);
|
||||||
|
|
||||||
|
void print_error(int err);
|
||||||
|
public:
|
||||||
|
VideoDev_SVBCam();
|
||||||
|
~VideoDev_SVBCam();
|
||||||
|
int GetDeviceList(std::list<std::string> *list);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in new issue