Skip to content

Commit e6ac4a5

Browse files
committed
use libcamera
1 parent 4839f9b commit e6ac4a5

4 files changed

Lines changed: 37 additions & 2 deletions

File tree

qml/SettingsMenu.qml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import QtQuick.Dialogs
55
import Qt.labs.platform
66
import QtQml
77
import GPhotoCamera
8+
import Libcamera
89
import "content"
910

1011
SettingsMenuForm {
@@ -32,13 +33,23 @@ SettingsMenuForm {
3233
{
3334
listModel.push(gphotoCameras[i])
3435
}
36+
var libcameras = libcamera.availableCameras();
37+
console.log("Libcamera Camera Count: " + Number(libcameras.length).toString())
38+
for(i = 0; i < libcameras.length; i++)
39+
{
40+
listModel.push(libcameras[i])
41+
}
3542
return listModel;
3643
}
3744

3845
GPhotoCamera {
3946
id: gphotoCamera
4047
}
4148

49+
Libcamera {
50+
id: libcamera
51+
}
52+
4253
MediaDevices
4354
{
4455
id: mediaDevices

qml/content/CameraSource.qml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import GPhotoCamera
2+
import Libcamera
23
import QtQuick
34
import QtMultimedia
45
import QtQuick.Controls
@@ -115,6 +116,20 @@ Item
115116
}
116117
}
117118

119+
Libcamera {
120+
id: libcamera
121+
122+
onErrorOccurred: function(errorString) {
123+
if(state === "Libcamera")
124+
{
125+
cameraSource.errorOccurred(errorString)
126+
}
127+
}
128+
onImageCaptured: function(image) {
129+
cameraSource.imageCaptured(image)
130+
}
131+
}
132+
118133
Camera {
119134
id: systemCamera
120135
cameraDevice: mediaDevices.defaultVideoInput
@@ -218,6 +233,13 @@ Item
218233
videoFrameInput: gphotoCamera
219234
}
220235
},
236+
State {
237+
name: "Libcamera"
238+
PropertyChanges {
239+
target: cameraSession
240+
videoFrameInput: libcamera
241+
}
242+
}
221243
State {
222244
name: "Error"
223245
PropertyChanges {

src/libcameracamera.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class LibcameraDevice : public QObject
2424
explicit LibcameraDevice(QObject *parent = nullptr);
2525
~LibcameraDevice() override;
2626

27-
QStringList availableCameras() const;
28-
QString getDefaultCamera() const;
27+
Q_INVOKABLE QStringList availableCameras() const;
28+
Q_INVOKABLE QString getDefaultCamera() const;
2929

3030
public slots:
3131
void startCamera(const QString &cameraId);

src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QQmlContext>
88
#include <QTranslator>
99
#include "gphotocamera.h"
10+
#include "libcameracamera.h"
1011
#include "translationhelper.h"
1112
#include "captureprocessor.h"
1213
#include "fakeprinter.h"
@@ -128,6 +129,7 @@ int main(int argc, char *argv[])
128129

129130
qmlRegisterType<CaptureProcessor>("CaptureProcessor", 1, 0, "CaptureProcessor");
130131
qmlRegisterType<GPhotoCameraDevice>("GPhotoCamera", 1, 0, "GPhotoCamera");
132+
qmlRegisterType<LibcameraDevice>("Libcamera", 1, 0, "Libcamera");
131133

132134
qmlRegisterInterface<AbstractPrinter>("AbstractPrinter", 1);
133135
qmlRegisterUncreatableType<AbstractPrinter>("Printer", 1, 0, "Printer", "Printer can only be created via PrinterFactory");

0 commit comments

Comments
 (0)