Indefinido até agora….


I Love Video4Linux!
Outubro 19, 2007, 2:21 pm
Arquivado em: Uncategorized

Fact, Video4Linux is crap not so good:

  1. It doesn’t have an userspace API like libasound, and forces everyone to rewrite everything;
  2. The API is not stable;
  3. The drivers don’t implement color conversion in kernel, so you have to do that too;
  4. V4L2 is almost 10 years old (it was created to fix some shortcomings of V4L1 and to support a wider range of devices), but a lot of drivers still use V4L1 (that is already obsolete),  then you have to implement support for both of them in your application.
  5. There isn’t a way to enumerate the supported resolutions in a video device, so you have to check that “brute forcing” the device!!

(code from Qtopia’s Camera App):

v4l2videocapturedevice.cpp
void V4L2VideoCaptureDevice::calcPhotoSizes()
{
QList<QSize> resolutions;

// standard resolutions – XGA, SVGA, VGA, CGA (roughly) and postage stamp
resolutions << QSize(1024, 768) << QSize(800, 600) << QSize(640, 480) << QSize(320, 200) << QSize(120, 120);

// test if the resolutions are supported (write back modifications)
QMutableListIterator<QSize> sizeIt(resolutions);

while (sizeIt.hasNext())
{
v4l2_format format;
QSize& currentSize = sizeIt.next();

memset(&format, 0, sizeof(format));

format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
format.fmt.pix.width = currentSize.width();
format.fmt.pix.height = currentSize.height();
format.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
format.fmt.pix.field = V4L2_FIELD_NONE;

if (ioctl(m_fd, VIDIOC_TRY_FMT, &format) == 0)
{
qWarning(“V4L2: Tried resolution & format (%d, %d, RGB4) – device wants (%d, %d, %4s)”,
currentSize.width(),
currentSize.height(),
format.fmt.pix.width,
format.fmt.pix.height,
(char const*)&format.fmt.pix.pixelformat);

unsigned int& imageType = m_imageTypes[QSize(format.fmt.pix.width, format.fmt.pix.height)];

if (imageType != V4L2_PIX_FMT_RGB32) // have been here? keep RGB32 if we can
{
imageType = format.fmt.pix.pixelformat;
}
}
}
}

(In fact there’s a experimental ioctl() that enumerates the supported resolutions, but that it’s not garanteed that it’s implemented in a driver, and it’s, well, experimental).

So, why there aren’t some kind of guidelines that “force” the drivers that are part of the official kernel tree to implement the necessary functions to, at least, make it easier to application developers?

P.S.: I know that there’s an effort to implement a userspace API, but it’s just in the beginning yet.