1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Properly set desktop capture region

We now capture the full screen by default, with code to handle modesetting, instead of always the FFmpeg default region of 1024x768
This commit is contained in:
tux3 2015-06-02 00:34:38 +02:00
parent bc946308c8
commit 37a3a8d9d6

View File

@ -1,4 +1,6 @@
#include <QDebug> #include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
extern "C" { extern "C" {
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavdevice/avdevice.h> #include <libavdevice/avdevice.h>
@ -61,7 +63,8 @@ out:
CameraDevice* CameraDevice::open(QString devName) CameraDevice* CameraDevice::open(QString devName)
{ {
return open(devName, nullptr); VideoMode mode{};
return open(devName, mode);
} }
CameraDevice* CameraDevice::open(QString devName, VideoMode mode) CameraDevice* CameraDevice::open(QString devName, VideoMode mode)
@ -71,21 +74,40 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode)
AVDictionary* options = nullptr; AVDictionary* options = nullptr;
if (false); if (false);
#ifdef Q_OS_LINUX
else if (devName.startsWith("x11grab#"))
{
QSize screen;
if (mode)
{
screen.setWidth(mode.width);
screen.setHeight(mode.height);
}
else
{
screen = QApplication::desktop()->screenGeometry().size();
// Workaround https://trac.ffmpeg.org/ticket/4574 by choping 1 px bottom and right
screen.setWidth(screen.width()-1);
screen.setHeight(screen.height()-1);
}
av_dict_set(&options, "video_size", QString("%1x%2").arg(screen.width()).arg(screen.height()).toStdString().c_str(), 0);
}
#endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
else if (iformat->name == QString("dshow")) else if (iformat->name == QString("dshow") && 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);
} }
#endif #endif
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
else if (iformat->name == QString("video4linux2,v4l2")) else if (iformat->name == QString("video4linux2,v4l2") && 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);
} }
#endif #endif
else else if (mode)
{ {
qWarning() << "Video mode-setting not implemented for input "<<iformat->name; qWarning() << "Video mode-setting not implemented for input "<<iformat->name;
(void)mode; (void)mode;