-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathVideoOverlay.qml
334 lines (284 loc) · 10.6 KB
/
VideoOverlay.qml
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
330
331
332
333
334
// -*- qml -*-
/*!
* This file is part of CameraPlus.
*
* Copyright (C) 2012-2014 Mohammed Sameer <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
import QtQuick 2.0
import QtCamera 1.0
import CameraPlus 1.0
BaseOverlay {
id: overlay
property bool recording: false
policyMode: recording == true ? CameraResources.Recording : CameraResources.Video
pressed: overlay.recording || pageBeingManipulated
inhibitDim: recording
captureButtonIconSource: overlay.recording ? cameraTheme.captureButtonStopRecordingIconId : cameraTheme.captureButtonVideoIconId
overlayCapturing: recording
zoomSliderVisible: true
canCapture: true
VideoMode {
id: videoMode
camera: cam
enablePreview: settings.enablePreview
onPreviewAvailable: overlay.previewAvailable(preview)
}
CaptureButton {
reversed: !settings.leftHandedMode
iconSource: cameraTheme.videoPauseIconId
visible: controlsVisible && overlay.recording
onClicked: videoMode.pauseRecording(!videoMode.paused)
PropertyAnimation on opacity {
easing.type: Easing.OutSine
loops: Animation.Infinite
from: 0.1
to: 0.5
duration: 1000
running: videoMode.paused
alwaysRunToEnd: true
}
}
CameraToolBarLabel {
id: selectedLabel
anchors.bottom: toolBar.top
anchors.bottomMargin: 20
}
CameraToolBar {
id: toolBar
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
anchors.left: parent.left
anchors.leftMargin: 20
opacity: 0.5
targetWidth: parent.width - (anchors.leftMargin * 2)
visible: controlsVisible
expanded: settings.showToolBar
onExpandedChanged: settings.showToolBar = expanded;
tools: CameraToolBarTools {
CameraToolIcon {
visible: deviceFeatures().isVideoTorchSupported
iconSource: deviceSettings().videoTorchOn ? cameraTheme.cameraTorchOnIconId : cameraTheme.cameraTorchOffIconId
onClicked: deviceSettings().videoTorchOn = !deviceSettings().videoTorchOn
}
CameraToolIcon {
visible: deviceFeatures().numberOfVideoSceneModes > 1 && !overlay.recording
iconSource: cameraTheme.videoSceneModeIcon(deviceSettings().videoSceneMode)
onClicked: toolBar.push(Qt.resolvedUrl("VideoSceneButton.qml"), {"selectedLabel": selectedLabel})
}
CameraToolIcon {
iconSource: deviceSettings().videoEvComp == 0 ? cameraTheme.cameraManualExposureIconId : ""
onClicked: toolBar.push(Qt.resolvedUrl("VideoEvCompButton.qml"))
CameraLabel {
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
visible: deviceSettings().videoEvComp != 0
text: deviceSettings().videoEvComp == 0 ? "" : deviceSettings().videoEvComp.toFixed(1)
}
}
CameraToolIcon {
iconSource: cameraTheme.whiteBalanceIcon(deviceSettings().videoWhiteBalance)
onClicked: toolBar.push(Qt.resolvedUrl("VideoWhiteBalanceButton.qml"), {"selectedLabel": selectedLabel})
visible: deviceFeatures().numberOfVideoWhiteBalanceModes > 1
}
CameraToolIcon {
iconSource: cameraTheme.colorFilterIcon(deviceSettings().videoColorFilter)
onClicked: toolBar.push(Qt.resolvedUrl("VideoColorFilterButton.qml"), {"selectedLabel": selectedLabel})
visible: deviceFeatures().numberOfVideoColorTones > 1
}
CameraToolIcon {
iconSource: deviceSettings().videoMuted ? cameraTheme.soundMuteOnIconId : cameraTheme.soundMuteOffIconId
onClicked: deviceSettings().videoMuted = !deviceSettings().videoMuted
}
RecordingDurationLabel {
visible: overlay.recording
duration: recordingDuration.duration
}
DeviceSelector {
visible: !overlay.recording
&& activePlugin.primaryCameraSupported
&& activePlugin.secondaryCameraSupported
}
}
}
Row {
anchors {
top: parent.top
topMargin: 20
left: settings.leftHandedMode ? undefined: parent.left
leftMargin: 20
right: settings.leftHandedMode ? parent.right : undefined
rightMargin: 20
}
height: 32
spacing: 5
visible: controlsVisible
CameraLabel {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
text: videoMode.currentResolution.commonName
font.bold: true
height: parent.height
}
Image {
id: gpsIndicator
height: parent.height
width: height
asynchronous: true
visible: settings.useGps
source: cameraTheme.gpsIndicatorIcon
PropertyAnimation on opacity {
easing.type: Easing.OutSine
loops: Animation.Infinite
from: 0.2
to: 1.0
duration: 1000
running: settings.useGps && !positionSource.position.horizontalAccuracyValid && viewfinder.camera.running
alwaysRunToEnd: true
}
}
}
Connections {
target: rootWindow
onActiveChanged: {
if (!rootWindow.active && overlay.recording) {
overlay.stopRecording()
}
}
}
Connections {
target: batteryMonitor
onGoodChanged: {
if (!batteryMonitor.good) {
overlay.batteryLow()
}
}
}
Timer {
id: recordingDuration
property int duration: 0
running: overlay.recording && !videoMode.paused
interval: 1000
repeat: true
onTriggered: {
duration = duration + 1
if (platformSettings.maximumVideoDuration != -1 &&
duration >= platformSettings.maximumVideoDuration) {
overlay.stopRecording()
showError(qsTr("Maximum recording time reached."))
} else if (!fileSystem.hasFreeSpace(platformSettings.temporaryVideoPath)) {
page.stopRecording()
showError(qsTr("Not enough space to continue recording."))
}
}
}
function resetToolBar() {
if (toolBar.depth() > 1) {
toolBar.pop()
}
}
function doStartRecording() {
if (!overlay.recording) {
return
}
if (!pipelineManager.acquired || pipelineManager.hijacked) {
showError(qsTr("Failed to acquire needed resources."))
overlay.recording = false
return
}
metaData.setMetaData()
if (!mountProtector.lock(platformSettings.temporaryVideoPath)) {
showError(qsTr("Failed to lock temporary videos directory."))
overlay.recording = false
return
}
if (!mountProtector.lock(platformSettings.videoPath)) {
showError(qsTr("Failed to lock videos directory."))
overlay.recording = false
mountProtector.unlockAll()
return
}
var file = fileNaming.videoFileName()
var tmpFile = fileNaming.temporaryVideoFileName()
if (!videoMode.startRecording(file, tmpFile)) {
showError(qsTr("Failed to record video. Please restart the camera."))
mountProtector.unlockAll()
overlay.recording = false
return
}
trackerStore.storeVideo(file);
resetToolBar()
}
function startRecording() {
if (!fileSystem.available) {
showError(qsTr("Camera cannot record videos in mass storage mode."))
} else if (!batteryMonitor.good) {
showError(qsTr("Not enough battery to record video."))
} else if (!fileSystem.hasFreeSpace(platformSettings.videoPath) || !fileSystem.hasFreeSpace(platformSettings.temporaryVideoPath)) {
showError(qsTr("Not enough space to record video."))
} else {
recordingDuration.duration = 0
overlay.recording = true
doStartRecording()
}
}
function stopRecording() {
videoMode.stopRecording(true)
mountProtector.unlockAll()
overlay.recording = false
}
function startCapture() {
if (overlay.recording) {
overlay.stopRecording()
} else {
overlay.startRecording()
}
}
function stopCapture() {
// This is a callback needed by CaptureControln when user cancels
// an attempt to capture. It's relevant only for images
}
function cameraError() {
overlay.stopRecording()
}
function policyLost() {
overlay.stopRecording()
}
function batteryLow() {
if (!overlay.recording) {
return
}
if (!batteryMonitor.good) {
overlay.stopRecording()
showError(qsTr("Not enough battery to record video."))
}
}
function cameraDeviceChanged() {
resetToolBar()
}
function applySettings() {
var s = deviceSettings()
camera.scene.value = s.videoSceneMode
camera.evComp.value = s.videoEvComp
camera.whiteBalance.value = s.videoWhiteBalance
camera.colorTone.value = s.videoColorFilter
camera.videoMute.enabled = s.videoMuted
camera.videoTorch.on = s.videoTorchOn
camera.focus.value = Focus.ContinuousNormal
videoSettings.setVideoResolution()
}
}