|
@@ -54,7 +54,7 @@
|
|
|
|
|
|
#include <usb_cam.h>
|
|
#include <usb_cam.h>
|
|
|
|
|
|
-#include <QDateTime>
|
|
|
|
|
|
+//#include <QDateTime>
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
|
|
#define CLEAR(x) memset (&(x), 0, sizeof (x))
|
|
#define CLEAR(x) memset (&(x), 0, sizeof (x))
|
|
@@ -63,7 +63,8 @@ namespace usb_cam {
|
|
|
|
|
|
static void errno_exit(const char * s)
|
|
static void errno_exit(const char * s)
|
|
{
|
|
{
|
|
- qDebug("%s error %d, %s", s, errno, strerror(errno));
|
|
|
|
|
|
+ std::cout<<s<<" error "<<errno<<" "<<strerror(errno)<<std::endl;
|
|
|
|
+// qDebug("%s error %d, %s", s, errno, strerror(errno));
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -373,7 +374,8 @@ int UsbCam::init_mjpeg_decoder(int image_width, int image_height)
|
|
avcodec_ = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
|
|
avcodec_ = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
|
|
if (!avcodec_)
|
|
if (!avcodec_)
|
|
{
|
|
{
|
|
- qDebug("Could not find MJPEG decoder");
|
|
|
|
|
|
+ std::cout<<" Could not find MJPEG decoder "<<std::endl;
|
|
|
|
+ // qDebug("Could not find MJPEG decoder");
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -403,7 +405,8 @@ int UsbCam::init_mjpeg_decoder(int image_width, int image_height)
|
|
/* open it */
|
|
/* open it */
|
|
if (avcodec_open2(avcodec_context_, avcodec_, &avoptions_) < 0)
|
|
if (avcodec_open2(avcodec_context_, avcodec_, &avoptions_) < 0)
|
|
{
|
|
{
|
|
- qDebug("Could not open MJPEG Decoder");
|
|
|
|
|
|
+ std::cout<<" Could not find MJPEG decoder "<<std::endl;
|
|
|
|
+// qDebug("Could not open MJPEG Decoder");
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
return 1;
|
|
@@ -426,7 +429,8 @@ void UsbCam::mjpeg2rgb(char *MJPEG, int len, char *RGB, int NumPixels)
|
|
|
|
|
|
if (decoded_len < 0)
|
|
if (decoded_len < 0)
|
|
{
|
|
{
|
|
- qDebug("Error while decoding frame.");
|
|
|
|
|
|
+ std::cout<<" Error while decoding frame."<<std::endl;
|
|
|
|
+// qDebug("Error while decoding frame.");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
#else
|
|
#else
|
|
@@ -435,7 +439,8 @@ void UsbCam::mjpeg2rgb(char *MJPEG, int len, char *RGB, int NumPixels)
|
|
|
|
|
|
if (!got_picture)
|
|
if (!got_picture)
|
|
{
|
|
{
|
|
- qDebug("Webcam: expected picture but didn't get it...");
|
|
|
|
|
|
+ std::cout<<" Webcam: expected picture but didn't get it... "<<std::endl;
|
|
|
|
+// qDebug("Webcam: expected picture but didn't get it...");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -444,7 +449,8 @@ void UsbCam::mjpeg2rgb(char *MJPEG, int len, char *RGB, int NumPixels)
|
|
int pic_size = avpicture_get_size(avcodec_context_->pix_fmt, xsize, ysize);
|
|
int pic_size = avpicture_get_size(avcodec_context_->pix_fmt, xsize, ysize);
|
|
if (pic_size != avframe_camera_size_)
|
|
if (pic_size != avframe_camera_size_)
|
|
{
|
|
{
|
|
- qDebug("outbuf size mismatch. pic_size: %d bufsize: %d", pic_size, avframe_camera_size_);
|
|
|
|
|
|
+ std::cout<<"outbuf size mismatch. pic_size:"<<pic_size<<" bufsize: "<<avframe_camera_size_<<std::endl;
|
|
|
|
+// qDebug("outbuf size mismatch. pic_size: %d bufsize: %d", pic_size, avframe_camera_size_);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -457,7 +463,8 @@ void UsbCam::mjpeg2rgb(char *MJPEG, int len, char *RGB, int NumPixels)
|
|
int size = avpicture_layout((AVPicture *)avframe_rgb_, AV_PIX_FMT_RGB24, xsize, ysize, (uint8_t *)RGB, avframe_rgb_size_);
|
|
int size = avpicture_layout((AVPicture *)avframe_rgb_, AV_PIX_FMT_RGB24, xsize, ysize, (uint8_t *)RGB, avframe_rgb_size_);
|
|
if (size != avframe_rgb_size_)
|
|
if (size != avframe_rgb_size_)
|
|
{
|
|
{
|
|
- qDebug("webcam: avpicture_layout error: %d", size);
|
|
|
|
|
|
+ std::cout<<" webcam: avpicture_layout error: "<<size<<std::endl;
|
|
|
|
+// qDebug("webcam: avpicture_layout error: %d", size);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -720,7 +727,8 @@ void UsbCam::init_read(unsigned int buffer_size)
|
|
|
|
|
|
if (!buffers_)
|
|
if (!buffers_)
|
|
{
|
|
{
|
|
- qDebug("Out of memory");
|
|
|
|
|
|
+ std::cout<<"Out of memory"<<std::endl;
|
|
|
|
+// qDebug("Out of memory");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -729,7 +737,8 @@ void UsbCam::init_read(unsigned int buffer_size)
|
|
|
|
|
|
if (!buffers_[0].start)
|
|
if (!buffers_[0].start)
|
|
{
|
|
{
|
|
- qDebug("Out of memory");
|
|
|
|
|
|
+ std::cout<<"Out of memory"<<std::endl;
|
|
|
|
+// qDebug("Out of memory");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -826,7 +835,8 @@ void UsbCam::init_userp(unsigned int buffer_size)
|
|
|
|
|
|
if (!buffers_)
|
|
if (!buffers_)
|
|
{
|
|
{
|
|
- qDebug("Out of memory");
|
|
|
|
|
|
+ std::cout<<"Out of memory"<<std::endl;
|
|
|
|
+// qDebug("Out of memory");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -837,7 +847,8 @@ void UsbCam::init_userp(unsigned int buffer_size)
|
|
|
|
|
|
if (!buffers_[n_buffers_].start)
|
|
if (!buffers_[n_buffers_].start)
|
|
{
|
|
{
|
|
- qDebug("Out of memory");
|
|
|
|
|
|
+ std::cout<<"Out of memory"<<std::endl;
|
|
|
|
+// qDebug("Out of memory");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -957,14 +968,22 @@ void UsbCam::init_device(int image_width, int image_height, int framerate)
|
|
if (xioctl(fd_, VIDIOC_G_PARM, &stream_params) < 0)
|
|
if (xioctl(fd_, VIDIOC_G_PARM, &stream_params) < 0)
|
|
errno_exit("Couldn't query v4l fps!");
|
|
errno_exit("Couldn't query v4l fps!");
|
|
|
|
|
|
- qDebug("Capability flag: 0x%x", stream_params.parm.capture.capability);
|
|
|
|
|
|
+ std::cout<<"Capability flag: "<<stream_params.parm.capture.capability<<std::endl;
|
|
|
|
+// qDebug("Capability flag: 0x%x", stream_params.parm.capture.capability);
|
|
|
|
|
|
stream_params.parm.capture.timeperframe.numerator = 1;
|
|
stream_params.parm.capture.timeperframe.numerator = 1;
|
|
stream_params.parm.capture.timeperframe.denominator = framerate;
|
|
stream_params.parm.capture.timeperframe.denominator = framerate;
|
|
if (xioctl(fd_, VIDIOC_S_PARM, &stream_params) < 0)
|
|
if (xioctl(fd_, VIDIOC_S_PARM, &stream_params) < 0)
|
|
- qDebug("Couldn't set camera framerate");
|
|
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Couldn't set camera framerate"<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ // qDebug("Couldn't set camera framerate");
|
|
else
|
|
else
|
|
- qDebug("Set framerate to be %i", framerate);
|
|
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Set framerate to be "<<framerate<<std::endl;
|
|
|
|
+// qDebug("Set framerate to be %i", framerate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
switch (io_)
|
|
switch (io_)
|
|
{
|
|
{
|
|
@@ -1049,10 +1068,12 @@ void UsbCam::start(const std::string& dev, io_method io_method,
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- qDebug("Unknown pixel format.");
|
|
|
|
|
|
+ std::cout<<"Unknown pixel format."<<std::endl;
|
|
|
|
+// qDebug("Unknown pixel format.");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
open_device();
|
|
open_device();
|
|
init_device(image_width, image_height, framerate);
|
|
init_device(image_width, image_height, framerate);
|
|
start_capturing();
|
|
start_capturing();
|
|
@@ -1116,7 +1137,8 @@ void UsbCam::grab_image(char *strdata, int *pnlen,const int nSize)
|
|
grab_image();
|
|
grab_image();
|
|
if(image_->image_size > nSize)
|
|
if(image_->image_size > nSize)
|
|
{
|
|
{
|
|
- qDebug("image size is %d . data buffer is %d small.",image_->image_size,nSize);
|
|
|
|
|
|
+ std::cout<<"image size is "<<image_->image_size<<" . data buffer is "<<nSize<<" small."<<std::endl;
|
|
|
|
+ // qDebug("image size is %d . data buffer is %d small.",image_->image_size,nSize);
|
|
*pnlen = 0;
|
|
*pnlen = 0;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1149,7 +1171,8 @@ void UsbCam::grab_image()
|
|
|
|
|
|
if (0 == r)
|
|
if (0 == r)
|
|
{
|
|
{
|
|
- qDebug("select timeout");
|
|
|
|
|
|
+ std::cout<<"select timeout."<<std::endl;
|
|
|
|
+ // qDebug("select timeout");
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1175,13 +1198,15 @@ void UsbCam::set_auto_focus(int value)
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- qDebug("V4L2_CID_FOCUS_AUTO is not supported");
|
|
|
|
|
|
+ std::cout<<" V4L2_CID_FOCUS_AUTO is not supported"<<std::endl;
|
|
|
|
+ // qDebug("V4L2_CID_FOCUS_AUTO is not supported");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
|
|
else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
|
|
{
|
|
{
|
|
- qDebug("V4L2_CID_FOCUS_AUTO is not supported");
|
|
|
|
|
|
+ std::cout<<" V4L2_CID_FOCUS_AUTO is not supported"<<std::endl;
|
|
|
|
+// qDebug("V4L2_CID_FOCUS_AUTO is not supported");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -1234,10 +1259,17 @@ void UsbCam::set_v4l_parameter(const std::string& param, const std::string& valu
|
|
pclose(stream);
|
|
pclose(stream);
|
|
// any output should be an error
|
|
// any output should be an error
|
|
if (output.length() > 0)
|
|
if (output.length() > 0)
|
|
- qDebug("%s", output.c_str());
|
|
|
|
|
|
+ {
|
|
|
|
+ std::cout<<output<<std::endl;
|
|
|
|
+// qDebug("%s", output.c_str());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- qDebug("usb_cam_node could not run '%s'", cmd.c_str());
|
|
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"usb_cam_node could not run '"<<cmd<<"'"<<std::endl;
|
|
|
|
+ // qDebug("usb_cam_node could not run '%s'", cmd.c_str());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
UsbCam::io_method UsbCam::io_method_from_string(const std::string& str)
|
|
UsbCam::io_method UsbCam::io_method_from_string(const std::string& str)
|