Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for bttv driver in v4lbuffer and (depracated?) v4l2buffer.

Added Rgb8 capture mode, which comes out very blue.

Added grey hack capture mode, which grabs a planar format if grey isn't
available.

Added very verbose mode to v4lbuffer, with optional switch in
open_video_source
  • Loading branch information...
commit 4f6eba5a99b775e29fbdf56bcc2369929ba4499d 1 parent 5250c8e
edrosten authored
View
7 cvd/Linux/v4lbuffer.h
@@ -37,6 +37,7 @@
#include <cvd/videobuffer.h>
#include <cvd/byte.h>
#include <cvd/rgb.h>
+#include <cvd/rgb8.h>
#include <cvd/timer.h>
#include <cvd/colourspaces.h>
#include <fcntl.h>
@@ -107,6 +108,12 @@ namespace V4L
static const unsigned int v4l2_fmt = V4L2_PIX_FMT_RGB24;
static const unsigned int v4l1_palette = VIDEO_PALETTE_RGB24;
};
+
+ template<> struct format<Rgb8>
+ {
+ static const unsigned int v4l2_fmt = V4L2_PIX_FMT_RGB32;
+ static const unsigned int v4l1_palette = VIDEO_PALETTE_RGB32;
+ };
#endif
class V4L2Client
View
9 cvd/videosource.h
@@ -104,7 +104,7 @@ namespace CVD {
void get_files_options(const VideoSource& vs, int& fps, int& ra_frames, VideoBufferFlags::OnEndOfBuffer& eob);
#if CVD_HAVE_V4L1BUFFER
- template <class T> VideoBuffer<T>* makeV4L1Buffer(const std::string& dev, const ImageRef& size)
+ template <class T> VideoBuffer<T>* makeV4L1Buffer(const std::string&, const ImageRef& )
{
throw VideoSourceException("V4L1Buffer cannot handle types other than byte, bayer, yuv422, Rgb<byte>");
}
@@ -129,6 +129,7 @@ namespace CVD {
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);
+ template <> VideoBuffer<Rgb8>* 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, bool& verbose);
@@ -136,7 +137,7 @@ namespace CVD {
#if CVD_HAVE_FFMPEG
- template <class T> VideoBuffer<T>* makeVideoFileBuffer(const std::string& file, VideoBufferFlags::OnEndOfBuffer eob)
+ template <class T> VideoBuffer<T>* makeVideoFileBuffer(const std::string& , VideoBufferFlags::OnEndOfBuffer )
{
throw VideoSourceException("VideoFileBuffer cannot handle types other than byte, Rgb<byte>");
}
@@ -149,7 +150,7 @@ namespace CVD {
#endif
#if CVD_HAVE_DVBUFFER
- template <class T> VideoBuffer<T>* makeDVBuffer2(int cam, int dmabufs, int bright, int exposure, int fps)
+ template <class T> VideoBuffer<T>* makeDVBuffer2(int , int , int , int , int )
{
throw VideoSourceException("DVBuffer2 cannot handle types other than byte, Rgb<byte>");
}
@@ -162,7 +163,7 @@ namespace CVD {
#endif
#if CVD_HAVE_QTBUFFER
- template <class T> VideoBuffer<T> * makeQTBuffer( const ImageRef & size, int input, bool showsettings)
+ template <class T> VideoBuffer<T> * makeQTBuffer( const ImageRef & , int , bool )
{
throw VideoSourceException("QTBuffer cannot handle types other than vuy422");
}
View
5 cvd_src/Linux/v4l2buffer.cc
@@ -289,8 +289,9 @@ V4L2Buffer_Base::V4L2Buffer_Base(const char *devname, bool fields, V4L2BufferBlo
sv4l2RequestBuffers.count=num_buffers;
sv4l2RequestBuffers.type=V4L2_BUF_TYPE_VIDEO_CAPTURE; //|V4L2_BUF_ATTR_DEVICEMEM;
sv4l2RequestBuffers.memory=V4L2_MEMORY_MMAP;
-
- if(0!=ioctl(m_nVideoFileDesc,VIDIOC_REQBUFS,&sv4l2RequestBuffers))
+
+ //bttv now returns num_buffers
+ if(ioctl(m_nVideoFileDesc,VIDIOC_REQBUFS,&sv4l2RequestBuffers)==-1)
throw Exceptions::V4L2Buffer::DeviceSetup(devname, "Request capture buffers");
num_buffers = sv4l2RequestBuffers.count;
View
43 cvd_src/Linux/v4lbuffer.cc
@@ -186,10 +186,6 @@ namespace V4L { // V4L
{
actual_fmt = f.pixelformat;
}
-
- //Turbobodge!!!! Remove this!! FIXME FIXME FIXME
- if(fmt == fourcc("RGB3") && f.pixelformat == fourcc("BGR3"))
- actual_fmt = f.pixelformat;
}
if(errno != EINVAL)
@@ -199,7 +195,7 @@ namespace V4L { // V4L
log << "Seleced format: " << unfourcc(fmt) << "\n";
-/* if (caps.driver == string("bttv"))
+ if (strcmp((const char*)caps.driver,"bttv") == 0)
{
v4l2_std_id stdId=V4L2_STD_PAL;
if(ioctl(fd, VIDIOC_S_STD, &stdId ))
@@ -212,7 +208,7 @@ namespace V4L { // V4L
if (0 != ioctl(fd, VIDIOC_S_INPUT, &v4l2Input))
throw string("VIDIOC_S_INPUT");
}
-*/
+
// Get / Set capture format.
struct v4l2_format format;
format.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -234,17 +230,27 @@ namespace V4L { // V4L
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";
-
+ log << "Setting format (VIDIOC_S_FMT)\n";
+ log << " size: " << format.fmt.pix.width << "x" << format.fmt.pix.height << "\n";
+ log << " format: " << unfourcc(format.fmt.pix.pixelformat) << "\n";
+ log << " field flag: " << format.fmt.pix.field << "\n";
+ log << " bytes per line: " << format.fmt.pix.bytesperline << "\n";
+ log << " image size: " << format.fmt.pix.sizeimage << "\n";
+ log << " colourspace: " << format.fmt.pix.colorspace << "\n";
+
if (0 != ioctl(fd, VIDIOC_S_FMT, &format))
throw string("VIDIOC_S_FMT");
+ log << "Getting format (VIDIOC_G_FMT)\n";
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";
+ log << " size: " << format.fmt.pix.width << "x" << format.fmt.pix.height << "\n";
+ log << " format: " << unfourcc(format.fmt.pix.pixelformat) << "\n";
+ log << " field flag: " << format.fmt.pix.field << "\n";
+ log << " bytes per line: " << format.fmt.pix.bytesperline << "\n";
+ log << " image size: " << format.fmt.pix.sizeimage << "\n";
+ log << " colourspace: " << format.fmt.pix.colorspace << "\n";
if (fmt != format.fmt.pix.pixelformat)
@@ -254,12 +260,21 @@ namespace V4L { // V4L
reqbufs.count = 10;
reqbufs.memory = V4L2_MEMORY_MMAP;
reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (0 != ioctl(fd,VIDIOC_REQBUFS,&reqbufs))
- throw string("VIDIOC_REQBUFS");
- cerr << "wtttf\n";
+ log << "Issuing VIDIOC_REQBUFS ioctl.\n";
+ int ret = ioctl(fd,VIDIOC_REQBUFS,&reqbufs);
+ log << " Return code: " << ret << "\n";
+
+ //WARNING!!!!!
+ //The documentation says -1 for error, 0 otherwise.
+ //The BTTV driver returns num_bufs on success!
+ //So the test against 0 fails.
+ if (ioctl(fd,VIDIOC_REQBUFS,&reqbufs) == -1)
+ throw string("VIDIOC_REQBUFS");
num_bufs = reqbufs.count;
+
+ log << "Number of buffers: " << num_bufs << "\n";
if (reqbufs.count < 2)
throw string("Insufficient buffers available");
View
6 cvd_src/videosource.cpp
@@ -336,11 +336,17 @@ namespace CVD {
return new CVD::V4LBuffer<CVD::Rgb<CVD::byte> >(dev, size, input, interlaced, 0, verbose);
}
+ template <> CVD::VideoBuffer<CVD::Rgb8>* makeV4LBuffer(const std::string& dev, const CVD::ImageRef& size, int input, bool interlaced, bool verbose)
+ {
+ return new CVD::V4LBuffer<CVD::Rgb8>(dev, size, input, interlaced, 0, verbose);
+ }
+
void get_v4l2_options(const VideoSource& vs, ImageRef& size, int& input, bool& interlaced, bool& verbose)
{
size = ImageRef(640,480);
input = -1;
interlaced = false;
+ verbose=0;
for (VideoSource::option_list::const_iterator it=vs.options.begin(); it != vs.options.end(); ++it) {
if (it->first == "size") {
std::string s = it->second;
View
23 progs/video_play_source.cc
@@ -44,7 +44,8 @@ template<class C> void play(string s)
VideoDisplay display(buffer->size());
- while(buffer->frame_pending())
+ //while(buffer->frame_pending())
+ for(;;)
{
VideoFrame<C>* frame = buffer->get_frame();
glDrawPixels(*frame);
@@ -55,14 +56,22 @@ template<class C> void play(string s)
int main(int argc, char* argv[])
{
- bool mono=0;
+ int type =0;
int arg=1;
- if(argc-1 >=1 && argv[arg] == string("-mono"))
+ if(argc-1 >=1)
{
- arg++;
- mono=1;
+ if(argv[arg] == string("-mono"))
+ {
+ arg++;
+ type=1;
+ }
+ else if(argv[arg] == string("-rgb8"))
+ {
+ arg++;
+ type=2;
+ }
}
if(arg != argc-1)
@@ -72,8 +81,10 @@ int main(int argc, char* argv[])
}
try
{
- if(mono)
+ if(type == 1)
play<byte>(argv[arg]);
+ else if(type == 2)
+ play<Rgb8>(argv[arg]);
else
play<Rgb<byte> >(argv[arg]);
}
Please sign in to comment.
Something went wrong with that request. Please try again.