mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
generic pixel format selection
This commit is contained in:
parent
c82e41ff6f
commit
ded8d87ba8
|
@ -113,6 +113,7 @@ QVector<VideoMode> v4l2::getDeviceModes(QString devName)
|
||||||
|
|
||||||
while(!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) {
|
while(!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) {
|
||||||
VideoMode mode;
|
VideoMode mode;
|
||||||
|
mode.pixel_format = vfse.pixel_format;
|
||||||
switch (vfse.type) {
|
switch (vfse.type) {
|
||||||
case V4L2_FRMSIZE_TYPE_DISCRETE:
|
case V4L2_FRMSIZE_TYPE_DISCRETE:
|
||||||
mode.width = vfse.discrete.width;
|
mode.width = vfse.discrete.width;
|
||||||
|
@ -169,3 +170,23 @@ QVector<QPair<QString, QString>> v4l2::getDeviceList()
|
||||||
}
|
}
|
||||||
return devices;
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace v4l2
|
||||||
{
|
{
|
||||||
QVector<VideoMode> getDeviceModes(QString devName);
|
QVector<VideoMode> getDeviceModes(QString devName);
|
||||||
QVector<QPair<QString, QString>> getDeviceList();
|
QVector<QPair<QString, QString>> getDeviceList();
|
||||||
|
QString getPixelFormatString(uint32_t pixel_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // V4L2_H
|
#endif // V4L2_H
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
|
@ -105,7 +104,7 @@ out:
|
||||||
|
|
||||||
CameraDevice* CameraDevice::open(QString devName)
|
CameraDevice* CameraDevice::open(QString devName)
|
||||||
{
|
{
|
||||||
VideoMode mode{0,0,0};
|
VideoMode mode{0,0,0,0};
|
||||||
return open(devName, mode);
|
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, "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, "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
|
#endif
|
||||||
#ifdef Q_OS_OSX
|
#ifdef Q_OS_OSX
|
||||||
|
@ -360,6 +363,15 @@ QVector<VideoMode> CameraDevice::getVideoModes(QString devName)
|
||||||
return {};
|
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()
|
bool CameraDevice::getDefaultInputFormat()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&iformatLock);
|
QMutexLocker locker(&iformatLock);
|
||||||
|
|
|
@ -59,6 +59,8 @@ public:
|
||||||
|
|
||||||
/// Get the list of video modes for a device
|
/// Get the list of video modes for a device
|
||||||
static QVector<VideoMode> getVideoModes(QString devName);
|
static QVector<VideoMode> 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
|
/// Returns the short name of the default defice
|
||||||
/// This is either the device in the settings
|
/// This is either the device in the settings
|
||||||
|
|
|
@ -35,7 +35,7 @@ extern "C" {
|
||||||
CameraSource* CameraSource::instance{nullptr};
|
CameraSource* CameraSource::instance{nullptr};
|
||||||
|
|
||||||
CameraSource::CameraSource()
|
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},
|
cctx{nullptr}, cctxOrig{nullptr}, videoStreamIndex{-1},
|
||||||
_isOpen{false}, streamBlocker{false}, subscriptions{0}
|
_isOpen{false}, streamBlocker{false}, subscriptions{0}
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ void CameraSource::open()
|
||||||
|
|
||||||
void CameraSource::open(const QString deviceName)
|
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)
|
void CameraSource::open(const QString DeviceName, VideoMode Mode)
|
||||||
|
|
|
@ -26,6 +26,7 @@ struct VideoMode
|
||||||
{
|
{
|
||||||
unsigned short width, height; ///< Displayed video resolution (NOT frame resolution)
|
unsigned short width, height; ///< Displayed video resolution (NOT frame resolution)
|
||||||
float FPS; ///< Max frames per second supported by the device at this 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
|
/// All zeros means a default/unspecified mode
|
||||||
operator bool() const
|
operator bool() const
|
||||||
|
@ -37,7 +38,8 @@ struct VideoMode
|
||||||
{
|
{
|
||||||
return width == other.width
|
return width == other.width
|
||||||
&& height == other.height
|
&& height == other.height
|
||||||
&& FPS == other.FPS;
|
&& FPS == other.FPS
|
||||||
|
&& pixel_format == other.pixel_format;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,8 @@ void AVForm::updateVideoModes(int curIndex)
|
||||||
str += tr("Default resolution");
|
str += tr("Default resolution");
|
||||||
if (mode.FPS)
|
if (mode.FPS)
|
||||||
str += tr(" at %1 FPS").arg(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);
|
bodyUI->videoModescomboBox->addItem(str);
|
||||||
}
|
}
|
||||||
if (videoModes.isEmpty())
|
if (videoModes.isEmpty())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user