blob: b08d19325b11ac5e87dcd4d51d5ca73a44498c4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import frequencymonitor
Rectangle {
id: root
border.color: palette.window
border.width: showBorder ? 1 : 0
color: "transparent"
property string contentType // "camera" or "video"
property string source
property real volume
property bool dummy: false
property bool autoStart: true
property bool started: false
property bool showFrameRate: false
property bool showBorder: false
property alias contentItem: contentLoader.item
signal initialized
signal error
signal videoFramePainted
Loader {
id: contentLoader
}
Connections {
id: framePaintedConnection
function onFramePainted() {
(frameRateLoader.item as FrequencyItem)?.notify()
root.videoFramePainted()
}
ignoreUnknownSignals: true
}
Connections {
id: errorConnection
function onFatalError() {
console.log("[qmlvideo] Content.onFatalError")
root.stop()
root.error()
}
ignoreUnknownSignals: true
}
Component {
id: frequencyItem
FrequencyItem {}
}
Loader {
id: frameRateLoader
sourceComponent: root.showFrameRate ? frequencyItem : undefined
onLoaded: {
item.parent = root
item.anchors.top = root.top
item.anchors.right = root.right
item.anchors.margins = 10
}
}
onWidthChanged: {
if (root.contentItem)
root.contentItem.width = width
}
onHeightChanged: {
if (root.contentItem)
root.contentItem.height = height
}
function initialize() {
if ("video" == contentType) {
contentLoader.source = "VideoItem.qml"
if (Loader.Error == contentLoader.status) {
contentLoader.source = "VideoDummy.qml"
dummy = true
}
contentLoader.item.volume = volume
} else if ("camera" == contentType) {
contentLoader.source = "CameraItem.qml"
if (Loader.Error == contentLoader.status) {
contentLoader.source = "CameraDummy.qml"
dummy = true
}
} else {
console.log("[qmlvideo] Content.initialize: error: invalid contentType")
}
if (contentLoader.item) {
contentLoader.item.sizeChanged.connect(updateRootSize)
contentLoader.item.parent = root
contentLoader.item.width = root.width
framePaintedConnection.target = contentLoader.item
errorConnection.target = contentLoader.item
if (root.autoStart)
root.start()
}
root.initialized()
}
function start() {
if (contentLoader.item) {
if (root.contentType == "video")
contentLoader.item.mediaSource = root.source
contentLoader.item.start()
root.started = true
}
}
// qmllint disable
function stop() {
if (contentLoader.item) {
contentLoader.item.stop()
if (root.contentType == "video")
contentLoader.item.mediaSource = ""
root.started = false
}
}
// qmllint enable
function updateRootSize() { root.height = (root.contentItem as Item).height }
}
|