qv4l2: Check and use result of read()
authorHans de Goede <hdegoede@redhat.com>
Fri, 31 Dec 2010 10:50:28 +0000 (11:50 +0100)
committerHans Verkuil <hverkuil@xs4all.nl>
Fri, 31 Dec 2010 15:06:07 +0000 (16:06 +0100)
qv4l2 was calling libv4lconvert_convert with a src size of fmt.pix.sizeimage,
rather then using the actual amount of bytes read. This causes decompressors
which check if they have consumed the entire compressed frame (ie pjpg) to
error out, because they were not being passed the actual frame size.

This patch fixes this, and also adds reporting of libv4lconvert_convert
errors.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
utils/qv4l2/qv4l2.cpp

index a085f86..1876b3c 100644 (file)
@@ -178,11 +178,18 @@ void ApplicationWindow::capFrame()
        switch (m_capMethod) {
        case methodRead:
                s = read(m_frameData, m_capSrcFormat.fmt.pix.sizeimage);
+               if (s < 0) {
+                       if (errno != EAGAIN) {
+                               error("read");
+                               m_capStartAct->setChecked(false);
+                       }
+                       return;
+               }
                if (useWrapper())
-                       memcpy(m_capImage->bits(), m_frameData, m_capSrcFormat.fmt.pix.sizeimage);
+                       memcpy(m_capImage->bits(), m_frameData, s);
                else
                        err = v4lconvert_convert(m_convertData, &m_capSrcFormat, &m_capDestFormat,
-                               m_frameData, m_capSrcFormat.fmt.pix.sizeimage,
+                               m_frameData, s,
                                m_capImage->bits(), m_capDestFormat.fmt.pix.sizeimage);
                break;
 
@@ -227,6 +234,9 @@ void ApplicationWindow::capFrame()
                qbuf(buf);
                break;
        }
+       if (err == -1)
+               error(v4lconvert_get_error_message(m_convertData));
+
        m_capture->setImage(*m_capImage);
        if (m_capture->frame() == 1)
                refresh();