added width, height parameters to setFormat(), working to set YUYV format but not RGB formats I tried

git-svn-id: svn://anubis/misc/WebcamTracker@127 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2009-08-12 03:29:35 +00:00
parent d7d82a28c4
commit c261550290
2 changed files with 19 additions and 15 deletions

View File

@ -59,7 +59,7 @@ bool WebcamTracker::open(const char * device)
void WebcamTracker::start() void WebcamTracker::start()
{ {
setFormat(); setFormat(640, 480);
requestBuffers(20); requestBuffers(20);
for (int i = 0; i < m_numbufs; i++) for (int i = 0; i < m_numbufs; i++)
{ {
@ -240,7 +240,7 @@ WebcamTracker::~WebcamTracker()
} }
} }
void WebcamTracker::setFormat() void WebcamTracker::setFormat(int width, int height)
{ {
v4l2_format fmt; v4l2_format fmt;
memset(&fmt, 0, sizeof(fmt)); memset(&fmt, 0, sizeof(fmt));
@ -248,24 +248,28 @@ void WebcamTracker::setFormat()
int ret = ioctl(m_fd, VIDIOC_G_FMT, &fmt); int ret = ioctl(m_fd, VIDIOC_G_FMT, &fmt);
if (ret != 0) if (ret != 0)
{ {
cerr << "Warning: VIDIOC_G_FMT ioctl failed, errno " << errno; int err = errno;
if (errno == EBUSY) cerr << "Warning: VIDIOC_G_FMT ioctl failed, errno " << err;
if (err == EBUSY)
cerr << " (EBUSY)"; cerr << " (EBUSY)";
if (errno == EINVAL) if (err == EINVAL)
cerr << " (EINVAL)"; cerr << " (EINVAL)";
cerr << endl; cerr << endl;
} }
cerr << "width: " << fmt.fmt.pix.width << endl; fmt.fmt.pix.width = width;
cerr << "height: " << fmt.fmt.pix.height << endl; fmt.fmt.pix.height = height;
cerr << "pixelformat: "; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
for (int s = 0; s < 32; s += 8) fmt.fmt.pix.bytesperline = width * 2;
cerr << (char)((fmt.fmt.pix.pixelformat >> s) & 0xFF); fmt.fmt.pix.sizeimage = fmt.fmt.pix.bytesperline * height;
cerr << endl;
cerr << "field: " << fmt.fmt.pix.field << endl;
cerr << "bytesperline: " << fmt.fmt.pix.bytesperline << endl;
ret = ioctl(m_fd, VIDIOC_S_FMT, &fmt); ret = ioctl(m_fd, VIDIOC_S_FMT, &fmt);
if (ret != 0) if (ret != 0)
{ {
cerr << "Warning: VIDIOC_S_FMT ioctl failed, errno " << errno << endl; int err = errno;
cerr << "Warning: VIDIOC_S_FMT ioctl failed, errno " << err;
if (err == EBUSY)
cerr << " (EBUSY)";
if (err == EINVAL)
cerr << " (EINVAL)";
cerr << endl;
} }
} }

View File

@ -25,7 +25,7 @@ class WebcamTracker
void dequeueBuffer(v4l2_buffer * dqbuf); void dequeueBuffer(v4l2_buffer * dqbuf);
void unmapBuffer(int i); void unmapBuffer(int i);
void freeBuffers(); void freeBuffers();
void setFormat(); void setFormat(int width, int height);
bool m_open; bool m_open;
int m_fd; int m_fd;