Skip to content

Commit be2f353

Browse files
committed
libcameradevice is a videoframeinput
1 parent 1abdde6 commit be2f353

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

qml/Application.qml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ ApplicationWindow {
7272

7373
Libcamera {
7474
id: libcamera
75-
76-
onErrorOccurred: function(errorString) {
77-
if(state === "Libcamera")
78-
{
79-
cameraSource.errorOccurred(errorString)
80-
}
81-
}
82-
onImageCaptured: function(image) {
83-
cameraSource.imageCaptured(image)
84-
}
8575
}
8676

8777
ApplicationFlow

qml/content/CameraSource.qml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Item
4040
var libcameras = libcamera.availableCameras()
4141
for (var j = 0; j < libcameras.length; j++) {
4242
if (libcameras[j] === cameraName) {
43-
libcamera.cameraName = cameraName
4443
cameraSource.state = "Libcamera"
4544
console.log("CameraSource using Libcamera camera device: " + cameraName)
4645
return
@@ -61,6 +60,10 @@ Item
6160
{
6261
//gphotoCamera.startCamera()
6362
}
63+
else if(state === "Libcamera")
64+
{
65+
libcamera.startCamera(cameraName)
66+
}
6467
else
6568
{
6669
console.log("No camera available to start!")
@@ -77,6 +80,10 @@ Item
7780
{
7881
//gphotoCamera.stopCamera()
7982
}
83+
else if(state === "Libcamera")
84+
{
85+
libcamera.stopCamera()
86+
}
8087
else
8188
{
8289
console.log("No camera available to stop!")
@@ -105,6 +112,24 @@ Item
105112
id: mediaDevices
106113
}
107114

115+
Connections {
116+
target: libcamera
117+
function errorOccured(errorString) {
118+
if(state === "Libcamera")
119+
{
120+
cameraSource.errorOccurred(errorString)
121+
}
122+
}
123+
}
124+
125+
Connections
126+
{
127+
target: libcamera
128+
function imageCaptured(image) {
129+
cameraSource.imageCaptured(image)
130+
}
131+
}
132+
108133
GPhotoCamera {
109134
id: gphotoCamera
110135

src/libcameracamera.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using namespace libcamera;
1212

1313
LibcameraDevice::LibcameraDevice(QObject *parent)
14-
: QObject(parent),
14+
: QVideoFrameInput(parent),
1515
mWorkerThread(std::make_unique<QThread>(this))
1616
{
1717
// Create worker
@@ -158,6 +158,8 @@ void LibCameraWorker::startCamera(const QString &cameraId)
158158
}
159159
mCamera = cam;
160160

161+
mCamera->acquire();
162+
161163
// configure camera for viewfinder role (basic example)
162164
std::unique_ptr<CameraConfiguration> config =
163165
mCamera->generateConfiguration({ StreamRole::Viewfinder });

src/libcameracamera.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QTimer>
55
#include <QStringList>
66
#include <memory>
7+
#include <QVideoFrameInput>
78

89
#undef emit
910
#undef slots
@@ -17,7 +18,7 @@
1718

1819
class LibCameraWorker;
1920

20-
class LibcameraDevice : public QObject
21+
class LibcameraDevice : public QVideoFrameInput
2122
{
2223
Q_OBJECT
2324
public:

0 commit comments

Comments
 (0)