From 8b3ec9e74e7553243589b1ca8c221e435b5b2823 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Thu, 18 Aug 2011 14:20:34 +0200 Subject: [PATCH] qv4l2: don't change the format just because we use libv4l2. So some reason qv4l2 switched to the RGB24 format if the video node was opened through libv4l2. This is a completely unexpected side-effect that should not happen, especially since qv4l2 is usually used as a test utility. This may mean that a frame is converted twice: once inside libv4l2, then to get it into a format suitable for the screen. But that's OK. After all, that's what you asked for. Signed-off-by: Hans Verkuil --- utils/qv4l2/qv4l2.cpp | 37 +++++++++++++++---------------------- utils/qv4l2/qv4l2.h | 1 + 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/utils/qv4l2/qv4l2.cpp b/utils/qv4l2/qv4l2.cpp index 4102939..0fd17ab 100644 --- a/utils/qv4l2/qv4l2.cpp +++ b/utils/qv4l2/qv4l2.cpp @@ -188,12 +188,12 @@ void ApplicationWindow::capFrame() } return; } - if (useWrapper()) - memcpy(m_capImage->bits(), m_frameData, s); - else + if (m_mustConvert) err = v4lconvert_convert(m_convertData, &m_capSrcFormat, &m_capDestFormat, m_frameData, s, m_capImage->bits(), m_capDestFormat.fmt.pix.sizeimage); + else + memcpy(m_capImage->bits(), m_frameData, s); break; case methodMmap: @@ -205,13 +205,13 @@ void ApplicationWindow::capFrame() if (again) return; - if (useWrapper()) - memcpy(m_capImage->bits(), (unsigned char *)m_buffers[buf.index].start, - buf.bytesused); - else + if (m_mustConvert) err = v4lconvert_convert(m_convertData, &m_capSrcFormat, &m_capDestFormat, (unsigned char *)m_buffers[buf.index].start, buf.bytesused, m_capImage->bits(), m_capDestFormat.fmt.pix.sizeimage); + else + memcpy(m_capImage->bits(), (unsigned char *)m_buffers[buf.index].start, + buf.bytesused); qbuf(buf); break; @@ -230,13 +230,13 @@ void ApplicationWindow::capFrame() && buf.length == m_buffers[i].length) break; - if (useWrapper()) - memcpy(m_capImage->bits(), (unsigned char *)buf.m.userptr, - buf.bytesused); - else + if (m_mustConvert) err = v4lconvert_convert(m_convertData, &m_capSrcFormat, &m_capDestFormat, (unsigned char *)buf.m.userptr, buf.bytesused, m_capImage->bits(), m_capDestFormat.fmt.pix.sizeimage); + else + memcpy(m_capImage->bits(), (unsigned char *)buf.m.userptr, + buf.bytesused); qbuf(buf); break; @@ -438,34 +438,27 @@ void ApplicationWindow::capStart(bool start) } m_capMethod = m_genTab->capMethod(); g_fmt_cap(m_capSrcFormat); - if (useWrapper() && - m_capSrcFormat.fmt.pix.pixelformat != V4L2_PIX_FMT_RGB24) { - v4l2_fract interval; - bool interval_ok = get_interval(interval); - m_capSrcFormat.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24; - s_fmt(m_capSrcFormat); - g_fmt_cap(m_capSrcFormat); - if (interval_ok) - set_interval(interval); - } m_frameData = new unsigned char[m_capSrcFormat.fmt.pix.sizeimage]; m_capDestFormat = m_capSrcFormat; m_capDestFormat.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24; + m_mustConvert = true; for (int i = 0; supported_fmts[i].v4l2_pixfmt; i++) { if (supported_fmts[i].v4l2_pixfmt == m_capSrcFormat.fmt.pix.pixelformat) { m_capDestFormat.fmt.pix.pixelformat = supported_fmts[i].v4l2_pixfmt; dstFmt = supported_fmts[i].qt_pixfmt; + m_mustConvert = false; break; } } - if (!useWrapper()) { + if (m_mustConvert) { v4lconvert_try_format(m_convertData, &m_capDestFormat, &m_capSrcFormat); // v4lconvert_try_format sometimes modifies the source format if it thinks // that there is a better format available. Restore our selected source // format since we do not want that happening. g_fmt_cap(m_capSrcFormat); } + m_capture->setMinimumSize(m_capDestFormat.fmt.pix.width, m_capDestFormat.fmt.pix.height); m_capImage = new QImage(m_capDestFormat.fmt.pix.width, m_capDestFormat.fmt.pix.height, dstFmt); m_capImage->fill(0); diff --git a/utils/qv4l2/qv4l2.h b/utils/qv4l2/qv4l2.h index 0a3e5ef..1cbbbb3 100644 --- a/utils/qv4l2/qv4l2.h +++ b/utils/qv4l2/qv4l2.h @@ -91,6 +91,7 @@ private: unsigned char *m_frameData; unsigned m_nbuffers; struct v4lconvert_data *m_convertData; + bool m_mustConvert; CapMethod m_capMethod; private slots: -- 2.7.4