From ded8d87ba811eac0cb45f6df0eb0d2c040a3b2e5 Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 26 Jan 2016 13:14:58 -0600 Subject: [PATCH] generic pixel format selection --- src/platform/camera/v4l2.cpp | 21 +++++++++++++++++++++ src/platform/camera/v4l2.h | 1 + src/video/cameradevice.cpp | 18 +++++++++++++++--- src/video/cameradevice.h | 2 ++ src/video/camerasource.cpp | 4 ++-- src/video/videomode.h | 4 +++- src/widget/form/settings/avform.cpp | 2 ++ 7 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/platform/camera/v4l2.cpp b/src/platform/camera/v4l2.cpp index 172bd4695..392542dff 100644 --- a/src/platform/camera/v4l2.cpp +++ b/src/platform/camera/v4l2.cpp @@ -113,6 +113,7 @@ QVector v4l2::getDeviceModes(QString devName) while(!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) { VideoMode mode; + mode.pixel_format = vfse.pixel_format; switch (vfse.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: mode.width = vfse.discrete.width; @@ -169,3 +170,23 @@ QVector> v4l2::getDeviceList() } return devices; } + +QString v4l2::getPixelFormatString(uint32_t pixel_format) +{ + if (pixel_format == V4L2_PIX_FMT_H264) + { + return QString("h264"); + } + if (pixel_format == V4L2_PIX_FMT_MJPEG) + { + return QString("mjpeg"); + } + else if (pixel_format == V4L2_PIX_FMT_YUYV) + { + return QString("yuyv422"); + } + else { + return QString("unknown"); + } +} + diff --git a/src/platform/camera/v4l2.h b/src/platform/camera/v4l2.h index a4a8292e3..8d82de9cd 100644 --- a/src/platform/camera/v4l2.h +++ b/src/platform/camera/v4l2.h @@ -32,6 +32,7 @@ namespace v4l2 { QVector getDeviceModes(QString devName); QVector> getDeviceList(); + QString getPixelFormatString(uint32_t pixel_format); } #endif // V4L2_H diff --git a/src/video/cameradevice.cpp b/src/video/cameradevice.cpp index f774bfb12..1d55da2ac 100644 --- a/src/video/cameradevice.cpp +++ b/src/video/cameradevice.cpp @@ -17,7 +17,6 @@ along with qTox. If not, see . */ - #include #include #include @@ -105,7 +104,7 @@ out: CameraDevice* CameraDevice::open(QString devName) { - VideoMode mode{0,0,0}; + VideoMode mode{0,0,0,0}; return open(devName, mode); } @@ -164,7 +163,11 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode) { av_dict_set(&options, "video_size", QString("%1x%2").arg(mode.width).arg(mode.height).toStdString().c_str(), 0); av_dict_set(&options, "framerate", QString().setNum(mode.FPS).toStdString().c_str(), 0); - av_dict_set(&options, "pixel_format", "mjpeg", 0); + const char *pixel_format = v4l2::getPixelFormatString(mode.pixel_format).toStdString().c_str(); + if (strncmp(pixel_format, "unknown", 7) != 0) + { + av_dict_set(&options, "pixel_format", pixel_format, 0); + } } #endif #ifdef Q_OS_OSX @@ -360,6 +363,15 @@ QVector CameraDevice::getVideoModes(QString devName) return {}; } +QString CameraDevice::getPixelFormatString(uint32_t pixel_format) +{ +#ifdef Q_OS_LINUX + return v4l2::getPixelFormatString(pixel_format); +#else + return QString("unknown"); +#endif +} + bool CameraDevice::getDefaultInputFormat() { QMutexLocker locker(&iformatLock); diff --git a/src/video/cameradevice.h b/src/video/cameradevice.h index 83209aeeb..ced3d4e14 100644 --- a/src/video/cameradevice.h +++ b/src/video/cameradevice.h @@ -59,6 +59,8 @@ public: /// Get the list of video modes for a device static QVector getVideoModes(QString devName); + /// Get the name of the pixel format of a video mode + static QString getPixelFormatString(uint32_t pixel_format); /// Returns the short name of the default defice /// This is either the device in the settings diff --git a/src/video/camerasource.cpp b/src/video/camerasource.cpp index 25fd5473c..dd1beb143 100644 --- a/src/video/camerasource.cpp +++ b/src/video/camerasource.cpp @@ -35,7 +35,7 @@ extern "C" { CameraSource* CameraSource::instance{nullptr}; CameraSource::CameraSource() - : deviceName{"none"}, device{nullptr}, mode(VideoMode{0,0,0}), + : deviceName{"none"}, device{nullptr}, mode(VideoMode{0,0,0,0}), cctx{nullptr}, cctxOrig{nullptr}, videoStreamIndex{-1}, _isOpen{false}, streamBlocker{false}, subscriptions{0} { @@ -67,7 +67,7 @@ void CameraSource::open() void CameraSource::open(const QString deviceName) { - open(deviceName, VideoMode{0,0,0}); + open(deviceName, VideoMode{0,0,0,0}); } void CameraSource::open(const QString DeviceName, VideoMode Mode) diff --git a/src/video/videomode.h b/src/video/videomode.h index d3e17f98b..c1628f439 100644 --- a/src/video/videomode.h +++ b/src/video/videomode.h @@ -26,6 +26,7 @@ struct VideoMode { unsigned short width, height; ///< Displayed video resolution (NOT frame resolution) float FPS; ///< Max frames per second supported by the device at this resolution + uint32_t pixel_format; /// All zeros means a default/unspecified mode operator bool() const @@ -37,7 +38,8 @@ struct VideoMode { return width == other.width && height == other.height - && FPS == other.FPS; + && FPS == other.FPS + && pixel_format == other.pixel_format; } }; diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 849eaa3f2..71534df05 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -187,6 +187,8 @@ void AVForm::updateVideoModes(int curIndex) str += tr("Default resolution"); if (mode.FPS) str += tr(" at %1 FPS").arg(mode.FPS); + if (mode.pixel_format) + str += tr(" using %1").arg(CameraDevice::getPixelFormatString(mode.pixel_format)); bodyUI->videoModescomboBox->addItem(str); } if (videoModes.isEmpty())