Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <QIcon>
#include <QTimer>
#include "backend.h"
#include "mediautils.h"
#include "theme.h"
#include "translator.h"
#include "thumbprovider.h"

int main(int argc,char *argv[]) {
// Custom timestamped frame/buffer inputs require Qt's FFmpeg backend.
qputenv("QT_MEDIA_BACKEND","ffmpeg");
media::useFfmpeg();
QGuiApplication app(argc,argv);
app.setApplicationName("monologue");
app.setApplicationVersion("0.3.1");
Expand Down
8 changes: 8 additions & 0 deletions src/mediautils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ QString media::chooseSource(const QStringList &connected, const QString &preferr
if (connected.isEmpty() || connected.contains(remembered)) return remembered;
return connected.contains(preferred) ? preferred : connected.first();
}
void media::useFfmpeg() {
qputenv("QT_MEDIA_BACKEND", "ffmpeg");
// Loading the backend tries every hardware API before returning, about two
// seconds before the window can show, Vulkan alone most of one. Recording
// only needs the APIs behind NVENC (CUDA) and Intel and AMD's encoders (VA-API).
for (const char *variable : {"QT_FFMPEG_ENCODING_HW_DEVICE_TYPES", "QT_FFMPEG_DECODING_HW_DEVICE_TYPES"})
if (!qEnvironmentVariableIsSet(variable)) qputenv(variable, "cuda,vaapi");
}
double media::targetFps(double minimum, double maximum) { return std::clamp(30.0, minimum, maximum); }
int media::bestFormat(const QList<Format> &formats) {
int best = -1;
Expand Down
2 changes: 2 additions & 0 deletions src/mediautils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ QVideoFrameFormat::ColorSpace colorSpace(int v4l2Colorspace, int v4l2Encoding);
QVideoFrameFormat::ColorSpace cameraColorSpace(const QByteArray &device);
// Shares the source's image planes and capture times under a new format; later metadata changes stay independent.
QVideoFrame withFormat(const QVideoFrame &source, const QVideoFrameFormat &format);
// Chooses Qt's FFmpeg backend, which takes custom timestamped frames, before anything loads it.
void useFfmpeg();
double targetFps(double minimum, double maximum);
// The source to use: the remembered one while it's connected, else the default, else the first connected.
QString chooseSource(const QStringList &connected, const QString &preferred, const QString &remembered);
Expand Down
2 changes: 1 addition & 1 deletion tests/backend_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private slots:
}
};
int main(int argc,char**argv) {
qputenv("QT_MEDIA_BACKEND","ffmpeg");
media::useFfmpeg();
// Offscreen however it's started, so a test never opens a window on the desktop.
qputenv("QT_QPA_PLATFORM","offscreen");
// The desktop's platform theme plugin has no place in a test run.
Expand Down
3 changes: 2 additions & 1 deletion tests/camera_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include <QDir>
#include <QStandardPaths>
#include "backend.h"
#include "mediautils.h"
int main(int argc,char**argv) {
qputenv("QT_MEDIA_BACKEND","ffmpeg");
media::useFfmpeg();
QGuiApplication app(argc,argv);
app.setOrganizationName("omacom"); app.setApplicationName("monologue-camera-check");
Backend backend;
Expand Down
3 changes: 2 additions & 1 deletion tests/ui_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QVideoSink>
#include <QVideoFrame>
#include "theme.h"
#include "mediautils.h"

class UiTests : public QObject {
Q_OBJECT
Expand Down Expand Up @@ -302,7 +303,7 @@ QtObject {
}
};
int main(int argc,char**argv) {
qputenv("QT_MEDIA_BACKEND","ffmpeg");
media::useFfmpeg();
// Offscreen however it's started, so a test never opens a window on the desktop.
qputenv("QT_QPA_PLATFORM","offscreen");
// Rendered the same with or without a GPU, and without the desktop's platform theme plugin.
Expand Down
Loading