|
|
@ -83,6 +83,11 @@ VideoDev::VideoDev() {
|
|
|
|
inbuffer[i].size = 0;
|
|
|
|
inbuffer[i].size = 0;
|
|
|
|
inbuffer[i].data = NULL;
|
|
|
|
inbuffer[i].data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
conf_device = "";
|
|
|
|
|
|
|
|
conf_devicename = "";
|
|
|
|
|
|
|
|
conf_format = "";
|
|
|
|
|
|
|
|
conf_height = -1;
|
|
|
|
|
|
|
|
conf_width = -1;
|
|
|
|
vf.data = NULL;
|
|
|
|
vf.data = NULL;
|
|
|
|
vf.h = 0;
|
|
|
|
vf.h = 0;
|
|
|
|
vf.w = 0;
|
|
|
|
vf.w = 0;
|
|
|
@ -205,11 +210,14 @@ int VideoDev::SetCtrlValue(std::string name, int value) {
|
|
|
|
// start the video, start capturing, start thread
|
|
|
|
// start the video, start capturing, start thread
|
|
|
|
// after return of this function we can call the Ctrl thread
|
|
|
|
// after return of this function we can call the Ctrl thread
|
|
|
|
//
|
|
|
|
//
|
|
|
|
int VideoDev::Start(std::string dev, gboolean (*callback_func)(gpointer data)) {
|
|
|
|
int VideoDev::Start(std::string dev, int w, int h, std::string format, gboolean (*callback_func)(gpointer data)) {
|
|
|
|
if (running != 0 || thread != NULL) return VDEV_STATUS_ERROR;
|
|
|
|
if (running != 0 || thread != NULL) return VDEV_STATUS_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
running = 1;
|
|
|
|
running = 1;
|
|
|
|
conf_device = dev;
|
|
|
|
conf_device = dev;
|
|
|
|
|
|
|
|
conf_format = format;
|
|
|
|
|
|
|
|
conf_width = w;
|
|
|
|
|
|
|
|
conf_height = h;
|
|
|
|
callback = callback_func;
|
|
|
|
callback = callback_func;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -246,6 +254,13 @@ int VideoDev::Stop() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void VideoDev::GetVideoInfo(int *w, int *h, std::string *format) {
|
|
|
|
|
|
|
|
*format = conf_format;
|
|
|
|
|
|
|
|
*w = conf_width;
|
|
|
|
|
|
|
|
*h = conf_height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// try to read a video every 0.05ms (25hz)
|
|
|
|
// try to read a video every 0.05ms (25hz)
|
|
|
|
// running = 2 ... thread is running normaly
|
|
|
|
// running = 2 ... thread is running normaly
|
|
|
@ -407,6 +422,7 @@ int VideoDev::OpenInit() {
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
struct v4l2_capability vcap;
|
|
|
|
struct v4l2_capability vcap;
|
|
|
|
VideoDevCtrl vctl;
|
|
|
|
VideoDevCtrl vctl;
|
|
|
|
|
|
|
|
char txt[32];
|
|
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d %s Device: '%s'\n", __FILE__, __LINE__, __FUNCTION__, conf_device.c_str());
|
|
|
|
printf ("%s:%d %s Device: '%s'\n", __FILE__, __LINE__, __FUNCTION__, conf_device.c_str());
|
|
|
|
if (fd != -1) return VDEV_STATUS_ERROR;
|
|
|
|
if (fd != -1) return VDEV_STATUS_ERROR;
|
|
|
@ -465,14 +481,30 @@ int VideoDev::OpenInit() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// prepare resolution and pixelformat
|
|
|
|
CLEAR (fmt);
|
|
|
|
CLEAR (fmt);
|
|
|
|
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
fmt.fmt.pix.width = 1920;
|
|
|
|
if (conf_height != -1 && conf_width != -1) { // resolution
|
|
|
|
fmt.fmt.pix.height = 1080;
|
|
|
|
fmt.fmt.pix.width = conf_width;
|
|
|
|
// fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
|
|
|
|
fmt.fmt.pix.height = conf_height;
|
|
|
|
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
|
|
|
|
}
|
|
|
|
fmt.fmt.pix.field = V4L2_FIELD_NONE;
|
|
|
|
else {
|
|
|
|
|
|
|
|
fmt.fmt.pix.width = 1920;
|
|
|
|
|
|
|
|
fmt.fmt.pix.height = 1080;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conf_format.length() > 0) { // pixelformat
|
|
|
|
|
|
|
|
if (conf_format.compare("MJPG") == 0) fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
|
|
|
|
|
|
|
|
else if (conf_format.compare("YUYV") == 0) fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
|
|
|
|
|
|
|
|
else if (conf_format.compare("RGB4") == 0) fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
|
|
|
|
|
|
|
|
else fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
|
|
|
|
|
|
|
|
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.fmt.pix.field = V4L2_FIELD_NONE;
|
|
|
|
if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt)) {
|
|
|
|
if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt)) {
|
|
|
|
fprintf (stderr, "VIDIOC_S_FMT : %s", strerror (errno));
|
|
|
|
fprintf (stderr, "VIDIOC_S_FMT : %s", strerror (errno));
|
|
|
|
return VDEV_STATUS_ERROR;
|
|
|
|
return VDEV_STATUS_ERROR;
|
|
|
@ -486,6 +518,13 @@ int VideoDev::OpenInit() {
|
|
|
|
min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
|
|
|
|
min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
|
|
|
|
if (fmt.fmt.pix.sizeimage < min)
|
|
|
|
if (fmt.fmt.pix.sizeimage < min)
|
|
|
|
fmt.fmt.pix.sizeimage = min;
|
|
|
|
fmt.fmt.pix.sizeimage = min;
|
|
|
|
|
|
|
|
conf_width = fmt.fmt.pix.width;
|
|
|
|
|
|
|
|
conf_height = fmt.fmt.pix.height;
|
|
|
|
|
|
|
|
snprintf (txt, 32, "%c%c%c%c", ((char*)&fmt.fmt.pix.pixelformat)[0],
|
|
|
|
|
|
|
|
((char*)&fmt.fmt.pix.pixelformat)[1],
|
|
|
|
|
|
|
|
((char*)&fmt.fmt.pix.pixelformat)[2],
|
|
|
|
|
|
|
|
((char*)&fmt.fmt.pix.pixelformat)[3]);
|
|
|
|
|
|
|
|
conf_format = txt;
|
|
|
|
PrintFmt (&fmt);
|
|
|
|
PrintFmt (&fmt);
|
|
|
|
|
|
|
|
|
|
|
|
// init buffers
|
|
|
|
// init buffers
|
|
|
|