[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd cvd/videosource.h cvd/Linux/v4lbuffer.h ...
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd cvd/videosource.h cvd/Linux/v4lbuffer.h ... |
Date: |
Tue, 25 Nov 2008 18:32:31 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 08/11/25 18:32:31
Modified files:
cvd : videosource.h
cvd/Linux : v4lbuffer.h
cvd_src : videosource.cpp
cvd_src/Linux : v4lbuffer.cc
Log message:
Optional verbosity for v4lbuffer, for debugging v4l problems.
Set with a constructor parameter, or with verbose=1 in
open_video_source
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/videosource.h?cvsroot=libcvd&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/Linux/v4lbuffer.h?cvsroot=libcvd&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/videosource.cpp?cvsroot=libcvd&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/Linux/v4lbuffer.cc?cvsroot=libcvd&r1=1.6&r2=1.7
Patches:
Index: cvd/videosource.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/videosource.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- cvd/videosource.h 28 Aug 2008 18:23:07 -0000 1.13
+++ cvd/videosource.h 25 Nov 2008 18:32:30 -0000 1.14
@@ -120,17 +120,17 @@
#if CVD_INTERNAL_HAVE_V4LBUFFER
- template <class T> VideoBuffer<T>* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced)
+ template <class T> VideoBuffer<T>* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced, bool verbose)
{
throw VideoSourceException("V4LBuffer cannot handle types other than
byte, bayer, yuv422, Rgb<byte>");
}
- template <> VideoBuffer<byte>* makeV4LBuffer(const std::string& dev, const
ImageRef& size, int input, bool interlaced);
- template <> VideoBuffer<bayer>* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced);
- template <> VideoBuffer<yuv422>* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced);
- template <> VideoBuffer<Rgb<byte> >* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced);
+ template <> VideoBuffer<byte>* makeV4LBuffer(const std::string& dev, const
ImageRef& size, int input, bool interlaced, bool verbose);
+ template <> VideoBuffer<bayer>* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced, bool verbose);
+ template <> VideoBuffer<yuv422>* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced, bool verbose);
+ template <> VideoBuffer<Rgb<byte> >* makeV4LBuffer(const std::string& dev,
const ImageRef& size, int input, bool interlaced, bool verbose);
- void get_v4l2_options(const VideoSource& vs, ImageRef& size, int& input,
bool& interlaced);
+ void get_v4l2_options(const VideoSource& vs, ImageRef& size, int& input,
bool& interlaced, bool& verbose);
#endif
@@ -216,9 +216,9 @@
else if (vs.protocol == "v4l2") {
ImageRef size;
int input;
- bool interlaced;
- get_v4l2_options(vs, size, input, interlaced);
- return makeV4LBuffer<T>(vs.identifier, size, input, interlaced);
+ bool interlaced, verbose;
+ get_v4l2_options(vs, size, input, interlaced, verbose);
+ return makeV4LBuffer<T>(vs.identifier, size, input, interlaced,
verbose);
}
#endif
#if CVD_HAVE_DVBUFFER
@@ -372,7 +372,8 @@
'v4l2' protocol (V4LBuffer): identifier is device name
size = vga | qvga | pal | ntsc | <width>x<height> (default vga)
input = <number>
- interlaced | fields [= true | false | yes | no]
+ interlaced | fields [= <bool> ]
+ verbose [ = <bool> ]
'dc1394' protocol (DVBuffer): identifier is camera number
fps = <number> (default 30)
Index: cvd/Linux/v4lbuffer.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/Linux/v4lbuffer.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- cvd/Linux/v4lbuffer.h 15 Aug 2008 20:46:49 -0000 1.9
+++ cvd/Linux/v4lbuffer.h 25 Nov 2008 18:32:30 -0000 1.10
@@ -117,7 +117,7 @@
unsigned char* data;
double when;
};
- V4L2Client(int fd, unsigned int fmt, ImageRef size, int input, bool
fields, int frame_per_second);
+ V4L2Client(int fd, unsigned int fmt, ImageRef size, int input, bool
fields, int frame_per_second, bool verbose);
ImageRef getSize();
Buffer getFrame();
void releaseFrame(int id);
@@ -145,13 +145,13 @@
template <class T> class V4LBuffer : public VideoBuffer<T>
{
public:
- V4LBuffer(const std::string & dev, ImageRef size, int input=-1, bool
fields=false, int frames_per_second=0) : devname(dev)
+ V4LBuffer(const std::string & dev, ImageRef size, int input=-1, bool
fields=false, int frames_per_second=0, bool verbose=0) : devname(dev)
{
int device = open(devname.c_str(), O_RDWR | O_NONBLOCK);
if (device == -1)
throw Exceptions::V4LBuffer::DeviceOpen(dev);
try {
- v4l2 = new V4L::V4L2Client(device, V4L::format<T>::v4l2_fmt, size,
input, fields,frames_per_second);
+ v4l2 = new V4L::V4L2Client(device, V4L::format<T>::v4l2_fmt, size,
input, fields,frames_per_second, verbose);
}
catch (std::string& s) {
v4l2 = 0;
Index: cvd_src/videosource.cpp
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/videosource.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- cvd_src/videosource.cpp 28 Aug 2008 18:23:08 -0000 1.8
+++ cvd_src/videosource.cpp 25 Nov 2008 18:32:30 -0000 1.9
@@ -4,6 +4,33 @@
namespace CVD {
+ void tolower(std::string& s)
+ {
+ for (size_t i=0; i<s.length(); ++i)
+ s[i] = ::tolower(s[i]);
+ }
+
+ void tolower(char* s)
+ {
+ for (size_t i=0; s[i]; ++i)
+ s[i] = ::tolower(s[i]);
+ }
+
+ using std::tolower;
+
+ //If the flag is specified at all, but no parameter is
+ //given, this implies true.
+ bool parseBoolFlag(std::string s)
+ {
+ tolower(s);
+ if(s == "" || s == "yes" || s == "true" || s=="1")
+ return 1;
+ else if(s == "no" || s == "false" || s=="0")
+ return 0;
+ else
+ throw ParseException("invalid interlaced/fields setting
'"+s+"' (must be true/false or yes/no or 1/0)");
+ }
+
std::string escape(char c)
{
static std::string escaped[256];
@@ -135,11 +162,6 @@
}
- void tolower(std::string& s)
- {
- for (size_t i=0; i<s.length(); ++i)
- s[i] = ::tolower(s[i]);
- }
void parse(std::istream& in, VideoSource& vs)
{
@@ -294,27 +316,27 @@
#if CVD_INTERNAL_HAVE_V4LBUFFER
- template <> CVD::VideoBuffer<CVD::byte>* makeV4LBuffer(const std::string&
dev, const CVD::ImageRef& size, int input, bool interlaced)
+ template <> CVD::VideoBuffer<CVD::byte>* makeV4LBuffer(const std::string&
dev, const CVD::ImageRef& size, int input, bool interlaced, bool verbose)
{
- return new CVD::V4LBuffer<CVD::byte>(dev, size, input, interlaced);
+ return new CVD::V4LBuffer<CVD::byte>(dev, size, input, interlaced, 0,
verbose);
}
#ifdef V4L2_PIX_FMT_SBGGR8
- template <> CVD::VideoBuffer<CVD::bayer>* makeV4LBuffer(const
std::string& dev, const CVD::ImageRef& size, int input, bool interlaced)
+ template <> CVD::VideoBuffer<CVD::bayer>* makeV4LBuffer(const
std::string& dev, const CVD::ImageRef& size, int input, bool interlaced, bool
verbose)
{
- return new CVD::V4LBuffer<CVD::bayer>(dev, size, input, interlaced);
+ return new CVD::V4LBuffer<CVD::bayer>(dev, size, input, interlaced,
0, verbose);
}
#endif
- template <> CVD::VideoBuffer<CVD::yuv422>* makeV4LBuffer(const
std::string& dev, const CVD::ImageRef& size, int input, bool interlaced)
+ template <> CVD::VideoBuffer<CVD::yuv422>* makeV4LBuffer(const
std::string& dev, const CVD::ImageRef& size, int input, bool interlaced, bool
verbose)
{
- return new CVD::V4LBuffer<CVD::yuv422>(dev, size, input, interlaced);
+ return new CVD::V4LBuffer<CVD::yuv422>(dev, size, input, interlaced, 0,
verbose);
}
- template <> CVD::VideoBuffer<CVD::Rgb<CVD::byte> >* makeV4LBuffer(const
std::string& dev, const CVD::ImageRef& size, int input, bool interlaced)
+ template <> CVD::VideoBuffer<CVD::Rgb<CVD::byte> >* makeV4LBuffer(const
std::string& dev, const CVD::ImageRef& size, int input, bool interlaced, bool
verbose)
{
- return new CVD::V4LBuffer<CVD::Rgb<CVD::byte> >(dev, size, input,
interlaced);
+ return new CVD::V4LBuffer<CVD::Rgb<CVD::byte> >(dev, size, input,
interlaced, 0, verbose);
}
- void get_v4l2_options(const VideoSource& vs, ImageRef& size, int& input,
bool& interlaced)
+ void get_v4l2_options(const VideoSource& vs, ImageRef& size, int& input,
bool& interlaced, bool& verbose)
{
size = ImageRef(640,480);
input = -1;
@@ -339,18 +361,10 @@
}
} else if (it->first == "input") {
input = atoi(it->second.c_str());
+ } else if (it->first == "verbose") {
+ verbose = parseBoolFlag(it->second);
} else if (it->first == "interlaced" || it->first == "fields") {
- if (it->second.length()) {
- std::string s = it->second;
- tolower(s);
- if (s == "true" || s=="yes")
- interlaced = true;
- else if (s == "false" || s == "no")
- interlaced = false;
- else
- throw ParseException("invalid interlaced/fields setting
'"+s+"' (must be true/false or yes/no)");
- } else
- interlaced = true;
+ interlaced = parseBoolFlag(it->second);
} else
throw VideoSourceException("invalid option for 'v4l2' protocol:
"+it->first+"\n\t valid options: size, input, interlaced, fields");
}
Index: cvd_src/Linux/v4lbuffer.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/Linux/v4lbuffer.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- cvd_src/Linux/v4lbuffer.cc 23 Apr 2008 00:36:18 -0000 1.6
+++ cvd_src/Linux/v4lbuffer.cc 25 Nov 2008 18:32:31 -0000 1.7
@@ -52,6 +52,53 @@
what = "V4LBuffer: GetFrame on " + device + " failed: " + msg;
}
+
+class VPrint_
+{
+ public:
+ VPrint_(bool _p)
+ :p(_p)
+ {}
+
+ template<class C> VPrint_& operator<<(const C& c)
+ {
+ if(p)
+ cerr << c;
+
+ return *this;
+ }
+
+ bool p;
+};
+
+class VPrint: public VPrint_
+{
+ public:
+ VPrint(bool _b)
+ :VPrint_(_b){}
+
+ template<class C> VPrint_& operator<<(const C& c)
+ {
+ if(p)
+ cerr << "V4L2Client: " << c;
+
+ return *this;
+ }
+
+};
+
+string unfourcc(unsigned long c)
+{
+ string ret;
+ ret.resize(4);
+
+ ret[0] = c & 0xff;
+ ret[1] = (c>>8) & 0xff;
+ ret[2] = (c>>16) & 0xff;
+ ret[3] = (c>>24) & 0xff;
+ return ret;
+}
+
namespace V4L { // V4L
struct V4L2Client::State {
@@ -66,13 +113,40 @@
v4l2_buffer refbuf;
};
- V4L2Client::V4L2Client(int fd, unsigned int fmt, ImageRef size, int input,
bool fields, int frames_per_second)
+ V4L2Client::V4L2Client(int fd, unsigned int fmt, ImageRef size, int input,
bool fields, int frames_per_second, bool verbose)
{
state = 0;
+ VPrint log(verbose);
+
+ log << "verbose operation. Initializing\n";
+
struct v4l2_capability caps;
if (0 != ioctl(fd, VIDIOC_QUERYCAP, &caps))
+ {
throw string("VIDIOC_QUERYCAP failed");
+ }
+
+ log << "Capabilities: driver: " << caps.driver << "\n";
+ log << "Capabilities: card: " << caps.card << "\n";
+ log << "Capabilities: bus_info: " << caps.bus_info << "\n";
+ log << "Capabilities: version: " << caps.version << "\n";
+ log << "Capabilities: capabilities: 0x" << hex << caps.capabilities <<
dec << "\n";
+ log << "Capabilities: V4L2_CAP_VIDEO_CAPTURE = " <<
!!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE) << "\n";
+ log << "Capabilities: V4L2_CAP_VIDEO_OUTPUT = " <<
!!(caps.capabilities & V4L2_CAP_VIDEO_OUTPUT) << "\n";
+ log << "Capabilities: V4L2_CAP_VIDEO_OVERLAY = " <<
!!(caps.capabilities & V4L2_CAP_VIDEO_OVERLAY) << "\n";
+ log << "Capabilities: V4L2_CAP_VBI_CAPTURE = " <<
!!(caps.capabilities & V4L2_CAP_VBI_CAPTURE) << "\n";
+ log << "Capabilities: V4L2_CAP_VBI_OUTPUT = " <<
!!(caps.capabilities & V4L2_CAP_VBI_OUTPUT) << "\n";
+ log << "Capabilities: V4L2_CAP_SLICED_VBI_CAPTURE = " <<
!!(caps.capabilities & V4L2_CAP_SLICED_VBI_CAPTURE) << "\n";
+ log << "Capabilities: V4L2_CAP_SLICED_VBI_OUTPUT = " <<
!!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE) << "\n";
+ log << "Capabilities: V4L2_CAP_RDS_CAPTURE = " <<
!!(caps.capabilities & V4L2_CAP_SLICED_VBI_OUTPUT) << "\n";
+ log << "Capabilities: V4L2_CAP_VIDEO_OUTPUT_OVERLAY = " <<
!!(caps.capabilities & V4L2_CAP_VIDEO_OUTPUT_OVERLAY) << "\n";
+ log << "Capabilities: V4L2_CAP_TUNER = " <<
!!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE) << "\n";
+ log << "Capabilities: V4L2_CAP_AUDIO = " <<
!!(caps.capabilities & V4L2_CAP_TUNER) << "\n";
+ log << "Capabilities: V4L2_CAP_RADIO = " <<
!!(caps.capabilities & V4L2_CAP_RADIO) << "\n";
+ log << "Capabilities: V4L2_CAP_READWRITE = " <<
!!(caps.capabilities & V4L2_CAP_READWRITE) << "\n";
+ log << "Capabilities: V4L2_CAP_ASYNCIO = " <<
!!(caps.capabilities & V4L2_CAP_ASYNCIO) << "\n";
+ log << "Capabilities: V4L2_CAP_STREAMING = " <<
!!(caps.capabilities & V4L2_CAP_STREAMING) << "\n";
if (strcmp((const char*)caps.driver, "bttv")==0) {
v4l2_std_id stdId=V4L2_STD_PAL;
@@ -94,17 +168,27 @@
if (0 != ioctl(fd, VIDIOC_G_FMT, &format))
throw string("VIDIOC_G_FMT");
+ log << "G_FMT gives size/format/fields: " << format.fmt.pix.width <<
"x" << format.fmt.pix.height << " / "
+ << unfourcc(format.fmt.pix.pixelformat) << hex << " (0x" <<
format.fmt.pix.pixelformat << dec << ") / " << format.fmt.pix.field << "\n";
+
format.fmt.pix.width = size.x;
format.fmt.pix.height = size.y;
format.fmt.pix.pixelformat = fmt;
format.fmt.pix.field = fields ? V4L2_FIELD_ALTERNATE : V4L2_FIELD_ANY;
+ log << "S_FMT with size/format/fields: " << format.fmt.pix.width <<
"x" << format.fmt.pix.height << " / "
+ << unfourcc(format.fmt.pix.pixelformat) << hex << " (0x" <<
format.fmt.pix.pixelformat << dec << ") / " << format.fmt.pix.field << "\n";
+
if (0 != ioctl(fd, VIDIOC_S_FMT, &format))
throw string("VIDIOC_S_FMT");
if (0 != ioctl(fd, VIDIOC_G_FMT, &format))
throw string("VIDIOC_G_FMT");
+ log << "G_FMT gives size/format/fields: " << format.fmt.pix.width <<
"x" << format.fmt.pix.height << " / "
+ << unfourcc(format.fmt.pix.pixelformat) << hex << " (0x" <<
format.fmt.pix.pixelformat << dec << ") / " << format.fmt.pix.field << "\n";
+
+
if (fmt != format.fmt.pix.pixelformat)
throw string("Requested format not supported");
@@ -115,6 +199,8 @@
if (0 != ioctl(fd,VIDIOC_REQBUFS,&reqbufs))
throw string("VIDIOC_REQBUFS");
+ cerr << "wtttf\n";
+
num_bufs = reqbufs.count;
if (reqbufs.count < 2)
- [libcvd-members] libcvd cvd/videosource.h cvd/Linux/v4lbuffer.h ...,
Edward Rosten <=