VideoOutputAddEdit.qml
10.8 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/* Webcamoid, webcam capture application.
* Copyright (C) 2020 Gonzalo Exequiel Pedone
*
* Webcamoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Webcamoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Webcamoid. If not, see <http://www.gnu.org/licenses/>.
*
* Web-Site: http://webcamoid.github.io/
*/
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Ak
import Webcamoid
Dialog {
id: addEdit
standardButtons: Dialog.Ok | Dialog.Cancel
width: AkUnit.create(450 * AkTheme.controlScale, "dp").pixels
height: AkUnit.create(350 * AkTheme.controlScale, "dp").pixels
modal: true
signal edited()
signal openErrorDialog(string title, string message)
signal openOutputFormatDialog(int index, variant caps)
function addFormat(caps)
{
let component = Qt.createComponent("VideoFormatItem.qml")
if (component.status !== Component.Ready)
return
let obj = component.createObject(vcamFormats)
let format = AkVideoCaps.pixelFormatToString(caps.format)
let fps = AkFrac.create(caps.fps)
obj.text =
format
+ " " + caps.width + "x" + caps.height
+ " " + fps.value + " FPS"
obj.format = caps.format
obj.formatWidth = caps.width
obj.formatHeight = caps.height
obj.fps = fps.value
vcamFormats.minHeight += obj.height
obj.onClicked.connect((index => function () {
let element = vcamFormats.itemAt(index)
let caps =
AkVideoCaps.create(element.format,
element.formatWidth,
element.formatHeight,
AkFrac.create(element.fps,
1).toVariant())
addEdit.openOutputFormatDialog(index, caps)
})(vcamFormats.count - 1))
}
function changeFormat(index, caps)
{
let item = vcamFormats.itemAt(index)
if (!item)
return
let format = AkVideoCaps.pixelFormatToString(caps.format)
let fps = AkFrac.create(caps.fps)
item.text =
format
+ " " + caps.width + "x" + caps.height
+ " " + fps.value + " FPS"
item.format = caps.format
item.formatWidth = caps.width
item.formatHeight = caps.height
item.fps = fps.value
}
function removeFormat(index)
{
vcamFormats.removeItem(vcamFormats.itemAt(index))
}
function isSupported(format)
{
let formats = videoLayer.supportedOutputPixelFormats
for (let i in formats)
if (formats[i] == format)
return true
return false
}
function populateFormats()
{
let formats = []
if (deviceId.text) {
let outputCaps = videoLayer.supportedOutputVideoCaps(deviceId.text)
for (let caps in outputCaps)
formats.push(AkVideoCaps.create(outputCaps[caps]))
} else {
let defaultPixelFormats = [
AkVideoCaps.Format_yuyv422,
AkVideoCaps.Format_uyvy422,
AkVideoCaps.Format_xrgb,
AkVideoCaps.Format_rgb24
]
let pixelFormats = []
for (let i in defaultPixelFormats)
if (isSupported(defaultPixelFormats[i]))
pixelFormats.push(defaultPixelFormats[i])
let resolutions = [
Qt.size( 640, 480),
Qt.size( 160, 120),
Qt.size( 320, 240),
Qt.size( 800, 600),
Qt.size(1280, 720),
Qt.size(1920, 1080),
]
for (let format in pixelFormats)
for (let resolution in resolutions)
formats.push(AkVideoCaps.create(pixelFormats[format],
resolutions[resolution].width,
resolutions[resolution].height,
AkFrac.create(30, 1).toVariant()))
}
vcamFormats.clear()
for (let i in formats) {
let component = Qt.createComponent("VideoFormatItem.qml")
if (component.status !== Component.Ready)
continue
let obj = component.createObject(vcamFormats)
let caps = formats[i]
let format = AkVideoCaps.pixelFormatToString(caps.format)
let fps = AkFrac.create(caps.fps)
obj.text =
format
+ " " + caps.width + "x" + caps.height
+ " " + fps.value + " FPS"
obj.format = caps.format
obj.formatWidth = caps.width
obj.formatHeight = caps.height
obj.fps = fps.value
vcamFormats.minHeight += obj.height
obj.onClicked.connect((index => function () {
let element = vcamFormats.itemAt(index)
let caps =
AkVideoCaps.create(element.format,
element.formatWidth,
element.formatHeight,
AkFrac.create(element.fps,
1).toVariant())
addEdit.openOutputFormatDialog(index, caps)
})(i))
}
}
function openOptions(device)
{
title = device?
qsTr("Edit Virtual Camera"):
qsTr("Add Virtual Camera")
if (device)
deviceDescription.text = videoLayer.description(device)
else
deviceDescription.text =
"Virtual Camera " + mediaTools.currentTime("yyyyMMddhhmmss")
deviceId.text = device
populateFormats()
open()
}
onVisibleChanged: deviceDescription.forceActiveFocus()
ScrollView {
id: formatsView
anchors.fill: parent
contentHeight: formatsControls.height
clip: true
ColumnLayout {
id: formatsControls
width: formatsView.width
TextField {
id: deviceDescription
placeholderText: qsTr("Virtual camera name")
selectByMouse: true
Layout.fillWidth: true
visible: videoLayer.canEditVCamDescription && text.length > 0
}
Label {
id: lblDeviceDescription
text: deviceDescription.text
font.bold: true
visible: !videoLayer.canEditVCamDescription
&& text.length > 0
&& deviceId.text.length
}
Label {
id: deviceId
font.italic: true
visible: text.length > 0
}
Button {
text: qsTr("Add format")
icon.source: "image://icons/add"
flat: true
onClicked: {
let caps = AkVideoCaps.create()
addEdit.openOutputFormatDialog(-1, caps)
}
}
Button {
text: qsTr("Clear formats")
icon.source: "image://icons/no"
flat: true
onClicked: vcamFormats.clear()
}
OptionList {
id: vcamFormats
enableHighlight: false
Layout.fillWidth: true
Layout.minimumHeight: minHeight
property int minHeight: 0
function clear() {
minHeight = 0
for (let i = count - 1; i >= 0; i--)
removeItem(itemAt(i))
}
onActiveFocusChanged:
if (activeFocus && count > 0)
itemAt(currentIndex).forceActiveFocus()
Keys.onUpPressed:
if (count > 0)
itemAt(currentIndex).forceActiveFocus()
Keys.onDownPressed:
if (count > 0)
itemAt(currentIndex).forceActiveFocus()
}
}
}
onAccepted: {
if (videoLayer.clientsPids.length > 0) {
let title = deviceId.text?
qsTr("Can't edit the virtual camera"):
qsTr("Can't add the virtual camera")
let message = Commons.vcamDriverBusyMessage()
addEdit.openErrorDialog(title, message)
return
}
if (vcamFormats.count < 1 || !deviceDescription.text) {
let title = deviceId.text?
qsTr("Error editing the virtual camera"):
qsTr("Error adding the virtual camera")
let message = qsTr("Camera description and formats can't be empty.")
addEdit.openErrorDialog(title, message)
return
}
let formats = []
for (let i = 0; i < vcamFormats.count; i++) {
let element = vcamFormats.itemAt(i)
let caps = AkVideoCaps.create(element.format,
element.formatWidth,
element.formatHeight,
AkFrac.create(element.fps,
1).toVariant())
formats.push(caps.toVariant())
}
if (deviceId.text) {
let ok = videoLayer.editOutput(deviceId.text,
deviceDescription.text,
formats)
addEdit.edited()
if (!ok) {
let title = qsTr("Error editing the virtual camera")
addEdit.openErrorDialog(title, videoLayer.outputError)
}
} else {
let videoOutput =
videoLayer.createOutput(VideoLayer.OutputVirtualCamera,
deviceDescription.text,
formats)
if (videoOutput) {
videoLayer.videoOutput = videoOutput
} else if (videoLayer.outputError) {
let title = qsTr("Error creating the virtual camera")
addEdit.openErrorDialog(title, videoLayer.outputError)
}
}
}
}