QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GStreamerVideoBackend.cc
Go to the documentation of this file.
2
3#include <QtCore/QCoreApplication>
4
5#include "GStreamer.h"
8#include "GStreamerSelfTest.h"
9#include "GstVideoReceiver.h"
10#include "HwBuffers/HwBuffers.h"
11#include "QGCLoggingCategory.h"
13
14QGC_LOGGING_CATEGORY(GStreamerVideoBackendLog, "Video.GStreamer.VideoBackend")
15
16#ifdef Q_OS_ANDROID
17#include <jni.h>
18
19// GStreamer's Android plugins (e.g. androidmedia) look up the JNI state in libgstreamer_android.so, which keeps what
20// this sets (Platform/gst_android_jni.c).
21extern "C" void qgc_gst_android_set_jni_state(JavaVM* javaVm, jobject context, jobject classLoader);
22#endif
23
25{
26 HwBuffers::configureQtGraphics(softwareRendering);
27}
28
30{
31#ifdef QGC_HAS_ANY_GPU_PATH
32 constexpr bool gpuVideoPath = true;
33#else
34 constexpr bool gpuVideoPath = false;
35#endif
36 return {.streaming = true, .pipelineSettings = true, .gpuVideoPath = gpuVideoPath, .asyncInit = true};
37}
38
40{
41 // GStreamer's setup isn't retried, so nothing plays through it in this process any more.
42 if (state() == State::Failed) {
43 return new QtMultimediaVideoReceiver(parent);
44 }
45 return new GstVideoReceiver(parent);
46}
47
49{
50 if (state() != State::Unprepared) {
51 qCWarning(GStreamerVideoBackendLog) << "Environment prepared again after GStreamer setup started";
52 }
54 State expected = State::Unprepared;
55 (void) _state.compare_exchange_strong(expected, State::Prepared, std::memory_order_acq_rel);
56 return result;
57}
58
60{
61 switch (state()) {
63 return true;
64 case State::Failed:
65 return false;
67 qCWarning(GStreamerVideoBackendLog) << "Initializing GStreamer without preparing its environment";
68 break;
69 case State::Prepared:
70 break;
71 }
72 const bool initialized = GStreamer::initialize(params);
73 _state.store(initialized ? State::Initialized : State::Failed, std::memory_order_release);
74 return initialized;
75}
76
78{
79 return QCoreApplication::translate("GStreamerVideoBackend",
80 "GStreamer failed to initialize, so video streams are played by Qt Multimedia "
81 "instead. The application log has the details.");
82}
83
85{
86 if (state() != State::Initialized) {
87 qCWarning(GStreamerVideoBackendLog) << "GStreamer self-test skipped: GStreamer isn't initialized";
88 return false;
89 }
91}
92
97
102
107
109{
111}
112
113void GStreamerVideoBackend::setAndroidJniState([[maybe_unused]] void* javaVm, [[maybe_unused]] void* appContext,
114 [[maybe_unused]] void* classLoader)
115{
116#ifdef Q_OS_ANDROID
117 qgc_gst_android_set_jni_state(static_cast<JavaVM*>(javaVm), static_cast<jobject>(appContext),
118 static_cast<jobject>(classLoader));
119#endif
120}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
VideoDecoderOption
The decoders VideoSettings' forceVideoDecoder can force. The values are persisted.
void setDebugLevel(int level) override
Capabilities capabilities() const override
void configureQtGraphics(bool softwareRendering) override
void onMainWindowReady(QQuickWindow *window) override
bool selfTest() override
GStreamer::SelfTest::run() once initialized; false, logged, otherwise.
void applyDecoderPriorities(VideoDecoderOption option) override
QString initFailureMessage() const override
What to tell the user once initialize() has failed: what failed, and what plays the streams instead.
QList< VideoDecoderOption > availableDecoderFamilies() override
The hardware decoder families present, as forceVideoDecoder values (never Default or Software).
@ Prepared
The environment is set up for gst_init().
@ Initialized
GStreamer runs, with the plugins video needs.
@ Failed
initialize() failed; Qt Multimedia plays the streams.
bool initialize(const InitParams &params) override
GStreamer::initialize() the first time; afterwards that call's outcome.
void setAndroidJniState(void *javaVm, void *appContext, void *classLoader) override
EnvPrepResult prepareEnvironment() override
Points GStreamer at its plugins, scanner and registry (GStreamer::Environment::prepareEnvironment()).
VideoReceiver * createReceiver(QObject *parent) override
A receiver that can play: once initialize() has failed, one that needs no initialization.
Also logs the receiver's worker, its PipelineSession with the branches, and PipelineDotDumper.
BundledRuntime bundledRuntime()
The bundled runtime the last prepareEnvironment() applied; empty before it ran.
VideoBackend::EnvPrepResult prepareEnvironment(const QString &appDir)
bool run(const Environment::BundledRuntime &runtime)
QList< VideoDecoderOption > availableDecoderFamilies()
void onMainWindowReady(QQuickWindow *window)
Definition GStreamer.cc:317
void setDebugLevel(int level)
void setCodecPriorities(VideoDecoderOption option)
DecoderRankApplier::apply() on the process's applier. GUI thread.
bool initialize(const VideoBackend::InitParams &params)
Definition GStreamer.cc:232
void configureQtGraphics(bool softwareRendering)
Definition HwBuffers.cc:141
What the backend offers.