QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoStreamOutput.qml
Go to the documentation of this file.
1import QtQuick
2import QtMultimedia
3
4import QGroundControl
5
6// Displays a video stream: registers itself with the stream's controller, which hands it to the stream's receiver.
7VideoOutput {
8 id: root
9
10 /// The stream shown. The output follows a change of it: the main picture's stream is another one once a stream
11 /// in a tile takes its place.
12 required property VideoStreamController stream
13
14 property bool _completed: false
15 property VideoStreamController _registeredStream: null
16 // Qt defect, seen in Qt 6.12.0: QQuickVideoOutput::itemChange() never calls QQuickItem::itemChange()
17 // (qtmultimedia/src/multimediaquick/qquickvideooutput.cpp), so a VideoOutput emits no windowChanged and its own
18 // Window.window goes stale. Hence the parent's window; moving to another window (PiP pop-out) needs a
19 // re-registration. Once the minimum Qt has the fix, QGCQVideoSinkController can connect to windowChanged, and
20 // _window, _completed and on_WindowChanged can go.
21 readonly property QtObject _window: parent ? parent.Window.window : null
22 // A lost stream's last frame stays up while it reconnects; a stopped or replaced stream's is cleared.
23 readonly property bool _keepsFrame: root.stream.decoding || root.stream.reconnecting
24
25 // Registers with the stream, anew if it is the same one. The stream it leaves keeps playing into the output that
26 // takes over from this one, if one registers in the same pass.
27 function _register() {
28 if (root._registeredStream && root._registeredStream !== root.stream) {
29 root._registeredStream.unregisterVideoOutput(root)
30 }
31 root._registeredStream = root.stream
32 root.stream.registerVideoOutput(root)
33 }
34
35 // The rotation the camera reports for the stream (VIDEO_STREAM_INFORMATION.rotation). VideoOutput applies its
36 // orientation on top of each frame's own rotation and mirroring, which qgcqvideosink takes from the stream's
37 // orientation tag: a stream that carries a tag and also reports a rotation is turned by both.
38 orientation: root.stream.rotation
39 endOfStreamPolicy: VideoOutput.KeepLastFrame
40 opacity: root.stream.decoding ? 1 : 0.5
41
42 on_KeepsFrameChanged: {
43 if (!root._keepsFrame) {
44 root.clearOutput()
45 }
46 }
47
48 on_WindowChanged: {
49 if (root._completed && root._window) {
50 root._register()
51 }
52 }
53
54 onStreamChanged: {
55 if (root._completed) {
56 root._register()
57 }
58 }
59
60 Component.onCompleted: {
61 root._completed = true
62 root._register()
63 }
64
65 Component.onDestruction: {
66 if (root._registeredStream) {
67 root._registeredStream.unregisterVideoOutput(root)
68 }
69 }
70}