Newer
Older
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
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.15
import QtQuick.Window 2.14
import QtQuick.Controls 2.15
import QtQuick.Controls.Universal 2.12
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.14
import QtQuick.Controls.Styles 1.4
import net.jami.Models 1.0
import net.jami.Adapters 1.0
import net.jami.Enums 1.0
import Qt.labs.platform 1.1
import "../../commoncomponents"
ColumnLayout {
id: root
property real aspectRatio: 0.75
property bool previewAvailable: false
property int itemWidth
Connections {
target: RenderManager
enabled: root.visible
function onVideoDeviceListChanged() {
populateVideoSettings()
}
}
function populateVideoSettings() {
deviceComboBoxSetting.comboModel.reset()
var count = deviceComboBoxSetting.comboModel.deviceCount() > 0
deviceComboBoxSetting.setEnabled(count)
resolutionComboBoxSetting.setEnabled(count)
fpsComboBoxSetting.setEnabled(count)
deviceComboBoxSetting.setCurrentIndex(deviceComboBoxSetting.comboModel.getCurrentSettingIndex())
slotDeviceBoxCurrentIndexChanged(deviceComboBoxSetting.modelIndex)
hardwareAccelControl.checked = AVModel.getHardwareAcceleration()
try {
startPreviewing(false)
} catch (err2){ console.log("Start preview fail when populate video settings, exception: "+ err2.message) }
}
function slotDeviceBoxCurrentIndexChanged(index) {
if(deviceComboBoxSetting.comboModel.deviceCount() <= 0)
return
try {
var deviceId = deviceComboBoxSetting.comboModel.data(deviceComboBoxSetting.comboModel.index(index, 0), VideoInputDeviceModel.DeviceId)
var deviceName = deviceComboBoxSetting.comboModel.data(deviceComboBoxSetting.comboModel.index(index, 0), VideoInputDeviceModel.DeviceName)
if(deviceId.length === 0) {
console.warn("Couldn't find device: " + deviceName)
return
}
AVModel.setCurrentVideoCaptureDevice(deviceId)
AVModel.setDefaultDevice(deviceId)
setFormatListForCurrentDevice()
startPreviewing(true)
} catch(err){ console.warn(err.message) }
}
function startPreviewing(force = false, async = true) {
AccountAdapter.startPreviewing(force, async)
previewAvailable = true
}
function setFormatListForCurrentDevice() {
var device = AVModel.getCurrentVideoCaptureDevice()
if (SettingsAdapter.get_DeviceCapabilitiesSize(device) === 0)
return
try {
resolutionComboBoxSetting.comboModel.reset()
resolutionComboBoxSetting.setCurrentIndex(resolutionComboBoxSetting.comboModel.getCurrentSettingIndex())
slotFormatCurrentIndexChanged(resolutionComboBoxSetting.modelIndex, true)
} catch(err){ console.warn("Exception: " + err.message) }
}
function stopPreviewing(async = true) {
AccountAdapter.stopPreviewing(async)
}
function slotFormatCurrentIndexChanged(index, isResolutionIndex) {
var resolution
var rate
if(isResolutionIndex) {
resolution = resolutionComboBoxSetting.comboModel.data(resolutionComboBoxSetting.comboModel.index(index, 0), VideoFormatResolutionModel.Resolution)
fpsComboBoxSetting.comboModel.currentResolution = resolution
fpsComboBoxSetting.setCurrentIndex(fpsComboBoxSetting.comboModel.getCurrentSettingIndex())
rate = fpsComboBoxSetting.comboModel.data(fpsComboBoxSetting.comboModel.index(index, 0), VideoFormatFpsModel.FPS)
} else {
resolution = resolutionComboBoxSetting.comboModel.data(resolutionComboBoxSetting.comboModel.index(index, 0), VideoFormatResolutionModel.Resolution)
fpsComboBoxSetting.comboModel.currentResolution = resolution
rate = fpsComboBoxSetting.comboModel.data(fpsComboBoxSetting.comboModel.model.index(index, 0), VideoFormatFpsModel.FPS)
}
try {
SettingsAdapter.set_Video_Settings_Rate_And_Resolution(AVModel.getCurrentVideoCaptureDevice(),rate,resolution)
updatePreviewRatio(resolution)
} catch(error){ console.warn(error.message) }
}
function updatePreviewRatio(resolution) {
var res = resolution.split("x")
var ratio = res[1] / res[0]
if (ratio) {
aspectRatio = ratio
} else {
console.error("Could not scale recording video preview")
}
}
ElidedTextLabel {
Layout.fillWidth: true
Layout.preferredHeight: JamiTheme.preferredFieldHeight
fontSize: JamiTheme.headerFontSize
maxWidth: itemWidth * 2
}
SettingsComboBox {
id: deviceComboBoxSetting
Layout.fillWidth: true
Layout.maximumHeight: JamiTheme.preferredFieldHeight
Layout.leftMargin: JamiTheme.preferredMarginSize
fontPointSize: JamiTheme.settingsFontSize
comboModel: VideoInputDeviceModel {}
widthOfComboBox: itemWidth
role: "DeviceName_UTF8"
onIndexChanged: {
slotDeviceBoxCurrentIndexChanged(modelIndex)
}
}
SettingsComboBox {
id: resolutionComboBoxSetting
Layout.fillWidth: true
Layout.maximumHeight: JamiTheme.preferredFieldHeight
Layout.leftMargin: JamiTheme.preferredMarginSize
fontPointSize: JamiTheme.settingsFontSize
comboModel: VideoFormatResolutionModel {}
widthOfComboBox: itemWidth
tipText: JamiStrings.selectVideoResolution
role: "Resolution_UTF8"
onIndexChanged: {
slotFormatCurrentIndexChanged(modelIndex, true)
}
}
SettingsComboBox {
id: fpsComboBoxSetting
Layout.fillWidth: true
Layout.maximumHeight: JamiTheme.preferredFieldHeight
Layout.leftMargin: JamiTheme.preferredMarginSize
fontPointSize: JamiTheme.settingsFontSize
comboModel: VideoFormatFpsModel {}
widthOfComboBox: itemWidth
role: "FPS_ToDisplay_UTF8"
onIndexChanged: {
slotFormatCurrentIndexChanged(modelIndex, false)
}
}
// Toggle switch to enable hardware acceleration
ToggleSwitch {
id: hardwareAccelControl
Layout.fillWidth: true
Layout.leftMargin: JamiTheme.preferredMarginSize
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
fontPointSize: JamiTheme.settingsFontSize
onSwitchToggled: {
AVModel.setHardwareAcceleration(checked)
videoSettings.startPreviewing(true)
}
}
// video Preview
Rectangle {
id: rectBox
Layout.alignment: Qt.AlignHCenter
Layout.maximumHeight: width * aspectRatio
Layout.minimumHeight: width * aspectRatio
Layout.preferredHeight: width * aspectRatio
Layout.minimumWidth: 200
Layout.maximumWidth: 400
Layout.preferredWidth: itemWidth * 2
Layout.bottomMargin: JamiTheme.preferredMarginSize
color: "white"
radius: 5
PreviewRenderer {
id: previewWidget
anchors.fill: rectBox
anchors.centerIn: rectBox
layer.enabled: true
layer.effect: OpacityMask {
maskSource: rectBox
}
}
}
Label {
visible: !previewAvailable
Layout.fillWidth: true
Layout.preferredHeight: JamiTheme.preferredFieldHeight
Layout.bottomMargin: JamiTheme.preferredMarginSize
font.pointSize: JamiTheme.settingsFontSize
font.kerning: true
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}