summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/camera/icamera.h40
-rw-r--r--src/camera/innomakerov9281.cpp49
-rw-r--r--src/camera/innomakerov9281.h25
-rw-r--r--src/camera/ov9281.cpp1
-rw-r--r--src/camera/ov9281.h15
5 files changed, 116 insertions, 14 deletions
diff --git a/src/camera/icamera.h b/src/camera/icamera.h
new file mode 100644
index 0000000..4245a68
--- /dev/null
+++ b/src/camera/icamera.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#ifdef emit
+#define emit_backup emit
+#undef emit
+#endif
+
+#ifdef slots
+#define slots_backup slots
+#undef slots
+#endif
+
+#include <libcamera/base/signal.h>
+
+#ifdef emit_backup
+#define emit emit_backup
+#endif
+
+#ifdef slots_backup
+#define slots slots_backup
+#endif
+
+#include "image.h"
+
+// class ICamera
+// {
+// public:
+// virtual bool setExposureTimeMs(int value) = 0;
+// virtual bool setGain(int value) = 0;
+// };
+
+class ICamera
+{
+public:
+ libcamera::Signal<std::shared_ptr<Pixels>> newPixels;
+ libcamera::Signal<std::shared_ptr<Image>> newImage;
+
+public:
+ virtual bool startStream() = 0;
+};
diff --git a/src/camera/innomakerov9281.cpp b/src/camera/innomakerov9281.cpp
index 6d7aa4a..a2d3136 100644
--- a/src/camera/innomakerov9281.cpp
+++ b/src/camera/innomakerov9281.cpp
@@ -9,6 +9,8 @@
#include <sys/mman.h>
#include <unistd.h>
+#include <iostream>
+
#include "constants.h"
// #include "rotaryencoder.h"
@@ -25,12 +27,15 @@ extern uint64_t corr_elapsed_ns;
extern uint64_t max_elapsed_ns;
extern uint64_t value_elapsed_ns;
-constexpr char videoDevice[] = "/dev/video0";
+// constexpr char videoDevice[] = "/dev/video0";
InnoMakerOV9281::InnoMakerOV9281() {}
InnoMakerOV9281::~InnoMakerOV9281()
{
+ m_streamThread.request_stop();
+ m_streamThread.join();
+
int ret{-1};
for (int i = 0; i < BUFFER_COUNT; ++i) {
@@ -55,6 +60,48 @@ InnoMakerOV9281::~InnoMakerOV9281()
// std::cout << __func__ << ": success" << std::endl;
}
+std::vector<std::shared_ptr<ICamera> > InnoMakerOV9281::search()
+{
+ // return only one camera for now
+ std::cout << std::boolalpha;
+ auto cam = std::make_shared<InnoMakerOV9281>();
+
+ if (!cam->init())
+ return {};
+
+ if (!cam->setExposureTimeMs(3000))
+ return {};
+
+ if (!cam->setGain(3000))
+ return {};
+
+ return {cam};
+}
+
+bool InnoMakerOV9281::startStream()
+{
+ m_streamThread = std::jthread{[&](std::stop_token stopToken) {
+ std::cout << "InnoMakerOV9281: start stream" << std::endl;
+
+ while (!stopToken.stop_requested()) {
+ std::shared_ptr<Image> image = std::make_shared<Image>();
+ getImage(*image);
+// FIXME: backup emit value
+#ifdef emit
+#undef emit
+ std::cout << "emit new image" << std::endl << std::flush;
+ newImage.emit(image);
+ auto pixels = image->pixels();
+ newPixels.emit(pixels);
+ }
+#define emit
+#endif
+ std::cout << "InnoMakerOV9281: stream interruption requested" << std::endl;
+ }};
+
+ return true;
+}
+
bool InnoMakerOV9281::init()
{
if (!openCam())
diff --git a/src/camera/innomakerov9281.h b/src/camera/innomakerov9281.h
index 51485cb..2c1fb7c 100644
--- a/src/camera/innomakerov9281.h
+++ b/src/camera/innomakerov9281.h
@@ -2,18 +2,17 @@
#include <cstdint>
+#include <thread>
+
#include "constants.h"
#include "image.h"
-class ICamera
-{
-public:
- virtual bool setExposureTimeMs(int value) = 0;
- virtual bool setGain(int value) = 0;
-};
+#include "icamera.h"
class InnoMakerOV9281 : public ICamera
{
+ constexpr static char videoDevice[] = "/dev/video0";
+
public:
using buffer_t = std::array<uint8_t, img_size>;
@@ -22,13 +21,22 @@ public:
~InnoMakerOV9281();
public:
+ static std::vector<std::shared_ptr<ICamera>> search();
+
+public:
+ bool startStream();
+
bool init();
- bool setExposureTimeMs(int value) override;
- bool setGain(int value) override;
+ bool setExposureTimeMs(int value);
+ bool setGain(int value);
bool getImage(Image &image);
+public:
+ libcamera::Signal<std::shared_ptr<Pixels>> newPixels;
+ libcamera::Signal<std::shared_ptr<Image>> newImage;
+
private:
bool setCamParam(unsigned int v4l2controlId, int value);
bool openCam();
@@ -40,4 +48,5 @@ private:
static constexpr uint8_t BUFFER_COUNT{3};
uint8_t *video_buffer_ptr[BUFFER_COUNT];
// buffer_t m_buf;
+ std::jthread m_streamThread;
};
diff --git a/src/camera/ov9281.cpp b/src/camera/ov9281.cpp
index 48f445f..1a324e4 100644
--- a/src/camera/ov9281.cpp
+++ b/src/camera/ov9281.cpp
@@ -209,6 +209,7 @@ void OV9281::onRequestCompleted(libcamera::Request *completed_request)
img->rotate();
auto pixels = img->pixels();
+// FIXME: backup emit value
#ifdef emit
#undef emit
if (!pixels) {
diff --git a/src/camera/ov9281.h b/src/camera/ov9281.h
index 1f2011a..83a86ac 100644
--- a/src/camera/ov9281.h
+++ b/src/camera/ov9281.h
@@ -4,9 +4,12 @@
#include <memory>
#include <vector>
-#include <libcamera/base/signal.h>
#include <libcamera/formats.h>
+#include <QObject>
+
+#include "icamera.h"
+
namespace libcamera {
class Camera;
class CameraConfiguration;
@@ -18,8 +21,10 @@ class Request;
class Image;
class Pixels;
-class OV9281
+class OV9281 : public QObject, public ICamera
{
+ Q_OBJECT
+
public:
~OV9281();
@@ -29,15 +34,15 @@ public:
// public functions
public:
- bool startStream();
+ bool startStream() override;
void printControls();
// signals
public:
// TODO: image->pixels in separate thread
// TODO: respect sender/receiver threads
- libcamera::Signal<std::shared_ptr<Pixels>> newPixels;
- libcamera::Signal<std::shared_ptr<Image>> newImage;
+ // libcamera::Signal<std::shared_ptr<Pixels>> newPixels;
+ // libcamera::Signal<std::shared_ptr<Image>> newImage;
private:
explicit OV9281(const std::shared_ptr<libcamera::Camera> &camera);